Skip to content

Commit 561e917

Browse files
committed
Bump simplecpp
1 parent b1547a3 commit 561e917

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

externals/simplecpp/simplecpp.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
24822482
// Assuming this is a UTF-8 encoded code point.
24832483
// This decoder may not completely validate the input.
24842484
// Noncharacters are neither rejected nor replaced.
2485-
2485+
24862486
int additional_bytes;
24872487
if (value >= 0xf5) // higher values would result in code points above 0x10ffff
24882488
throw std::runtime_error("assumed UTF-8 encoded source, but sequence is invalid");
@@ -2494,26 +2494,26 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
24942494
additional_bytes = 1;
24952495
else
24962496
throw std::runtime_error("assumed UTF-8 encoded source, but sequence is invalid");
2497-
2497+
24982498
value &= (1 << (6 - additional_bytes)) - 1;
24992499

25002500
while (additional_bytes--) {
2501-
if(pos + 1 >= str.size())
2501+
if (pos + 1 >= str.size())
25022502
throw std::runtime_error("assumed UTF-8 encoded source, but character literal ends unexpectedly");
2503-
2503+
25042504
unsigned char c = str[pos++];
2505-
2505+
25062506
if (((c >> 6) != 2) // ensure c has form 0xb10xxxxxx
25072507
|| (!value && additional_bytes == 1 && c < 0xa0) // overlong 3-bytes encoding
25082508
|| (!value && additional_bytes == 2 && c < 0x90)) // overlong 4-bytes encoding
25092509
throw std::runtime_error("assumed UTF-8 encoded source, but sequence is invalid");
2510-
2510+
25112511
value = (value << 6) | (c & ((1 << 7) - 1));
25122512
}
25132513

25142514
if (value >= 0xd800 && value <= 0xdfff)
25152515
throw std::runtime_error("assumed UTF-8 encoded source, but sequence is invalid");
2516-
2516+
25172517
if ((utf8 && value > 0x7f) || (utf16 && value > 0xffff) || value > 0x10ffff)
25182518
throw std::runtime_error("code point too large");
25192519
}
@@ -2804,7 +2804,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
28042804
return true;
28052805
}
28062806

2807-
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage)
2807+
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
28082808
{
28092809
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
28102810
sizeOfType.insert(std::make_pair("char", sizeof(char)));
@@ -3119,7 +3119,17 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
31193119
tok = tmp->previous;
31203120
}
31213121
try {
3122-
conditionIsTrue = (evaluate(expr, sizeOfType) != 0);
3122+
if (ifCond) {
3123+
std::string E;
3124+
for (const simplecpp::Token *tok = expr.cfront(); tok; tok = tok->next)
3125+
E += (E.empty() ? "" : " ") + tok->str();
3126+
const long long result = evaluate(expr, sizeOfType);
3127+
conditionIsTrue = (result != 0);
3128+
ifCond->push_back(IfCond(rawtok->location, E, result));
3129+
} else {
3130+
const long long result = evaluate(expr, sizeOfType);
3131+
conditionIsTrue = (result != 0);
3132+
}
31233133
} catch (const std::exception &e) {
31243134
if (outputList) {
31253135
Output out(rawtok->location.files);

externals/simplecpp/simplecpp.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ namespace simplecpp {
287287
bool macroValueKnown;
288288
};
289289

290+
/** Tracking #if/#elif expressions */
291+
struct SIMPLECPP_LIB IfCond {
292+
explicit IfCond(const Location& location, const std::string &E, long long result) : location(location), E(E), result(result) {}
293+
Location location; // location of #if/#elif
294+
std::string E; // preprocessed condition
295+
long long result; // condition result
296+
};
297+
290298
/**
291299
* Command line preprocessor settings.
292300
* On the command line these are configured by -D, -U, -I, --include, -std
@@ -314,8 +322,9 @@ namespace simplecpp {
314322
* @param dui defines, undefs, and include paths
315323
* @param outputList output: list that will receive output messages
316324
* @param macroUsage output: macro usage
325+
* @param ifCond output: #if/#elif expressions
317326
*/
318-
SIMPLECPP_LIB void preprocess(TokenList &output, const TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, TokenList*> &filedata, const DUI &dui, OutputList *outputList = NULL, std::list<MacroUsage> *macroUsage = NULL);
327+
SIMPLECPP_LIB void preprocess(TokenList &output, const TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, TokenList*> &filedata, const DUI &dui, OutputList *outputList = NULL, std::list<MacroUsage> *macroUsage = NULL, std::list<IfCond> *ifCond = NULL);
319328

320329
/**
321330
* Deallocate data

0 commit comments

Comments
 (0)