diff --git a/framaCIRGen_src/ACSLComment.cpp b/framaCIRGen_src/ACSLComment.cpp index e5c18ec6d483c84a8b80388e0f88867680ff105e..72e4b97a54272c198f0b3775e3a1024eae322143 100644 --- a/framaCIRGen_src/ACSLComment.cpp +++ b/framaCIRGen_src/ACSLComment.cpp @@ -32,6 +32,7 @@ #include "clang/Parse/Parser.h" #include "clang/AST/ASTConsumer.h" #include "clang/Sema/Scope.h" +#include <sstream> #include <string> bool @@ -261,12 +262,18 @@ void ACSLComment::parseGhostGlobal( code = code.substr(_startOfGhost); clang::SourceLocation loc = getSourceLocation().getLocWithOffset(_startOfGhost); // FIXME - check this for correct location + auto& source_manager = compilerInstance.getSourceManager(); + auto filename = source_manager.getFilename(loc); + auto line = source_manager.getSpellingLineNumber(loc); + std::ostringstream content; + content << "#line " << line << " \"" << filename.str() << "\"\n"; + auto buffer = content.str(); + buffer+=code; clang::Preprocessor& cpp = compilerInstance.getPreprocessor(); clang::Parser* parser = static_cast<clang::Parser*>(cpp.getCodeCompletionHandler()); std::unique_ptr<llvm::MemoryBuffer> buff = - llvm::MemoryBuffer::getMemBufferCopy(code, "ghost.cxx"); - clang::SourceManager& source_manager = compilerInstance.getSourceManager(); + llvm::MemoryBuffer::getMemBufferCopy(buffer, filename); clang::FileID file = source_manager.createFileID( std::move(buff),clang::SrcMgr::C_User,0,0,loc);