We don't need the ASTContext for the diagnostics, only the language
options, which we can get from the compiler invocation. It worries me
how many categorically different states the ASTUnit class can be in
depending on how it is being constructed/used.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206909
91177308-0d34-0410-b5e6-
96231b3b80d8
assert(TheSema && "ASTUnit does not have a Sema object!");
return *TheSema;
}
+
+ const LangOptions &getLangOpts() const {
+ assert(LangOpts && " ASTUnit does not have language options");
+ return *LangOpts;
+ }
const FileManager &getFileManager() const { return *FileMgr; }
FileManager &getFileManager() { return *FileMgr; }
}
void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
- // Steal the created target, context, and preprocessor.
+ // Steal the created target, context, and preprocessor if they have been
+ // created.
+ assert(CI.hasInvocation() && "missing invocation");
+ LangOpts = CI.getInvocation().getLangOpts();
TheSema.reset(CI.takeSema());
Consumer.reset(CI.takeASTConsumer());
if (CI.hasASTContext())
for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
DEnd = Unit->stored_diag_end();
D != DEnd; ++D) {
- CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOpts());
+ CXStoredDiagnostic Diag(*D, Unit->getLangOpts());
CXString Msg = clang_formatDiagnostic(&Diag,
clang_defaultDiagnosticDisplayOptions());
fprintf(stderr, "%s\n", clang_getCString(Msg));