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:
parent
faca02d438
commit
46d78d731b
|
@ -91,56 +91,6 @@ type::Type* ProgramBuilder::TypeOf(ast::Expression* expr) const {
|
||||||
|
|
||||||
ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
|
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) {
|
ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(ast::Variable* v) {
|
||||||
return create<ast::VariableDeclStatement>(v);
|
return create<ast::VariableDeclStatement>(v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,6 +494,12 @@ class ProgramBuilder {
|
||||||
return create<ast::IdentifierExpression>(Symbols().Register(name));
|
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 source the source information
|
||||||
/// @param name the identifier name
|
/// @param name the identifier name
|
||||||
/// @return an ast::IdentifierExpression with the given name
|
/// @return an ast::IdentifierExpression with the given name
|
||||||
|
@ -743,15 +749,6 @@ class ProgramBuilder {
|
||||||
ty.array(subtype, n), ExprList(std::forward<ARGS>(args)...));
|
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 name the variable name
|
||||||
/// @param storage the variable storage class
|
/// @param storage the variable storage class
|
||||||
/// @param type the variable type
|
/// @param type the variable type
|
||||||
|
@ -761,8 +758,11 @@ class ProgramBuilder {
|
||||||
ast::Variable* Var(const std::string& name,
|
ast::Variable* Var(const std::string& name,
|
||||||
ast::StorageClass storage,
|
ast::StorageClass storage,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor = nullptr,
|
||||||
ast::VariableDecorationList decorations);
|
ast::VariableDecorationList decorations = {}) {
|
||||||
|
return create<ast::Variable>(Symbols().Register(name), storage, type, false,
|
||||||
|
constructor, decorations);
|
||||||
|
}
|
||||||
|
|
||||||
/// @param source the variable source
|
/// @param source the variable source
|
||||||
/// @param name the variable name
|
/// @param name the variable name
|
||||||
|
@ -775,17 +775,43 @@ class ProgramBuilder {
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
ast::StorageClass storage,
|
ast::StorageClass storage,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor = nullptr,
|
||||||
ast::VariableDecorationList decorations);
|
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 storage the variable storage class
|
||||||
/// @param type the variable type
|
/// @param type the variable type
|
||||||
/// @returns a constant `ast::Variable` with the given name, storage and type.
|
/// @param constructor constructor expression
|
||||||
/// The variable will be built with a nullptr constructor and no decorations.
|
/// @param decorations variable decorations
|
||||||
ast::Variable* Const(const std::string& name,
|
/// @returns a `ast::Variable` with the given symbol, storage and type
|
||||||
|
ast::Variable* Var(Symbol symbol,
|
||||||
ast::StorageClass storage,
|
ast::StorageClass storage,
|
||||||
type::Type* type);
|
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 name the variable name
|
||||||
/// @param storage the variable storage class
|
/// @param storage the variable storage class
|
||||||
|
@ -796,8 +822,11 @@ class ProgramBuilder {
|
||||||
ast::Variable* Const(const std::string& name,
|
ast::Variable* Const(const std::string& name,
|
||||||
ast::StorageClass storage,
|
ast::StorageClass storage,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor = nullptr,
|
||||||
ast::VariableDecorationList decorations);
|
ast::VariableDecorationList decorations = {}) {
|
||||||
|
return create<ast::Variable>(Symbols().Register(name), storage, type, true,
|
||||||
|
constructor, decorations);
|
||||||
|
}
|
||||||
|
|
||||||
/// @param source the variable source
|
/// @param source the variable source
|
||||||
/// @param name the variable name
|
/// @param name the variable name
|
||||||
|
@ -810,9 +839,45 @@ class ProgramBuilder {
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
ast::StorageClass storage,
|
ast::StorageClass storage,
|
||||||
type::Type* type,
|
type::Type* type,
|
||||||
ast::Expression* constructor,
|
ast::Expression* constructor = nullptr,
|
||||||
ast::VariableDecorationList decorations);
|
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()
|
/// @param args the arguments to pass to Var()
|
||||||
/// @returns a `ast::Variable` constructed by calling Var() with the arguments
|
/// @returns a `ast::Variable` constructed by calling Var() with the arguments
|
||||||
/// of `args`, which is automatically registered as a global variable with the
|
/// of `args`, which is automatically registered as a global variable with the
|
||||||
|
|
Loading…
Reference in New Issue