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 @@ -816,7 +816,18 @@ class TranslateASTVisitor final
816816 if (encodeMacroInvocations) {
817817 for (auto I = curMacroInvocationStack.rbegin (), E = curMacroInvocationStack.rend ();
818818 I != E; ++I) {
819- cbor_encode_uint (&childEnc, uintptr_t (I->macro ));
819+ CborEncoder expansionEnc;
820+ cbor_encoder_create_array (&childEnc, &expansionEnc, 2 );
821+
822+ cbor_encode_uint (&expansionEnc, uintptr_t (I->macro ));
823+
824+ if (!I->parameter .empty ()) {
825+ cbor_encode_string (&expansionEnc, I->parameter .str ());
826+ } else {
827+ cbor_encode_null (&expansionEnc);
828+ }
829+
830+ cbor_encoder_close_container (&childEnc, &expansionEnc);
820831 }
821832 }
822833 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 @@ -985,8 +985,8 @@ impl ConversionContext {
985985 } ;
986986
987987 if expected_ty & EXPR != 0 {
988- for mac_id in & node. macro_invocations {
989- let mac = CDeclId ( self . visit_node_type ( * mac_id , MACRO_DECL ) ) ;
988+ for info in & node. macro_invocations {
989+ let mac = CDeclId ( self . visit_node_type ( info . macro_id , MACRO_DECL ) ) ;
990990 self . typed_context
991991 . macro_invocations
992992 . entry ( CExprId ( new_id) )
You can’t perform that action at this time.
0 commit comments