Skip to content

Commit d1406d5

Browse files
committed
bump simplecpp (fixing problem with newlines in macro calls)
1 parent 1a76521 commit d1406d5

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

externals/simplecpp/simplecpp.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ std::string simplecpp::TokenList::readUntil(std::istream &istr, const Location &
796796
clear();
797797
if (outputList) {
798798
Output err(files);
799-
err.type = Output::ERROR;
799+
err.type = Output::SYNTAX_ERROR;
800800
err.location = location;
801801
err.msg = std::string("No pair for character (") + start + "). Can't process file. File is either invalid or unicode, which is currently not supported.";
802802
outputList->push_back(err);
@@ -887,8 +887,31 @@ class Macro {
887887
const std::map<TokenString,Macro> &macros,
888888
std::vector<std::string> &files) const {
889889
std::set<TokenString> expandedmacros;
890+
890891
TokenList output2(files);
891-
rawtok = expand(&output2, rawtok->location, rawtok, macros, expandedmacros);
892+
893+
if (functionLike() && rawtok->next && rawtok->next->op == '(') {
894+
// Copy macro call to a new tokenlist with no linebreaks
895+
const Token * const rawtok1 = rawtok;
896+
TokenList rawtokens2(files);
897+
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
898+
rawtok = rawtok->next;
899+
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
900+
rawtok = rawtok->next;
901+
int par = 1;
902+
while (rawtok && par > 0) {
903+
if (rawtok->op == '(')
904+
++par;
905+
else if (rawtok->op == ')')
906+
--par;
907+
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
908+
rawtok = rawtok->next;
909+
}
910+
if (expand(&output2, rawtok1->location, rawtokens2.cfront(), macros, expandedmacros))
911+
rawtok = rawtok1->next;
912+
} else {
913+
rawtok = expand(&output2, rawtok->location, rawtok, macros, expandedmacros);
914+
}
892915
while (output2.cback() && rawtok) {
893916
unsigned int par = 0;
894917
Token* macro2tok = output2.back();
@@ -977,12 +1000,12 @@ class Macro {
9771000

9781001
/** Struct that is thrown when macro is expanded with wrong number of parameters */
9791002
struct wrongNumberOfParameters : public Error {
980-
wrongNumberOfParameters(const Location &loc, const std::string &macroName) : Error(loc, "Syntax error. Wrong number of parameters for macro \'" + macroName + "\'.") {}
1003+
wrongNumberOfParameters(const Location &loc, const std::string &macroName) : Error(loc, "Wrong number of parameters for macro \'" + macroName + "\'.") {}
9811004
};
9821005

9831006
/** Struct that is thrown when there is invalid ## usage */
9841007
struct invalidHashHash : public Error {
985-
invalidHashHash(const Location &loc, const std::string &macroName) : Error(loc, "Syntax error. Invalid ## usage when expanding \'" + macroName + "\'.") {}
1008+
invalidHashHash(const Location &loc, const std::string &macroName) : Error(loc, "Invalid ## usage when expanding \'" + macroName + "\'.") {}
9861009
};
9871010
private:
9881011
/** Create new token where Token::macro is set for replaced tokens */
@@ -1885,7 +1908,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
18851908
conditionIsTrue = (evaluate(expr, sizeOfType) != 0);
18861909
} catch (const std::exception &) {
18871910
Output out(rawtok->location.files);
1888-
out.type = Output::ERROR;
1911+
out.type = Output::SYNTAX_ERROR;
18891912
out.location = rawtok->location;
18901913
out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition";
18911914
if (outputList)
@@ -1953,7 +1976,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
19531976
rawtok = macro->second.expand(&tokens, rawtok, macros, files);
19541977
} catch (const simplecpp::Macro::Error &err) {
19551978
Output out(err.location.files);
1956-
out.type = Output::ERROR;
1979+
out.type = Output::SYNTAX_ERROR;
19571980
out.location = err.location;
19581981
out.msg = err.what;
19591982
if (outputList)

0 commit comments

Comments
 (0)