Skip to content

Commit 59f860f

Browse files
committed
fix: Set the offset of the EOF token to the end of the main file
1 parent a2c521d commit 59f860f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/parser/cxx/preprocessor.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,8 +2905,14 @@ void Preprocessor::beginPreprocessing(std::string source, std::string fileName,
29052905

29062906
void Preprocessor::endPreprocessing(std::vector<Token> &tokens) {
29072907
if (tokens.empty()) return;
2908-
auto sourceFileId = tokens.back().fileId();
2909-
tokens.emplace_back(TokenKind::T_EOF_SYMBOL, sourceFileId);
2908+
2909+
// assume the main source file is the first one
2910+
const auto mainSourceFileId = 1;
2911+
2912+
// place the EOF token at the end of the main source file
2913+
const auto offset = d->sourceFiles_[mainSourceFileId - 1]->source.size();
2914+
auto &tk = tokens.emplace_back(TokenKind::T_EOF_SYMBOL, offset);
2915+
tk.setFileId(mainSourceFileId);
29102916
}
29112917

29122918
auto Preprocessor::continuePreprocessing(std::vector<Token> &tokens) -> Status {

0 commit comments

Comments
 (0)