Skip to content

Commit

Permalink
WIP: feat(wgsl-in): parse diagnostic attrs. on fns
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Oct 3, 2024
1 parent cf23d97 commit 3cc8523
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions naga/src/front/wgsl/parse/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub struct Function<'a> {
pub arguments: Vec<FunctionArgument<'a>>,
pub result: Option<FunctionResult<'a>>,
pub body: Block<'a>,
pub diagnostic_filter_head: Option<Handle<DiagnosticFilterNode>>,
}

#[derive(Debug)]
Expand Down
18 changes: 17 additions & 1 deletion naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,7 @@ impl Parser {
fn function_decl<'a>(
&mut self,
lexer: &mut Lexer<'a>,
diagnostic_filter_head: Option<Handle<DiagnosticFilterNode>>,
out: &mut ast::TranslationUnit<'a>,
dependencies: &mut FastIndexSet<ast::Dependency<'a>>,
) -> Result<ast::Function<'a>, Error<'a>> {
Expand Down Expand Up @@ -2251,6 +2252,7 @@ impl Parser {
arguments,
result,
body,
diagnostic_filter_head,
};

// done
Expand Down Expand Up @@ -2282,6 +2284,7 @@ impl Parser {
types: &mut out.types,
unresolved: &mut dependencies,
};
let mut diagnostic_filters = DiagnosticFilterMap::new();

self.push_rule_span(Rule::Attribute, lexer);
while lexer.skip(Token::Attribute) {
Expand All @@ -2291,6 +2294,13 @@ impl Parser {
bind_index.set(self.general_expression(lexer, &mut ctx)?, name_span)?;
lexer.expect(Token::Paren(')'))?;
}
("diagnostic", _name_span) => {
if let Some(filter) = self.diagnostic_filter(lexer)? {
let span = self.peek_rule_span(lexer);
diagnostic_filters.add(filter, span)?;
// TODO: ensure that it makes sense to apply this attribute
}
}
("group", name_span) => {
lexer.expect(Token::Paren('('))?;
bind_group.set(self.general_expression(lexer, &mut ctx)?, name_span)?;
Expand Down Expand Up @@ -2424,7 +2434,13 @@ impl Parser {
Some(ast::GlobalDeclKind::Var(var))
}
(Token::Word("fn"), _) => {
let function = self.function_decl(lexer, out, &mut dependencies)?;
let diagnostic_filter_head = Self::write_diagnostic_filters(
&mut out.diagnostic_filters,
diagnostic_filters,
out.diagnostic_filter_head,
);
let function =
self.function_decl(lexer, diagnostic_filter_head, out, &mut dependencies)?;
Some(ast::GlobalDeclKind::Fn(ast::Function {
entry_point: if let Some(stage) = stage.value {
if stage == ShaderStage::Compute && workgroup_size.value.is_none() {
Expand Down

0 comments on commit 3cc8523

Please sign in to comment.