File tree Expand file tree Collapse file tree
c2rust-transpile/src/c_ast Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -821,7 +821,18 @@ class TranslateASTVisitor final
821821 if (encodeMacroInvocations) {
822822 for (auto I = curMacroInvocationStack.rbegin (), E = curMacroInvocationStack.rend ();
823823 I != E; ++I) {
824- cbor_encode_uint (&childEnc, uintptr_t (I->macro ));
824+ CborEncoder expansionEnc;
825+ cbor_encoder_create_array (&childEnc, &expansionEnc, 2 );
826+
827+ cbor_encode_uint (&expansionEnc, uintptr_t (I->macro ));
828+
829+ if (!I->parameter .empty ()) {
830+ cbor_encode_string (&expansionEnc, I->parameter .str ());
831+ } else {
832+ cbor_encode_null (&expansionEnc);
833+ }
834+
835+ cbor_encoder_close_container (&childEnc, &expansionEnc);
825836 }
826837 }
827838 cbor_encoder_close_container (&local, &childEnc);
Original file line number Diff line number Diff line change 1+ use serde:: Deserialize ;
12use serde_bytes:: ByteBuf ;
23use serde_cbor:: error;
34use std:: collections:: { HashMap , VecDeque } ;
@@ -108,11 +109,17 @@ pub struct AstNode {
108109 // Stack of macros this node was expanded from, beginning with the initial
109110 // macro call and ending with the leaf. This needs to be a stack for nested
110111 // macro definitions.
111- pub macro_invocations : Vec < u64 > ,
112+ pub macro_invocations : Vec < MacroInvocationInfoRaw > ,
112113 pub macro_invocation_text : Option < String > ,
113114 pub extras : Vec < Value > ,
114115}
115116
117+ #[ derive( Debug , Clone , Deserialize ) ]
118+ pub struct MacroInvocationInfoRaw {
119+ pub macro_id : u64 ,
120+ pub parameter : Option < String > ,
121+ }
122+
116123#[ derive( Debug , Clone ) ]
117124pub struct TypeNode {
118125 pub tag : TypeTag ,
@@ -260,7 +267,8 @@ pub fn process(items: Value) -> error::Result<AstContext> {
260267 } ;
261268
262269 // entry[10]
263- let macro_invocations = from_value :: < Vec < u64 > > ( entry. pop_front ( ) . unwrap ( ) ) . unwrap ( ) ;
270+ let macro_invocations =
271+ from_value :: < Vec < MacroInvocationInfoRaw > > ( entry. pop_front ( ) . unwrap ( ) ) . unwrap ( ) ;
264272
265273 let macro_invocation_text = expect_opt_str ( & entry. pop_front ( ) . unwrap ( ) )
266274 . unwrap ( )
Original file line number Diff line number Diff line change @@ -1024,8 +1024,8 @@ impl ConversionContext {
10241024 } ;
10251025
10261026 if expected_ty & EXPR != 0 {
1027- for mac_id in & node. macro_invocations {
1028- let mac = CDeclId ( self . visit_node_type ( * mac_id , MACRO_DECL ) ) ;
1027+ for info in & node. macro_invocations {
1028+ let mac = CDeclId ( self . visit_node_type ( info . macro_id , MACRO_DECL ) ) ;
10291029 self . typed_context
10301030 . macro_invocations
10311031 . entry ( CExprId ( new_id) )
You can’t perform that action at this time.
0 commit comments