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:
dan sinclair 2020-03-30 22:46:48 +00:00 committed by dan sinclair
parent a322f5ddfa
commit e49bd5eeb4
14 changed files with 69 additions and 68 deletions

View File

@ -179,8 +179,8 @@ set(TINT_LIB_SRCS
ast/variable.h ast/variable.h
ast/variable_decoration.cc ast/variable_decoration.cc
ast/variable_decoration.h ast/variable_decoration.h
ast/variable_statement.cc ast/variable_decl_statement.cc
ast/variable_statement.h ast/variable_decl_statement.h
context.h context.h
context.cc context.cc
reader/reader.cc reader/reader.cc
@ -302,7 +302,7 @@ set(TINT_TEST_SRCS
ast/unary_method_expression_test.cc ast/unary_method_expression_test.cc
ast/unary_op_expression_test.cc ast/unary_op_expression_test.cc
ast/unless_statement_test.cc ast/unless_statement_test.cc
ast/variable_statement_test.cc ast/variable_decl_statement_test.cc
ast/variable_test.cc ast/variable_test.cc
type_manager_test.cc type_manager_test.cc
validator_impl_import_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_method_test.cc
writer/wgsl/generator_impl_unary_op_test.cc writer/wgsl/generator_impl_unary_op_test.cc
writer/wgsl/generator_impl_unless_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 writer/wgsl/generator_impl_variable_test.cc
) )
endif() endif()

View File

@ -30,7 +30,7 @@
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/switch_statement.h" #include "src/ast/switch_statement.h"
#include "src/ast/unless_statement.h" #include "src/ast/unless_statement.h"
#include "src/ast/variable_statement.h" #include "src/ast/variable_decl_statement.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -111,9 +111,9 @@ UnlessStatement* Statement::AsUnless() {
return static_cast<UnlessStatement*>(this); return static_cast<UnlessStatement*>(this);
} }
VariableStatement* Statement::AsVariable() { VariableDeclStatement* Statement::AsVariableDecl() {
assert(IsVariable()); assert(IsVariableDecl());
return static_cast<VariableStatement*>(this); return static_cast<VariableDeclStatement*>(this);
} }
} // namespace ast } // namespace ast

View File

