Skip to content

Commit cc76d59

Browse files
committed
2
1 parent 20ed366 commit cc76d59

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ int main(int argc, char **argv)
132132
rawtokens->removeComments();
133133
simplecpp::TokenList outputTokens(files);
134134
if (precompile) {
135-
std::ofstream f(filename + std::string(".pc"));
136-
f << simplecpp::precompileHeader(*rawtokens, files, dui, &outputList);
135+
std::cout << simplecpp::precompileHeader(*rawtokens, files, dui, &outputList);
137136
} else {
138137
std::map<std::string, simplecpp::TokenList*> filedata;
139138
simplecpp::preprocess(outputTokens, *rawtokens, files, filedata, dui, &outputList);

simplecpp.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,13 @@ namespace simplecpp {
16811681
return invalidHashHash(loc, macroName, "Combining '\\"+ tokenA->str()+ "' and '"+ strAB.substr(tokenA->str().size()) + "' yields universal character '\\" + strAB + "'. This is undefined behavior according to C standard chapter 5.1.1.2, paragraph 4.");
16821682
}
16831683
};
1684+
1685+
std::string dump() const {
1686+
std::string ret;
1687+
for (const Token *tok = nameTokDef; sameline(nameTokDef,tok); tok = tok->next)
1688+
ret += "\n" + toString(tok->location.col) + ":" + tok->str();
1689+
return ret.substr(1);
1690+
}
16841691
private:
16851692
/** Create new token where Token::macro is set for replaced tokens */
16861693
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=nullptr) const {
@@ -3826,11 +3833,14 @@ std::string simplecpp::precompileHeader(const TokenList &rawtokens, std::vector<
38263833
macroMap);
38273834

38283835
std::string ret;
3836+
ret = "files\n";
3837+
for (int i = 0; i < files.size(); ++i)
3838+
ret += toString(i) + ":" + files[i] + "\n";
3839+
ret += "tokens\n";
38293840
unsigned int fileIndex = 0;
38303841
unsigned int line = 0;
38313842
unsigned int col = 0;
38323843
for (const simplecpp::Token *tok = output.cfront(); tok; tok = tok->next) {
3833-
ret += "\n";
38343844
if (tok->location.fileIndex != fileIndex) {
38353845
fileIndex = tok->location.fileIndex;
38363846
ret += "f" + toString(fileIndex);
@@ -3843,11 +3853,10 @@ std::string simplecpp::precompileHeader(const TokenList &rawtokens, std::vector<
38433853
col = tok->location.col;
38443854
ret += "c" + toString(col);
38453855
}
3846-
ret += ":" + tok->str();
3847-
}
3848-
for (simplecpp::MacroMap::const_iterator it = macroMap.begin(); it != macroMap.end(); ++it) {
3849-
ret += "\nM" + it->second.name();
3856+
ret += ":" + tok->str() + "\n";
38503857
}
3858+
for (simplecpp::MacroMap::const_iterator it = macroMap.begin(); it != macroMap.end(); ++it)
3859+
ret += "[MACRO]\n" + it->second.dump() + "\n";
38513860
return ret;
38523861
}
38533862

0 commit comments

Comments
 (0)