2010-02-16 09:31:36 +00:00
|
|
|
//===-- ASTMerge.cpp - AST Merging Frontent Action --------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/FrontendActions.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/ASTDiagnostic.h"
|
|
|
|
#include "clang/AST/ASTImporter.h"
|
2010-04-06 15:53:59 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2010-02-16 09:31:36 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
ASTConsumer *ASTMergeAction::CreateASTConsumer(CompilerInstance &CI,
|
2011-10-20 21:14:49 +00:00
|
|
|
StringRef InFile) {
|
2010-02-16 09:31:36 +00:00
|
|
|
return AdaptedAction->CreateASTConsumer(CI, InFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI,
|
2011-10-20 21:14:49 +00:00
|
|
|
StringRef Filename) {
|
2010-02-16 09:31:36 +00:00
|
|
|
// FIXME: This is a hack. We need a better way to communicate the
|
|
|
|
// AST file, compiler instance, and file name than member variables
|
|
|
|
// of FrontendAction.
|
2012-04-14 14:01:31 +00:00
|
|
|
AdaptedAction->setCurrentInput(getCurrentInput(), takeCurrentASTUnit());
|
2010-02-16 09:31:36 +00:00
|
|
|
AdaptedAction->setCompilerInstance(&CI);
|
|
|
|
return AdaptedAction->BeginSourceFileAction(CI, Filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTMergeAction::ExecuteAction() {
|
|
|
|
CompilerInstance &CI = getCompilerInstance();
|
|
|
|
CI.getDiagnostics().getClient()->BeginSourceFile(
|
2012-04-14 14:01:31 +00:00
|
|
|
CI.getASTContext().getLangOpts());
|
2010-02-16 09:31:36 +00:00
|
|
|
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
|
|
|
|
&CI.getASTContext());
|
2012-04-14 14:01:31 +00:00
|
|
|
IntrusiveRefCntPtr<DiagnosticIDs>
|
2011-02-20 13:06:31 +00:00
|
|
|
DiagIDs(CI.getDiagnostics().getDiagnosticIDs());
|
2010-02-16 09:31:36 +00:00
|
|
|
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
|
2012-04-14 14:01:31 +00:00
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine>
|
2011-10-20 21:14:49 +00:00
|
|
|
Diags(new DiagnosticsEngine(DiagIDs, CI.getDiagnostics().getClient(),
|
2011-02-20 13:06:31 +00:00
|
|
|
/*ShouldOwnClient=*/false));
|
|
|
|
ASTUnit *Unit = ASTUnit::LoadFromASTFile(ASTFiles[I], Diags,
|
|
|
|
CI.getFileSystemOpts(), false);
|
2010-02-16 09:31:36 +00:00
|
|
|
if (!Unit)
|
|
|
|
continue;
|
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
ASTImporter Importer(CI.getASTContext(),
|
2010-02-16 09:31:36 +00:00
|
|
|
CI.getFileManager(),
|
|
|
|
Unit->getASTContext(),
|
2011-02-20 13:06:31 +00:00
|
|
|
Unit->getFileManager(),
|
|
|
|
/*MinimalImport=*/false);
|
2010-02-16 09:31:36 +00:00
|
|
|
|
|
|
|
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
|
|
|
|
for (DeclContext::decl_iterator D = TU->decls_begin(),
|
|
|
|
DEnd = TU->decls_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
// Don't re-import __va_list_tag, __builtin_va_list.
|
|
|
|
if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
|
|
|
|
if (IdentifierInfo *II = ND->getIdentifier())
|
|
|
|
if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Importer.Import(*D);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete Unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
AdaptedAction->ExecuteAction();
|
|
|
|
CI.getDiagnostics().getClient()->EndSourceFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTMergeAction::EndSourceFileAction() {
|
|
|
|
return AdaptedAction->EndSourceFileAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTMergeAction::ASTMergeAction(FrontendAction *AdaptedAction,
|
2012-04-14 14:01:31 +00:00
|
|
|
ArrayRef<std::string> ASTFiles)
|
|
|
|
: AdaptedAction(AdaptedAction), ASTFiles(ASTFiles.begin(), ASTFiles.end()) {
|
2010-02-16 09:31:36 +00:00
|
|
|
assert(AdaptedAction && "ASTMergeAction needs an action to adapt");
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTMergeAction::~ASTMergeAction() {
|
|
|
|
delete AdaptedAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::usesPreprocessorOnly() const {
|
|
|
|
return AdaptedAction->usesPreprocessorOnly();
|
|
|
|
}
|
|
|
|
|
2011-10-20 21:14:49 +00:00
|
|
|
TranslationUnitKind ASTMergeAction::getTranslationUnitKind() {
|
|
|
|
return AdaptedAction->getTranslationUnitKind();
|
2010-02-16 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::hasPCHSupport() const {
|
|
|
|
return AdaptedAction->hasPCHSupport();
|
|
|
|
}
|
|
|
|
|
2010-07-13 17:21:42 +00:00
|
|
|
bool ASTMergeAction::hasASTFileSupport() const {
|
|
|
|
return AdaptedAction->hasASTFileSupport();
|
2010-02-16 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::hasCodeCompletionSupport() const {
|
|
|
|
return AdaptedAction->hasCodeCompletionSupport();
|
|
|
|
}
|