ProgramBuilder: make Const helpers require a constructor arg
This was originally used to find and fix tests that were not initializing constants, but these were independently fixed by jrprice@ recently (see https://dawn-review.googlesource.com/c/tint/+/50042) recently. Still, this change is useful to avoid this happening again. Bug: tint:792 Change-Id: I0119a1a6ade7a70a0d110ef0aac80f4eaf37a7b4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50560 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
a083f329a7
commit
e0448d3d64
|
@ -1218,13 +1218,13 @@ class ProgramBuilder {
|
|||
|
||||
/// @param name the variable name
|
||||
/// @param type the variable type
|
||||
/// @param constructor optional constructor expression
|
||||
/// @param constructor constructor expression
|
||||
/// @param decorations optional variable decorations
|
||||
/// @returns a constant `ast::Variable` with the given name and type
|
||||
template <typename NAME>
|
||||
ast::Variable* Const(NAME&& name,
|
||||
ast::Type* type,
|
||||
ast::Expression* constructor = nullptr,
|
||||
ast::Expression* constructor,
|
||||
ast::DecorationList decorations = {}) {
|
||||
type = ty.MaybeCreateTypename(type);
|
||||
return create<ast::Variable>(Sym(std::forward<NAME>(name)),
|
||||
|
@ -1235,14 +1235,14 @@ class ProgramBuilder {
|
|||
/// @param source the variable source
|
||||
/// @param name the variable name
|
||||
/// @param type the variable type
|
||||
/// @param constructor optional constructor expression
|
||||
/// @param constructor constructor expression
|
||||
/// @param decorations optional variable decorations
|
||||
/// @returns a constant `ast::Variable` with the given name and type
|
||||
template <typename NAME>
|
||||
ast::Variable* Const(const Source& source,
|
||||
NAME&& name,
|
||||
ast::Type* type,
|
||||
ast::Expression* constructor = nullptr,
|
||||
ast::Expression* constructor,
|
||||
ast::DecorationList decorations = {}) {
|
||||
type = ty.MaybeCreateTypename(type);
|
||||
return create<ast::Variable>(source, Sym(std::forward<NAME>(name)),
|
||||
|
@ -1320,13 +1320,40 @@ class ProgramBuilder {
|
|||
return var;
|
||||
}
|
||||
|
||||
/// @param args the arguments to pass to Const()
|
||||
/// @param name the variable name
|
||||
/// @param type the variable type
|
||||
/// @param constructor constructor expression
|
||||
/// @param decorations optional variable decorations
|
||||
/// @returns a const `ast::Variable` constructed by calling Var() with the
|
||||
/// arguments of `args`, which is automatically registered as a global
|
||||
/// variable with the ast::Module.
|
||||
template <typename... ARGS>
|
||||
ast::Variable* GlobalConst(ARGS&&... args) {
|
||||
auto* var = Const(std::forward<ARGS>(args)...);
|
||||
template <typename NAME>
|
||||
ast::Variable* GlobalConst(NAME&& name,
|
||||
typ::Type type,
|
||||
ast::Expression* constructor,
|
||||
ast::DecorationList decorations = {}) {
|
||||
auto* var = Const(std::forward<NAME>(name), type, constructor,
|
||||
std::move(decorations));
|
||||
AST().AddGlobalVariable(var);
|
||||
return var;
|
||||
}
|
||||
|
||||
/// @param source the variable source
|
||||
/// @param name the variable name
|
||||
/// @param type the variable type
|
||||
/// @param constructor constructor expression
|
||||
/// @param decorations optional variable decorations
|
||||
/// @returns a const `ast::Variable` constructed by calling Var() with the
|
||||
/// arguments of `args`, which is automatically registered as a global
|
||||
/// variable with the ast::Module.
|
||||
template <typename NAME>
|
||||
ast::Variable* GlobalConst(const Source& source,
|
||||
NAME&& name,
|
||||
typ::Type type,
|
||||
ast::Expression* constructor,
|
||||
ast::DecorationList decorations = {}) {
|
||||
auto* var = Const(source, std::forward<NAME>(name), type, constructor,
|
||||
std::move(decorations));
|
||||
AST().AddGlobalVariable(var);
|
||||
return var;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue