瀏覽代碼

cppparser: Fix expansion of function macro used without parentheses

rdb 1 年之前
父節點
當前提交
e63ba11af2
共有 2 個文件被更改,包括 8 次插入19 次删除
  1. 8 17
      dtool/src/cppparser/cppPreprocessor.cxx
  2. 0 2
      dtool/src/cppparser/cppPreprocessor.h

+ 8 - 17
dtool/src/cppparser/cppPreprocessor.cxx

@@ -2233,6 +2233,14 @@ r_expand_manifests(string &expr, bool expand_undefined,
           if (expanded.count(manifest) == 0) {
             vector_string args;
             if (manifest->_has_parameters) {
+              // If it's not followed by a parenthesis, don't expand it.
+              while (p < expr.size() && isspace(expr[p])) {
+                p++;
+              }
+              if (p >= expr.size() || expr[p] != '(') {
+                continue;
+              }
+
               extract_manifest_args_inline(manifest->_name, manifest->_num_parameters,
                                            manifest->_variadic_param, args, expr, p);
             }
@@ -2502,23 +2510,6 @@ expand_has_include_function(string &expr, size_t q, size_t &p, YYLTYPE loc) {
   p = q + result.size();
 }
 
-/**
- *
- */
-void CPPPreprocessor::
-expand_manifest_inline(string &expr, size_t q, size_t &p,
-                       const CPPManifest *manifest) {
-  vector_string args;
-  if (manifest->_has_parameters) {
-    extract_manifest_args_inline(manifest->_name, manifest->_num_parameters,
-                                 manifest->_variadic_param, args, expr, p);
-  }
-  string result = manifest->expand(args);
-
-  expr = expr.substr(0, q) + result + expr.substr(p);
-  p = q + result.size();
-}
-
 /**
  *
  */

+ 0 - 2
dtool/src/cppparser/cppPreprocessor.h

@@ -160,8 +160,6 @@ private:
                              int va_arg, vector_string &args);
   void expand_defined_function(std::string &expr, size_t q, size_t &p);
   void expand_has_include_function(std::string &expr, size_t q, size_t &p, YYLTYPE loc);
-  void expand_manifest_inline(std::string &expr, size_t q, size_t &p,
-                              const CPPManifest *manifest);
   void extract_manifest_args_inline(const std::string &name, int num_args,
                                     int va_arg, vector_string &args,
                                     const std::string &expr, size_t &p);