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