ProgramBuilder: Add Symbol overloads of Var(), Const(), Global(), GlobalConst()

Useful if you have a symbol already

Change-Id: Ib9e15ea761f58ee67dc3cc722d9129cd5369d92b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41481
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-02-10 21:34:26 +00:00 committed by Commit Bot service account
parent faca02d438
commit 46d78d731b
2 changed files with 88 additions and 73 deletions

View File

@ -91,56 +91,6 @@ type::Type* ProgramBuilder::TypeOf(ast::Expression* expr) const {
ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
ast::Variable* ProgramBuilder::Var(const std::string& name,
ast::StorageClass storage,
type::Type* type) {
return Var(name, storage, type, nullptr, {});
}
ast::Variable* ProgramBuilder::Var(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
return create<ast::Variable>(Symbols().Register(name), storage, type, false,
constructor, decorations);
}
ast::Variable* ProgramBuilder::Var(const Source& source,
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
return create<ast::Variable>(source, Symbols().Register(name), storage, type,
false, constructor, decorations);
}
ast::Variable* ProgramBuilder::Const(const std::string& name,
ast::StorageClass storage,
type::Type* type) {
return Const(name, storage, type, nullptr, {});
}
ast::Variable* ProgramBuilder::Const(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
return create<ast::Variable>(Symbols().Register(name), storage, type, true,
constructor, decorations);
}
ast::Variable* ProgramBuilder::Const(const Source& source,
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations) {
return create<ast::Variable>(source, Symbols().Register(name), storage, type,
true, constructor, decorations);
}
ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(ast::Variable* v) {
return create<ast::VariableDeclStatement>(v);
}

View File

@ -494,6 +494,12 @@ class ProgramBuilder {
return create<ast::IdentifierExpression>(Symbols().Register(name));
}
/// @param symbol the identifier symbol
/// @return an ast::IdentifierExpression with the given symbol
ast::IdentifierExpression* Expr(Symbol symbol) {
return create<ast::IdentifierExpression>(symbol);
}
/// @param source the source information
/// @param name the identifier name
/// @return an ast::IdentifierExpression with the given name
@ -743,15 +749,6 @@ class ProgramBuilder {
ty.array(subtype, n), ExprList(std::forward<ARGS>(args)...));
}
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
/// @returns a `ast::Variable` with the given name, storage and type. The
/// variable will be built with a nullptr constructor and no decorations.
ast::Variable* Var(const std::string& name,
ast::StorageClass storage,
type::Type* type);
/// @param name the variable name
/// @param storage the variable storage class
/// @param type the variable type
@ -761,8 +758,11 @@ class ProgramBuilder {
ast::Variable* Var(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(Symbols().Register(name), storage, type, false,
constructor, decorations);
}
/// @param source the variable source
/// @param name the variable name
@ -775,17 +775,43 @@ class ProgramBuilder {
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(source, Symbols().Register(name), storage,
type, false, constructor, decorations);
}
/// @param name the variable name
/// @param symbol the variable symbol
/// @param storage the variable storage class
/// @param type the variable type
/// @returns a constant `ast::Variable` with the given name, storage and type.
/// The variable will be built with a nullptr constructor and no decorations.
ast::Variable* Const(const std::string& name,
ast::StorageClass storage,
type::Type* type);
/// @param constructor constructor expression
/// @param decorations variable decorations
/// @returns a `ast::Variable` with the given symbol, storage and type
ast::Variable* Var(Symbol symbol,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(symbol, storage, type, false, constructor,
decorations);
}
/// @param source the variable source
/// @param symbol the variable symbol
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor constructor expression
/// @param decorations variable decorations
/// @returns a `ast::Variable` with the given symbol, storage and type
ast::Variable* Var(const Source& source,
Symbol symbol,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(source, symbol, storage, type, false,
constructor, decorations);
}
/// @param name the variable name
/// @param storage the variable storage class
@ -796,8 +822,11 @@ class ProgramBuilder {
ast::Variable* Const(const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(Symbols().Register(name), storage, type, true,
constructor, decorations);
}
/// @param source the variable source
/// @param name the variable name
@ -810,9 +839,45 @@ class ProgramBuilder {
const std::string& name,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor,
ast::VariableDecorationList decorations);
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(source, Symbols().Register(name), storage,
type, true, constructor, decorations);
}
/// @param symbol the variable symbol
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor optional constructor expression
/// @param decorations optional variable decorations
/// @returns a constant `ast::Variable` with the given symbol, storage and
/// type
ast::Variable* Const(Symbol symbol,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(symbol, storage, type, true, constructor,
decorations);
}
/// @param source the variable source
/// @param symbol the variable symbol
/// @param storage the variable storage class
/// @param type the variable type
/// @param constructor optional constructor expression
/// @param decorations optional variable decorations
/// @returns a constant `ast::Variable` with the given symbol, storage and
/// type
ast::Variable* Const(const Source& source,
Symbol symbol,
ast::StorageClass storage,
type::Type* type,
ast::Expression* constructor = nullptr,
ast::VariableDecorationList decorations = {}) {
return create<ast::Variable>(source, symbol, storage, type, true,
constructor, decorations);
}
/// @param args the arguments to pass to Var()
/// @returns a `ast::Variable` constructed by calling Var() with the arguments
/// of `args`, which is automatically registered as a global variable with the