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 @@ -822,7 +822,19 @@ class TranslateASTVisitor final
822822 if (encodeMacroInvocations) {
823823 for (auto I = curMacroInvocationStack.rbegin (), E = curMacroInvocationStack.rend ();
824824 I != E; ++I) {
825- cbor_encode_uint (&childEnc, uintptr_t (I->macro ));
825+ CborEncoder expansionEnc;
826+ cbor_encoder_create_array (&childEnc, &expansionEnc, 3 );
827+
828+ cbor_encode_uint (&expansionEnc, I->key );
829+ cbor_encode_uint (&expansionEnc, uintptr_t (I->macro ));
830+
831+ if (!I->parameter .empty ()) {
832+ cbor_encode_string (&expansionEnc, I->parameter .str ());
833+ } else {
834+ cbor_encode_null (&expansionEnc);
835+ }
836+
837+ cbor_encoder_close_container (&childEnc, &expansionEnc);
826838 }
827839 }
828840 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,18 @@ 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 key : u32 ,
120+ pub macro_id : u64 ,
121+ pub parameter : Option < String > ,
122+ }
123+
116124#[ derive( Debug , Clone ) ]
117125pub struct TypeNode {
118126 pub tag : TypeTag ,
@@ -260,7 +268,8 @@ pub fn process(items: Value) -> error::Result<AstContext> {
260268 } ;
261269
262270 // entry[10]
263- let macro_invocations = from_value :: < Vec < u64 > > ( entry. pop_front ( ) . unwrap ( ) ) . unwrap ( ) ;
271+ let macro_invocations =
272+ from_value :: < Vec < MacroInvocationInfoRaw > > ( entry. pop_front ( ) . unwrap ( ) ) . unwrap ( ) ;
264273
265274 let macro_invocation_text = expect_opt_str ( & entry. pop_front ( ) . unwrap ( ) )
266275 . unwrap ( )
Original file line number Diff line number Diff line change @@ -1047,8 +1047,8 @@ impl ConversionContext {
10471047 } ;
10481048
10491049 if expected_ty & EXPR != 0 {
1050- for mac_id in & node. macro_invocations {
1051- let mac = CDeclId ( self . visit_node_type ( * mac_id , MACRO_DECL ) ) ;
1050+ for info in & node. macro_invocations {
1051+ let mac = CDeclId ( self . visit_node_type ( info . macro_id , MACRO_DECL ) ) ;
10521052 self . typed_context
10531053 . macro_invocations
10541054 . entry ( CExprId ( new_id) )
You can’t perform that action at this time.
0 commit comments