xref: /aosp_15_r20/external/clang/lib/StaticAnalyzer/Frontend/ModelConsumer.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===//
2*67e74705SXin Li //
3*67e74705SXin Li //                     The LLVM Compiler Infrastructure
4*67e74705SXin Li //
5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source
6*67e74705SXin Li // License. See LICENSE.TXT for details.
7*67e74705SXin Li //
8*67e74705SXin Li //===----------------------------------------------------------------------===//
9*67e74705SXin Li ///
10*67e74705SXin Li /// \file
11*67e74705SXin Li /// \brief This file implements an ASTConsumer for consuming model files.
12*67e74705SXin Li ///
13*67e74705SXin Li /// This ASTConsumer handles the AST of a parsed model file. All top level
14*67e74705SXin Li /// function definitions will be collected from that model file for later
15*67e74705SXin Li /// retrieval during the static analysis. The body of these functions will not
16*67e74705SXin Li /// be injected into the ASTUnit of the analyzed translation unit. It will be
17*67e74705SXin Li /// available through the BodyFarm which is utilized by the AnalysisDeclContext
18*67e74705SXin Li /// class.
19*67e74705SXin Li ///
20*67e74705SXin Li //===----------------------------------------------------------------------===//
21*67e74705SXin Li 
22*67e74705SXin Li #include "clang/StaticAnalyzer/Frontend/ModelConsumer.h"
23*67e74705SXin Li #include "clang/AST/Decl.h"
24*67e74705SXin Li #include "clang/AST/DeclGroup.h"
25*67e74705SXin Li 
26*67e74705SXin Li using namespace clang;
27*67e74705SXin Li using namespace ento;
28*67e74705SXin Li 
ModelConsumer(llvm::StringMap<Stmt * > & Bodies)29*67e74705SXin Li ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)
30*67e74705SXin Li     : Bodies(Bodies) {}
31*67e74705SXin Li 
HandleTopLevelDecl(DeclGroupRef D)32*67e74705SXin Li bool ModelConsumer::HandleTopLevelDecl(DeclGroupRef D) {
33*67e74705SXin Li   for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
34*67e74705SXin Li 
35*67e74705SXin Li     // Only interested in definitions.
36*67e74705SXin Li     const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I);
37*67e74705SXin Li     if (func && func->hasBody()) {
38*67e74705SXin Li       Bodies.insert(std::make_pair(func->getName(), func->getBody()));
39*67e74705SXin Li     }
40*67e74705SXin Li   }
41*67e74705SXin Li   return true;
42*67e74705SXin Li }
43