MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / parse_attrs_for_checking

Function parse_attrs_for_checking

crates/rustc_codegen_spirv/src/symbols.rs:424–505  ·  view source on GitHub ↗

FIXME(eddyb) maybe move this to `attr`?

(
    sym: &'a Symbols,
    attrs: &'a [Attribute],
)

Source from the content-addressed store, hash-verified

422
423// FIXME(eddyb) maybe move this to `attr`?
424pub(crate) fn parse_attrs_for_checking<'a>(
425 sym: &'a Symbols,
426 attrs: &'a [Attribute],
427) -> impl Iterator<Item = Result<(Span, SpirvAttribute), ParseAttrError>> + 'a {
428 attrs.iter().flat_map(move |attr| {
429 let (whole_attr_error, args) = match attr.kind {
430 AttrKind::Normal(ref normal) => {
431 // #[...]
432 let s = &normal.item.path.segments;
433 if s.len() > 1 && s[0].ident.name == sym.rust_gpu {
434 // #[rust_gpu ...]
435 if s.len() != 2 || s[1].ident.name != sym.spirv {
436 // #[rust_gpu::...] but not #[rust_gpu::spirv]
437 (
438 Some(Err((
439 attr.span,
440 "unknown `rust_gpu` attribute, expected `rust_gpu::spirv`"
441 .to_string(),
442 ))),
443 Default::default(),
444 )
445 } else if let Some(args) = attr.meta_item_list() {
446 // #[rust_gpu::spirv(...)]
447 (None, args)
448 } else {
449 // #[rust_gpu::spirv]
450 (
451 Some(Err((
452 attr.span,
453 "#[rust_gpu::spirv(..)] attribute must have at least one argument"
454 .to_string(),
455 ))),
456 Default::default(),
457 )
458 }
459 } else {
460 // #[...] but not #[rust_gpu ...]
461 (None, Default::default())
462 }
463 }
464 AttrKind::DocComment(..) => (None, Default::default()), // doccomment
465 };
466
467 whole_attr_error
468 .into_iter()
469 .chain(args.into_iter().map(move |ref arg| {
470 let span = arg.span();
471 let parsed_attr = if arg.has_name(sym.descriptor_set) {
472 SpirvAttribute::DescriptorSet(parse_attr_int_value(arg)?)
473 } else if arg.has_name(sym.binding) {
474 SpirvAttribute::Binding(parse_attr_int_value(arg)?)
475 } else if arg.has_name(sym.input_attachment_index) {
476 SpirvAttribute::InputAttachmentIndex(parse_attr_int_value(arg)?)
477 } else if arg.has_name(sym.spec_constant) {
478 SpirvAttribute::SpecConstant(parse_spec_constant_attr(sym, arg)?)
479 } else {
480 let name = match arg.ident() {
481 Some(i) => i,

Callers 2

parseMethod · 0.85

Calls 9

parse_attr_int_valueFunction · 0.85
SpecConstantClass · 0.85
parse_spec_constant_attrFunction · 0.85
EntryClass · 0.85
parse_entry_attrsFunction · 0.85
iterMethod · 0.80
into_iterMethod · 0.80
spanMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected