ast: Make all non-semantic fields const

Annotate those that are set by the TypeDeterminer as "Semantic Info"

Bug: tint:396
Bug: tint:390
Change-Id: I0705c64e8e23d97a6430230728f82e64dd92efb7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35165
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-15 14:52:38 +00:00 committed by Commit Bot service account
parent 9df857de9a
commit be96376d8e
55 changed files with 111 additions and 110 deletions

View File

@ -49,7 +49,7 @@ class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> {
AccessDecoration* Clone(CloneContext* ctx) const override; AccessDecoration* Clone(CloneContext* ctx) const override;
private: private:
AccessControl value_ = ast::AccessControl::kReadWrite; AccessControl const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -64,8 +64,8 @@ class ArrayAccessorExpression
private: private:
ArrayAccessorExpression(const ArrayAccessorExpression&) = delete; ArrayAccessorExpression(const ArrayAccessorExpression&) = delete;
Expression* array_ = nullptr; Expression* const array_;
Expression* idx_expr_ = nullptr; Expression* const idx_expr_;
}; };
} // namespace ast } // namespace ast

View File

@ -61,8 +61,8 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
private: private:
AssignmentStatement(const AssignmentStatement&) = delete; AssignmentStatement(const AssignmentStatement&) = delete;
Expression* lhs_ = nullptr; Expression* const lhs_;
Expression* rhs_ = nullptr; Expression* const rhs_;
}; };
} // namespace ast } // namespace ast

View File

@ -127,9 +127,9 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
private: private:
BinaryExpression(const BinaryExpression&) = delete; BinaryExpression(const BinaryExpression&) = delete;
BinaryOp op_ = BinaryOp::kNone; BinaryOp const op_;
Expression* lhs_ = nullptr; Expression* const lhs_;
Expression* rhs_ = nullptr; Expression* const rhs_;
}; };
inline std::ostream& operator<<(std::ostream& out, BinaryOp op) { inline std::ostream& operator<<(std::ostream& out, BinaryOp op) {

View File

@ -49,7 +49,7 @@ class BindingDecoration
BindingDecoration* Clone(CloneContext* ctx) const override; BindingDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t value_; uint32_t const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -61,8 +61,8 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
private: private:
BitcastExpression(const BitcastExpression&) = delete; BitcastExpression(const BitcastExpression&) = delete;
type::Type* type_ = nullptr; type::Type* const type_;
Expression* expr_ = nullptr; Expression* const expr_;
}; };
} // namespace ast } // namespace ast

View File

@ -83,7 +83,7 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
private: private:
BlockStatement(const BlockStatement&) = delete; BlockStatement(const BlockStatement&) = delete;
StatementList statements_; StatementList const statements_;
}; };
} // namespace ast } // namespace ast

View File

@ -52,7 +52,7 @@ class BoolLiteral : public Castable<BoolLiteral, Literal> {
BoolLiteral* Clone(CloneContext* ctx) const override; BoolLiteral* Clone(CloneContext* ctx) const override;
private: private:
bool value_; bool const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -48,7 +48,7 @@ class BuiltinDecoration
BuiltinDecoration* Clone(CloneContext* ctx) const override; BuiltinDecoration* Clone(CloneContext* ctx) const override;
private: private:
Builtin builtin_ = Builtin::kNone; Builtin const builtin_;
}; };
} // namespace ast } // namespace ast

View File

@ -60,8 +60,8 @@ class CallExpression : public Castable<CallExpression, Expression> {
private: private:
CallExpression(const CallExpression&) = delete; CallExpression(const CallExpression&) = delete;
Expression* func_ = nullptr; Expression* const func_;
ExpressionList params_; ExpressionList const params_;
}; };
} // namespace ast } // namespace ast

View File

@ -57,7 +57,7 @@ class CallStatement : public Castable<CallStatement, Statement> {
private: private:
CallStatement(const CallStatement&) = delete; CallStatement(const CallStatement&) = delete;
CallExpression* call_ = nullptr; CallExpression* const call_;
}; };
} // namespace ast } // namespace ast

View File

@ -73,8 +73,8 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
private: private:
CaseStatement(const CaseStatement&) = delete; CaseStatement(const CaseStatement&) = delete;
CaseSelectorList selectors_; CaseSelectorList const selectors_;
BlockStatement* body_ = nullptr; BlockStatement* const body_;
}; };
/// A list of case statements /// A list of case statements

View File

