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 Nov 5, 2024
1 parent 15e911f commit fd9851a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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 @@ -133,6 +133,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
19 changes: 13 additions & 6 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,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 @@ -2279,6 +2280,7 @@ impl Parser {
arguments,
result,
body,
diagnostic_filter_head,
};

// done
Expand Down Expand Up @@ -2339,17 +2341,16 @@ 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) {
let (name, name_span) = lexer.next_ident_with_span()?;
if let Some(DirectiveKind::Diagnostic) = DirectiveKind::from_ident(name) {
if let Some(_filter) = self.diagnostic_filter(lexer)? {
if let Some(filter) = self.diagnostic_filter(lexer)? {
let span = self.peek_rule_span(lexer);
return Err(Error::DiagnosticNotYetImplementedAtParseSite {
span,
site_name_plural: "functions",
});
diagnostic_filters.add(filter, span)?;
// TODO: ensure that it makes sense to apply this attribute
}
}
match name {
Expand Down Expand Up @@ -2491,7 +2492,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_leaf,
);
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 fd9851a

Please sign in to comment.