Skip to content

Commit a9b01c3

Browse files
committed
empty [skip ci]
1 parent c5d3993 commit a9b01c3

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

externals/simplecpp/simplecpp.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,9 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
32683268
sizeOfType.insert(std::make_pair("double *", sizeof(double *)));
32693269
sizeOfType.insert(std::make_pair("long double *", sizeof(long double *)));
32703270

3271+
// use a dummy vector for the macros because as this is not part of the file and would add an empty entry - e.g. /usr/include/poll.h
3272+
std::vector<std::string> dummy;
3273+
32713274
const bool hasInclude = (dui.std.size() == 5 && dui.std.compare(0,3,"c++") == 0 && dui.std >= "c++17");
32723275
MacroMap macros;
32733276
for (std::list<std::string>::const_iterator it = dui.defines.begin(); it != dui.defines.end(); ++it) {
@@ -3279,26 +3282,26 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
32793282
continue;
32803283
const std::string lhs(macrostr.substr(0,eq));
32813284
const std::string rhs(eq==std::string::npos ? std::string("1") : macrostr.substr(eq+1));
3282-
const Macro macro(lhs, rhs, files);
3285+
const Macro macro(lhs, rhs, dummy);
32833286
macros.insert(std::pair<TokenString,Macro>(macro.name(), macro));
32843287
}
32853288

3286-
macros.insert(std::make_pair("__FILE__", Macro("__FILE__", "__FILE__", files)));
3287-
macros.insert(std::make_pair("__LINE__", Macro("__LINE__", "__LINE__", files)));
3288-
macros.insert(std::make_pair("__COUNTER__", Macro("__COUNTER__", "__COUNTER__", files)));
3289+
macros.insert(std::make_pair("__FILE__", Macro("__FILE__", "__FILE__", dummy)));
3290+
macros.insert(std::make_pair("__LINE__", Macro("__LINE__", "__LINE__", dummy)));
3291+
macros.insert(std::make_pair("__COUNTER__", Macro("__COUNTER__", "__COUNTER__", dummy)));
32893292
struct tm ltime = {};
32903293
getLocaltime(ltime);
3291-
macros.insert(std::make_pair("__DATE__", Macro("__DATE__", getDateDefine(&ltime), files)));
3292-
macros.insert(std::make_pair("__TIME__", Macro("__TIME__", getTimeDefine(&ltime), files)));
3294+
macros.insert(std::make_pair("__DATE__", Macro("__DATE__", getDateDefine(&ltime), dummy)));
3295+
macros.insert(std::make_pair("__TIME__", Macro("__TIME__", getTimeDefine(&ltime), dummy)));
32933296

32943297
if (!dui.std.empty()) {
32953298
std::string std_def = simplecpp::getCStdString(dui.std);
32963299
if (!std_def.empty()) {
3297-
macros.insert(std::make_pair("__STDC_VERSION__", Macro("__STDC_VERSION__", std_def, files)));
3300+
macros.insert(std::make_pair("__STDC_VERSION__", Macro("__STDC_VERSION__", std_def, dummy)));
32983301
} else {
32993302
std_def = simplecpp::getCppStdString(dui.std);
33003303
if (!std_def.empty())
3301-
macros.insert(std::make_pair("__cplusplus", Macro("__cplusplus", std_def, files)));
3304+
macros.insert(std::make_pair("__cplusplus", Macro("__cplusplus", std_def, dummy)));
33023305
}
33033306
}
33043307

externals/simplecpp/simplecpp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ namespace simplecpp {
272272
/** sizeof(T) */
273273
std::map<std::string, std::size_t> sizeOfType;
274274

275+
const std::vector<std::string>& getFiles() const {
276+
return files;
277+
}
278+
275279
private:
276280
void combineOperators();
277281

lib/tokenlist.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void TokenList::determineCppC()
9595
{
9696
// only try to determine if it wasn't enforced
9797
if (mLang == Standards::Language::None) {
98+
ASSERT_LANG(!getSourceFilePath().empty());
9899
mLang = Path::identify(getSourceFilePath(), mSettings ? mSettings->cppProbe : false);
99100
// TODO: cannot enable assert as this might occur for unknown extensions
100101
//ASSERT_LANG(mLang != Standards::Language::None);
@@ -372,11 +373,11 @@ bool TokenList::createTokensInternal(std::istream &code, const std::string& file
372373
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
373374
void TokenList::createTokens(simplecpp::TokenList&& tokenList)
374375
{
375-
if (tokenList.cfront()) {
376+
// tokenList.cfront() might be NULL if the file contained nothing to tokenize so we need to check the files instead
377+
if (!tokenList.getFiles().empty()) {
376378
// this is a copy
377-
// TODO: the same as TokenList.files - move that instead
378379
// TODO: this points to mFiles when called from createTokens(std::istream &, const std::string&)
379-
mOrigFiles = mFiles = tokenList.cfront()->location.files;
380+
mOrigFiles = mFiles = tokenList.getFiles();
380381
}
381382
else
382383
mFiles.clear();

0 commit comments

Comments
 (0)