@ -48,7 +48,7 @@ class ConstantIdDecoration
ConstantIdDecoration* Clone(CloneContext* ctx) const override; ConstantIdDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t value_ = 0; uint32_t const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -69,8 +69,8 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
private: private:
ElseStatement(const ElseStatement&) = delete; ElseStatement(const ElseStatement&) = delete;
Expression* condition_ = nullptr; Expression* const condition_;
BlockStatement* body_ = nullptr; BlockStatement* const body_;
}; };
/// A list of else statements /// A list of else statements

View File

@ -52,7 +52,7 @@ class Expression : public Castable<Expression, Node> {
private: private:
Expression(const Expression&) = delete; Expression(const Expression&) = delete;
type::Type* result_type_ = nullptr; type::Type* result_type_ = nullptr; // Semantic info
}; };
/// A list of expressions /// A list of expressions

View File

@ -50,7 +50,7 @@ class FloatLiteral : public Castable<FloatLiteral, Literal> {
FloatLiteral* Clone(CloneContext* ctx) const override; FloatLiteral* Clone(CloneContext* ctx) const override;
private: private:
float value_; float const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -202,15 +202,16 @@ class Function : public Castable<Function, Node> {
const std::vector<std::pair<Variable*, Function::BindingInfo>> const std::vector<std::pair<Variable*, Function::BindingInfo>>
ReferencedSampledTextureVariablesImpl(bool multisampled) const; ReferencedSampledTextureVariablesImpl(bool multisampled) const;
Symbol symbol_; Symbol const symbol_;
std::string name_; std::string const name_;
VariableList params_; VariableList const params_;
type::Type* return_type_ = nullptr; type::Type* const return_type_;
BlockStatement* body_ = nullptr; BlockStatement* const body_;
std::vector<Variable*> referenced_module_vars_;
std::vector<Variable*> local_referenced_module_vars_; std::vector<Variable*> referenced_module_vars_; // Semantic info
std::vector<Symbol> ancestor_entry_points_; std::vector<Variable*> local_referenced_module_vars_; // Semantic info
FunctionDecorationList decorations_; std::vector<Symbol> ancestor_entry_points_; // Semantic info
FunctionDecorationList decorations_; // Semantic info
}; };
/// A list of functions /// A list of functions

View File

@ -83,10 +83,11 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
private: private:
IdentifierExpression(const IdentifierExpression&) = delete; IdentifierExpression(const IdentifierExpression&) = delete;
Intrinsic intrinsic_ = Intrinsic::kNone; Symbol const sym_;
std::unique_ptr<intrinsic::Signature> intrinsic_sig_; std::string const name_;
Symbol sym_;
std::string name_; Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info
std::unique_ptr<intrinsic::Signature> intrinsic_sig_; // Semantic info
}; };
} // namespace ast } // namespace ast

View File

@ -51,8 +51,6 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// @returns the else statements /// @returns the else statements
const ElseStatementList& else_statements() const { return else_statements_; } const ElseStatementList& else_statements() const { return else_statements_; }
/// @returns the else statements
ElseStatementList& else_statements() { return else_statements_; }
/// @returns true if there are else statements /// @returns true if there are else statements
bool has_else_statements() const { return !else_statements_.empty(); } bool has_else_statements() const { return !else_statements_.empty(); }
@ -76,9 +74,9 @@ class IfStatement : public Castable<IfStatement, Statement> {
private: private:
IfStatement(const IfStatement&) = delete; IfStatement(const IfStatement&) = delete;
Expression* condition_ = nullptr; Expression* const condition_;
BlockStatement* body_ = nullptr; BlockStatement* const body_;
ElseStatementList else_statements_; ElseStatementList const else_statements_;
}; };
} // namespace ast } // namespace ast

View File

@ -52,7 +52,7 @@ class Literal : public Castable<Literal, Node> {
explicit Literal(const Source& source, type::Type* type); explicit Literal(const Source& source, type::Type* type);
private: private:
type::Type* type_ = nullptr; type::Type* const type_;
}; };
} // namespace ast } // namespace ast

View File

@ -49,7 +49,7 @@ class LocationDecoration
LocationDecoration* Clone(CloneContext* ctx) const override; LocationDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t value_; uint32_t const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -71,8 +71,8 @@ class LoopStatement : public Castable<LoopStatement, Statement> {
private: private:
LoopStatement(const LoopStatement&) = delete; LoopStatement(const LoopStatement&) = delete;
BlockStatement* body_ = nullptr; BlockStatement* const body_;
BlockStatement* continuing_ = nullptr; BlockStatement* const continuing_;
}; };
} // namespace ast } // namespace ast

View File

