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