From 4e018d0a208894938f1e5fc6e070b2c85b48152e Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Mon, 6 Feb 2012 09:40:52 -0800 Subject: [PATCH] Improve tracking of source position in the presence of /* */ comments. Don't let the preprocessor remove comments anymore, so that the rules in lex.ll can handle them. Fix lCComment() to update the source position as it eats characters in comments. --- lex.ll | 4 +++- module.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lex.ll b/lex.ll index 9797e4e5..e5e395c3 100644 --- a/lex.ll +++ b/lex.ll @@ -309,8 +309,10 @@ lParseBinary(const char *ptr, SourcePos pos, char **endPtr) { static void lCComment(SourcePos *pos) { char c, prev = 0; - + while ((c = yyinput()) != 0) { + ++pos->last_column; + if (c == '\n') { pos->last_line++; pos->last_column = 1; diff --git a/module.cpp b/module.cpp index 3881ae2b..6bd79332 100644 --- a/module.cpp +++ b/module.cpp @@ -1170,6 +1170,10 @@ Module::execPreprocessor(const char* infilename, llvm::raw_string_ostream* ostre inst.createSourceManager(inst.getFileManager()); inst.InitializeSourceManager(infilename); + // Don't remove comments in the preprocessor, so that we can accurately + // track the source file position by handling them ourselves. + inst.getPreprocessorOutputOpts().ShowComments = 1; + clang::PreprocessorOptions &opts = inst.getPreprocessorOpts(); // Add defs for ISPC and PI