diff --git a/src/program_builder.cc b/src/program_builder.cc index 780da734d3..11b960d5b7 100644 --- a/src/program_builder.cc +++ b/src/program_builder.cc @@ -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(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(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(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(source, Symbols().Register(name), storage, type, - true, constructor, decorations); -} - ast::VariableDeclStatement* ProgramBuilder::WrapInStatement(ast::Variable* v) { return create(v); } diff --git a/src/program_builder.h b/src/program_builder.h index c7c8bb5df0..22ccfe23f9 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -494,6 +494,12 @@ class ProgramBuilder { return create(Symbols().Register(name)); } + /// @param symbol the identifier symbol + /// @return an ast::IdentifierExpression with the given symbol + ast::IdentifierExpression* Expr(Symbol symbol) { + return create(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)...)); } - /// @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(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(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(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(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(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(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(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(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