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;
private:
AccessControl value_ = ast::AccessControl::kReadWrite;
AccessControl const value_;
};
} // namespace ast

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -51,8 +51,6 @@ class IfStatement : public Castable<IfStatement, Statement> {
/// @returns the 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
bool has_else_statements() const { return !else_statements_.empty(); }
@ -76,9 +74,9 @@ class IfStatement : public Castable<IfStatement, Statement> {
private:
IfStatement(const IfStatement&) = delete;
Expression* condition_ = nullptr;
BlockStatement* body_ = nullptr;
ElseStatementList else_statements_;
Expression* const condition_;
BlockStatement* const body_;
ElseStatementList const else_statements_;
};
} // namespace ast

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::ReturnStatement);
namespace tint {
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)
: Base(source), value_(value) {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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