Skip to content
Draft
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
31 changes: 6 additions & 25 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,6 @@ static const std::string COMMENT_END("*/");

void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, OutputList *outputList)
{
std::stack<simplecpp::Location> loc;

unsigned int multiline = 0U;

const Token *oldLastToken = nullptr;
Expand Down Expand Up @@ -704,26 +702,15 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
if (!llTok->next)
continue;
if (llNextToken->next) {
// #file "file.c"
if (llNextToken->str() == "file" &&
llNextToken->next->str()[0] == '\"')
{
const Token *strtok = cback();
while (strtok->comment)
strtok = strtok->previous;
loc.push(location);
location.fileIndex = fileIndex(strtok->str().substr(1U, strtok->str().size() - 2U));
location.line = 1U;
}
// TODO: add support for "# 3"
// #3 "file.c"
// #line 3 "file.c"
else if ((llNextToken->number &&
llNextToken->next->str()[0] == '\"') ||
(llNextToken->str() == "line" &&
llNextToken->next->number &&
llNextToken->next->next &&
llNextToken->next->next->str()[0] == '\"'))
if ((llNextToken->number &&
llNextToken->next->str()[0] == '\"') ||
(llNextToken->str() == "line" &&
llNextToken->next->number &&
llNextToken->next->next &&
llNextToken->next->next->str()[0] == '\"'))
{
const Token *strtok = cback();
while (strtok->comment)
Expand All @@ -744,12 +731,6 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
lineDirective(location.fileIndex, std::atol(numtok->str().c_str()), &location);
}
}
// #endfile
else if (llNextToken->str() == "endfile" && !loc.empty())
{
location = loc.top();
loc.pop();
}
}

continue;
Expand Down
2 changes: 0 additions & 2 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2138,8 +2138,6 @@ static void location11()
preprocess(code));
}

// TODO: test #file/#endfile

static void missingHeader1()
{
const char code[] = "#include \"notexist.h\"\n";
Expand Down
Loading