diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 5f495632c..093657d96 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -1146,7 +1146,7 @@ void simplifyNumbers(simplecpp::TokenList &expr) { } } -long long evaluate(simplecpp::TokenList expr, const std::map &sizeOfType) { +long long evaluate(simplecpp::TokenList &expr, const std::map &sizeOfType) { simplifySizeof(expr, sizeOfType); simplifyName(expr); simplifyNumbers(expr); @@ -1262,7 +1262,7 @@ std::map simplecpp::load(const simplecpp::To return ret; } -simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens, std::vector &files, const std::map &filedata, const struct simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list *macroUsage) +void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector &files, const std::map &filedata, const struct simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list *macroUsage) { std::map sizeOfType(rawtokens.sizeOfType); sizeOfType.insert(std::pair(std::string("char"), sizeof(char))); @@ -1312,7 +1312,6 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens std::set pragmaOnce; - TokenList output(files); for (const Token *rawtok = rawtokens.cbegin(); rawtok || !includetokenstack.empty();) { if (rawtok == NULL) { rawtok = includetokenstack.top(); @@ -1338,7 +1337,8 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens err.msg = '#' + rawtok->str + ' ' + err.msg; outputList->push_back(err); } - return TokenList(files); + output.clear(); + return; } if (rawtok->str == DEFINE) { @@ -1416,7 +1416,8 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens out.msg = "failed to expand \'" + tok->str + "\', " + err.what; if (outputList) outputList->push_back(out); - return TokenList(files); + output.clear(); + return; } for (const Token *tok2 = value.cbegin(); tok2; tok2 = tok2->next) expr.push_back(new Token(tok2->str, tok->location)); @@ -1433,7 +1434,8 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition"; if (outputList) outputList->push_back(out); - return TokenList(files); + output.clear(); + return; } } @@ -1487,7 +1489,8 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens out.msg = err.what; if (outputList) outputList->push_back(out); - return TokenList(files); + output.clear(); + return; } continue; } @@ -1511,6 +1514,4 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens } } } - - return output; } diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index 4bbe9abc2..7a8909937 100644 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -257,7 +257,7 @@ std::map load(const TokenList &rawtokens, std::vector &files, const std::map &filedata, const struct DUI &dui, OutputList *outputList = 0, std::list *macroUsage = 0); +void preprocess(TokenList &output, const TokenList &rawtokens, std::vector &files, const std::map &filedata, const struct DUI &dui, OutputList *outputList = 0, std::list *macroUsage = 0); } #endif diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e67ec3403..9425a17b1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -521,7 +521,8 @@ std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std simplecpp::OutputList outputList; std::list macroUsage; - const simplecpp::TokenList &tokens2 = simplecpp::preprocess(tokens1, files, tokenlists, dui, &outputList, ¯oUsage); + simplecpp::TokenList tokens2(files); + simplecpp::preprocess(tokens2, tokens1, files, tokenlists, dui, &outputList, ¯oUsage); bool showerror = (!_settings.userDefines.empty() && !_settings.force); for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 1b86ed569..b758bb6af 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -49,7 +49,8 @@ public: std::vector files; const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList); const std::map filedata; - const simplecpp::TokenList tokens2 = simplecpp::preprocess(tokens1, files, filedata, simplecpp::DUI(), &outputList); + simplecpp::TokenList tokens2(files); + simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI(), &outputList); if (errorLogger) { for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {