Skip to content

Commit c02dd5b

Browse files
committed
bump simplecpp
1 parent 0e1590b commit c02dd5b

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

externals/simplecpp/simplecpp.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,26 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
501501
oldLastToken = cback();
502502
const std::string lastline(lastLine());
503503
if (lastline == "# file %str%") {
504+
const Token *strtok = cback();
505+
while (strtok->comment)
506+
strtok = strtok->previous;
504507
loc.push(location);
505-
location.fileIndex = fileIndex(cback()->str().substr(1U, cback()->str().size() - 2U));
508+
location.fileIndex = fileIndex(strtok->str().substr(1U, strtok->str().size() - 2U));
506509
location.line = 1U;
507510
} else if (lastline == "# line %num%") {
508-
lineDirective(location.fileIndex, std::atol(cback()->str().c_str()), &location);
511+
const Token *numtok = cback();
512+
while (numtok->comment)
513+
numtok = numtok->previous;
514+
lineDirective(location.fileIndex, std::atol(numtok->str().c_str()), &location);
509515
} else if (lastline == "# %num% %str%" || lastline == "# line %num% %str%") {
510-
lineDirective(fileIndex(replaceAll(cback()->str().substr(1U, cback()->str().size() - 2U),"\\\\","\\")),
511-
std::atol(cback()->previous->str().c_str()), &location);
516+
const Token *strtok = cback();
517+
while (strtok->comment)
518+
strtok = strtok->previous;
519+
const Token *numtok = strtok->previous;
520+
while (numtok->comment)
521+
numtok = numtok->previous;
522+
lineDirective(fileIndex(replaceAll(strtok->str().substr(1U, strtok->str().size() - 2U),"\\\\","\\")),
523+
std::atol(numtok->str().c_str()), &location);
512524
}
513525
// #endfile
514526
else if (lastline == "# endfile" && !loc.empty()) {
@@ -1393,10 +1405,12 @@ namespace simplecpp {
13931405
};
13941406
private:
13951407
/** Create new token where Token::macro is set for replaced tokens */
1396-
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced) const {
1408+
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=NULL) const {
13971409
Token *tok = new Token(str,loc);
13981410
if (replaced)
13991411
tok->macro = nameTokDef->str();
1412+
if (expandedFromToken)
1413+
tok->setExpandedFrom(expandedFromToken, this);
14001414
return tok;
14011415
}
14021416

@@ -1614,12 +1628,12 @@ namespace simplecpp {
16141628
throw invalidHashHash(tok->location, name());
16151629
TokenList new_output(files);
16161630
if (!expandArg(&new_output, tok, parametertokens2))
1617-
output->push_back(newMacroToken(tok->str(), loc, isReplaced(expandedmacros)));
1631+
output->push_back(newMacroToken(tok->str(), loc, isReplaced(expandedmacros), tok));
16181632
else if (new_output.empty()) // placemarker token
16191633
output->push_back(newMacroToken("", loc, isReplaced(expandedmacros)));
16201634
else
16211635
for (const Token *tok2 = new_output.cfront(); tok2; tok2 = tok2->next)
1622-
output->push_back(newMacroToken(tok2->str(), loc, isReplaced(expandedmacros)));
1636+
output->push_back(newMacroToken(tok2->str(), loc, isReplaced(expandedmacros), tok2));
16231637
tok = tok->next;
16241638
} else {
16251639
tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens2);
@@ -1710,7 +1724,7 @@ namespace simplecpp {
17101724
const Token *expandToken(TokenList *output, const Location &loc, const Token *tok, const std::map<TokenString,Macro> &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens) const {
17111725
// Not name..
17121726
if (!tok->name) {
1713-
output->push_back(newMacroToken(tok->str(), loc, true));
1727+
output->push_back(newMacroToken(tok->str(), loc, true, tok));
17141728
return tok->next;
17151729
}
17161730

@@ -1734,14 +1748,14 @@ namespace simplecpp {
17341748
return recursiveExpandToken(output, temp, loc, tok, macros, expandedmacros2, parametertokens);
17351749
}
17361750
if (!sameline(tok, tok->next) || tok->next->op != '(') {
1737-
output->push_back(newMacroToken(tok->str(), loc, true));
1751+
output->push_back(newMacroToken(tok->str(), loc, true, tok));
17381752
return tok->next;
17391753
}
17401754
TokenList tokens(files);
17411755
tokens.push_back(new Token(*tok));
17421756
const Token *tok2 = appendTokens(&tokens, loc, tok->next, macros, expandedmacros, parametertokens);
17431757
if (!tok2) {
1744-
output->push_back(newMacroToken(tok->str(), loc, true));
1758+
output->push_back(newMacroToken(tok->str(), loc, true, tok));
17451759
return tok->next;
17461760
}
17471761
TokenList temp(files);
@@ -1779,7 +1793,7 @@ namespace simplecpp {
17791793
}
17801794
}
17811795

1782-
output->push_back(newMacroToken(tok->str(), loc, true));
1796+
output->push_back(newMacroToken(tok->str(), loc, true, tok));
17831797
return tok->next;
17841798
}
17851799

@@ -1811,10 +1825,10 @@ namespace simplecpp {
18111825
return true;
18121826
for (const Token *partok = parametertokens[argnr]->next; partok != parametertokens[argnr + 1U];) {
18131827
const std::map<TokenString, Macro>::const_iterator it = macros.find(partok->str());
1814-
if (it != macros.end() && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end()))
1828+
if (it != macros.end() && !partok->isExpandedFrom(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end()))
18151829
partok = it->second.expand(output, loc, partok, macros, expandedmacros);
18161830
else {
1817-
output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros)));
1831+
output->push_back(newMacroToken(partok->str(), loc, isReplaced(expandedmacros), partok));
18181832
output->back()->macro = partok->macro;
18191833
partok = partok->next;
18201834
}

externals/simplecpp/simplecpp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,21 @@ namespace simplecpp {
149149
return tok;
150150
}
151151

152+
void setExpandedFrom(const Token *tok, const void* m) {
153+
mExpandedFrom = tok->mExpandedFrom;
154+
mExpandedFrom.insert(m);
155+
}
156+
bool isExpandedFrom(const void* m) const {
157+
return mExpandedFrom.find(m) != mExpandedFrom.end();
158+
}
159+
152160
void printAll() const;
153161
void printOut() const;
154162
private:
155163
TokenString string;
156164

165+
std::set<const void*> mExpandedFrom;
166+
157167
// Not implemented - prevent assignment
158168
Token &operator=(const Token &tok);
159169
};

0 commit comments

Comments
 (0)