Przeglądaj źródła

cppparser: don't expand function-style macro if not followed by (

rdb 6 lat temu
rodzic
commit
657af0edb5
1 zmienionych plików z 16 dodań i 1 usunięć
  1. 16 1
      dtool/src/cppparser/cppPreprocessor.cxx

+ 16 - 1
dtool/src/cppparser/cppPreprocessor.cxx

@@ -1942,7 +1942,22 @@ get_identifier(int c) {
   // Is it a manifest?
   // Is it a manifest?
   Manifests::const_iterator mi = _manifests.find(name);
   Manifests::const_iterator mi = _manifests.find(name);
   if (mi != _manifests.end() && !should_ignore_manifest((*mi).second)) {
   if (mi != _manifests.end() && !should_ignore_manifest((*mi).second)) {
-    return expand_manifest((*mi).second);
+    // If the manifest is expecting arguments, we don't expand it unless the
+    // the next token is an open-parenthesis.
+    CPPManifest *manifest = (*mi).second;
+    if (manifest->_has_parameters) {
+      while (c != EOF && isspace(c)) {
+        get();
+        c = peek();
+      }
+      if (c == '(') {
+        // It is followed by a parenthesis, so we can expand this.
+        return expand_manifest(manifest);
+      }
+    } else {
+      // Non-function-like macros are always expanded.
+      return expand_manifest(manifest);
+    }
   }
   }
   if (name == "__FILE__") {
   if (name == "__FILE__") {
     return get_literal(SIMPLE_STRING, loc, loc.file._filename_as_referenced);
     return get_literal(SIMPLE_STRING, loc, loc.file._filename_as_referenced);