2010-02-09 19:21:46 +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/AST/ASTContext.h"
|
2010-02-09 22:37:58 +00:00
|
|
|
#include "clang/AST/ASTDiagnostic.h"
|
2010-02-09 19:21:46 +00:00
|
|
|
#include "clang/AST/ASTImporter.h"
|
2010-04-05 23:52:57 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2012-12-04 09:13:33 +00:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/FrontendActions.h"
|
2010-02-09 19:21:46 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2014-08-10 19:56:51 +00:00
|
|
|
std::unique_ptr<ASTConsumer>
|
|
|
|
ASTMergeAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
2010-02-09 19:21:46 +00:00
|
|
|
return AdaptedAction->CreateASTConsumer(CI, InFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI,
|
2011-07-23 10:55:15 +00:00
|
|
|
StringRef Filename) {
|
2010-02-09 19:21:46 +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-01-20 16:28:04 +00:00
|
|
|
AdaptedAction->setCurrentInput(getCurrentInput(), takeCurrentASTUnit());
|
2010-02-09 19:21:46 +00:00
|
|
|
AdaptedAction->setCompilerInstance(&CI);
|
|
|
|
return AdaptedAction->BeginSourceFileAction(CI, Filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTMergeAction::ExecuteAction() {
|
|
|
|
CompilerInstance &CI = getCompilerInstance();
|
2010-02-10 17:16:49 +00:00
|
|
|
CI.getDiagnostics().getClient()->BeginSourceFile(
|
2013-05-03 22:58:43 +00:00
|
|
|
CI.getASTContext().getLangOpts());
|
2010-02-09 22:37:58 +00:00
|
|
|
CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
|
|
|
|
&CI.getASTContext());
|
2012-02-20 14:00:23 +00:00
|
|
|
IntrusiveRefCntPtr<DiagnosticIDs>
|
2010-11-18 20:06:41 +00:00
|
|
|
DiagIDs(CI.getDiagnostics().getDiagnosticIDs());
|
2010-02-09 19:21:46 +00:00
|
|
|
for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
|
2012-02-20 14:00:23 +00:00
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine>
|
2012-10-23 22:26:28 +00:00
|
|
|
Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(),
|
2013-05-03 22:58:43 +00:00
|
|
|
new ForwardingDiagnosticConsumer(
|
|
|
|
*CI.getDiagnostics().getClient()),
|
|
|
|
/*ShouldOwnClient=*/true));
|
2015-06-20 18:53:08 +00:00
|
|
|
std::unique_ptr<ASTUnit> Unit =
|
2015-07-17 01:19:54 +00:00
|
|
|
ASTUnit::LoadFromASTFile(ASTFiles[I], CI.getPCHContainerReader(),
|
2015-06-20 18:53:08 +00:00
|
|
|
Diags, CI.getFileSystemOpts(), false);
|
|
|
|
|
2010-02-09 19:21:46 +00:00
|
|
|
if (!Unit)
|
|
|
|
continue;
|
|
|
|
|
2010-11-18 20:06:41 +00:00
|
|
|
ASTImporter Importer(CI.getASTContext(),
|
2010-02-10 00:15:17 +00:00
|
|
|
CI.getFileManager(),
|
|
|
|
Unit->getASTContext(),
|
2011-01-18 03:11:38 +00:00
|
|
|
Unit->getFileManager(),
|
|
|
|
/*MinimalImport=*/false);
|
2010-02-09 19:21:46 +00:00
|
|
|
|
|
|
|
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
|
2014-03-07 19:56:05 +00:00
|
|
|
for (auto *D : TU->decls()) {
|
2010-02-16 00:04:46 +00:00
|
|
|
// Don't re-import __va_list_tag, __builtin_va_list.
|
2014-03-07 19:56:05 +00:00
|
|
|
if (const auto *ND = dyn_cast<NamedDecl>(D))
|
2010-02-16 00:04:46 +00:00
|
|
|
if (IdentifierInfo *II = ND->getIdentifier())
|
|
|
|
if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
|
|
|
|
continue;
|
|
|
|
|
2015-04-28 18:24:12 +00:00
|
|
|
Decl *ToD = Importer.Import(D);
|
|
|
|
|
|
|
|
if (ToD) {
|
|
|
|
DeclGroupRef DGR(ToD);
|
|
|
|
CI.getASTConsumer().HandleTopLevelDecl(DGR);
|
|
|
|
}
|
2010-02-09 19:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 17:16:49 +00:00
|
|
|
AdaptedAction->ExecuteAction();
|
|
|
|
CI.getDiagnostics().getClient()->EndSourceFile();
|
2010-02-09 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTMergeAction::EndSourceFileAction() {
|
|
|
|
return AdaptedAction->EndSourceFileAction();
|
|
|
|
}
|
|
|
|
|
2016-02-07 19:28:36 +00:00
|
|
|
ASTMergeAction::ASTMergeAction(std::unique_ptr<FrontendAction> adaptedAction,
|
2012-02-04 01:36:04 +00:00
|
|
|
ArrayRef<std::string> ASTFiles)
|
2016-02-07 19:28:36 +00:00
|
|
|
: AdaptedAction(std::move(adaptedAction)), ASTFiles(ASTFiles.begin(), ASTFiles.end()) {
|
2010-02-09 19:21:46 +00:00
|
|
|
assert(AdaptedAction && "ASTMergeAction needs an action to adapt");
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTMergeAction::~ASTMergeAction() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::usesPreprocessorOnly() const {
|
|
|
|
return AdaptedAction->usesPreprocessorOnly();
|
|
|
|
}
|
|
|
|
|
2011-08-25 22:30:56 +00:00
|
|
|
TranslationUnitKind ASTMergeAction::getTranslationUnitKind() {
|
|
|
|
return AdaptedAction->getTranslationUnitKind();
|
2010-02-09 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::hasPCHSupport() const {
|
|
|
|
return AdaptedAction->hasPCHSupport();
|
|
|
|
}
|
|
|
|
|
2010-06-07 23:24:43 +00:00
|
|
|
bool ASTMergeAction::hasASTFileSupport() const {
|
|
|
|
return AdaptedAction->hasASTFileSupport();
|
2010-02-09 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTMergeAction::hasCodeCompletionSupport() const {
|
|
|
|
return AdaptedAction->hasCodeCompletionSupport();
|
|
|
|
}
|