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