Preprocessor: simplecpp optimisations
This commit is contained in:
parent
79ac409c7d
commit
99307846cf
|
@ -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);
|
simplifySizeof(expr, sizeOfType);
|
||||||
simplifyName(expr);
|
simplifyName(expr);
|
||||||
simplifyNumbers(expr);
|
simplifyNumbers(expr);
|
||||||
|
@ -1262,7 +1262,7 @@ std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::To
|
||||||
return ret;
|
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);
|
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
|
||||||
sizeOfType.insert(std::pair<std::string, std::size_t>(std::string("char"), sizeof(char)));
|
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;
|
std::set<std::string> pragmaOnce;
|
||||||
|
|
||||||
TokenList output(files);
|
|
||||||
for (const Token *rawtok = rawtokens.cbegin(); rawtok || !includetokenstack.empty();) {
|
for (const Token *rawtok = rawtokens.cbegin(); rawtok || !includetokenstack.empty();) {
|
||||||
if (rawtok == NULL) {
|
if (rawtok == NULL) {
|
||||||
rawtok = includetokenstack.top();
|
rawtok = includetokenstack.top();
|
||||||
|
@ -1338,7 +1337,8 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens
|
||||||
err.msg = '#' + rawtok->str + ' ' + err.msg;
|
err.msg = '#' + rawtok->str + ' ' + err.msg;
|
||||||
outputList->push_back(err);
|
outputList->push_back(err);
|
||||||
}
|
}
|
||||||
return TokenList(files);
|
output.clear();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawtok->str == DEFINE) {
|
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;
|
out.msg = "failed to expand \'" + tok->str + "\', " + err.what;
|
||||||
if (outputList)
|
if (outputList)
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
return TokenList(files);
|
output.clear();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (const Token *tok2 = value.cbegin(); tok2; tok2 = tok2->next)
|
for (const Token *tok2 = value.cbegin(); tok2; tok2 = tok2->next)
|
||||||
expr.push_back(new Token(tok2->str, tok->location));
|
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";
|
out.msg = "failed to evaluate " + std::string(rawtok->str == IF ? "#if" : "#elif") + " condition";
|
||||||
if (outputList)
|
if (outputList)
|
||||||
outputList->push_back(out);
|
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;
|
out.msg = err.what;
|
||||||
if (outputList)
|
if (outputList)
|
||||||
outputList->push_back(out);
|
outputList->push_back(out);
|
||||||
return TokenList(files);
|
output.clear();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1511,6 +1514,4 @@ simplecpp::TokenList simplecpp::preprocess(const simplecpp::TokenList &rawtokens
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,7 +257,7 @@ std::map<std::string, TokenList*> load(const TokenList &rawtokens, std::vector<s
|
||||||
*
|
*
|
||||||
* @todo simplify interface
|
* @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
|
#endif
|
||||||
|
|
|
@ -521,7 +521,8 @@ std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std
|
||||||
|
|
||||||
simplecpp::OutputList outputList;
|
simplecpp::OutputList outputList;
|
||||||
std::list<simplecpp::MacroUsage> macroUsage;
|
std::list<simplecpp::MacroUsage> 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);
|
bool showerror = (!_settings.userDefines.empty() && !_settings.force);
|
||||||
for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {
|
for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {
|
||||||
|
|
|
@ -49,7 +49,8 @@ public:
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList);
|
const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList);
|
||||||
const std::map<std::string, simplecpp::TokenList*> filedata;
|
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) {
|
if (errorLogger) {
|
||||||
for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {
|
for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {
|
||||||
|
|
Loading…
Reference in New Issue