blob: d01454f9dc64d1772f735dc99f5dc2e2ec462f09 [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"
21#include "llvm/System/Path.h"
Douglas Gregor4db64a42010-01-23 00:14:00 +000022#include <vector>
Ted Kremenekab188932010-01-05 19:32:54 +000023
24using namespace clang;
25
26/// IgnoreDiagnosticsClient - A DiagnosticsClient that just ignores emitted
27/// warnings and errors.
28class IgnoreDiagnosticsClient : public DiagnosticClient {
29public:
30 virtual ~IgnoreDiagnosticsClient() {}
31 virtual void HandleDiagnostic(Diagnostic::Level, const DiagnosticInfo &) {}
32};
33
Douglas Gregora030b7c2010-01-22 20:35:53 +000034class CIndexer {
Ted Kremenekab188932010-01-05 19:32:54 +000035 DiagnosticOptions DiagOpts;
36 IgnoreDiagnosticsClient IgnoreDiagClient;
37 llvm::OwningPtr<Diagnostic> TextDiags;
38 Diagnostic IgnoreDiags;
39 bool UseExternalASTGeneration;
40 bool OnlyLocalDecls;
41 bool DisplayDiagnostics;
42
43 llvm::sys::Path ClangPath;
44
45public:
Douglas Gregora030b7c2010-01-22 20:35:53 +000046 CIndexer() : IgnoreDiags(&IgnoreDiagClient), UseExternalASTGeneration(false),
47 OnlyLocalDecls(false), DisplayDiagnostics(false)
48 {
Ted Kremenekab188932010-01-05 19:32:54 +000049 TextDiags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0));
50 }
51
Ted Kremenekab188932010-01-05 19:32:54 +000052 /// \brief Whether we only want to see "local" declarations (that did not
53 /// come from a previous precompiled header). If false, we want to see all
54 /// declarations.
55 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
56 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
57
58 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
59 void setDisplayDiagnostics(bool Display = true) {
60 DisplayDiagnostics = Display;
61 }
62
63 bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
64 void setUseExternalASTGeneration(bool Value) {
65 UseExternalASTGeneration = Value;
66 }
67
68 Diagnostic &getDiags() {
69 return DisplayDiagnostics ? *TextDiags : IgnoreDiags;
70 }
71
72 /// \brief Get the path of the clang binary.
73 const llvm::sys::Path& getClangPath();
74
75 /// \brief Get the path of the clang resource files.
76 std::string getClangResourcesPath();
Ted Kremenek4b333d22010-01-12 00:36:38 +000077
78 static CXString createCXString(const char *String, bool DupString = false);
Ted Kremenekab188932010-01-05 19:32:54 +000079};
80
Douglas Gregor4db64a42010-01-23 00:14:00 +000081namespace clang {
82 /**
83 * \brief Given a set of "unsaved" files, create temporary files and
84 * construct the clang -cc1 argument list needed to perform the remapping.
85 *
86 * \returns true if an error occurred.
87 */
88 bool RemapFiles(unsigned num_unsaved_files,
89 struct CXUnsavedFile *unsaved_files,
90 std::vector<std::string> &RemapArgs,
91 std::vector<llvm::sys::Path> &TemporaryFiles);
92}
93
Ted Kremenekab188932010-01-05 19:32:54 +000094#endif