blob: 1a4e4b7b8f0b1aa8f047535622153956e14dac5a [file] [log] [blame]
Ted Kremenek0ec2cca2010-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 Kremenek0ec2cca2010-01-05 19:32:54 +000019#include "clang/Frontend/CompilerInstance.h"
20#include "clang/Frontend/ASTUnit.h"
21#include "llvm/System/Path.h"
22
23using namespace clang;
24
25/// IgnoreDiagnosticsClient - A DiagnosticsClient that just ignores emitted
26/// warnings and errors.
27class IgnoreDiagnosticsClient : public DiagnosticClient {
28public:
29 virtual ~IgnoreDiagnosticsClient() {}
30 virtual void HandleDiagnostic(Diagnostic::Level, const DiagnosticInfo &) {}
31};
32
Douglas Gregor87752492010-01-22 20:35:53 +000033class CIndexer {
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000034 DiagnosticOptions DiagOpts;
35 IgnoreDiagnosticsClient IgnoreDiagClient;
36 llvm::OwningPtr<Diagnostic> TextDiags;
37 Diagnostic IgnoreDiags;
38 bool UseExternalASTGeneration;
39 bool OnlyLocalDecls;
40 bool DisplayDiagnostics;
41
42 llvm::sys::Path ClangPath;
43
44public:
Douglas Gregor87752492010-01-22 20:35:53 +000045 CIndexer() : IgnoreDiags(&IgnoreDiagClient), UseExternalASTGeneration(false),
46 OnlyLocalDecls(false), DisplayDiagnostics(false)
47 {
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000048 TextDiags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0));
49 }
50
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000051 /// \brief Whether we only want to see "local" declarations (that did not
52 /// come from a previous precompiled header). If false, we want to see all
53 /// declarations.
54 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
55 void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
56
57 bool getDisplayDiagnostics() const { return DisplayDiagnostics; }
58 void setDisplayDiagnostics(bool Display = true) {
59 DisplayDiagnostics = Display;
60 }
61
62 bool getUseExternalASTGeneration() const { return UseExternalASTGeneration; }
63 void setUseExternalASTGeneration(bool Value) {
64 UseExternalASTGeneration = Value;
65 }
66
67 Diagnostic &getDiags() {
68 return DisplayDiagnostics ? *TextDiags : IgnoreDiags;
69 }
70
71 /// \brief Get the path of the clang binary.
72 const llvm::sys::Path& getClangPath();
73
74 /// \brief Get the path of the clang resource files.
75 std::string getClangResourcesPath();
Ted Kremenek46157972010-01-12 00:36:38 +000076
77 static CXString createCXString(const char *String, bool DupString = false);
Ted Kremenek0ec2cca2010-01-05 19:32:54 +000078};
79
80#endif