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