File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -973,6 +973,21 @@ impl TypedAstContext {
973973 }
974974 }
975975
976+ /// Sort the top-level declarations with macros coming last.
977+ /// This is needed during conversion so that when recreating macros,
978+ /// we can look up the [`Translation::expr_override_tys`],
979+ /// which are set when the macro expansion expressions are converted.
980+ pub fn sort_top_decls_for_converting ( & mut self ) {
981+ self . c_decls_top . sort_unstable_by_key ( |decl_id| {
982+ let reverse_order = match self . c_decls . get ( decl_id) . unwrap ( ) . kind {
983+ CDeclKind :: MacroFunction { .. } => 0 ,
984+ CDeclKind :: MacroObject { .. } => 1 ,
985+ _ => 2 ,
986+ } ;
987+ -reverse_order
988+ } ) ;
989+ }
990+
976991 /// Sort the top-level declarations by file and source location
977992 /// so that we preserve the ordering of all declarations in each file.
978993 /// This preserves the order when we emit the converted declarations.
Original file line number Diff line number Diff line change @@ -681,6 +681,8 @@ pub fn translate(
681681 }
682682 }
683683
684+ t. ast_context . sort_top_decls_for_converting ( ) ;
685+
684686 // Export top-level value declarations.
685687 // We do this in a conversion pass and then an insertion pass
686688 // so that the conversion order can differ from the order they're emitted in.
You can’t perform that action at this time.
0 commit comments