aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Frontend/CompilerInstance.h46
-rw-r--r--lib/Frontend/CompilerInstance.cpp10
-rw-r--r--tools/clang-cc/clang-cc.cpp21
3 files changed, 67 insertions, 10 deletions
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index c503d7a09f..fb52383465 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -20,6 +20,8 @@ class LLVMContext;
namespace clang {
class Diagnostic;
class DiagnosticClient;
+class FileManager;
+class SourceManager;
class TargetInfo;
/// CompilerInstance - Helper class for managing a single instance of the Clang
@@ -57,6 +59,12 @@ class CompilerInstance {
/// The target being compiled for.
llvm::OwningPtr<TargetInfo> Target;
+ /// The file manager.
+ llvm::OwningPtr<FileManager> FileMgr;
+
+ /// The source manager.
+ llvm::OwningPtr<SourceManager> SourceMgr;
+
public:
/// Create a new compiler instance with the given LLVM context, optionally
/// taking ownership of it.
@@ -192,6 +200,44 @@ public:
void setTarget(TargetInfo *Value) { Target.reset(Value); }
/// }
+ /// @name File Manager
+ /// {
+
+ FileManager &getFileManager() const { return *FileMgr; }
+
+ /// takeFileManager - Remove the current file manager and give ownership to
+ /// the caller.
+ FileManager *takeFileManager() { return FileMgr.take(); }
+
+ /// setFileManager - Replace the current file manager; the compiler instance
+ /// takes ownership of \arg Value.
+ void setFileManager(FileManager *Value) { FileMgr.reset(Value); }
+
+ /// }
+ /// @name Source Manager
+ /// {
+
+ SourceManager &getSourceManager() const { return *SourceMgr; }
+
+ /// takeSourceManager - Remove the current source manager and give ownership
+ /// to the caller.
+ SourceManager *takeSourceManager() { return SourceMgr.take(); }
+
+ /// setSourceManager - Replace the current source manager; the compiler
+ /// instance takes ownership of \arg Value.
+ void setSourceManager(SourceManager *Value) { SourceMgr.reset(Value); }
+
+ /// }
+ /// @name Construction Utility Methods
+ /// {
+
+ /// Create the file manager and replace any existing one with it.
+ void createFileManager();
+
+ /// Create the source manager and replace any existing one with it.
+ void createSourceManager();
+
+ /// }
};
} // end namespace clang
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index e791f24ee8..2d1f498e5c 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -9,6 +9,8 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/LLVMContext.h"
using namespace clang;
@@ -23,3 +25,11 @@ CompilerInstance::~CompilerInstance() {
if (OwnsLLVMContext)
delete LLVMContext;
}
+
+void CompilerInstance::createFileManager() {
+ FileMgr.reset(new FileManager());
+}
+
+void CompilerInstance::createSourceManager() {
+ SourceMgr.reset(new SourceManager());
+}
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 3f3cd6ed15..6c8d78ebc1 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -762,8 +762,7 @@ static void ProcessInputFile(CompilerInstance &CI, Preprocessor &PP,
/// ProcessInputFile - Process a single AST input file with the specified state.
///
static void ProcessASTInputFile(CompilerInstance &CI, const std::string &InFile,
- ProgActions PA, FileManager &FileMgr) {
- const FrontendOptions &FEOpts = CI.getFrontendOpts();
+ ProgActions PA) {
std::string Error;
llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, &Error));
if (!AST) {
@@ -793,12 +792,13 @@ static void ProcessASTInputFile(CompilerInstance &CI, const std::string &InFile,
// Stream the input AST to the consumer.
CI.getDiagnostics().getClient()->BeginSourceFile(PP.getLangOptions());
- ParseAST(PP, Consumer.get(), AST->getASTContext(), FEOpts.ShowStats);
+ ParseAST(PP, Consumer.get(), AST->getASTContext(),
+ CI.getFrontendOpts().ShowStats);
CI.getDiagnostics().getClient()->EndSourceFile();
// Release the consumer and the AST, in that order since the consumer may
// perform actions in its destructor which require the context.
- if (FEOpts.DisableFree) {
+ if (CI.getFrontendOpts().DisableFree) {
Consumer.take();
AST.take();
} else {
@@ -988,23 +988,23 @@ int main(int argc, char **argv) {
ProgAction = InheritanceView;
// Create the source manager.
- SourceManager SourceMgr;
+ Clang.createSourceManager();
// Create a file manager object to provide access to and cache the filesystem.
- FileManager FileMgr;
+ Clang.createFileManager();
for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) {
const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second;
// AST inputs are handled specially.
if (IsAST) {
- ProcessASTInputFile(Clang, InFile, ProgAction, FileMgr);
+ ProcessASTInputFile(Clang, InFile, ProgAction);
continue;
}
// Reset the ID tables if we are reusing the SourceManager.
if (i)
- SourceMgr.clearIDTables();
+ Clang.getSourceManager().clearIDTables();
// Set up the preprocessor with these options.
llvm::OwningPtr<Preprocessor>
@@ -1012,7 +1012,8 @@ int main(int argc, char **argv) {
Clang.getPreprocessorOpts(),
Clang.getHeaderSearchOpts(),
Clang.getDependencyOutputOpts(),
- Clang.getTarget(), SourceMgr, FileMgr));
+ Clang.getTarget(), Clang.getSourceManager(),
+ Clang.getFileManager()));
// Process the source file.
Clang.getDiagnostics().getClient()->BeginSourceFile(Clang.getLangOpts());
@@ -1026,7 +1027,7 @@ int main(int argc, char **argv) {
(NumDiagnostics == 1 ? "" : "s"));
if (Clang.getFrontendOpts().ShowStats) {
- FileMgr.PrintStats();
+ Clang.getFileManager().PrintStats();
fprintf(stderr, "\n");
}