macros: Parse :meta properly

This allows us to match attribute bodies in macro invocations, which we
can use later down the line to perform conditional compilation
This commit is contained in:
Arthur Cohen 2022-03-24 15:55:42 +01:00
parent 6c99a5a8f1
commit 7fa6e72b1a
3 changed files with 26 additions and 6 deletions

View File

@ -490,11 +490,7 @@ MacroExpander::match_fragment (Parser<MacroInvocLexer> &parser,
// is meta attributes?
case AST::MacroFragSpec::META:
// parser.parse_inner_attribute ?
// parser.parse_outer_attribute ?
// parser.parse_attribute_body ?
// parser.parse_doc_comment ?
gcc_unreachable ();
parser.parse_attribute_body ();
break;
case AST::MacroFragSpec::TT:

View File

@ -143,6 +143,7 @@ public:
AST::Visibility parse_visibility ();
std::unique_ptr<AST::IdentifierPattern> parse_identifier_pattern ();
std::unique_ptr<AST::TokenTree> parse_token_tree ();
AST::Attribute parse_attribute_body ();
private:
void skip_after_semicolon ();
@ -162,7 +163,6 @@ private:
AST::Attribute parse_inner_attribute ();
AST::AttrVec parse_outer_attributes ();
AST::Attribute parse_outer_attribute ();
AST::Attribute parse_attribute_body ();
std::unique_ptr<AST::AttrInput> parse_attr_input ();
AST::Attribute parse_doc_comment ();

View File

@ -0,0 +1,24 @@
// { dg-additional-options "-frust-cfg=A" }
macro_rules! attr {
(#[$attr:meta] $s:stmt) => {
#[$attr]
$s;
};
}
fn main() -> i32 {
let mut a = 0;
attr! {
#[cfg(A)]
a = 3
};
attr! {
#[cfg(B)]
a = 40
};
a - 3
}