139d628a0SDimitry Andric //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===// 239d628a0SDimitry Andric // 339d628a0SDimitry Andric // The LLVM Compiler Infrastructure 439d628a0SDimitry Andric // 539d628a0SDimitry Andric // This file is distributed under the University of Illinois Open Source 639d628a0SDimitry Andric // License. See LICENSE.TXT for details. 739d628a0SDimitry Andric // 839d628a0SDimitry Andric //===----------------------------------------------------------------------===// 939d628a0SDimitry Andric /// 1039d628a0SDimitry Andric /// \file 11*4ba319b5SDimitry Andric /// This file implements an ASTConsumer for consuming model files. 1239d628a0SDimitry Andric /// 1339d628a0SDimitry Andric /// This ASTConsumer handles the AST of a parsed model file. All top level 1439d628a0SDimitry Andric /// function definitions will be collected from that model file for later 1539d628a0SDimitry Andric /// retrieval during the static analysis. The body of these functions will not 1639d628a0SDimitry Andric /// be injected into the ASTUnit of the analyzed translation unit. It will be 1739d628a0SDimitry Andric /// available through the BodyFarm which is utilized by the AnalysisDeclContext 1839d628a0SDimitry Andric /// class. 1939d628a0SDimitry Andric /// 2039d628a0SDimitry Andric //===----------------------------------------------------------------------===// 2139d628a0SDimitry Andric 2239d628a0SDimitry Andric #include "clang/StaticAnalyzer/Frontend/ModelConsumer.h" 2339d628a0SDimitry Andric #include "clang/AST/Decl.h" 2439d628a0SDimitry Andric #include "clang/AST/DeclGroup.h" 2539d628a0SDimitry Andric 2639d628a0SDimitry Andric using namespace clang; 2739d628a0SDimitry Andric using namespace ento; 2839d628a0SDimitry Andric ModelConsumer(llvm::StringMap<Stmt * > & Bodies)2939d628a0SDimitry AndricModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies) 3039d628a0SDimitry Andric : Bodies(Bodies) {} 3139d628a0SDimitry Andric HandleTopLevelDecl(DeclGroupRef D)3239d628a0SDimitry Andricbool ModelConsumer::HandleTopLevelDecl(DeclGroupRef D) { 3339d628a0SDimitry Andric for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { 3439d628a0SDimitry Andric 3539d628a0SDimitry Andric // Only interested in definitions. 3639d628a0SDimitry Andric const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I); 3739d628a0SDimitry Andric if (func && func->hasBody()) { 3839d628a0SDimitry Andric Bodies.insert(std::make_pair(func->getName(), func->getBody())); 3939d628a0SDimitry Andric } 4039d628a0SDimitry Andric } 4139d628a0SDimitry Andric return true; 4239d628a0SDimitry Andric } 43