clang  6.0.0svn
ModelConsumer.cpp
Go to the documentation of this file.
1 //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file implements an ASTConsumer for consuming model files.
12 ///
13 /// This ASTConsumer handles the AST of a parsed model file. All top level
14 /// function definitions will be collected from that model file for later
15 /// retrieval during the static analysis. The body of these functions will not
16 /// be injected into the ASTUnit of the analyzed translation unit. It will be
17 /// available through the BodyFarm which is utilized by the AnalysisDeclContext
18 /// class.
19 ///
20 //===----------------------------------------------------------------------===//
21 
23 #include "clang/AST/Decl.h"
24 #include "clang/AST/DeclGroup.h"
25 
26 using namespace clang;
27 using namespace ento;
28 
29 ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)
30  : Bodies(Bodies) {}
31 
33  for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
34 
35  // Only interested in definitions.
36  const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I);
37  if (func && func->hasBody()) {
38  Bodies.insert(std::make_pair(func->getName(), func->getBody()));
39  }
40  }
41  return true;
42 }
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
iterator end()
Definition: DeclGroup.h:106
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
Definition: Decl.cpp:2612
iterator begin()
Definition: DeclGroup.h:100
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body (definition).
Definition: Decl.cpp:2576
ModelConsumer(llvm::StringMap< Stmt *> &Bodies)
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
Dataflow Directional Tag Classes.
This file implements clang::ento::ModelConsumer which is an ASTConsumer for model files...
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:270