Rename VariableStatement to VariableDeclStatement.
This CL renames VariableStatement to VariableDeclStatement to make it clearer what it was modeling. Bug: tint:25 Change-Id: Idd0d27fad7cc402f286e1abad74092c9d1961d91 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18341 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
a322f5ddfa
commit
e49bd5eeb4
|
@ -179,8 +179,8 @@ set(TINT_LIB_SRCS
|
|||
ast/variable.h
|
||||
ast/variable_decoration.cc
|
||||
ast/variable_decoration.h
|
||||
ast/variable_statement.cc
|
||||
ast/variable_statement.h
|
||||
ast/variable_decl_statement.cc
|
||||
ast/variable_decl_statement.h
|
||||
context.h
|
||||
context.cc
|
||||
reader/reader.cc
|
||||
|
@ -302,7 +302,7 @@ set(TINT_TEST_SRCS
|
|||
ast/unary_method_expression_test.cc
|
||||
ast/unary_op_expression_test.cc
|
||||
ast/unless_statement_test.cc
|
||||
ast/variable_statement_test.cc
|
||||
ast/variable_decl_statement_test.cc
|
||||
ast/variable_test.cc
|
||||
type_manager_test.cc
|
||||
validator_impl_import_test.cc
|
||||
|
@ -458,7 +458,7 @@ if(${TINT_BUILD_WGSL_WRITER})
|
|||
writer/wgsl/generator_impl_unary_method_test.cc
|
||||
writer/wgsl/generator_impl_unary_op_test.cc
|
||||
writer/wgsl/generator_impl_unless_test.cc
|
||||
writer/wgsl/generator_impl_variable_statement_test.cc
|
||||
writer/wgsl/generator_impl_variable_decl_statement_test.cc
|
||||
writer/wgsl/generator_impl_variable_test.cc
|
||||
)
|
||||
endif()
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "src/ast/return_statement.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/unless_statement.h"
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
@ -111,9 +111,9 @@ UnlessStatement* Statement::AsUnless() {
|
|||
return static_cast<UnlessStatement*>(this);
|
||||
}
|
||||
|
||||
VariableStatement* Statement::AsVariable() {
|
||||
assert(IsVariable());
|
||||
return static_cast<VariableStatement*>(this);
|
||||
VariableDeclStatement* Statement::AsVariableDecl() {
|
||||
assert(IsVariableDecl());
|
||||
return static_cast<VariableDeclStatement*>(this);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
|
|
|
@ -34,7 +34,7 @@ class RegardlessStatement;
|
|||
class ReturnStatement;
|
||||
class SwitchStatement;
|
||||
class UnlessStatement;
|
||||
class VariableStatement;
|
||||
class VariableDeclStatement;
|
||||
|
||||
/// Base statement class
|
||||
class Statement : public Node {
|
||||
|
@ -70,7 +70,7 @@ class Statement : public Node {
|
|||
/// @returns true if this is an unless statement
|
||||
virtual bool IsUnless() const { return false; }
|
||||
/// @returns true if this is an variable statement
|
||||
virtual bool IsVariable() const { return false; }
|
||||
virtual bool IsVariableDecl() const { return false; }
|
||||
|
||||
/// @returns the statement as an assign statement
|
||||
AssignmentStatement* AsAssign();
|
||||
|
@ -101,7 +101,7 @@ class Statement : public Node {
|
|||
/// @returns the statement as an unless statement
|
||||
UnlessStatement* AsUnless();
|
||||
/// @returns the statement as an variable statement
|
||||
VariableStatement* AsVariable();
|
||||
VariableDeclStatement* AsVariableDecl();
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace ast {
|
|||
|
||||
class DecoratedVariable;
|
||||
|
||||
/// A Variable statement.
|
||||
/// A variable.
|
||||
class Variable : public Node {
|
||||
public:
|
||||
/// Create a new empty variable statement
|
||||
|
|
|
@ -12,29 +12,29 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
VariableStatement::VariableStatement() : Statement() {}
|
||||
VariableDeclStatement::VariableDeclStatement() : Statement() {}
|
||||
|
||||
VariableStatement::VariableStatement(std::unique_ptr<Variable> variable)
|
||||
VariableDeclStatement::VariableDeclStatement(std::unique_ptr<Variable> variable)
|
||||
: Statement(), variable_(std::move(variable)) {}
|
||||
|
||||
VariableStatement::VariableStatement(const Source& source,
|
||||
VariableDeclStatement::VariableDeclStatement(const Source& source,
|
||||
std::unique_ptr<Variable> variable)
|
||||
: Statement(source), variable_(std::move(variable)) {}
|
||||
|
||||
VariableStatement::~VariableStatement() = default;
|
||||
VariableDeclStatement::~VariableDeclStatement() = default;
|
||||
|
||||
bool VariableStatement::IsValid() const {
|
||||
bool VariableDeclStatement::IsValid() const {
|
||||
return variable_ != nullptr && variable_->IsValid();
|
||||
}
|
||||
|
||||
void VariableStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
void VariableDeclStatement::to_str(std::ostream& out, size_t indent) const {
|
||||
make_indent(out, indent);
|
||||
out << "VariableStatement{" << std::endl;
|
||||
out << "VariableDeclStatement{" << std::endl;
|
||||
variable_->to_str(out, indent + 2);
|
||||
make_indent(out, indent);
|
||||
out << "}" << std::endl;
|
|
@ -12,8 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_AST_VARIABLE_STATEMENT_H_
|
||||
#define SRC_AST_VARIABLE_STATEMENT_H_
|
||||
#ifndef SRC_AST_VARIABLE_DECL_STATEMENT_H_
|
||||
#define SRC_AST_VARIABLE_DECL_STATEMENT_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
@ -25,21 +25,22 @@
|
|||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A variable statement
|
||||
class VariableStatement : public Statement {
|
||||
/// A variable declaration statement
|
||||
class VariableDeclStatement : public Statement {
|
||||
public:
|
||||
/// Constructor
|
||||
VariableStatement();
|
||||
VariableDeclStatement();
|
||||
/// Constructor
|
||||
/// @param variable the variable
|
||||
explicit VariableStatement(std::unique_ptr<Variable> variable);
|
||||
explicit VariableDeclStatement(std::unique_ptr<Variable> variable);
|
||||
/// Constructor
|
||||
/// @param source the variable statement source
|
||||
/// @param variable the variable
|
||||
VariableStatement(const Source& source, std::unique_ptr<Variable> variable);
|
||||
VariableDeclStatement(const Source& source,
|
||||
std::unique_ptr<Variable> variable);
|
||||
/// Move constructor
|
||||
VariableStatement(VariableStatement&&) = default;
|
||||
~VariableStatement() override;
|
||||
VariableDeclStatement(VariableDeclStatement&&) = default;
|
||||
~VariableDeclStatement() override;
|
||||
|
||||
/// Sets the variable
|
||||
/// @param variable the variable to set
|
||||
|
@ -50,7 +51,7 @@ class VariableStatement : public Statement {
|
|||
Variable* variable() const { return variable_.get(); }
|
||||
|
||||
/// @returns true if this is an variable statement
|
||||
bool IsVariable() const override { return true; }
|
||||
bool IsVariableDecl() const override { return true; }
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
@ -61,7 +62,7 @@ class VariableStatement : public Statement {
|
|||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
|
||||
private:
|
||||
VariableStatement(const VariableStatement&) = delete;
|
||||
VariableDeclStatement(const VariableDeclStatement&) = delete;
|
||||
|
||||
std::unique_ptr<Variable> variable_;
|
||||
};
|
||||
|
@ -69,4 +70,4 @@ class VariableStatement : public Statement {
|
|||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_AST_VARIABLE_STATEMENT_H_
|
||||
#endif // SRC_AST_VARIABLE_DECL_STATEMENT_H_
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
|
@ -22,59 +22,59 @@ namespace tint {
|
|||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using VariableStatementTest = testing::Test;
|
||||
using VariableDeclStatementTest = testing::Test;
|
||||
|
||||
TEST_F(VariableStatementTest, Creation) {
|
||||
TEST_F(VariableDeclStatementTest, Creation) {
|
||||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
|
||||
auto var_ptr = var.get();
|
||||
|
||||
VariableStatement stmt(std::move(var));
|
||||
VariableDeclStatement stmt(std::move(var));
|
||||
EXPECT_EQ(stmt.variable(), var_ptr);
|
||||
}
|
||||
|
||||
TEST_F(VariableStatementTest, Creation_WithSource) {
|
||||
TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
||||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableStatement stmt(Source{20, 2}, std::move(var));
|
||||
VariableDeclStatement stmt(Source{20, 2}, std::move(var));
|
||||
auto src = stmt.source();
|
||||
EXPECT_EQ(src.line, 20);
|
||||
EXPECT_EQ(src.column, 2);
|
||||
}
|
||||
|
||||
TEST_F(VariableStatementTest, IsVariable) {
|
||||
VariableStatement s;
|
||||
EXPECT_TRUE(s.IsVariable());
|
||||
TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
||||
VariableDeclStatement s;
|
||||
EXPECT_TRUE(s.IsVariableDecl());
|
||||
}
|
||||
|
||||
TEST_F(VariableStatementTest, IsValid) {
|
||||
TEST_F(VariableDeclStatementTest, IsValid) {
|
||||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
|
||||
VariableStatement stmt(std::move(var));
|
||||
VariableDeclStatement stmt(std::move(var));
|
||||
EXPECT_TRUE(stmt.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableStatementTest, IsValid_InvalidVariable) {
|
||||
TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
|
||||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("", StorageClass::kNone, &f32);
|
||||
VariableStatement stmt(std::move(var));
|
||||
VariableDeclStatement stmt(std::move(var));
|
||||
EXPECT_FALSE(stmt.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableStatementTest, IsValid_NullVariable) {
|
||||
VariableStatement stmt;
|
||||
TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
|
||||
VariableDeclStatement stmt;
|
||||
EXPECT_FALSE(stmt.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableStatementTest, ToStr) {
|
||||
TEST_F(VariableDeclStatementTest, ToStr) {
|
||||
type::F32Type f32;
|
||||
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableStatement stmt(Source{20, 2}, std::move(var));
|
||||
VariableDeclStatement stmt(Source{20, 2}, std::move(var));
|
||||
std::ostringstream out;
|
||||
stmt.to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), R"( VariableStatement{
|
||||
EXPECT_EQ(out.str(), R"( VariableDeclStatement{
|
||||
Variable{
|
||||
a
|
||||
none
|
|
@ -63,7 +63,7 @@
|
|||
#include "src/ast/unary_method_expression.h"
|
||||
#include "src/ast/unary_op.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/reader/wgsl/lexer.h"
|
||||
#include "src/type_manager.h"
|
||||
|
||||
|
@ -1667,7 +1667,7 @@ std::unique_ptr<ast::ContinueStatement> ParserImpl::continue_stmt() {
|
|||
// : variable_decl
|
||||
// | variable_decl EQUAL logical_or_expression
|
||||
// | CONST variable_ident_decl EQUAL logical_or_expression
|
||||
std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
|
||||
std::unique_ptr<ast::VariableDeclStatement> ParserImpl::variable_stmt() {
|
||||
auto t = peek();
|
||||
auto source = t.source();
|
||||
if (t.IsConst()) {
|
||||
|
@ -1702,7 +1702,7 @@ std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
|
|||
var->set_is_const(true);
|
||||
var->set_constructor(std::move(constructor));
|
||||
|
||||
return std::make_unique<ast::VariableStatement>(source, std::move(var));
|
||||
return std::make_unique<ast::VariableDeclStatement>(source, std::move(var));
|
||||
}
|
||||
|
||||
auto var = variable_decl();
|
||||
|
@ -1724,7 +1724,7 @@ std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
|
|||
var->set_constructor(std::move(constructor));
|
||||
}
|
||||
|
||||
return std::make_unique<ast::VariableStatement>(source, std::move(var));
|
||||
return std::make_unique<ast::VariableDeclStatement>(source, std::move(var));
|
||||
}
|
||||
|
||||
// if_stmt
|
||||
|
|
|
@ -201,7 +201,7 @@ class ParserImpl {
|
|||
std::unique_ptr<ast::ContinueStatement> continue_stmt();
|
||||
/// Parses a `variable_stmt` grammar element
|
||||
/// @returns the parsed variable or nullptr
|
||||
std::unique_ptr<ast::VariableStatement> variable_stmt();
|
||||
std::unique_ptr<ast::VariableDeclStatement> variable_stmt();
|
||||
/// Parses a `if_stmt` grammar element
|
||||
/// @returns the parsed statement or nullptr
|
||||
std::unique_ptr<ast::IfStatement> if_stmt();
|
||||
|
|
|
@ -36,7 +36,7 @@ TEST_F(ParserImplTest, CaseBody_Statements) {
|
|||
auto e = p->case_body();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_EQ(e.size(), 2);
|
||||
EXPECT_TRUE(e[0]->IsVariable());
|
||||
EXPECT_TRUE(e[0]->IsVariableDecl());
|
||||
EXPECT_TRUE(e[1]->IsAssign());
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ TEST_F(ParserImplTest, Statement_Variable) {
|
|||
auto e = p->statement();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsVariable());
|
||||
ASSERT_TRUE(e->IsVariableDecl());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, Statement_Variable_Invalid) {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/statement.h"
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||
|
||||
|
@ -28,7 +28,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
|
|||
auto e = p->variable_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsVariable());
|
||||
ASSERT_TRUE(e->IsVariableDecl());
|
||||
ASSERT_NE(e->variable(), nullptr);
|
||||
EXPECT_EQ(e->variable()->name(), "a");
|
||||
|
||||
|
@ -40,7 +40,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
|
|||
auto e = p->variable_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsVariable());
|
||||
ASSERT_TRUE(e->IsVariableDecl());
|
||||
ASSERT_NE(e->variable(), nullptr);
|
||||
EXPECT_EQ(e->variable()->name(), "a");
|
||||
|
||||
|
@ -69,7 +69,7 @@ TEST_F(ParserImplTest, VariableStmt_Const) {
|
|||
auto e = p->variable_stmt();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_NE(e, nullptr);
|
||||
ASSERT_TRUE(e->IsVariable());
|
||||
ASSERT_TRUE(e->IsVariableDecl());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableStmt_Const_InvalidVarIdent) {
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#include "src/ast/unary_method_expression.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
#include "src/ast/unless_statement.h"
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
|
@ -752,8 +752,8 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
|
|||
if (stmt->IsSwitch()) {
|
||||
return EmitSwitch(stmt->AsSwitch());
|
||||
}
|
||||
if (stmt->IsVariable()) {
|
||||
return EmitVariable(stmt->AsVariable()->variable());
|
||||
if (stmt->IsVariableDecl()) {
|
||||
return EmitVariable(stmt->AsVariableDecl()->variable());
|
||||
}
|
||||
if (stmt->IsUnless()) {
|
||||
return EmitUnless(stmt->AsUnless());
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/variable_statement.h"
|
||||
#include "src/ast/variable_decl_statement.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -28,12 +28,12 @@ namespace {
|
|||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_VariableStatement) {
|
||||
TEST_F(GeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
|
||||
ast::VariableStatement stmt(std::move(var));
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
GeneratorImpl g;
|
||||
g.increment_indent();
|
Loading…
Reference in New Issue