@ -64,8 +64,8 @@ class MemberAccessorExpression
private: private:
MemberAccessorExpression(const MemberAccessorExpression&) = delete; MemberAccessorExpression(const MemberAccessorExpression&) = delete;
Expression* struct_ = nullptr; Expression* const struct_;
IdentifierExpression* member_ = nullptr; IdentifierExpression* const member_;
}; };
} // namespace ast } // namespace ast

View File

@ -75,7 +75,7 @@ class Node : public Castable<Node> {
private: private:
Node(const Node&) = delete; Node(const Node&) = delete;
Source source_; Source const source_;
}; };
} // namespace ast } // namespace ast

View File

@ -22,7 +22,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ReturnStatement);
namespace tint { namespace tint {
namespace ast { namespace ast {
ReturnStatement::ReturnStatement(const Source& source) : Base(source) {} ReturnStatement::ReturnStatement(const Source& source)
: Base(source), value_(nullptr) {}
ReturnStatement::ReturnStatement(const Source& source, Expression* value) ReturnStatement::ReturnStatement(const Source& source, Expression* value)
: Base(source), value_(value) {} : Base(source), value_(value) {}

View File

@ -62,7 +62,7 @@ class ReturnStatement : public Castable<ReturnStatement, Statement> {
private: private:
ReturnStatement(const ReturnStatement&) = delete; ReturnStatement(const ReturnStatement&) = delete;
Expression* value_ = nullptr; Expression* const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -58,7 +58,7 @@ class ScalarConstructorExpression
private: private:
ScalarConstructorExpression(const ScalarConstructorExpression&) = delete; ScalarConstructorExpression(const ScalarConstructorExpression&) = delete;
Literal* literal_ = nullptr; Literal* const literal_;
}; };
} // namespace ast } // namespace ast

View File

@ -48,7 +48,7 @@ class SetDecoration : public Castable<SetDecoration, VariableDecoration> {
SetDecoration* Clone(CloneContext* ctx) const override; SetDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t value_; uint32_t const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -50,7 +50,7 @@ class SintLiteral : public Castable<SintLiteral, IntLiteral> {
SintLiteral* Clone(CloneContext* ctx) const override; SintLiteral* Clone(CloneContext* ctx) const override;
private: private:
int32_t value_; int32_t const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -47,7 +47,7 @@ class StageDecoration : public Castable<StageDecoration, FunctionDecoration> {
StageDecoration* Clone(CloneContext* ctx) const override; StageDecoration* Clone(CloneContext* ctx) const override;
private: private:
PipelineStage stage_ = PipelineStage::kNone; PipelineStage const stage_;
}; };
} // namespace ast } // namespace ast

View File

@ -48,7 +48,7 @@ class StrideDecoration : public Castable<StrideDecoration, ArrayDecoration> {
StrideDecoration* Clone(CloneContext* ctx) const override; StrideDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t stride_; uint32_t const stride_;
}; };
} // namespace ast } // namespace ast

View File

@ -74,8 +74,8 @@ class Struct : public Castable<Struct, Node> {
private: private:
Struct(const Struct&) = delete; Struct(const Struct&) = delete;
StructMemberList members_; StructMemberList const members_;
StructDecorationList decorations_; StructDecorationList const decorations_;
}; };
} // namespace ast } // namespace ast

View File

@ -77,9 +77,9 @@ class StructMember : public Castable<StructMember, Node> {
private: private:
StructMember(const StructMember&) = delete; StructMember(const StructMember&) = delete;
std::string name_; std::string const name_;
type::Type* type_ = nullptr; type::Type* const type_;
StructMemberDecorationList decorations_; StructMemberDecorationList const decorations_;
}; };
/// A list of struct members /// A list of struct members

View File

@ -49,7 +49,7 @@ class StructMemberOffsetDecoration
StructMemberOffsetDecoration* Clone(CloneContext* ctx) const override; StructMemberOffsetDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t offset_; uint32_t const offset_;
}; };
} // namespace ast } // namespace ast

View File

@ -45,8 +45,6 @@ class SwitchStatement : public Castable<SwitchStatement, Statement> {
/// @returns true if this is a default statement /// @returns true if this is a default statement
bool IsDefault() const { return condition_ == nullptr; } bool IsDefault() const { return condition_ == nullptr; }
/// @returns the Switch body
CaseStatementList& body() { return body_; }
/// @returns the Switch body /// @returns the Switch body
const CaseStatementList& body() const { return body_; } const CaseStatementList& body() const { return body_; }
@ -69,8 +67,8 @@ class SwitchStatement : public Castable<SwitchStatement, Statement> {
private: private:
SwitchStatement(const SwitchStatement&) = delete; SwitchStatement(const SwitchStatement&) = delete;
Expression* condition_ = nullptr; Expression* const condition_;
CaseStatementList body_; CaseStatementList const body_;
}; };
} // namespace ast } // namespace ast

