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