bump simplecpp (fixing problem with newlines in macro calls)
This commit is contained in:
parent
1a765213ad
commit
d1406d51e5
|
@ -796,7 +796,7 @@ std::string simplecpp::TokenList::readUntil(std::istream &istr, const Location &
|
||||||
clear();
|
clear();
|
||||||
if (outputList) {
|
if (outputList) {
|
||||||
Output err(files);
|
Output err(files);
|
||||||
err.type = Output::ERROR;
|
err.type = Output::SYNTAX_ERROR;
|
||||||
err.location = location;
|
err.location = location;
|
||||||
err.msg = std::string("No pair for character (") + start + "). Can't process file. File is either invalid or unicode, which is currently not supported.";
|
err.msg = std::string("No pair for character (") + start + "). Can't process file. File is either invalid or unicode, which is currently not supported.";
|
||||||
outputList->push_back(err);
|
outputList->push_back(err);
|
||||||
|
@ -887,8 +887,31 @@ public:
|
||||||
const std::map<TokenString,Macro> ¯os,
|
const std::map<TokenString,Macro> ¯os,
|
||||||
std::vector<std::string> &files) const {
|
std::vector<std::string> &files) const {
|
||||||
std::set<TokenString> expandedmacros;
|
std::set<TokenString> expandedmacros;
|
||||||
|
|
||||||
TokenList output2(files);
|
TokenList output2(files);
|
||||||
|
|
||||||
|
if (functionLike() && rawtok->next && rawtok->next->op == '(') {
|
||||||
|
// Copy macro call to a new tokenlist with no linebreaks
|
||||||
|
const Token * const rawtok1 = rawtok;
|
||||||
|
TokenList rawtokens2(files);
|
||||||
|
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
|
||||||
|
rawtok = rawtok->next;
|
||||||
|
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
|
||||||
|
rawtok = rawtok->next;
|
||||||
|
int par = 1;
|
||||||
|
while (rawtok && par > 0) {
|
||||||
|
if (rawtok->op == '(')
|
||||||
|
++par;
|
||||||
|
else if (rawtok->op == ')')
|
||||||
|
--par;
|
||||||
|
rawtokens2.push_back(new Token(rawtok->str, rawtok1->location));
|
||||||
|
rawtok = rawtok->next;
|
||||||
|
}
|
||||||
|
if (expand(&output2, rawtok1->location, rawtokens2.cfront(), macros, expandedmacros))
|
||||||
|
rawtok = rawtok1->next;
|
||||||
|
} else {
|
||||||
rawtok = expand(&output2, rawtok->location, rawtok, macros, expandedmacros);
|
rawtok = expand(&output2, rawtok->location, rawtok, macros, expandedmacros);
|
||||||
|
}
|
||||||
while (output2.cback() && rawtok) {
|
while (output2.cback() && rawtok) {
|
||||||
unsigned int par = 0;
|
unsigned int par = 0;
|
||||||
Token* macro2tok = output2.back();
|
Token* macro2tok = output2.back();
|
||||||
|
@ -977,12 +1000,12 @@ public:
|
||||||
|
|
||||||
/** Struct that is thrown when macro is expanded with wrong number of parameters */
|
/** Struct that is thrown when macro is expanded with wrong number of parameters */
|
||||||
struct wrongNumberOfParameters : public Error {
|
struct wrongNumberOfParameters : public Error {
|
||||||
wrongNumberOfParameters(const Location &loc, const std::string ¯oName) : Error(loc, "Syntax error. Wrong number of parameters for macro \'" + macroName + "\'.") {}
|
wrongNumberOfParameters(const Location &loc, const std::string ¯oName) : Error(loc, "Wrong number of parameters for macro \'" + macroName + "\'.") {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Struct that is thrown when there is invalid ## usage */
|
/** Struct that is thrown when there is invalid ## usage */
|
||||||
struct invalidHashHash : public Error {
|
struct invalidHashHash : public Error {
|
||||||
invalidHashHash(const Location &loc, const std::string ¯oName) : Error(loc, "Syntax error. Invalid ## usage when expanding \'" + macroName + "\'.") {}
|
invalidHashHash(const Location &loc, const std::string ¯oName) : Error(loc, "Invalid ## usage when expanding \'" + macroName + "\'.") {}
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
/** Create new token where Token::macro is set for replaced tokens */
|
/** Create new token where Token::macro is set for replaced tokens */
|
||||||
|
@ -1885,7 +1908,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
conditionIsTrue = (evaluate(expr, sizeOfType) != 0);
|
conditionIsTrue = (evaluate(expr, sizeOfType) != 0);
|
||||||
} catch (const std::exception &) {
|
} catch (const std::exception &) {
|
||||||
Output out(rawtok->location.files);
|
Output out(rawtok->location.files);
|
||||||
out.type = Output::ERROR;
|
out.type = Output::SYNTAX_ERROR;
|
||||||
out.location = rawtok->location;
|
out.location = rawtok->location;
|
||||||
out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition";
|
out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition";
|
||||||
if (outputList)
|
if (outputList)
|
||||||
|
@ -1953,7 +1976,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
|
||||||
rawtok = macro->second.expand(&tokens, rawtok, macros, files);
|
rawtok = macro->second.expand(&tokens, rawtok, macros, files);
|
||||||
} catch (const simplecpp::Macro::Error &err) {
|
} catch (const simplecpp::Macro::Error &err) {
|
||||||
Output out(err.location.files);
|
Output out(err.location.files);
|
||||||
out.type = Output::ERROR;
|
out.type = Output::SYNTAX_ERROR;
|
||||||
out.location = err.location;
|
out.location = err.location;
|
||||||
out.msg = err.what;
|
out.msg = err.what;
|
||||||
if (outputList)
|
if (outputList)
|
||||||
|
|
Loading…
Reference in New Issue