Path: blob/main/contrib/llvm-project/clang/lib/StaticAnalyzer/Frontend/ModelConsumer.cpp
35266 views
//===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file implements an ASTConsumer for consuming model files.10///11/// This ASTConsumer handles the AST of a parsed model file. All top level12/// function definitions will be collected from that model file for later13/// retrieval during the static analysis. The body of these functions will not14/// be injected into the ASTUnit of the analyzed translation unit. It will be15/// available through the BodyFarm which is utilized by the AnalysisDeclContext16/// class.17///18//===----------------------------------------------------------------------===//1920#include "clang/StaticAnalyzer/Frontend/ModelConsumer.h"21#include "clang/AST/Decl.h"22#include "clang/AST/DeclGroup.h"2324using namespace clang;25using namespace ento;2627ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)28: Bodies(Bodies) {}2930bool ModelConsumer::HandleTopLevelDecl(DeclGroupRef DeclGroup) {31for (const Decl *D : DeclGroup) {32// Only interested in definitions.33const auto *func = llvm::dyn_cast<FunctionDecl>(D);34if (func && func->hasBody()) {35Bodies.insert(std::make_pair(func->getName(), func->getBody()));36}37}38return true;39}404142