clang  13.0.0git
ModelConsumer.cpp
Go to the documentation of this file.
1 //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file implements an ASTConsumer for consuming model files.
11 ///
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
17 /// class.
18 ///
19 //===----------------------------------------------------------------------===//
20 
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/DeclGroup.h"
24 
25 using namespace clang;
26 using namespace ento;
27 
28 ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)
29  : Bodies(Bodies) {}
30 
32  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
33 
34  // Only interested in definitions.
35  const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I);
36  if (func && func->hasBody()) {
37  Bodies.insert(std::make_pair(func->getName(), func->getBody()));
38  }
39  }
40  return true;
41 }
clang::DeclGroupRef::begin
iterator begin()
Definition: DeclGroup.h:99
clang::DeclGroupRef::end
iterator end()
Definition: DeclGroup.h:105
Decl.h
clang::ento::ModelConsumer::ModelConsumer
ModelConsumer(llvm::StringMap< Stmt * > &Bodies)
Definition: ModelConsumer.cpp:28
clang::FunctionDecl::getBody
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2980
ModelConsumer.h
DeclGroup.h
clang::ento::ModelConsumer::HandleTopLevelDecl
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ModelConsumer.cpp:31
clang::FunctionDecl::hasBody
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2900
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang
Dataflow Directional Tag Classes.
Definition: CalledOnceCheck.h:17
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1821
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250