Preprocessor: simplecpp optimisations

This commit is contained in:
Daniel Marjamäki 2016-07-21 19:42:26 +02:00
parent 79ac409c7d
commit 99307846cf
4 changed files with 15 additions and 12 deletions

View File

@ -1146,7 +1146,7 @@ void simplifyNumbers(simplecpp::TokenList &expr) {
}
}
long long evaluate(simplecpp::TokenList expr, const std::map<std::string, std::size_t> &sizeOfType) {
long long evaluate(simplecpp::TokenList &expr, const std::map<std::string, std::size_t> &sizeOfType) {
simplifySizeof(expr, sizeOfType);
simplifyName(expr);
simplifyNumbers(expr);
@ -1262,7 +1262,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
return ret;
}
simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, const std::map<std::string, simplecpp::TokenList *> &filedata, const struct simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<struct simplecpp::MacroUsage> *macroUsage)
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, const std::map<std::string, simplecpp::TokenList *> &filedata, const struct simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<struct simplecpp::MacroUsage> *macroUsage)
{
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("char"), sizeof(char)));
@ -1312,7 +1312,6 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens
std::set<std::string> 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;
}

View File

@ -257,7 +257,7 @@ std::map<std::string, TokenList*> load(const TokenList &rawtokens, std::vector<s
*
* @todo simplify interface
*/
TokenList preprocess(const TokenList &rawtokens, std::vector<std::string> &files, const std::map<std::string, TokenList*> &filedata, const struct DUI &dui, OutputList *outputList = 0, std::list<struct MacroUsage> *macroUsage = 0);
void preprocess(TokenList &output, const TokenList &rawtokens, std::vector<std::string> &files, const std::map<std::string, TokenList*> &filedata, const struct DUI &dui, OutputList *outputList = 0, std::list<struct MacroUsage> *macroUsage = 0);
}
#endif

View File

@ -521,7 +521,8 @@ std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std
simplecpp::OutputList outputList;
std::list<simplecpp::MacroUsage> macroUsage;
const simplecpp::TokenList &tokens2 = simplecpp::preprocess(tokens1, files, tokenlists, dui, &outputList, &macroUsage);
simplecpp::TokenList tokens2(files);
simplecpp::preprocess(tokens2, tokens1, files, tokenlists, dui, &outputList, &macroUsage);
bool showerror = (!_settings.userDefines.empty() && !_settings.force);
for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {

View File

@ -49,7 +49,8 @@ public:
std::vector<std::string> files;
const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList);
const std::map<std::string, simplecpp::TokenList*> 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) {