Introduce semantic::Info
Will hold the mutable fields that currently reside in the otherwise immutable-AST. Change the AST string methods to accept a `const semantic::Info&`. This is required as some nodes include type-resolved information in their output strings. Bug: tint:390 Change-Id: Iba494a9c5645ce2096da0a8cfe63a4309a9d9c3c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39003 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
63049a420e
commit
dd1b6fca9f
3
BUILD.gn
3
BUILD.gn
|
@ -378,6 +378,8 @@ source_set("libtint_core_src") {
|
|||
"src/reader/reader.cc",
|
||||
"src/reader/reader.h",
|
||||
"src/scope_stack.h",
|
||||
"src/semantic/info.h",
|
||||
"src/semantic/sem_info.cc",
|
||||
"src/source.cc",
|
||||
"src/source.h",
|
||||
"src/symbol.cc",
|
||||
|
@ -778,7 +780,6 @@ source_set("tint_unittests_core_src") {
|
|||
"src/ast/decoration_test.cc",
|
||||
"src/ast/discard_statement_test.cc",
|
||||
"src/ast/else_statement_test.cc",
|
||||
"src/ast/expression_test.cc",
|
||||
"src/ast/fallthrough_statement_test.cc",
|
||||
"src/ast/float_literal_test.cc",
|
||||
"src/ast/function_test.cc",
|
||||
|
|
|
@ -192,6 +192,8 @@ set(TINT_LIB_SRCS
|
|||
reader/reader.cc
|
||||
reader/reader.h
|
||||
scope_stack.h
|
||||
semantic/info.h
|
||||
semantic/sem_info.cc
|
||||
source.cc
|
||||
source.h
|
||||
symbol.cc
|
||||
|
@ -408,7 +410,6 @@ if(${TINT_BUILD_TESTS})
|
|||
ast/decoration_test.cc
|
||||
ast/discard_statement_test.cc
|
||||
ast/else_statement_test.cc
|
||||
ast/expression_test.cc
|
||||
ast/fallthrough_statement_test.cc
|
||||
ast/float_literal_test.cc
|
||||
ast/function_test.cc
|
||||
|
|
|
@ -27,7 +27,9 @@ AccessDecoration::AccessDecoration(const Source& source, AccessControl val)
|
|||
|
||||
AccessDecoration::~AccessDecoration() = default;
|
||||
|
||||
void AccessDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
void AccessDecoration::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "AccessDecoration{" << value_ << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,12 @@ class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> {
|
|||
AccessControl value() const { return value_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST_F(AccessDecorationTest, Is) {
|
|||
TEST_F(AccessDecorationTest, ToStr) {
|
||||
auto* d = create<AccessDecoration>(ast::AccessControl::kReadOnly);
|
||||
std::ostringstream out;
|
||||
d->to_str(out, 0);
|
||||
d->to_str(Sem(), out, 0);
|
||||
EXPECT_EQ(out.str(), R"(AccessDecoration{read_only}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -47,11 +47,13 @@ bool ArrayAccessorExpression::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ArrayAccessorExpression::to_str(std::ostream& out, size_t indent) const {
|
||||
void ArrayAccessorExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "ArrayAccessor[" << result_type_str() << "]{" << std::endl;
|
||||
array_->to_str(out, indent + 2);
|
||||
idx_expr_->to_str(out, indent + 2);
|
||||
out << "ArrayAccessor[" << result_type_str(sem) << "]{" << std::endl;
|
||||
array_->to_str(sem, out, indent + 2);
|
||||
idx_expr_->to_str(sem, out, indent + 2);
|
||||
make_indent(out, indent);
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -57,9 +57,12 @@ class ArrayAccessorExpression
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
ArrayAccessorExpression(const ArrayAccessorExpression&) = delete;
|
||||
|
|
|
@ -93,7 +93,7 @@ TEST_F(ArrayAccessorExpressionTest, ToStr) {
|
|||
|
||||
auto* exp = create<ArrayAccessorExpression>(ary, idx);
|
||||
std::ostringstream out;
|
||||
exp->to_str(out, 2);
|
||||
exp->to_str(Sem(), out, 2);
|
||||
|
||||
EXPECT_EQ(demangle(out.str()), R"( ArrayAccessor[not set]{
|
||||
Identifier[not set]{ary}
|
||||
|
|
|
@ -45,11 +45,13 @@ bool AssignmentStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void AssignmentStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void AssignmentStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Assignment{" << std::endl;
|
||||
lhs_->to_str(out, indent + 2);
|
||||
rhs_->to_str(out, indent + 2);
|
||||
lhs_->to_str(sem, out, indent + 2);
|
||||
rhs_->to_str(sem, out, indent + 2);
|
||||
make_indent(out, indent);
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -54,9 +54,12 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
AssignmentStatement(const AssignmentStatement&) = delete;
|
||||
|
|
|
@ -93,7 +93,7 @@ TEST_F(AssignmentStatementTest, ToStr) {
|
|||
|
||||
auto* stmt = create<AssignmentStatement>(lhs, rhs);
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
|
||||
EXPECT_EQ(demangle(out.str()), R"( Assignment{
|
||||
Identifier[not set]{lhs}
|
||||
|
|
|
@ -47,15 +47,17 @@ bool BinaryExpression::IsValid() const {
|
|||
return op_ != BinaryOp::kNone;
|
||||
}
|
||||
|
||||
void BinaryExpression::to_str(std::ostream& out, size_t indent) const {
|
||||
void BinaryExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Binary[" << result_type_str() << "]{" << std::endl;
|
||||
lhs_->to_str(out, indent + 2);
|
||||
out << "Binary[" << result_type_str(sem) << "]{" << std::endl;
|
||||
lhs_->to_str(sem, out, indent + 2);
|
||||
|
||||
make_indent(out, indent + 2);
|
||||
out << op_ << std::endl;
|
||||
|
||||
rhs_->to_str(out, indent + 2);
|
||||
rhs_->to_str(sem, out, indent + 2);
|
||||
make_indent(out, indent);
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -120,9 +120,12 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
BinaryExpression(const BinaryExpression&) = delete;
|
||||
|
|
|
@ -106,7 +106,7 @@ TEST_F(BinaryExpressionTest, ToStr) {
|
|||
|
||||
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
|
||||
std::ostringstream out;
|
||||
r->to_str(out, 2);
|
||||
r->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Binary[not set]{
|
||||
Identifier[not set]{lhs}
|
||||
equal
|
||||
|
|
|
@ -27,7 +27,9 @@ BindingDecoration::BindingDecoration(const Source& source, uint32_t val)
|
|||
|
||||
BindingDecoration::~BindingDecoration() = default;
|
||||
|
||||
void BindingDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
void BindingDecoration::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "BindingDecoration{" << value_ << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,12 @@ class BindingDecoration
|
|||
uint32_t value() const { return value_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(BindingDecorationTest, Is) {
|
|||
TEST_F(BindingDecorationTest, ToStr) {
|
||||
auto* d = create<BindingDecoration>(2);
|
||||
std::ostringstream out;
|
||||
d->to_str(out, 0);
|
||||
d->to_str(Sem(), out, 0);
|
||||
EXPECT_EQ(out.str(), R"(BindingDecoration{2}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -41,11 +41,13 @@ bool BitcastExpression::IsValid() const {
|
|||
return type_ != nullptr;
|
||||
}
|
||||
|
||||
void BitcastExpression::to_str(std::ostream& out, size_t indent) const {
|
||||
void BitcastExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Bitcast[" << result_type_str() << "]<" << type_->type_name() << ">{"
|
||||
<< std::endl;
|
||||
expr_->to_str(out, indent + 2);
|
||||
out << "Bitcast[" << result_type_str(sem) << "]<" << type_->type_name()
|
||||
<< ">{" << std::endl;
|
||||
expr_->to_str(sem, out, indent + 2);
|
||||
make_indent(out, indent);
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -54,9 +54,12 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
BitcastExpression(const BitcastExpression&) = delete;
|
||||
|
|
|
@ -79,7 +79,7 @@ TEST_F(BitcastExpressionTest, ToStr) {
|
|||
|
||||
auto* exp = create<BitcastExpression>(ty.f32(), expr);
|
||||
std::ostringstream out;
|
||||
exp->to_str(out, 2);
|
||||
exp->to_str(Sem(), out, 2);
|
||||
|
||||
EXPECT_EQ(demangle(out.str()), R"( Bitcast[not set]<__f32>{
|
||||
Identifier[not set]{expr}
|
||||
|
|
|
@ -44,12 +44,14 @@ bool BlockStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void BlockStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void BlockStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Block{" << std::endl;
|
||||
|
||||
for (auto* stmt : *this) {
|
||||
stmt->to_str(out, indent + 2);
|
||||
stmt->to_str(sem, out, indent + 2);
|
||||
}
|
||||
|
||||
make_indent(out, indent);
|
||||
|
|
|
@ -76,9 +76,12 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
BlockStatement(const BlockStatement&) = delete;
|
||||
|
|
|
@ -87,7 +87,7 @@ TEST_F(BlockStatementTest, ToStr) {
|
|||
});
|
||||
|
||||
std::ostringstream out;
|
||||
b->to_str(out, 2);
|
||||
b->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Block{
|
||||
Discard{}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ BoolLiteral::BoolLiteral(const Source& source, type::Type* type, bool value)
|
|||
|
||||
BoolLiteral::~BoolLiteral() = default;
|
||||
|
||||
std::string BoolLiteral::to_str() const {
|
||||
std::string BoolLiteral::to_str(const semantic::Info&) const {
|
||||
return value_ ? "true" : "false";
|
||||
}
|
||||
|
||||
|
|
|
@ -40,8 +40,9 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
|
|||
/// @returns the name for this literal. This name is unique to this value.
|
||||
std::string name() const override;
|
||||
|
||||
/// @param sem the semantic info for the program
|
||||
/// @returns the literal as a string
|
||||
std::string to_str() const override;
|
||||
std::string to_str(const semantic::Info& sem) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -59,8 +59,8 @@ TEST_F(BoolLiteralTest, ToStr) {
|
|||
auto* t = create<BoolLiteral>(&bool_type, true);
|
||||
auto* f = create<BoolLiteral>(&bool_type, false);
|
||||
|
||||
EXPECT_EQ(t->to_str(), "true");
|
||||
EXPECT_EQ(f->to_str(), "false");
|
||||
EXPECT_EQ(t->to_str(Sem()), "true");
|
||||
EXPECT_EQ(f->to_str(Sem()), "false");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -36,7 +36,9 @@ bool BreakStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void BreakStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void BreakStatement::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Break{}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,12 @@ class BreakStatement : public Castable<BreakStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
BreakStatement(const BreakStatement&) = delete;
|
||||
|
|
|
@ -42,7 +42,7 @@ TEST_F(BreakStatementTest, IsValid) {
|
|||
TEST_F(BreakStatementTest, ToStr) {
|
||||
auto* stmt = create<BreakStatement>();
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Break{}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ BuiltinDecoration::BuiltinDecoration(const Source& source, Builtin builtin)
|
|||
|
||||
BuiltinDecoration::~BuiltinDecoration() = default;
|
||||
|
||||
void BuiltinDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
void BuiltinDecoration::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "BuiltinDecoration{" << builtin_ << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -35,9 +35,12 @@ class BuiltinDecoration
|
|||
Builtin value() const { return builtin_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(BuiltinDecorationTest, Is) {
|
|||
TEST_F(BuiltinDecorationTest, ToStr) {
|
||||
auto* d = create<BuiltinDecoration>(Builtin::kFragDepth);
|
||||
std::ostringstream out;
|
||||
d->to_str(out, 0);
|
||||
d->to_str(Sem(), out, 0);
|
||||
EXPECT_EQ(out.str(), R"(BuiltinDecoration{frag_depth}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -48,15 +48,17 @@ bool CallExpression::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void CallExpression::to_str(std::ostream& out, size_t indent) const {
|
||||
void CallExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Call[" << result_type_str() << "]{" << std::endl;
|
||||
func_->to_str(out, indent + 2);
|
||||
out << "Call[" << result_type_str(sem) << "]{" << std::endl;
|
||||
func_->to_str(sem, out, indent + 2);
|
||||
|
||||
make_indent(out, indent + 2);
|
||||
out << "(" << std::endl;
|
||||
for (auto* param : params_)
|
||||
param->to_str(out, indent + 4);
|
||||
param->to_str(sem, out, indent + 4);
|
||||
|
||||
make_indent(out, indent + 2);
|
||||
out << ")" << std::endl;
|
||||
|
|
|
@ -53,9 +53,12 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
CallExpression(const CallExpression&) = delete;
|
||||
|
|
|
@ -97,7 +97,7 @@ TEST_F(CallExpressionTest, ToStr_NoParams) {
|
|||
auto* func = Expr("func");
|
||||
auto* stmt = create<CallExpression>(func, ExpressionList{});
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
|
||||
Identifier[not set]{func}
|
||||
(
|
||||
|
@ -114,7 +114,7 @@ TEST_F(CallExpressionTest, ToStr_WithParams) {
|
|||
|
||||
auto* stmt = create<CallExpression>(func, params);
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
|
||||
Identifier[not set]{func}
|
||||
(
|
||||
|
|
|
@ -39,8 +39,10 @@ bool CallStatement::IsValid() const {
|
|||
return call_ != nullptr && call_->IsValid();
|
||||
}
|
||||
|
||||
void CallStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
call_->to_str(out, indent);
|
||||
void CallStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
call_->to_str(sem, out, indent);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
|
|
@ -50,9 +50,12 @@ class CallStatement : public Castable<CallStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
CallStatement(const CallStatement&) = delete;
|
||||
|
|
|
@ -58,7 +58,7 @@ TEST_F(CallStatementTest, ToStr) {
|
|||
create<CallExpression>(Expr("func"), ExpressionList{}));
|
||||
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
c->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
|
||||
Identifier[not set]{func}
|
||||
(
|
||||
|
|
|
@ -40,7 +40,9 @@ bool CaseStatement::IsValid() const {
|
|||
return body_ != nullptr && body_->IsValid();
|
||||
}
|
||||
|
||||
void CaseStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void CaseStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
|
||||
if (IsDefault()) {
|
||||
|
@ -53,14 +55,14 @@ void CaseStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
out << ", ";
|
||||
|
||||
first = false;
|
||||
out << selector->to_str();
|
||||
out << selector->to_str(sem);
|
||||
}
|
||||
out << "{" << std::endl;
|
||||
}
|
||||
|
||||
if (body_ != nullptr) {
|
||||
for (auto* stmt : *body_) {
|
||||
stmt->to_str(out, indent + 2);
|
||||
stmt->to_str(sem, out, indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,9 +66,12 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
CaseStatement(const CaseStatement&) = delete;
|
||||
|
|
|
@ -135,7 +135,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
|
|||
auto* c = create<CaseStatement>(CaseSelectorList{b}, body);
|
||||
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
c->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Case -2{
|
||||
Discard{}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
|
|||
auto* c = create<CaseStatement>(CaseSelectorList{b}, body);
|
||||
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
c->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Case 2{
|
||||
Discard{}
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
|
|||
auto* c = create<CaseStatement>(b, body);
|
||||
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
c->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Case 1, 2{
|
||||
Discard{}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
|
|||
auto* c = create<CaseStatement>(CaseSelectorList{}, body);
|
||||
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
c->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Default{
|
||||
Discard{}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ ConstantIdDecoration::ConstantIdDecoration(const Source& source, uint32_t val)
|
|||
|
||||
ConstantIdDecoration::~ConstantIdDecoration() = default;
|
||||
|
||||
void ConstantIdDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
void ConstantIdDecoration::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "ConstantIdDecoration{" << value_ << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -35,9 +35,12 @@ class ConstantIdDecoration
|
|||
uint32_t value() const { return value_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -39,7 +39,7 @@ TEST_F(ConstantIdDecorationTest, Is) {
|
|||
TEST_F(ConstantIdDecorationTest, ToStr) {
|
||||
auto* d = create<ConstantIdDecoration>(1200);
|
||||
std::ostringstream out;
|
||||
d->to_str(out, 0);
|
||||
d->to_str(Sem(), out, 0);
|
||||
EXPECT_EQ(out.str(), R"(ConstantIdDecoration{1200}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -36,7 +36,9 @@ bool ContinueStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ContinueStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void ContinueStatement::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Continue{}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -45,9 +45,12 @@ class ContinueStatement : public Castable<ContinueStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
ContinueStatement(const ContinueStatement&) = delete;
|
||||
|
|
|
@ -42,7 +42,7 @@ TEST_F(ContinueStatementTest, IsValid) {
|
|||
TEST_F(ContinueStatementTest, ToStr) {
|
||||
auto* stmt = create<ContinueStatement>();
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Continue{}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -36,7 +36,9 @@ bool DiscardStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void DiscardStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void DiscardStatement::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Discard{}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,12 @@ class DiscardStatement : public Castable<DiscardStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
DiscardStatement(const DiscardStatement&) = delete;
|
||||
|
|
|
@ -54,7 +54,7 @@ TEST_F(DiscardStatementTest, IsValid) {
|
|||
TEST_F(DiscardStatementTest, ToStr) {
|
||||
auto* stmt = create<DiscardStatement>();
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Discard{}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -43,14 +43,16 @@ bool ElseStatement::IsValid() const {
|
|||
return condition_ == nullptr || condition_->IsValid();
|
||||
}
|
||||
|
||||
void ElseStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void ElseStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Else{" << std::endl;
|
||||
if (condition_ != nullptr) {
|
||||
make_indent(out, indent + 2);
|
||||
out << "(" << std::endl;
|
||||
|
||||
condition_->to_str(out, indent + 4);
|
||||
condition_->to_str(sem, out, indent + 4);
|
||||
|
||||
make_indent(out, indent + 2);
|
||||
out << ")" << std::endl;
|
||||
|
@ -61,7 +63,7 @@ void ElseStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
|
||||
if (body_ != nullptr) {
|
||||
for (auto* stmt : *body_) {
|
||||
stmt->to_str(out, indent + 4);
|
||||
stmt->to_str(sem, out, indent + 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,9 +62,12 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
ElseStatement(const ElseStatement&) = delete;
|
||||
|
|
|
@ -115,7 +115,7 @@ TEST_F(ElseStatementTest, ToStr) {
|
|||
});
|
||||
auto* e = create<ElseStatement>(cond, body);
|
||||
std::ostringstream out;
|
||||
e->to_str(out, 2);
|
||||
e->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Else{
|
||||
(
|
||||
ScalarConstructor[not set]{true}
|
||||
|
@ -133,7 +133,7 @@ TEST_F(ElseStatementTest, ToStr_NoCondition) {
|
|||
});
|
||||
auto* e = create<ElseStatement>(nullptr, body);
|
||||
std::ostringstream out;
|
||||
e->to_str(out, 2);
|
||||
e->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Else{
|
||||
{
|
||||
Discard{}
|
||||
|
|
|
@ -38,7 +38,7 @@ class Expression : public Castable<Expression, Node> {
|
|||
|
||||
/// @returns a string representation of the result type or 'not set' if no
|
||||
/// result type present
|
||||
std::string result_type_str() const {
|
||||
std::string result_type_str(const semantic::Info&) const {
|
||||
return result_type_ ? result_type_->type_name() : "not set";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/expression.h"
|
||||
|
||||
#include "src/ast/test_helper.h"
|
||||
#include "src/type/alias_type.h"
|
||||
#include "src/type/i32_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
class FakeExpr : public Expression {
|
||||
public:
|
||||
FakeExpr() : Expression(Source{}) {}
|
||||
|
||||
FakeExpr* Clone(CloneContext*) const override { return nullptr; }
|
||||
bool IsValid() const override { return true; }
|
||||
void to_str(std::ostream&, size_t) const override {}
|
||||
};
|
||||
|
||||
using ExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(ExpressionTest, set_result_type) {
|
||||
FakeExpr e;
|
||||
e.set_result_type(ty.i32());
|
||||
ASSERT_NE(e.result_type(), nullptr);
|
||||
EXPECT_TRUE(e.result_type()->Is<type::I32>());
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, set_result_type_alias) {
|
||||
auto* a = ty.alias("a", ty.i32());
|
||||
auto* b = ty.alias("b", a);
|
||||
|
||||
FakeExpr e;
|
||||
e.set_result_type(b);
|
||||
ASSERT_NE(e.result_type(), nullptr);
|
||||
EXPECT_TRUE(e.result_type()->Is<type::I32>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
|
@ -37,7 +37,9 @@ bool FallthroughStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void FallthroughStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void FallthroughStatement::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Fallthrough{}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,12 @@ class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
FallthroughStatement(const FallthroughStatement&) = delete;
|
||||
|
|
|
@ -50,7 +50,7 @@ TEST_F(FallthroughStatementTest, IsValid) {
|
|||
TEST_F(FallthroughStatementTest, ToStr) {
|
||||
auto* stmt = create<FallthroughStatement>();
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Fallthrough{}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ FloatLiteral::FloatLiteral(const Source& source, type::Type* type, float value)
|
|||
|
||||
FloatLiteral::~FloatLiteral() = default;
|
||||
|
||||
std::string FloatLiteral::to_str() const {
|
||||
std::string FloatLiteral::to_str(const semantic::Info&) const {
|
||||
return std::to_string(value_);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,9 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
|
|||
/// @returns the name for this literal. This name is unique to this value.
|
||||
std::string name() const override;
|
||||
|
||||
/// @param sem the semantic info for the program
|
||||
/// @returns the literal as a string
|
||||
std::string to_str() const override;
|
||||
std::string to_str(const semantic::Info& sem) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -46,7 +46,7 @@ TEST_F(FloatLiteralTest, Is) {
|
|||
TEST_F(FloatLiteralTest, ToStr) {
|
||||
auto* f = create<FloatLiteral>(ty.f32(), 42.1f);
|
||||
|
||||
EXPECT_EQ(f->to_str(), "42.099998");
|
||||
EXPECT_EQ(f->to_str(Sem()), "42.099998");
|
||||
}
|
||||
|
||||
TEST_F(FloatLiteralTest, ToName) {
|
||||
|
|
|
@ -247,13 +247,15 @@ bool Function::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Function::to_str(std::ostream& out, size_t indent) const {
|
||||
void Function::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Function " << symbol_.to_str() << " -> " << return_type_->type_name()
|
||||
<< std::endl;
|
||||
|
||||
for (auto* deco : decorations()) {
|
||||
deco->to_str(out, indent);
|
||||
deco->to_str(sem, out, indent);
|
||||
}
|
||||
|
||||
make_indent(out, indent);
|
||||
|
@ -263,7 +265,7 @@ void Function::to_str(std::ostream& out, size_t indent) const {
|
|||
out << std::endl;
|
||||
|
||||
for (auto* param : params_)
|
||||
param->to_str(out, indent + 2);
|
||||
param->to_str(sem, out, indent + 2);
|
||||
|
||||
make_indent(out, indent);
|
||||
}
|
||||
|
@ -274,7 +276,7 @@ void Function::to_str(std::ostream& out, size_t indent) const {
|
|||
|
||||
if (body_ != nullptr) {
|
||||
for (auto* stmt : *body_) {
|
||||
stmt->to_str(out, indent + 2);
|
||||
stmt->to_str(sem, out, indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -184,9 +184,12 @@ class Function : public Castable<Function, Node> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// @returns the type name for this function
|
||||
std::string type_name() const;
|
||||
|
|
|
@ -245,7 +245,7 @@ TEST_F(FunctionTest, ToStr) {
|
|||
FunctionDecorationList{});
|
||||
|
||||
std::ostringstream out;
|
||||
f->to_str(out, 2);
|
||||
f->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Function func -> __void
|
||||
()
|
||||
{
|
||||
|
@ -262,7 +262,7 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
|
|||
FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6)});
|
||||
|
||||
std::ostringstream out;
|
||||
f->to_str(out, 2);
|
||||
f->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Function func -> __void
|
||||
WorkgroupDecoration{2 4 6}
|
||||
()
|
||||
|
@ -283,7 +283,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
|
|||
FunctionDecorationList{});
|
||||
|
||||
std::ostringstream out;
|
||||
f->to_str(out, 2);
|
||||
f->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Function func -> __void
|
||||
(
|
||||
Variable{
|
||||
|
|
|
@ -27,7 +27,9 @@ GroupDecoration::GroupDecoration(const Source& source, uint32_t val)
|
|||
|
||||
GroupDecoration::~GroupDecoration() = default;
|
||||
|
||||
void GroupDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
void GroupDecoration::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "GroupDecoration{" << value_ << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -35,9 +35,12 @@ class GroupDecoration : public Castable<GroupDecoration, VariableDecoration> {
|
|||
uint32_t value() const { return value_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(GroupDecorationTest, Is) {
|
|||
TEST_F(GroupDecorationTest, ToStr) {
|
||||
auto* d = create<GroupDecoration>(2);
|
||||
std::ostringstream out;
|
||||
d->to_str(out, 0);
|
||||
d->to_str(Sem(), out, 0);
|
||||
EXPECT_EQ(out.str(), R"(GroupDecoration{2}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -38,9 +38,11 @@ bool IdentifierExpression::IsValid() const {
|
|||
return sym_.IsValid();
|
||||
}
|
||||
|
||||
void IdentifierExpression::to_str(std::ostream& out, size_t indent) const {
|
||||
void IdentifierExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Identifier[" << result_type_str() << "]{" << sym_.to_str() << "}"
|
||||
out << "Identifier[" << result_type_str(sem) << "]{" << sym_.to_str() << "}"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,9 +76,12 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
IdentifierExpression(const IdentifierExpression&) = delete;
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST_F(IdentifierExpressionTest, IsValid) {
|
|||
TEST_F(IdentifierExpressionTest, ToStr) {
|
||||
auto* i = Expr("ident");
|
||||
std::ostringstream out;
|
||||
i->to_str(out, 2);
|
||||
i->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Identifier[not set]{ident}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -67,7 +67,9 @@ bool IfStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void IfStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void IfStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "If{" << std::endl;
|
||||
|
||||
|
@ -75,7 +77,7 @@ void IfStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
make_indent(out, indent + 2);
|
||||
out << "(" << std::endl;
|
||||
|
||||
condition_->to_str(out, indent + 4);
|
||||
condition_->to_str(sem, out, indent + 4);
|
||||
|
||||
// Close if conditional
|
||||
make_indent(out, indent + 2);
|
||||
|
@ -87,7 +89,7 @@ void IfStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
|
||||
if (body_ != nullptr) {
|
||||
for (auto* stmt : *body_) {
|
||||
stmt->to_str(out, indent + 4);
|
||||
stmt->to_str(sem, out, indent + 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +102,7 @@ void IfStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
out << "}" << std::endl;
|
||||
|
||||
for (auto* e : else_statements_) {
|
||||
e->to_str(out, indent);
|
||||
e->to_str(sem, out, indent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,9 +67,12 @@ class IfStatement : public Castable<IfStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
IfStatement(const IfStatement&) = delete;
|
||||
|
|
|
@ -168,7 +168,7 @@ TEST_F(IfStatementTest, ToStr) {
|
|||
auto* stmt = create<IfStatement>(cond, body, ElseStatementList{});
|
||||
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( If{
|
||||
(
|
||||
Identifier[not set]{cond}
|
||||
|
@ -196,7 +196,7 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
|
|||
});
|
||||
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( If{
|
||||
(
|
||||
Identifier[not set]{cond}
|
||||
|
|
|
@ -28,9 +28,11 @@ bool Literal::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Literal::to_str(std::ostream& out, size_t indent) const {
|
||||
void Literal::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << to_str();
|
||||
out << to_str(sem);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
|
|
@ -35,12 +35,16 @@ class Literal : public Castable<Literal, Node> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// @param sem the semantic info for the program
|
||||
/// @returns the literal as a string
|
||||
virtual std::string to_str() const = 0;
|
||||
virtual std::string to_str(const semantic::Info& sem) const = 0;
|
||||
|
||||
/// @returns the name for this literal. This name is unique to this value.
|
||||
virtual std::string name() const = 0;
|
||||
|
|
|
@ -27,7 +27,9 @@ LocationDecoration::LocationDecoration(const Source& source, uint32_t val)
|
|||
|
||||
LocationDecoration::~LocationDecoration() = default;
|
||||
|
||||
void LocationDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||
void LocationDecoration::to_str(const semantic::Info&,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "LocationDecoration{" << value_ << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,12 @@ class LocationDecoration
|
|||
uint32_t value() const { return value_; }
|
||||
|
||||
/// Outputs the decoration to the given stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -42,7 +42,7 @@ TEST_F(LocationDecorationTest, Is) {
|
|||
TEST_F(LocationDecorationTest, ToStr) {
|
||||
auto* d = create<LocationDecoration>(2);
|
||||
std::ostringstream out;
|
||||
d->to_str(out, 0);
|
||||
d->to_str(Sem(), out, 0);
|
||||
EXPECT_EQ(out.str(), R"(LocationDecoration{2}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -46,13 +46,15 @@ bool LoopStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void LoopStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void LoopStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Loop{" << std::endl;
|
||||
|
||||
if (body_ != nullptr) {
|
||||
for (auto* stmt : *body_) {
|
||||
stmt->to_str(out, indent + 2);
|
||||
stmt->to_str(sem, out, indent + 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +63,7 @@ void LoopStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
out << "continuing {" << std::endl;
|
||||
|
||||
for (auto* stmt : *continuing_) {
|
||||
stmt->to_str(out, indent + 4);
|
||||
stmt->to_str(sem, out, indent + 4);
|
||||
}
|
||||
|
||||
make_indent(out, indent + 2);
|
||||
|
|
|
@ -64,9 +64,12 @@ class LoopStatement : public Castable<LoopStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
LoopStatement(const LoopStatement&) = delete;
|
||||
|
|
|
@ -171,7 +171,7 @@ TEST_F(LoopStatementTest, ToStr) {
|
|||
|
||||
auto* l = create<LoopStatement>(body, nullptr);
|
||||
std::ostringstream out;
|
||||
l->to_str(out, 2);
|
||||
l->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Loop{
|
||||
Discard{}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) {
|
|||
|
||||
auto* l = create<LoopStatement>(body, continuing);
|
||||
std::ostringstream out;
|
||||
l->to_str(out, 2);
|
||||
l->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Loop{
|
||||
Discard{}
|
||||
continuing {
|
||||
|
|
|
@ -48,11 +48,13 @@ bool MemberAccessorExpression::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void MemberAccessorExpression::to_str(std::ostream& out, size_t indent) const {
|
||||
void MemberAccessorExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "MemberAccessor[" << result_type_str() << "]{" << std::endl;
|
||||
struct_->to_str(out, indent + 2);
|
||||
member_->to_str(out, indent + 2);
|
||||
out << "MemberAccessor[" << result_type_str(sem) << "]{" << std::endl;
|
||||
struct_->to_str(sem, out, indent + 2);
|
||||
member_->to_str(sem, out, indent + 2);
|
||||
make_indent(out, indent);
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
|
|
|
@ -57,9 +57,12 @@ class MemberAccessorExpression
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
MemberAccessorExpression(const MemberAccessorExpression&) = delete;
|
||||
|
|
|
@ -78,7 +78,7 @@ TEST_F(MemberAccessorExpressionTest, ToStr) {
|
|||
auto* stmt =
|
||||
create<MemberAccessorExpression>(Expr("structure"), Expr("member"));
|
||||
std::ostringstream out;
|
||||
stmt->to_str(out, 2);
|
||||
stmt->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( MemberAccessor[not set]{
|
||||
Identifier[not set]{structure}
|
||||
Identifier[not set]{member}
|
||||
|
|
|
@ -81,7 +81,9 @@ Module* Module::Clone(CloneContext* ctx) const {
|
|||
ctx->Clone(global_variables_));
|
||||
}
|
||||
|
||||
void Module::to_str(std::ostream& out, size_t indent) const {
|
||||
void Module::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Module{" << std::endl;
|
||||
indent += 2;
|
||||
|
@ -91,25 +93,25 @@ void Module::to_str(std::ostream& out, size_t indent) const {
|
|||
out << alias->symbol().to_str() << " -> " << alias->type()->type_name()
|
||||
<< std::endl;
|
||||
if (auto* str = alias->type()->As<type::Struct>()) {
|
||||
str->impl()->to_str(out, indent);
|
||||
str->impl()->to_str(sem, out, indent);
|
||||
}
|
||||
} else if (auto* str = ty->As<type::Struct>()) {
|
||||
out << str->symbol().to_str() << " ";
|
||||
str->impl()->to_str(out, indent);
|
||||
str->impl()->to_str(sem, out, indent);
|
||||
}
|
||||
}
|
||||
for (auto* var : global_variables_) {
|
||||
var->to_str(out, indent);
|
||||
var->to_str(sem, out, indent);
|
||||
}
|
||||
for (auto* func : functions_) {
|
||||
func->to_str(out, indent);
|
||||
func->to_str(sem, out, indent);
|
||||
}
|
||||
out << "}" << std::endl;
|
||||
}
|
||||
|
||||
std::string Module::to_str() const {
|
||||
std::string Module::to_str(const semantic::Info& sem) const {
|
||||
std::ostringstream out;
|
||||
to_str(out, 0);
|
||||
to_str(sem, out, 0);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -89,12 +89,16 @@ class Module : public Castable<Module, Node> {
|
|||
Module* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
/// @param sem the semantic info for the program
|
||||
/// @returns a string representation of the Builder
|
||||
std::string to_str() const;
|
||||
std::string to_str(const semantic::Info& sem) const;
|
||||
|
||||
private:
|
||||
std::vector<type::Type*> constructed_types_;
|
||||
|
|
|
@ -122,8 +122,8 @@ fn main() -> void {
|
|||
|
||||
// Expect the AST printed with to_str() to match
|
||||
Demangler demanger;
|
||||
EXPECT_EQ(demanger.Demangle(src.Symbols(), src.AST().to_str()),
|
||||
demanger.Demangle(dst.Symbols(), dst.AST().to_str()));
|
||||
EXPECT_EQ(demanger.Demangle(src.Symbols(), src.AST().to_str(src.Sem())),
|
||||
demanger.Demangle(dst.Symbols(), dst.AST().to_str(dst.Sem())));
|
||||
|
||||
// Check that none of the AST nodes or type pointers in dst are found in src
|
||||
std::unordered_set<ast::Node*> src_nodes;
|
||||
|
@ -135,7 +135,7 @@ fn main() -> void {
|
|||
src_types.emplace(src_type);
|
||||
}
|
||||
for (auto* dst_node : dst.Nodes().Objects()) {
|
||||
ASSERT_EQ(src_nodes.count(dst_node), 0u) << dst_node->str();
|
||||
ASSERT_EQ(src_nodes.count(dst_node), 0u) << dst_node->str(dst.Sem());
|
||||
}
|
||||
for (auto* dst_type : dst.Types()) {
|
||||
ASSERT_EQ(src_types.count(dst_type), 0u) << dst_type->type_name();
|
||||
|
|
|
@ -36,7 +36,7 @@ TEST_F(ModuleTest, Creation) {
|
|||
}
|
||||
|
||||
TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
|
||||
const auto str = Program(std::move(*this)).AST().to_str();
|
||||
const auto str = Program(std::move(*this)).to_str();
|
||||
auto* const expected = "Module{\n}\n";
|
||||
EXPECT_EQ(str, expected);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ void Node::make_indent(std::ostream& out, size_t indent) const {
|
|||
out << " ";
|
||||
}
|
||||
|
||||
std::string Node::str() const {
|
||||
std::string Node::str(const semantic::Info& sem) const {
|
||||
std::ostringstream out;
|
||||
to_str(out, 0);
|
||||
to_str(sem, out, 0);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ class CloneContext;
|
|||
namespace type {
|
||||
class Type;
|
||||
}
|
||||
namespace semantic {
|
||||
class Info;
|
||||
}
|
||||
|
||||
namespace ast {
|
||||
|
||||
|
@ -52,13 +55,17 @@ class Node : public Castable<Node> {
|
|||
virtual bool IsValid() const = 0;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
virtual void to_str(std::ostream& out, size_t indent) const = 0;
|
||||
virtual void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const = 0;
|
||||
|
||||
/// Convenience wrapper around the to_str() method.
|
||||
/// @param sem the semantic info for the program
|
||||
/// @returns the node as a string
|
||||
std::string str() const;
|
||||
std::string str(const semantic::Info& sem) const;
|
||||
|
||||
protected:
|
||||
/// Create a new node
|
||||
|
|
|
@ -27,7 +27,7 @@ NullLiteral::NullLiteral(const Source& source, type::Type* type)
|
|||
|
||||
NullLiteral::~NullLiteral() = default;
|
||||
|
||||
std::string NullLiteral::to_str() const {
|
||||
std::string NullLiteral::to_str(const semantic::Info&) const {
|
||||
return "null " + type()->type_name();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,9 @@ class NullLiteral : public Castable<NullLiteral, Literal> {
|
|||
/// @returns the name for this literal. This name is unique to this value.
|
||||
std::string name() const override;
|
||||
|
||||
/// @param sem the semantic info for the program
|
||||
/// @returns the literal as a string
|
||||
std::string to_str() const override;
|
||||
std::string to_str(const semantic::Info& sem) const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_F(NullLiteralTest, Is) {
|
|||
TEST_F(NullLiteralTest, ToStr) {
|
||||
auto* i = create<NullLiteral>(ty.i32());
|
||||
|
||||
EXPECT_EQ(i->to_str(), "null __i32");
|
||||
EXPECT_EQ(i->to_str(Sem()), "null __i32");
|
||||
}
|
||||
|
||||
TEST_F(NullLiteralTest, Name_I32) {
|
||||
|
|
|
@ -44,7 +44,9 @@ bool ReturnStatement::IsValid() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
void ReturnStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void ReturnStatement::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "Return{";
|
||||
|
||||
|
@ -54,7 +56,7 @@ void ReturnStatement::to_str(std::ostream& out, size_t indent) const {
|
|||
make_indent(out, indent + 2);
|
||||
out << "{" << std::endl;
|
||||
|
||||
value_->to_str(out, indent + 4);
|
||||
value_->to_str(sem, out, indent + 4);
|
||||
|
||||
make_indent(out, indent + 2);
|
||||
out << "}" << std::endl;
|
||||
|
|
|
@ -55,9 +55,12 @@ class ReturnStatement : public Castable<ReturnStatement, Statement> {
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
ReturnStatement(const ReturnStatement&) = delete;
|
||||
|
|
|
@ -76,7 +76,7 @@ TEST_F(ReturnStatementTest, ToStr_WithValue) {
|
|||
auto* expr = Expr("expr");
|
||||
auto* r = create<ReturnStatement>(expr);
|
||||
std::ostringstream out;
|
||||
r->to_str(out, 2);
|
||||
r->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(demangle(out.str()), R"( Return{
|
||||
{
|
||||
Identifier[not set]{expr}
|
||||
|
@ -88,7 +88,7 @@ TEST_F(ReturnStatementTest, ToStr_WithValue) {
|
|||
TEST_F(ReturnStatementTest, ToStr_WithoutValue) {
|
||||
auto* r = create<ReturnStatement>();
|
||||
std::ostringstream out;
|
||||
r->to_str(out, 2);
|
||||
r->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( Return{}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -41,11 +41,12 @@ bool ScalarConstructorExpression::IsValid() const {
|
|||
return literal_ != nullptr;
|
||||
}
|
||||
|
||||
void ScalarConstructorExpression::to_str(std::ostream& out,
|
||||
void ScalarConstructorExpression::to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "ScalarConstructor[" << result_type_str() << "]{" << literal_->to_str()
|
||||
<< "}" << std::endl;
|
||||
out << "ScalarConstructor[" << result_type_str(sem) << "]{"
|
||||
<< literal_->to_str(sem) << "}" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
|
|
@ -51,9 +51,12 @@ class ScalarConstructorExpression
|
|||
bool IsValid() const override;
|
||||
|
||||
/// Writes a representation of the node to the output stream
|
||||
/// @param sem the semantic info for the program
|
||||
/// @param out the stream to write to
|
||||
/// @param indent number of spaces to indent the node when writing
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
void to_str(const semantic::Info& sem,
|
||||
std::ostream& out,
|
||||
size_t indent) const override;
|
||||
|
||||
private:
|
||||
ScalarConstructorExpression(const ScalarConstructorExpression&) = delete;
|
||||
|
|
|
@ -50,7 +50,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
|
|||
TEST_F(ScalarConstructorExpressionTest, ToStr) {
|
||||
auto* c = Expr(true);
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
c->to_str(Sem(), out, 2);
|
||||
EXPECT_EQ(out.str(), R"( ScalarConstructor[not set]{true}
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ SintLiteral::SintLiteral(const Source& source, type::Type* type, int32_t value)
|
|||
|
||||
SintLiteral::~SintLiteral() = default;
|
||||
|
||||
std::string SintLiteral::to_str() const {
|
||||
std::string SintLiteral::to_str(const semantic::Info&) const {
|
||||
return std::to_string(value_);
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue