mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Add Source parameter to decoration constructors
Once a `Decoration` has been parsed, it'll be placed into a `DecorationList` and validated later in the parse. In order to create error diagnostics that refer back to the decoration, we need to know its source. Bug: tint:282 Bug: tint:291 Change-Id: I38de708adbd041601b61d7e0a4d0402e9a2fe526 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31722 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
35298800a6
commit
34a2eb1999
@@ -635,7 +635,7 @@ bool FunctionEmitter::EmitFunctionDeclaration() {
|
||||
|
||||
if (ep_info_ != nullptr) {
|
||||
ast_fn->add_decoration(
|
||||
std::make_unique<ast::StageDecoration>(ep_info_->stage));
|
||||
std::make_unique<ast::StageDecoration>(ep_info_->stage, Source{}));
|
||||
}
|
||||
|
||||
ast_module_.AddFunction(std::move(ast_fn));
|
||||
|
||||
@@ -392,7 +392,8 @@ ParserImpl::ConvertMemberDecoration(uint32_t struct_type_id,
|
||||
<< ShowType(struct_type_id);
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<ast::StructMemberOffsetDecoration>(decoration[1]);
|
||||
return std::make_unique<ast::StructMemberOffsetDecoration>(decoration[1],
|
||||
Source{});
|
||||
case SpvDecorationNonReadable:
|
||||
// WGSL doesn't have a member decoration for this. Silently drop it.
|
||||
return nullptr;
|
||||
@@ -781,7 +782,8 @@ bool ParserImpl::ApplyArrayDecorations(
|
||||
<< ": multiple ArrayStride decorations";
|
||||
}
|
||||
ast::ArrayDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::StrideDecoration>(stride));
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StrideDecoration>(stride, Source{}));
|
||||
ast_type->set_decorations(std::move(decos));
|
||||
} else {
|
||||
return Fail() << "invalid array type ID " << type_id
|
||||
@@ -804,10 +806,10 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
const auto decoration = struct_decorations[0][0];
|
||||
if (decoration == SpvDecorationBlock) {
|
||||
ast_struct_decorations.push_back(
|
||||
std::make_unique<ast::StructBlockDecoration>());
|
||||
std::make_unique<ast::StructBlockDecoration>(Source{}));
|
||||
} else if (decoration == SpvDecorationBufferBlock) {
|
||||
ast_struct_decorations.push_back(
|
||||
std::make_unique<ast::StructBlockDecoration>());
|
||||
std::make_unique<ast::StructBlockDecoration>(Source{}));
|
||||
remap_buffer_block_type_.insert(type_id);
|
||||
} else {
|
||||
Fail() << "struct with ID " << type_id
|
||||
@@ -1006,7 +1008,8 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||
ast::VariableDecorationList spec_id_decos;
|
||||
for (const auto& deco : GetDecorationsFor(inst.result_id())) {
|
||||
if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) {
|
||||
auto cid = std::make_unique<ast::ConstantIdDecoration>(deco[1]);
|
||||
auto cid =
|
||||
std::make_unique<ast::ConstantIdDecoration>(deco[1], Source{});
|
||||
spec_id_decos.push_back(std::move(cid));
|
||||
break;
|
||||
}
|
||||
@@ -1142,8 +1145,8 @@ bool ParserImpl::EmitModuleScopeVariables() {
|
||||
enum_converter_.ToStorageClass(builtin_position_.storage_class),
|
||||
ConvertType(builtin_position_.member_type_id)));
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(
|
||||
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kPosition));
|
||||
decos.push_back(std::make_unique<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kPosition, Source{}));
|
||||
var->set_decorations(std::move(decos));
|
||||
|
||||
ast_module_.AddGlobalVariable(std::move(var));
|
||||
@@ -1188,7 +1191,7 @@ std::unique_ptr<ast::Variable> ParserImpl::MakeVariable(uint32_t id,
|
||||
return nullptr;
|
||||
}
|
||||
ast_decorations.emplace_back(
|
||||
std::make_unique<ast::BuiltinDecoration>(ast_builtin));
|
||||
std::make_unique<ast::BuiltinDecoration>(ast_builtin, Source{}));
|
||||
}
|
||||
if (deco[0] == SpvDecorationLocation) {
|
||||
if (deco.size() != 2) {
|
||||
@@ -1197,7 +1200,7 @@ std::unique_ptr<ast::Variable> ParserImpl::MakeVariable(uint32_t id,
|
||||
return nullptr;
|
||||
}
|
||||
ast_decorations.emplace_back(
|
||||
std::make_unique<ast::LocationDecoration>(deco[1]));
|
||||
std::make_unique<ast::LocationDecoration>(deco[1], Source{}));
|
||||
}
|
||||
if (deco[0] == SpvDecorationDescriptorSet) {
|
||||
if (deco.size() == 1) {
|
||||
@@ -1206,7 +1209,7 @@ std::unique_ptr<ast::Variable> ParserImpl::MakeVariable(uint32_t id,
|
||||
return nullptr;
|
||||
}
|
||||
ast_decorations.emplace_back(
|
||||
std::make_unique<ast::SetDecoration>(deco[1]));
|
||||
std::make_unique<ast::SetDecoration>(deco[1], Source{}));
|
||||
}
|
||||
if (deco[0] == SpvDecorationBinding) {
|
||||
if (deco.size() == 1) {
|
||||
@@ -1215,7 +1218,7 @@ std::unique_ptr<ast::Variable> ParserImpl::MakeVariable(uint32_t id,
|
||||
return nullptr;
|
||||
}
|
||||
ast_decorations.emplace_back(
|
||||
std::make_unique<ast::BindingDecoration>(deco[1]));
|
||||
std::make_unique<ast::BindingDecoration>(deco[1], Source{}));
|
||||
}
|
||||
}
|
||||
if (!ast_decorations.empty()) {
|
||||
|
||||
@@ -439,6 +439,7 @@ bool ParserImpl::variable_decoration_list(ast::VariableDecorationList& decos) {
|
||||
// | SET INT PAREN_LEFT_LITERAL PAREN_RIGHT
|
||||
std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||
auto t = peek();
|
||||
auto source = t.source();
|
||||
if (t.IsLocation()) {
|
||||
next(); // consume the peek
|
||||
|
||||
@@ -460,7 +461,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||
set_error(t, "missing ) for location decoration");
|
||||
return {};
|
||||
}
|
||||
return std::make_unique<ast::LocationDecoration>(val);
|
||||
return std::make_unique<ast::LocationDecoration>(val, source);
|
||||
}
|
||||
if (t.IsBuiltin()) {
|
||||
next(); // consume the peek
|
||||
@@ -488,7 +489,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||
set_error(t, "missing ) for builtin decoration");
|
||||
return {};
|
||||
}
|
||||
return std::make_unique<ast::BuiltinDecoration>(builtin);
|
||||
return std::make_unique<ast::BuiltinDecoration>(builtin, source);
|
||||
}
|
||||
if (t.IsBinding()) {
|
||||
next(); // consume the peek
|
||||
@@ -512,7 +513,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::make_unique<ast::BindingDecoration>(val);
|
||||
return std::make_unique<ast::BindingDecoration>(val, source);
|
||||
}
|
||||
if (t.IsSet()) {
|
||||
next(); // consume the peek
|
||||
@@ -536,7 +537,7 @@ std::unique_ptr<ast::VariableDecoration> ParserImpl::variable_decoration() {
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::make_unique<ast::SetDecoration>(val);
|
||||
return std::make_unique<ast::SetDecoration>(val, source);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@@ -1335,6 +1336,9 @@ bool ParserImpl::array_decoration_list(ast::ArrayDecorationList& decos) {
|
||||
|
||||
for (;;) {
|
||||
t = next();
|
||||
|
||||
auto source = t.source();
|
||||
|
||||
if (!t.IsStride()) {
|
||||
set_error(t, "unknown array decoration");
|
||||
return false;
|
||||
@@ -1356,7 +1360,7 @@ bool ParserImpl::array_decoration_list(ast::ArrayDecorationList& decos) {
|
||||
return false;
|
||||
}
|
||||
uint32_t stride = static_cast<uint32_t>(t.to_i32());
|
||||
decos.push_back(std::make_unique<ast::StrideDecoration>(stride));
|
||||
decos.push_back(std::make_unique<ast::StrideDecoration>(stride, source));
|
||||
|
||||
t = next();
|
||||
if (!t.IsParenRight()) {
|
||||
@@ -1546,7 +1550,7 @@ bool ParserImpl::struct_decoration_decl(ast::StructDecorationList& decos) {
|
||||
// : BLOCK
|
||||
std::unique_ptr<ast::StructDecoration> ParserImpl::struct_decoration(Token t) {
|
||||
if (t.IsBlock()) {
|
||||
return std::make_unique<ast::StructBlockDecoration>();
|
||||
return std::make_unique<ast::StructBlockDecoration>(t.source());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1677,6 +1681,8 @@ ParserImpl::struct_member_decoration() {
|
||||
if (!t.IsOffset())
|
||||
return nullptr;
|
||||
|
||||
auto source = t.source();
|
||||
|
||||
next(); // Consume the peek
|
||||
|
||||
t = next();
|
||||
@@ -1702,7 +1708,7 @@ ParserImpl::struct_member_decoration() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_unique<ast::StructMemberOffsetDecoration>(val);
|
||||
return std::make_unique<ast::StructMemberOffsetDecoration>(val, source);
|
||||
}
|
||||
|
||||
// function_decl
|
||||
@@ -1797,6 +1803,7 @@ bool ParserImpl::function_decoration_decl(ast::FunctionDecorationList& decos) {
|
||||
// (COMMA INT_LITERAL (COMMA INT_LITERAL)?)? PAREN_RIGHT
|
||||
std::unique_ptr<ast::FunctionDecoration> ParserImpl::function_decoration() {
|
||||
auto t = peek();
|
||||
auto source = t.source();
|
||||
if (t.IsWorkgroupSize()) {
|
||||
next(); // Consume the peek
|
||||
|
||||
@@ -1858,7 +1865,7 @@ std::unique_ptr<ast::FunctionDecoration> ParserImpl::function_decoration() {
|
||||
}
|
||||
|
||||
return std::make_unique<ast::WorkgroupDecoration>(uint32_t(x), uint32_t(y),
|
||||
uint32_t(z));
|
||||
uint32_t(z), source);
|
||||
}
|
||||
if (t.IsStage()) {
|
||||
next(); // Consume the peek
|
||||
@@ -1883,7 +1890,7 @@ std::unique_ptr<ast::FunctionDecoration> ParserImpl::function_decoration() {
|
||||
set_error(t, "missing ) for stage decoration");
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<ast::StageDecoration>(stage);
|
||||
return std::make_unique<ast::StageDecoration>(stage, source);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user