View File

@ -66,8 +66,8 @@ class AccessControl : public Castable<AccessControl, Type> {
AccessControl* Clone(CloneContext* ctx) const override; AccessControl* Clone(CloneContext* ctx) const override;
private: private:
ast::AccessControl access_ = ast::AccessControl::kReadOnly; ast::AccessControl const access_;
Type* subtype_ = nullptr; Type* const subtype_;
}; };
} // namespace type } // namespace type

View File

@ -63,9 +63,9 @@ class Alias : public Castable<Alias, Type> {
Alias* Clone(CloneContext* ctx) const override; Alias* Clone(CloneContext* ctx) const override;
private: private:
Symbol symbol_; Symbol const symbol_;
std::string name_; std::string const name_;
Type* subtype_ = nullptr; Type* const subtype_;
}; };
} // namespace type } // namespace type

View File

@ -76,9 +76,9 @@ class Array : public Castable<Array, Type> {
Array* Clone(CloneContext* ctx) const override; Array* Clone(CloneContext* ctx) const override;
private: private:
Type* subtype_ = nullptr; Type* const subtype_;
uint32_t size_ = 0; uint32_t const size_;
ArrayDecorationList decos_; ArrayDecorationList const decos_;
}; };
} // namespace type } // namespace type

View File

@ -61,9 +61,9 @@ class Matrix : public Castable<Matrix, Type> {
Matrix* Clone(CloneContext* ctx) const override; Matrix* Clone(CloneContext* ctx) const override;
private: private:
Type* subtype_ = nullptr; Type* const subtype_;
uint32_t rows_ = 2; uint32_t const rows_;
uint32_t columns_ = 2; uint32_t const columns_;
}; };
} // namespace type } // namespace type

View File

@ -46,7 +46,7 @@ class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
MultisampledTexture* Clone(CloneContext* ctx) const override; MultisampledTexture* Clone(CloneContext* ctx) const override;
private: private:
Type* type_ = nullptr; Type* const type_;
}; };
} // namespace type } // namespace type

View File

@ -50,8 +50,8 @@ class Pointer : public Castable<Pointer, Type> {
Pointer* Clone(CloneContext* ctx) const override; Pointer* Clone(CloneContext* ctx) const override;
private: private:
Type* subtype_; Type* const subtype_;
StorageClass storage_class_; StorageClass const storage_class_;
}; };
} // namespace type } // namespace type

View File

@ -46,7 +46,7 @@ class SampledTexture : public Castable<SampledTexture, Texture> {
SampledTexture* Clone(CloneContext* ctx) const override; SampledTexture* Clone(CloneContext* ctx) const override;
private: private:
Type* type_ = nullptr; Type* const type_;
}; };
} // namespace type } // namespace type

View File

@ -58,7 +58,7 @@ class Sampler : public Castable<Sampler, Type> {
Sampler* Clone(CloneContext* ctx) const override; Sampler* Clone(CloneContext* ctx) const override;
private: private:
SamplerKind kind_ = SamplerKind::kSampler; SamplerKind const kind_;
}; };
} // namespace type } // namespace type

View File

@ -101,9 +101,10 @@ class StorageTexture : public Castable<StorageTexture, Texture> {
StorageTexture* Clone(CloneContext* ctx) const override; StorageTexture* Clone(CloneContext* ctx) const override;
private: private:
Type* type_ = nullptr; ast::AccessControl const access_;
ast::AccessControl access_ = ast::AccessControl::kReadOnly; ImageFormat const image_format_;
ImageFormat image_format_ = ImageFormat::kRgba32Float;
Type* type_ = nullptr; // Semantic info
}; };
} // namespace type } // namespace type

View File

@ -68,9 +68,9 @@ class Struct : public Castable<Struct, Type> {
Struct* Clone(CloneContext* ctx) const override; Struct* Clone(CloneContext* ctx) const override;
private: private:
Symbol symbol_; Symbol const symbol_;
std::string name_; std::string const name_;
ast::Struct* struct_ = nullptr; ast::Struct* const struct_;
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const; uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;
}; };

View File

@ -56,7 +56,7 @@ class Texture : public Castable<Texture, Type> {
TextureDimension dim() const { return dim_; } TextureDimension dim() const { return dim_; }
private: private:
TextureDimension dim_ = TextureDimension::k1d; TextureDimension const dim_;
}; };
} // namespace type } // namespace type

