bump simplecpp

This commit is contained in:
Daniel Marjamäki 2022-07-27 21:46:03 +02:00
parent d6eb3a8f40
commit 5d5b6bda3a
1 changed files with 30 additions and 4 deletions

View File

@ -1471,12 +1471,16 @@ namespace simplecpp {
} }
static inline invalidHashHash cannotCombine(const Location &loc, const std::string &macroName, const Token *tokenA, const Token *tokenB) { static inline invalidHashHash cannotCombine(const Location &loc, const std::string &macroName, const Token *tokenA, const Token *tokenB) {
return invalidHashHash(loc, macroName, "Pasting '"+ tokenA->str()+ "' and '"+ tokenB->str() + "' yields an invalid token."); return invalidHashHash(loc, macroName, "Combining '"+ tokenA->str()+ "' and '"+ tokenB->str() + "' yields an invalid token.");
} }
static inline invalidHashHash unexpectedNewline(const Location &loc, const std::string &macroName) { static inline invalidHashHash unexpectedNewline(const Location &loc, const std::string &macroName) {
return invalidHashHash(loc, macroName, "Unexpected newline"); return invalidHashHash(loc, macroName, "Unexpected newline");
} }
static inline invalidHashHash universalCharacterUB(const Location &loc, const std::string &macroName, const Token* tokenA, const std::string& strAB) {
return invalidHashHash(loc, macroName, "Combining '\\"+ tokenA->str()+ "' and '"+ strAB.substr(tokenA->str().size()) + "' yields universal character '\\" + strAB + "'. This is undefined behavior according to C standard chapter 5.1.1.2, paragraph 4.");
}
}; };
private: private:
/** Create new token where Token::macro is set for replaced tokens */ /** Create new token where Token::macro is set for replaced tokens */
@ -2000,6 +2004,14 @@ namespace simplecpp {
strAB = A->str() + B->str(); strAB = A->str() + B->str();
} }
// producing universal character is undefined behavior
if (A->previous && A->previous->str() == "\\") {
if (strAB[0] == 'u' && strAB.size() == 5)
throw invalidHashHash::universalCharacterUB(tok->location, name(), A, strAB);
else if (strAB[0] == 'U' && strAB.size() == 9)
throw invalidHashHash::universalCharacterUB(tok->location, name(), A, strAB);
}
if (varargs && tokensB.empty() && tok->previous->str() == ",") if (varargs && tokensB.empty() && tok->previous->str() == ",")
output->deleteToken(A); output->deleteToken(A);
else if (strAB != "," && macros.find(strAB) == macros.end()) { else if (strAB != "," && macros.find(strAB) == macros.end()) {
@ -2671,8 +2683,19 @@ static void simplifyNumbers(simplecpp::TokenList &expr)
} }
} }
static void simplifyComments(simplecpp::TokenList &expr)
{
for (simplecpp::Token *tok = expr.front(); tok;) {
simplecpp::Token *d = tok;
tok = tok->next;
if (d->comment)
expr.deleteToken(d);
}
}
static long long evaluate(simplecpp::TokenList &expr, const std::map<std::string, std::size_t> &sizeOfType) static long long evaluate(simplecpp::TokenList &expr, const std::map<std::string, std::size_t> &sizeOfType)
{ {
simplifyComments(expr);
simplifySizeof(expr, sizeOfType); simplifySizeof(expr, sizeOfType);
simplifyName(expr); simplifyName(expr);
simplifyNumbers(expr); simplifyNumbers(expr);
@ -2917,7 +2940,8 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
return true; return true;
} }
static void getLocaltime(struct tm &ltime) { static void getLocaltime(struct tm &ltime)
{
time_t t; time_t t;
time(&t); time(&t);
#ifndef _WIN32 #ifndef _WIN32
@ -2927,13 +2951,15 @@ static void getLocaltime(struct tm &ltime) {
#endif #endif
} }
static std::string getDateDefine(struct tm *timep) { static std::string getDateDefine(struct tm *timep)
{
char buf[] = "??? ?? ????"; char buf[] = "??? ?? ????";
strftime(buf, sizeof(buf), "%b %d %Y", timep); strftime(buf, sizeof(buf), "%b %d %Y", timep);
return std::string("\"").append(buf).append("\""); return std::string("\"").append(buf).append("\"");
} }
static std::string getTimeDefine(struct tm *timep) { static std::string getTimeDefine(struct tm *timep)
{
char buf[] = "??:??:??"; char buf[] = "??:??:??";
strftime(buf, sizeof(buf), "%T", timep); strftime(buf, sizeof(buf), "%T", timep);
return std::string("\"").append(buf).append("\""); return std::string("\"").append(buf).append("\"");