Skip to content

Commit 8eee9e2

Browse files
committed
fix #452
1 parent 175750e commit 8eee9e2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

simplecpp.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
28182818

28192819
static const char * const altopData[] = {"and","or","bitand","bitor","compl","not","not_eq","xor"};
28202820
static const std::set<std::string> altop(&altopData[0], &altopData[8]);
2821-
static void simplifyName(simplecpp::TokenList &expr)
2821+
static bool simplifyName(simplecpp::TokenList &expr, simplecpp::OutputList *outputList)
28222822
{
28232823
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
28242824
if (tok->name) {
@@ -2832,9 +2832,20 @@ static void simplifyName(simplecpp::TokenList &expr)
28322832
if (alt)
28332833
continue;
28342834
}
2835+
if (tok->next && tok->next->str() == "(") {
2836+
if (outputList) {
2837+
simplecpp::Output err(tok->location.files);
2838+
err.type = simplecpp::Output::SYNTAX_ERROR;
2839+
err.location = tok->location;
2840+
err.msg = "Undefined function-like macro in directive";
2841+
outputList->push_back(err);
2842+
}
2843+
return false;
2844+
}
28352845
tok->setstr("0");
28362846
}
28372847
}
2848+
return true;
28382849
}
28392850

28402851
/*
@@ -3106,12 +3117,13 @@ static void simplifyComments(simplecpp::TokenList &expr)
31063117
}
31073118
}
31083119

3109-
static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t> &sizeOfType)
3120+
static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t> &sizeOfType, simplecpp::OutputList *outputList)
31103121
{
31113122
simplifyComments(expr);
31123123
simplifySizeof(expr, sizeOfType);
31133124
simplifyHasInclude(expr, dui);
3114-
simplifyName(expr);
3125+
if (!simplifyName(expr, outputList))
3126+
return 0;
31153127
simplifyNumbers(expr);
31163128
expr.constFold();
31173129
// TODO: handle invalid expressions
@@ -3820,11 +3832,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
38203832
std::string E;
38213833
for (const simplecpp::Token *tok = expr.cfront(); tok; tok = tok->next)
38223834
E += (E.empty() ? "" : " ") + tok->str();
3823-
const long long result = evaluate(expr, dui, sizeOfType);
3835+
const long long result = evaluate(expr, dui, sizeOfType, outputList);
38243836
conditionIsTrue = (result != 0);
38253837
ifCond->push_back(IfCond(rawtok->location, E, result));
38263838
} else {
3827-
const long long result = evaluate(expr, dui, sizeOfType);
3839+
const long long result = evaluate(expr, dui, sizeOfType, outputList);
38283840
conditionIsTrue = (result != 0);
38293841
}
38303842
} catch (const std::exception &e) {

0 commit comments

Comments
 (0)