Skip to content

Commit 1bc1fe1

Browse files
committed
use std::runtime_error
1 parent 1d237ad commit 1bc1fe1

2 files changed

Lines changed: 8 additions & 22 deletions

File tree

simplecpp.cpp

Lines changed: 7 additions & 21 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 bool simplifyName(simplecpp::TokenList &expr, simplecpp::OutputList *outputList)
2821+
static void simplifyName(simplecpp::TokenList &expr)
28222822
{
28232823
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
28242824
if (tok->name) {
@@ -2832,20 +2832,11 @@ static bool simplifyName(simplecpp::TokenList &expr, simplecpp::OutputList *outp
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: " + tok->str() + "( ... )";
2841-
outputList->push_back(err);
2842-
}
2843-
return false;
2844-
}
2835+
if (tok->next && tok->next->str() == "(")
2836+
throw std::runtime_error("undefined function-like macro invocation: " + tok->str() + "( ... )");
28452837
tok->setstr("0");
28462838
}
28472839
}
2848-
return true;
28492840
}
28502841

28512842
/*
@@ -3117,14 +3108,12 @@ static void simplifyComments(simplecpp::TokenList &expr)
31173108
}
31183109
}
31193110

3120-
static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t> &sizeOfType, simplecpp::OutputList *outputList, bool &ok)
3111+
static long long evaluate(simplecpp::TokenList &expr, const simplecpp::DUI &dui, const std::map<std::string, std::size_t> &sizeOfType)
31213112
{
31223113
simplifyComments(expr);
31233114
simplifySizeof(expr, sizeOfType);
31243115
simplifyHasInclude(expr, dui);
3125-
ok = simplifyName(expr, outputList);
3126-
if (!ok)
3127-
return 0;
3116+
simplifyName(expr);
31283117
simplifyNumbers(expr);
31293118
expr.constFold();
31303119
// TODO: handle invalid expressions
@@ -3829,20 +3818,17 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
38293818
tok = tmp->previous;
38303819
}
38313820
try {
3832-
bool ok = true;
38333821
if (ifCond) {
38343822
std::string E;
38353823
for (const simplecpp::Token *tok = expr.cfront(); tok; tok = tok->next)
38363824
E += (E.empty() ? "" : " ") + tok->str();
3837-
const long long result = evaluate(expr, dui, sizeOfType, outputList, ok);
3825+
const long long result = evaluate(expr, dui, sizeOfType);
38383826
conditionIsTrue = (result != 0);
38393827
ifCond->push_back(IfCond(rawtok->location, E, result));
38403828
} else {
3841-
const long long result = evaluate(expr, dui, sizeOfType, outputList, ok);
3829+
const long long result = evaluate(expr, dui, sizeOfType);
38423830
conditionIsTrue = (result != 0);
38433831
}
3844-
if (!ok)
3845-
return;
38463832
} catch (const std::exception &e) {
38473833
if (outputList) {
38483834
Output out(rawtok->location.files);

test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ static void ifUndefFuncStyleMacro()
18311831
"#endif\n";
18321832
simplecpp::OutputList outputList;
18331833
ASSERT_EQUALS("", preprocess(code, &outputList));
1834-
ASSERT_EQUALS("file0,1,syntax_error,Undefined function-like macro in directive: A( ... )\n", toString(outputList));
1834+
ASSERT_EQUALS("file0,1,syntax_error,failed to evaluate #if condition, undefined function-like macro invocation: A( ... )\n", toString(outputList));
18351835
}
18361836

18371837
static void location1()

0 commit comments

Comments
 (0)