mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-08 13:09:10 +00:00
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 name the variable name
|
||||||
/// @param type the variable type
|
/// @param type the variable type
|
||||||
/// @param constructor optional constructor expression
|
/// @param constructor constructor expression
|
||||||
/// @param decorations optional variable decorations
|
/// @param decorations optional variable decorations
|
||||||
/// @returns a constant `ast::Variable` with the given name and type
|
/// @returns a constant `ast::Variable` with the given name and type
|
||||||
template <typename NAME>
|
template <typename NAME>
|
||||||
ast::Variable* Const(NAME&& name,
|
ast::Variable* Const(NAME&& name,
|
||||||
ast::Type* type,
|
ast::Type* type,
|
||||||
ast::Expression* constructor = nullptr,
|
ast::Expression* constructor,
|
||||||
ast::DecorationList decorations = {}) {
|
ast::DecorationList decorations = {}) {
|
||||||
type = ty.MaybeCreateTypename(type);
|
type = ty.MaybeCreateTypename(type);
|
||||||
return create<ast::Variable>(Sym(std::forward<NAME>(name)),
|
return create<ast::Variable>(Sym(std::forward<NAME>(name)),
|
||||||
@ -1235,14 +1235,14 @@ class ProgramBuilder {
|
|||||||
/// @param source the variable source
|
/// @param source the variable source
|
||||||
/// @param name the variable name
|
/// @param name the variable name
|
||||||
/// @param type the variable type
|
/// @param type the variable type
|
||||||
/// @param constructor optional constructor expression
|
/// @param constructor constructor expression
|
||||||
/// @param decorations optional variable decorations
|
/// @param decorations optional variable decorations
|
||||||
/// @returns a constant `ast::Variable` with the given name and type
|
/// @returns a constant `ast::Variable` with the given name and type
|
||||||
template <typename NAME>
|
template <typename NAME>
|
||||||
ast::Variable* Const(const Source& source,
|
ast::Variable* Const(const Source& source,
|
||||||
NAME&& name,
|
NAME&& name,
|
||||||
ast::Type* type,
|
ast::Type* type,
|
||||||
ast::Expression* constructor = nullptr,
|
ast::Expression* constructor,
|
||||||
ast::DecorationList decorations = {}) {
|
ast::DecorationList decorations = {}) {
|
||||||
type = ty.MaybeCreateTypename(type);
|
type = ty.MaybeCreateTypename(type);
|
||||||
return create<ast::Variable>(source, Sym(std::forward<NAME>(name)),
|
return create<ast::Variable>(source, Sym(std::forward<NAME>(name)),
|
||||||
@ -1320,13 +1320,40 @@ class ProgramBuilder {
|
|||||||
return var;
|
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
|
/// @returns a const `ast::Variable` constructed by calling Var() with the
|
||||||
/// arguments of `args`, which is automatically registered as a global
|
/// arguments of `args`, which is automatically registered as a global
|
||||||
/// variable with the ast::Module.
|
/// variable with the ast::Module.
|
||||||
template <typename... ARGS>
|
template <typename NAME>
|
||||||
ast::Variable* GlobalConst(ARGS&&... args) {
|
ast::Variable* GlobalConst(NAME&& name,
|
||||||
auto* var = Const(std::forward<ARGS>(args)...);
|
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);
|
AST().AddGlobalVariable(var);
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user