MCPcopy Create free account
hub / github.com/KDAB/codebrowser / BrowserASTConsumer

Class BrowserASTConsumer

generator/main.cpp:147–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145};
146
147class BrowserASTConsumer : public clang::ASTConsumer
148{
149 clang::CompilerInstance &ci;
150 Annotator annotator;
151 DatabaseType WasInDatabase;
152public:
153 BrowserASTConsumer(clang::CompilerInstance &ci, ProjectManager &projectManager, DatabaseType WasInDatabase)
154 : clang::ASTConsumer(), ci(ci), annotator(projectManager), WasInDatabase(WasInDatabase)
155 {
156 //ci.getLangOpts().DelayedTemplateParsing = (true);
157 ci.getPreprocessor().enableIncrementalProcessing();
158 }
159 virtual ~BrowserASTConsumer() {
160 ci.getDiagnostics().setClient(new clang::IgnoringDiagConsumer, true);
161 }
162
163 virtual void Initialize(clang::ASTContext& Ctx) override {
164 annotator.setSourceMgr(Ctx.getSourceManager(), Ctx.getLangOpts());
165 annotator.setMangleContext(Ctx.createMangleContext());
166 ci.getPreprocessor().addPPCallbacks(maybe_unique(new PreprocessorCallback(
167 annotator, ci.getPreprocessor(), WasInDatabase == DatabaseType::ProcessFullDirectory)));
168 ci.getDiagnostics().setClient(new BrowserDiagnosticClient(annotator), true);
169 ci.getDiagnostics().setErrorLimit(0);
170 }
171
172 virtual bool HandleTopLevelDecl(clang::DeclGroupRef D) override {
173 if (ci.getDiagnostics().hasFatalErrorOccurred()) {
174 // Reset errors: (Hack to ignore the fatal errors.)
175 ci.getDiagnostics().Reset();
176 // When there was fatal error, processing the warnings may cause crashes
177 ci.getDiagnostics().setIgnoreAllWarnings(true);
178 }
179 return true;
180 }
181
182 virtual void HandleTranslationUnit(clang::ASTContext& Ctx) override {
183
184 /* if (PP.getDiagnostics().hasErrorOccurred())
185 return;*/
186 ci.getPreprocessor().getDiagnostics().getClient();
187
188
189 BrowserASTVisitor v(annotator);
190 v.TraverseDecl(Ctx.getTranslationUnitDecl());
191
192
193 annotator.generate(ci.getSema(), WasInDatabase != DatabaseType::NotInDatabase);
194 }
195
196 virtual bool shouldSkipFunctionBody(clang::Decl *D) override {
197 return !annotator.shouldProcess(
198 clang::FullSourceLoc(D->getLocation(),annotator.getSourceMgr())
199 .getExpansionLoc().getFileID());
200 }
201};
202
203class BrowserAction : public clang::ASTFrontendAction {
204 static std::set<std::string> processed;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected