blob: aa63ec0238086e44dd671092b93eccc393a0576a [file] [log] [blame]
Ted Kremenekab188932010-01-05 19:32:54 +00001//===- CIndexer.h - Clang-C Source Indexing Library -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines CIndexer, a subclass of Indexer that provides extra
11// functionality needed by the CIndex library.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_CINDEXER_H
16#define LLVM_CLANG_CINDEXER_H
17
18#include "clang-c/Index.h"
Ted Kremenekab188932010-01-05 19:32:54 +000019#include "clang/Frontend/CompilerInstance.h"
20#include "clang/Frontend/ASTUnit.h"
Douglas Gregorfc8ea232010-01-26 17:06:03 +000021#include "llvm/ADT/StringRef.h"
Ted Kremenekab188932010-01-05 19:32:54 +000022#include "llvm/System/Path.h"
Douglas Gregor4db64a42010-01-23 00:14:00 +000023#include <vector>
Ted Kremenekab188932010-01-05 19:32:54 +000024
25using namespace clang;
26
27/// IgnoreDiagnosticsClient - A DiagnosticsClient that just ignores emitted
28/// warnings and errors.
29class IgnoreDiagnosticsClient : public DiagnosticClient {
30public:
31 virtual ~IgnoreDiagnosticsClient() {}
32 virtual void HandleDiagnostic(Diagnostic::Level, const DiagnosticInfo &) {}
33};
34
Douglas Gregora030b7c2010-01-22 20:35:53 +000035class CIndexer {
Ted Kremenekab188932010-01-05 19:32:54 +000036 DiagnosticOptions DiagOpts;
37 IgnoreDiagnosticsClient IgnoreDiagClient;
38 llvm::OwningPtr<Diagnostic> TextDiags;
39 Diagnostic IgnoreDiags;
40 bool UseExternalASTGeneration;
41 bool OnlyLocalDecls;
42 bool DisplayDiagnostics;
43
44 llvm::sys::Path ClangPath;
45
46public:
Douglas Gregora030b7c2010-01-22 20:35:53 +000047 CIndexer() : IgnoreDiags(&IgnoreDiagClient), UseExternalASTGeneration(false),
48 OnlyLocalDecls(false), DisplayDiagnostics(false)
49 {
Ted Kremenekab188932010-01-05 19:32:54 +000050 TextDiags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0));
51 }
52
Ted Kremenekab188932010-01-05 19:32:54 +000053 /// \brief Whether we only want to see "local" declarations (that did not
54 /// come from a previous precompiled header). If false, we want to see all
55 /// declarations.
56 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
57 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
58
59 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
60 void setDisplayDiagnostics(bool Display = true) {
61 DisplayDiagnostics = Display;
62 }
63
64 bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
65 void setUseExternalASTGeneration(bool Value) {
66 UseExternalASTGeneration = Value;
67 }
68
69 Diagnostic &getDiags() {
70 return DisplayDiagnostics ? *TextDiags : IgnoreDiags;
71 }
72
73 /// \brief Get the path of the clang binary.
74 const llvm::sys::Path& getClangPath();
75
76 /// \brief Get the path of the clang resource files.
77 std::string getClangResourcesPath();
Ted Kremenek4b333d22010-01-12 00:36:38 +000078
79 static CXString createCXString(const char *String, bool DupString = false);
Douglas Gregorfc8ea232010-01-26 17:06:03 +000080 static CXString createCXString(llvm::StringRef String,
81 bool DupString = false);
Ted Kremenekab188932010-01-05 19:32:54 +000082};
83
Douglas Gregor4db64a42010-01-23 00:14:00 +000084namespace clang {
85 /**
86 * \brief Given a set of "unsaved" files, create temporary files and
87 * construct the clang -cc1 argument list needed to perform the remapping.
88 *
89 * \returns true if an error occurred.
90 */
91 bool RemapFiles(unsigned num_unsaved_files,
92 struct CXUnsavedFile *unsaved_files,
93 std::vector<std::string> &RemapArgs,
94 std::vector<llvm::sys::Path> &TemporaryFiles);
95}
96
Ted Kremenekab188932010-01-05 19:32:54 +000097#endif