10b57cec5SDimitry Andric //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric /// 90b57cec5SDimitry Andric /// \file 100b57cec5SDimitry Andric /// This file implements an ASTConsumer for consuming model files. 110b57cec5SDimitry Andric /// 120b57cec5SDimitry Andric /// This ASTConsumer handles the AST of a parsed model file. All top level 130b57cec5SDimitry Andric /// function definitions will be collected from that model file for later 140b57cec5SDimitry Andric /// retrieval during the static analysis. The body of these functions will not 150b57cec5SDimitry Andric /// be injected into the ASTUnit of the analyzed translation unit. It will be 160b57cec5SDimitry Andric /// available through the BodyFarm which is utilized by the AnalysisDeclContext 170b57cec5SDimitry Andric /// class. 180b57cec5SDimitry Andric /// 190b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Frontend/ModelConsumer.h" 220b57cec5SDimitry Andric #include "clang/AST/Decl.h" 230b57cec5SDimitry Andric #include "clang/AST/DeclGroup.h" 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric using namespace clang; 260b57cec5SDimitry Andric using namespace ento; 270b57cec5SDimitry Andric ModelConsumer(llvm::StringMap<Stmt * > & Bodies)280b57cec5SDimitry AndricModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies) 290b57cec5SDimitry Andric : Bodies(Bodies) {} 300b57cec5SDimitry Andric HandleTopLevelDecl(DeclGroupRef DeclGroup)31*06c3fb27SDimitry Andricbool ModelConsumer::HandleTopLevelDecl(DeclGroupRef DeclGroup) { 32*06c3fb27SDimitry Andric for (const Decl *D : DeclGroup) { 330b57cec5SDimitry Andric // Only interested in definitions. 34*06c3fb27SDimitry Andric const auto *func = llvm::dyn_cast<FunctionDecl>(D); 350b57cec5SDimitry Andric if (func && func->hasBody()) { 360b57cec5SDimitry Andric Bodies.insert(std::make_pair(func->getName(), func->getBody())); 370b57cec5SDimitry Andric } 380b57cec5SDimitry Andric } 390b57cec5SDimitry Andric return true; 400b57cec5SDimitry Andric } 41