cppparser: Fix expansion of function macro used without parentheses

This commit is contained in:
rdb 2024-03-28 01:18:19 +01:00
parent 1213d95560
commit e63ba11af2
2 changed files with 8 additions and 19 deletions

View File

@ -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();
}
/**
*
*/

View File

@ -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);