@ -34,7 +34,7 @@ class RegardlessStatement;
class ReturnStatement; class ReturnStatement;
class SwitchStatement; class SwitchStatement;
class UnlessStatement; class UnlessStatement;
class VariableStatement; class VariableDeclStatement;
/// Base statement class /// Base statement class
class Statement : public Node { class Statement : public Node {
@ -70,7 +70,7 @@ class Statement : public Node {
/// @returns true if this is an unless statement /// @returns true if this is an unless statement
virtual bool IsUnless() const { return false; } virtual bool IsUnless() const { return false; }
/// @returns true if this is an variable statement /// @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 /// @returns the statement as an assign statement
AssignmentStatement* AsAssign(); AssignmentStatement* AsAssign();
@ -101,7 +101,7 @@ class Statement : public Node {
/// @returns the statement as an unless statement /// @returns the statement as an unless statement
UnlessStatement* AsUnless(); UnlessStatement* AsUnless();
/// @returns the statement as an variable statement /// @returns the statement as an variable statement
VariableStatement* AsVariable(); VariableDeclStatement* AsVariableDecl();
protected: protected:
/// Constructor /// Constructor

View File

@ -30,7 +30,7 @@ namespace ast {
class DecoratedVariable; class DecoratedVariable;
/// A Variable statement. /// A variable.
class Variable : public Node { class Variable : public Node {
public: public:
/// Create a new empty variable statement /// Create a new empty variable statement

View File

@ -12,29 +12,29 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/ast/variable_statement.h" #include "src/ast/variable_decl_statement.h"
namespace tint { namespace tint {
namespace ast { 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)) {} : Statement(), variable_(std::move(variable)) {}
VariableStatement::VariableStatement(const Source& source, VariableDeclStatement::VariableDeclStatement(const Source& source,
std::unique_ptr<Variable> variable) std::unique_ptr<Variable> variable)
: Statement(source), variable_(std::move(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(); 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); make_indent(out, indent);
out << "VariableStatement{" << std::endl; out << "VariableDeclStatement{" << std::endl;
variable_->to_str(out, indent + 2); variable_->to_str(out, indent + 2);
make_indent(out, indent); make_indent(out, indent);
out << "}" << std::endl; out << "}" << std::endl;

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_AST_VARIABLE_STATEMENT_H_ #ifndef SRC_AST_VARIABLE_DECL_STATEMENT_H_
#define SRC_AST_VARIABLE_STATEMENT_H_ #define SRC_AST_VARIABLE_DECL_STATEMENT_H_
#include <memory> #include <memory>
#include <utility> #include <utility>
@ -25,21 +25,22 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
/// A variable statement /// A variable declaration statement
class VariableStatement : public Statement { class VariableDeclStatement : public Statement {
public: public:
/// Constructor /// Constructor
VariableStatement(); VariableDeclStatement();
/// Constructor /// Constructor
/// @param variable the variable /// @param variable the variable
explicit VariableStatement(std::unique_ptr<Variable> variable); explicit VariableDeclStatement(std::unique_ptr<Variable> variable);
/// Constructor /// Constructor
/// @param source the variable statement source /// @param source the variable statement source
/// @param variable the variable /// @param variable the variable
VariableStatement(const Source& source, std::unique_ptr<Variable> variable); VariableDeclStatement(const Source& source,
std::unique_ptr<Variable> variable);
/// Move constructor /// Move constructor
VariableStatement(VariableStatement&&) = default; VariableDeclStatement(VariableDeclStatement&&) = default;
~VariableStatement() override; ~VariableDeclStatement() override;
/// Sets the variable /// Sets the variable
/// @param variable the variable to set /// @param variable the variable to set
@ -50,7 +51,7 @@ class VariableStatement : public Statement {
Variable* variable() const { return variable_.get(); } Variable* variable() const { return variable_.get(); }
/// @returns true if this is an variable statement /// @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 /// @returns true if the node is valid
bool IsValid() const override; bool IsValid() const override;
@ -61,7 +62,7 @@ class VariableStatement : public Statement {
void to_str(std::ostream& out, size_t indent) const override; void to_str(std::ostream& out, size_t indent) const override;
private: private:
VariableStatement(const VariableStatement&) = delete; VariableDeclStatement(const VariableDeclStatement&) = delete;
std::unique_ptr<Variable> variable_; std::unique_ptr<Variable> variable_;
}; };
@ -69,4 +70,4 @@ class VariableStatement : public Statement {
} // namespace ast } // namespace ast
} // namespace tint } // namespace tint
#endif // SRC_AST_VARIABLE_STATEMENT_H_ #endif // SRC_AST_VARIABLE_DECL_STATEMENT_H_

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "src/ast/variable_statement.h" #include "src/ast/variable_decl_statement.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
@ -22,59 +22,59 @@ namespace tint {
namespace ast { namespace ast {
namespace { namespace {
using VariableStatementTest = testing::Test; using VariableDeclStatementTest = testing::Test;
TEST_F(VariableStatementTest, Creation) { TEST_F(VariableDeclStatementTest, Creation) {
type::F32Type f32; type::F32Type f32;
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32); auto var = std::make_unique<Variable>("a", StorageClass::kNone, &f32);
auto var_ptr = var.get(); auto var_ptr = var.get();
VariableStatement stmt(std::move(var)); VariableDeclStatement stmt(std::move(var));
EXPECT_EQ(stmt.variable(), var_ptr); EXPECT_EQ(stmt.variable(), var_ptr);
} }
TEST_F(VariableStatementTest, Creation_WithSource) { TEST_F(VariableDeclStatementTest, Creation_WithSource) {
type::F32Type f32; type::F32Type f32;
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &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(); auto src = stmt.source();
EXPECT_EQ(src.line, 20); EXPECT_EQ(src.line, 20);
EXPECT_EQ(src.column, 2); EXPECT_EQ(src.column, 2);
} }
TEST_F(VariableStatementTest, IsVariable) { TEST_F(VariableDeclStatementTest, IsVariableDecl) {
VariableStatement s; VariableDeclStatement s;
EXPECT_TRUE(s.IsVariable()); EXPECT_TRUE(s.IsVariableDecl());
} }
TEST_F(VariableStatementTest, IsValid) { TEST_F(VariableDeclStatementTest, IsValid) {
type::F32Type f32; type::F32Type f32;
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &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()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(VariableStatementTest, IsValid_InvalidVariable) { TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
type::F32Type f32; type::F32Type f32;
auto var = std::make_unique<Variable>("", StorageClass::kNone, &f32); auto var = std::make_unique<Variable>("", StorageClass::kNone, &f32);
VariableStatement stmt(std::move(var)); VariableDeclStatement stmt(std::move(var));
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(VariableStatementTest, IsValid_NullVariable) { TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
VariableStatement stmt; VariableDeclStatement stmt;
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(VariableStatementTest, ToStr) { TEST_F(VariableDeclStatementTest, ToStr) {
type::F32Type f32; type::F32Type f32;
auto var = std::make_unique<Variable>("a", StorageClass::kNone, &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; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( VariableStatement{ EXPECT_EQ(out.str(), R"( VariableDeclStatement{
Variable{ Variable{
a a
none none

View File

@ -63,7 +63,7 @@
#include "src/ast/unary_method_expression.h" #include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op.h" #include "src/ast/unary_op.h"
#include "src/ast/unary_op_expression.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/reader/wgsl/lexer.h"
#include "src/type_manager.h" #include "src/type_manager.h"
@ -1667,7 +1667,7 @@ std::unique_ptr<ast::ContinueStatement> ParserImpl::continue_stmt() {
// : variable_decl // : variable_decl
// | variable_decl EQUAL logical_or_expression // | variable_decl EQUAL logical_or_expression
// | CONST variable_ident_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 t = peek();
auto source = t.source(); auto source = t.source();
if (t.IsConst()) { if (t.IsConst()) {
@ -1702,7 +1702,7 @@ std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
var->set_is_const(true); var->set_is_const(true);
var->set_constructor(std::move(constructor)); 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(); auto var = variable_decl();
@ -1724,7 +1724,7 @@ std::unique_ptr<ast::VariableStatement> ParserImpl::variable_stmt() {
var->set_constructor(std::move(constructor)); 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 // if_stmt

View File

@ -201,7 +201,7 @@ class ParserImpl {
std::unique_ptr<ast::ContinueStatement> continue_stmt(); std::unique_ptr<ast::ContinueStatement> continue_stmt();
/// Parses a `variable_stmt` grammar element /// Parses a `variable_stmt` grammar element
/// @returns the parsed variable or nullptr /// @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 /// Parses a `if_stmt` grammar element
/// @returns the parsed statement or nullptr /// @returns the parsed statement or nullptr
std::unique_ptr<ast::IfStatement> if_stmt(); std::unique_ptr<ast::IfStatement> if_stmt();

View File

@ -36,7 +36,7 @@ TEST_F(ParserImplTest, CaseBody_Statements) {
auto e = p->case_body(); auto e = p->case_body();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e.size(), 2); ASSERT_EQ(e.size(), 2);
EXPECT_TRUE(e[0]->IsVariable()); EXPECT_TRUE(e[0]->IsVariableDecl());
EXPECT_TRUE(e[1]->IsAssign()); EXPECT_TRUE(e[1]->IsAssign());
} }

View File

@ -130,7 +130,7 @@ TEST_F(ParserImplTest, Statement_Variable) {
auto e = p->statement(); auto e = p->statement();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); ASSERT_NE(e, nullptr);
ASSERT_TRUE(e->IsVariable()); ASSERT_TRUE(e->IsVariableDecl());
} }
TEST_F(ParserImplTest, Statement_Variable_Invalid) { TEST_F(ParserImplTest, Statement_Variable_Invalid) {

View File

@ -14,7 +14,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/statement.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.h"
#include "src/reader/wgsl/parser_impl_test_helper.h" #include "src/reader/wgsl/parser_impl_test_helper.h"
@ -28,7 +28,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
auto e = p->variable_stmt(); auto e = p->variable_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); ASSERT_NE(e, nullptr);
ASSERT_TRUE(e->IsVariable()); ASSERT_TRUE(e->IsVariableDecl());
ASSERT_NE(e->variable(), nullptr); ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->name(), "a"); EXPECT_EQ(e->variable()->name(), "a");
@ -40,7 +40,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
auto e = p->variable_stmt(); auto e = p->variable_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); ASSERT_NE(e, nullptr);
ASSERT_TRUE(e->IsVariable()); ASSERT_TRUE(e->IsVariableDecl());
ASSERT_NE(e->variable(), nullptr); ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->name(), "a"); EXPECT_EQ(e->variable()->name(), "a");
@ -69,7 +69,7 @@ TEST_F(ParserImplTest, VariableStmt_Const) {
auto e = p->variable_stmt(); auto e = p->variable_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); ASSERT_NE(e, nullptr);
ASSERT_TRUE(e->IsVariable()); ASSERT_TRUE(e->IsVariableDecl());
} }
TEST_F(ParserImplTest, VariableStmt_Const_InvalidVarIdent) { TEST_F(ParserImplTest, VariableStmt_Const_InvalidVarIdent) {

View File

@ -59,7 +59,7 @@
#include "src/ast/unary_method_expression.h" #include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op_expression.h" #include "src/ast/unary_op_expression.h"
#include "src/ast/unless_statement.h" #include "src/ast/unless_statement.h"
#include "src/ast/variable_statement.h" #include "src/ast/variable_decl_statement.h"
namespace tint { namespace tint {
namespace writer { namespace writer {
@ -752,8 +752,8 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
if (stmt->IsSwitch()) { if (stmt->IsSwitch()) {
return EmitSwitch(stmt->AsSwitch()); return EmitSwitch(stmt->AsSwitch());
} }
if (stmt->IsVariable()) { if (stmt->IsVariableDecl()) {
return EmitVariable(stmt->AsVariable()->variable()); return EmitVariable(stmt->AsVariableDecl()->variable());
} }
if (stmt->IsUnless()) { if (stmt->IsUnless()) {
return EmitUnless(stmt->AsUnless()); return EmitUnless(stmt->AsUnless());

View File

@ -18,7 +18,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/variable.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" #include "src/writer/wgsl/generator_impl.h"
namespace tint { namespace tint {
@ -28,12 +28,12 @@ namespace {
using GeneratorImplTest = testing::Test; using GeneratorImplTest = testing::Test;
TEST_F(GeneratorImplTest, Emit_VariableStatement) { TEST_F(GeneratorImplTest, Emit_VariableDeclStatement) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = auto var =
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32); std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
ast::VariableStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
GeneratorImpl g; GeneratorImpl g;
g.increment_indent(); g.increment_indent();