FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix #700: `macro` not set for tokens expanded from `__LINE__` inside function-like macros by ludviggunne · Pull Request #701 · cppcheck-opensource/simplecpp · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions simplecpp.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1994,14 +1994,17 @@ namespace simplecpp {

if (nameTokInst->str() == "__FILE__") {
output.push_back(new Token('\"'+output.file(loc)+'\"', loc));
output.back()->macro = "__FILE__";
return nameTokInst->next;
}
if (nameTokInst->str() == "__LINE__") {
output.push_back(new Token(toString(loc.line), loc));
output.back()->macro = "__LINE__";
return nameTokInst->next;
}
if (nameTokInst->str() == "__COUNTER__") {
output.push_back(new Token(toString(usageList.size()-1U), loc));
output.back()->macro = "__COUNTER__";
return nameTokInst->next;
}

Expand Down
26 changes: 26 additions & 0 deletions test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3782,6 +3782,31 @@ static void tokenMacro5()
ASSERT_EQUALS("SET_BPF_JUMP", tok->macro);
}

static void tokenMacro6()
{
const char code[] = "#define FILE() __FILE__\n"
"#define LINE() __LINE__\n"
"#define COUNTER() __COUNTER__\n"
"FILE()\n"
"LINE()\n"
"COUNTER()\n";
std::vector<std::string> files;
simplecpp::FileDataCache cache;
simplecpp::TokenList tokenList(files);
const simplecpp::TokenList rawtokens = makeTokenList(code,files);
simplecpp::preprocess(tokenList, rawtokens, files, cache, simplecpp::DUI());
const simplecpp::Token *tok;

tok = tokenList.cfront();
ASSERT_EQUALS("__FILE__", tok->macro);

tok = tok->next;
ASSERT_EQUALS("__LINE__", tok->macro);

tok = tok->next;
ASSERT_EQUALS("__COUNTER__", tok->macro);
}

static void undef()
{
const char code[] = "#define A\n"
Expand Down Expand Up @@ -4781,6 +4806,7 @@ static void runTests(int argc, char **argv, Input input)
TEST_CASE(tokenMacro3);
TEST_CASE(tokenMacro4);
TEST_CASE(tokenMacro5);
TEST_CASE(tokenMacro6);

TEST_CASE(undef);

Expand Down
Loading

Back | FazBrowse Home | New Git URL