Browse Source

cppparser: Perform macro expansion on macro arguments

Fixes #1638
rdb 1 year ago
parent
commit
c923cf6ee5
1 changed files with 13 additions and 2 deletions
  1. 13 2
      dtool/src/cppparser/cppPreprocessor.cxx

+ 13 - 2
dtool/src/cppparser/cppPreprocessor.cxx

@@ -2180,8 +2180,12 @@ expand_manifest(const CPPManifest *manifest, const YYLTYPE &loc) {
                           manifest->_variadic_param, args);
   }
 
-  string expanded = " " + manifest->expand(args) + " ";
-  push_string(expanded, true);
+  // Perform expansion on the macro arguments.
+  for (string &arg : args) {
+    std::set<const CPPManifest *> expanded;
+    expanded.insert(manifest);
+    r_expand_manifests(arg, false, loc, expanded);
+  }
 
   string expanded = " " + manifest->expand(args) + " ";
   push_expansion(expanded, manifest, loc);
@@ -2228,6 +2232,13 @@ r_expand_manifests(string &expr, bool expand_undefined,
                                            manifest->_variadic_param, args, expr, p);
             }
 
+            // Perform expansion on the macro arguments.
+            for (string &arg : args) {
+              std::set<const CPPManifest *> ignore = expanded;
+              ignore.insert(manifest);
+              r_expand_manifests(arg, expand_undefined, loc, ignore);
+            }
+
             string result = manifest->expand(args);
 
             // Recurse, but adding the manifest we just expanded to the list