View File

@ -58,8 +58,8 @@ class Vector : public Castable<Vector, Type> {
Vector* Clone(CloneContext* ctx) const override; Vector* Clone(CloneContext* ctx) const override;
private: private:
Type* subtype_ = nullptr; Type* const subtype_;
uint32_t size_ = 2; uint32_t const size_;
}; };
} // namespace type } // namespace type

View File

@ -63,8 +63,8 @@ class TypeConstructorExpression
private: private:
TypeConstructorExpression(const TypeConstructorExpression&) = delete; TypeConstructorExpression(const TypeConstructorExpression&) = delete;
type::Type* type_ = nullptr; type::Type* const type_;
ExpressionList values_; ExpressionList const values_;
}; };
} // namespace ast } // namespace ast

View File

@ -50,7 +50,7 @@ class UintLiteral : public Castable<UintLiteral, IntLiteral> {
UintLiteral* Clone(CloneContext* ctx) const override; UintLiteral* Clone(CloneContext* ctx) const override;
private: private:
uint32_t value_; uint32_t const value_;
}; };
} // namespace ast } // namespace ast

View File

@ -61,8 +61,8 @@ class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
private: private:
UnaryOpExpression(const UnaryOpExpression&) = delete; UnaryOpExpression(const UnaryOpExpression&) = delete;
UnaryOp op_ = UnaryOp::kNegation; UnaryOp const op_;
Expression* expr_ = nullptr; Expression* const expr_;
}; };
} // namespace ast } // namespace ast

View File

@ -34,11 +34,11 @@ Variable::Variable(const Source& source,
VariableDecorationList decorations) VariableDecorationList decorations)
: Base(source), : Base(source),
name_(name), name_(name),
storage_class_(sc),
type_(type), type_(type),
is_const_(is_const), is_const_(is_const),
constructor_(constructor), constructor_(constructor),
decorations_(std::move(decorations)) {} decorations_(std::move(decorations)),
storage_class_(sc) {}
Variable::Variable(Variable&&) = default; Variable::Variable(Variable&&) = default;

View File

@ -162,13 +162,14 @@ class Variable : public Castable<Variable, Node> {
private: private:
Variable(const Variable&) = delete; Variable(const Variable&) = delete;
std::string name_; std::string const name_;
StorageClass storage_class_ = StorageClass::kNone;
// The value type if a const or formal paramter, and the store type if a var // The value type if a const or formal paramter, and the store type if a var
type::Type* type_ = nullptr; type::Type* const type_;
bool is_const_ = false; bool const is_const_;
Expression* constructor_ = nullptr; Expression* const constructor_;
VariableDecorationList decorations_; VariableDecorationList const decorations_;
StorageClass storage_class_ = StorageClass::kNone; // Semantic info
}; };
/// A list of variables /// A list of variables

View File

@ -59,7 +59,7 @@ class VariableDeclStatement
private: private:
VariableDeclStatement(const VariableDeclStatement&) = delete; VariableDeclStatement(const VariableDeclStatement&) = delete;
Variable* variable_ = nullptr; Variable* const variable_;
}; };
} // namespace ast } // namespace ast

View File

@ -23,12 +23,12 @@ namespace tint {
namespace ast { namespace ast {
WorkgroupDecoration::WorkgroupDecoration(const Source& source, uint32_t x) WorkgroupDecoration::WorkgroupDecoration(const Source& source, uint32_t x)
: Base(source), x_(x) {} : WorkgroupDecoration(source, x, 1, 1) {}
WorkgroupDecoration::WorkgroupDecoration(const Source& source, WorkgroupDecoration::WorkgroupDecoration(const Source& source,
uint32_t x, uint32_t x,
uint32_t y) uint32_t y)
: Base(source), x_(x), y_(y) {} : WorkgroupDecoration(source, x, y, 1) {}
WorkgroupDecoration::WorkgroupDecoration(const Source& source, WorkgroupDecoration::WorkgroupDecoration(const Source& source,
uint32_t x, uint32_t x,

View File

@ -64,9 +64,9 @@ class WorkgroupDecoration
WorkgroupDecoration* Clone(CloneContext* ctx) const override; WorkgroupDecoration* Clone(CloneContext* ctx) const override;
private: private:
uint32_t x_ = 1; uint32_t const x_;
uint32_t y_ = 1; uint32_t const y_;
uint32_t z_ = 1; uint32_t const z_;
}; };
} // namespace ast } // namespace ast