Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class FileStream : public simplecpp::TokenList::Stream {
: file(fopen(filename.c_str(), "rb"))
{
if (!file) {
files.push_back(filename);
files.emplace_back(filename);
throw simplecpp::Output(simplecpp::Output::FILE_NOT_FOUND, {}, "File is missing: " + filename);
}
init();
Expand Down Expand Up @@ -490,7 +490,7 @@ simplecpp::TokenList::TokenList(const std::string &filename, std::vector<std::st
FileStream stream(filename, filenames);
readfile(stream,filename,outputList);
} catch (const simplecpp::Output & e) {
outputList->push_back(e);
outputList->emplace_back(e);
}
}

Expand Down Expand Up @@ -625,7 +625,7 @@ static void portabilityBackslash(simplecpp::OutputList *outputList, const simple
location,
"Combination 'backslash space newline' is not portable."
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}

static bool isStringLiteralPrefix(const std::string &str)
Expand Down Expand Up @@ -674,7 +674,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
location,
"The code contains unhandled character(s) (character code=" + std::to_string(static_cast<int>(ch)) + "). Neither unicode nor extended ascii is supported."
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
clear();
return;
Expand Down Expand Up @@ -876,7 +876,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
location,
"Invalid newline in raw string delimiter."
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
return;
}
Expand All @@ -890,7 +890,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
location,
"Raw string missing terminating delimiter."
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
return;
}
Expand Down Expand Up @@ -1434,7 +1434,7 @@ std::string simplecpp::TokenList::readUntil(Stream &stream, const Location &loca
location,
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(std::move(err));
outputList->emplace_back(std::move(err));
}
return "";
}
Expand Down Expand Up @@ -1472,7 +1472,7 @@ unsigned int simplecpp::TokenList::fileIndex(const std::string &filename)
if (files[i] == filename)
return i;
}
files.push_back(filename);
files.emplace_back(filename);
return files.size() - 1U;
}

Expand Down Expand Up @@ -1754,7 +1754,7 @@ namespace simplecpp {
break;
}
if (argtok->op != ',')
args.push_back(argtok->str());
args.emplace_back(argtok->str());
argtok = argtok->next;
}
if (!sameline(nametoken, argtok)) {
Expand Down Expand Up @@ -1832,19 +1832,19 @@ namespace simplecpp {
return {};

std::vector<const Token *> parametertokens;
parametertokens.push_back(nameTokInst->next);
parametertokens.emplace_back(nameTokInst->next);
unsigned int par = 0U;
for (const Token *tok = nameTokInst->next->next; calledInDefine ? sameline(tok, nameTokInst) : (tok != nullptr); tok = tok->next) {
if (tok->op == '(')
++par;
else if (tok->op == ')') {
if (par == 0U) {
parametertokens.push_back(tok);
parametertokens.emplace_back(tok);
break;
}
--par;
} else if (par == 0U && tok->op == ',' && (!variadic || parametertokens.size() < args.size()))
parametertokens.push_back(tok);
parametertokens.emplace_back(tok);
}
return parametertokens;
}
Expand Down Expand Up @@ -1894,7 +1894,7 @@ namespace simplecpp {
std::cout << " expand " << name() << " " << locstring(defineLocation()) << std::endl;
#endif

usageList.push_back(loc);
usageList.emplace_back(loc);

if (nameTokInst->str() == "__FILE__") {
output.push_back(new Token('\"'+output.file(loc)+'\"', loc));
Expand Down Expand Up @@ -1954,11 +1954,11 @@ namespace simplecpp {
for (const Token *tok = parametertokens1[0]; tok && par < parametertokens1.size(); tok = tok->next) {
if (tok->str() == "__COUNTER__") {
tokensparams.push_back(new Token(toString(counterMacro.usageList.size()), tok->location));
counterMacro.usageList.push_back(tok->location);
counterMacro.usageList.emplace_back(tok->location);
} else {
tokensparams.push_back(new Token(*tok));
if (tok == parametertokens1[par]) {
parametertokens2.push_back(tokensparams.cback());
parametertokens2.emplace_back(tokensparams.cback());
par++;
}
}
Expand Down Expand Up @@ -3183,7 +3183,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
{},
"Can not open include file '" + filename + "' that is explicitly included."
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
continue;
}
Expand All @@ -3197,7 +3197,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
if (dui.removeComments)
filedata->tokens.removeComments();

filelist.push_back(filedata->tokens.front());
filelist.emplace_back(filedata->tokens.front());
}

for (const Token *rawtok = rawtokens.cfront(); rawtok || !filelist.empty(); rawtok = rawtok ? rawtok->next : nullptr) {
Expand Down Expand Up @@ -3236,7 +3236,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
if (dui.removeComments)
filedata->tokens.removeComments();

filelist.push_back(filedata->tokens.front());
filelist.emplace_back(filedata->tokens.front());
}

return cache;
Expand All @@ -3257,7 +3257,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
err.location,
"failed to expand \'" + tok->str() + "\', " + err.what
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
return false;
}
Expand Down Expand Up @@ -3352,7 +3352,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
{},
e.what()
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
output.clear();
return;
Expand Down Expand Up @@ -3386,7 +3386,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
{},
"unknown standard specified: '" + dui.std + "'"
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
output.clear();
return;
Expand Down Expand Up @@ -3443,7 +3443,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"#" + rawtok->str() + " without #if"
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
output.clear();
return;
Expand All @@ -3464,7 +3464,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
std::move(msg)
};

outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
if (rawtok->str() == ERROR) {
output.clear();
Expand All @@ -3491,7 +3491,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"Failed to parse #define"
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
output.clear();
return;
Expand All @@ -3502,7 +3502,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
err.location,
"Failed to parse #define, " + err.what
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
output.clear();
return;
Expand Down Expand Up @@ -3543,7 +3543,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"No header in #include"
};
outputList->push_back(std::move(err));
outputList->emplace_back(std::move(err));
}
output.clear();
return;
Expand All @@ -3561,7 +3561,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"Header not found: " + inctok->str()
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
} else if (includetokenstack.size() >= 400) {
if (outputList) {
Expand All @@ -3570,7 +3570,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"#include nested too deeply"
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
} else if (pragmaOnce.find(filedata->filename) == pragmaOnce.end()) {
includetokenstack.push(gotoNextLine(rawtok));
Expand All @@ -3585,7 +3585,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"Syntax error in #" + rawtok->str()
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
output.clear();
return;
Expand All @@ -3596,10 +3596,10 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
conditionIsTrue = false;
else if (rawtok->str() == IFDEF) {
conditionIsTrue = (macros.find(rawtok->next->str()) != macros.end() || (hasInclude && rawtok->next->str() == HAS_INCLUDE));
maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);
maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location);
} else if (rawtok->str() == IFNDEF) {
conditionIsTrue = (macros.find(rawtok->next->str()) == macros.end() && !(hasInclude && rawtok->next->str() == HAS_INCLUDE));
maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);
maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location);
} else { /*if (rawtok->str() == IF || rawtok->str() == ELIF)*/
TokenList expr(files);
for (const Token *tok = rawtok->next; tok && tok->location.sameline(rawtok->location); tok = tok->next) {
Expand All @@ -3613,7 +3613,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
const bool par = (tok && tok->op == '(');
if (par)
tok = tok->next;
maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);
maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location);
if (tok) {
if (macros.find(tok->str()) != macros.end())
expr.push_back(new Token("1", tok->location));
Expand All @@ -3631,7 +3631,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"failed to evaluate " + std::string(rawtok->str() == IF ? "#if" : "#elif") + " condition"
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
output.clear();
return;
Expand Down Expand Up @@ -3674,15 +3674,15 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
"failed to evaluate " + std::string(rawtok->str() == IF ? "#if" : "#elif") + " condition"
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
output.clear();
return;
}
continue;
}

maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);
maybeUsedMacros[rawtok->next->str()].emplace_back(rawtok->next->location);

const Token *tmp = tok;
if (!preprocessToken(expr, tmp, macros, files, outputList)) {
Expand Down Expand Up @@ -3715,7 +3715,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
rawtok->location,
std::move(msg)
};
outputList->push_back(std::move(out));
outputList->emplace_back(std::move(out));
}
output.clear();
return;
Expand Down Expand Up @@ -3814,7 +3814,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
mu.macroName = macro.name();
mu.macroLocation = macro.defineLocation();
mu.useLocation = *usageIt;
macroUsage->push_back(std::move(mu));
macroUsage->emplace_back(std::move(mu));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ static void has_include_1()
" #endif\n"
"#endif";
simplecpp::DUI dui;
dui.includePaths.push_back(testSourceDir);
dui.includePaths.emplace_back(testSourceDir);
ASSERT_EQUALS("\n\nA", preprocess(code, dui)); // we default to latest standard internally
dui.std = "c++14";
ASSERT_EQUALS("", preprocess(code, dui));
Expand All @@ -1628,7 +1628,7 @@ static void has_include_2()
"#endif";
simplecpp::DUI dui;
dui.removeComments = true; // TODO: remove this
dui.includePaths.push_back(testSourceDir);
dui.includePaths.emplace_back(testSourceDir);
ASSERT_EQUALS("\n\nA", preprocess(code, dui)); // we default to latest standard internally
dui.std = "c++14";
ASSERT_EQUALS("", preprocess(code, dui));
Expand Down Expand Up @@ -1657,7 +1657,7 @@ static void has_include_3()
ASSERT_EQUALS("\n\n\n\nB", preprocess(code, dui));

// Unless -I is set (preferably, we should differentiate -I and -isystem...)
dui.includePaths.push_back(testSourceDir + "/testsuite");
dui.includePaths.emplace_back(testSourceDir + "/testsuite");
dui.std = "";
ASSERT_EQUALS("\n\nA", preprocess(code, dui)); // we default to latest standard internally
dui.std = "c++14";
Expand All @@ -1678,7 +1678,7 @@ static void has_include_4()
" #endif\n"
"#endif";
simplecpp::DUI dui;
dui.includePaths.push_back(testSourceDir); // we default to latest standard internally
dui.includePaths.emplace_back(testSourceDir); // we default to latest standard internally
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
dui.std = "c++14";
ASSERT_EQUALS("", preprocess(code, dui));
Expand All @@ -1699,7 +1699,7 @@ static void has_include_5()
"#endif";
simplecpp::DUI dui;
ASSERT_EQUALS("\n\nA", preprocess(code, dui)); // we default to latest standard internally
dui.includePaths.push_back(testSourceDir);
dui.includePaths.emplace_back(testSourceDir);
dui.std = "c++14";
ASSERT_EQUALS("", preprocess(code, dui));
dui.std = "c++17";
Expand All @@ -1718,7 +1718,7 @@ static void has_include_6()
" #endif\n"
"#endif";
simplecpp::DUI dui;
dui.includePaths.push_back(testSourceDir);
dui.includePaths.emplace_back(testSourceDir);
ASSERT_EQUALS("\n\nA", preprocess(code, dui)); // we default to latest standard internally
dui.std = "c++99";
ASSERT_EQUALS("", preprocess(code, dui));
Expand Down