Bump simplecpp

This commit is contained in:
Daniel Marjamäki 2021-07-21 20:29:00 +02:00
parent b1547a387e
commit 561e9174fa
2 changed files with 29 additions and 10 deletions

View File

@ -2498,7 +2498,7 @@ long long simplecpp::characterLiteralToLL(const std::string& str)
value &= (1 << (6 - additional_bytes)) - 1; value &= (1 << (6 - additional_bytes)) - 1;
while (additional_bytes--) { while (additional_bytes--) {
if(pos + 1 >= str.size()) if (pos + 1 >= str.size())
throw std::runtime_error("assumed UTF-8 encoded source, but character literal ends unexpectedly"); throw std::runtime_error("assumed UTF-8 encoded source, but character literal ends unexpectedly");
unsigned char c = str[pos++]; unsigned char c = str[pos++];
@ -2804,7 +2804,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
return true; return true;
} }
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) 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)
{ {
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType); std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
sizeOfType.insert(std::make_pair("char", sizeof(char))); sizeOfType.insert(std::make_pair("char", sizeof(char)));
@ -3119,7 +3119,17 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
tok = tmp->previous; tok = tmp->previous;
} }
try { try {
conditionIsTrue = (evaluate(expr, sizeOfType) != 0); if (ifCond) {
std::string E;
for (const simplecpp::Token *tok = expr.cfront(); tok; tok = tok->next)
E += (E.empty() ? "" : " ") + tok->str();
const long long result = evaluate(expr, sizeOfType);
conditionIsTrue = (result != 0);
ifCond->push_back(IfCond(rawtok->location, E, result));
} else {
const long long result = evaluate(expr, sizeOfType);
conditionIsTrue = (result != 0);
}
} catch (const std::exception &e) { } catch (const std::exception &e) {
if (outputList) { if (outputList) {
Output out(rawtok->location.files); Output out(rawtok->location.files);

View File

@ -287,6 +287,14 @@ namespace simplecpp {
bool macroValueKnown; bool macroValueKnown;
}; };
/** Tracking #if/#elif expressions */
struct SIMPLECPP_LIB IfCond {
explicit IfCond(const Location& location, const std::string &E, long long result) : location(location), E(E), result(result) {}
Location location; // location of #if/#elif
std::string E; // preprocessed condition
long long result; // condition result
};
/** /**
* Command line preprocessor settings. * Command line preprocessor settings.
* On the command line these are configured by -D, -U, -I, --include, -std * On the command line these are configured by -D, -U, -I, --include, -std
@ -314,8 +322,9 @@ namespace simplecpp {
* @param dui defines, undefs, and include paths * @param dui defines, undefs, and include paths
* @param outputList output: list that will receive output messages * @param outputList output: list that will receive output messages
* @param macroUsage output: macro usage * @param macroUsage output: macro usage
* @param ifCond output: #if/#elif expressions
*/ */
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); 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);
/** /**
* Deallocate data * Deallocate data