clang API Documentation

ModelConsumer.cpp
Go to the documentation of this file.
00001 //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief This file implements an ASTConsumer for consuming model files.
00012 ///
00013 /// This ASTConsumer handles the AST of a parsed model file. All top level
00014 /// function definitions will be collected from that model file for later
00015 /// retrieval during the static analysis. The body of these functions will not
00016 /// be injected into the ASTUnit of the analyzed translation unit. It will be
00017 /// available through the BodyFarm which is utilized by the AnalysisDeclContext
00018 /// class.
00019 ///
00020 //===----------------------------------------------------------------------===//
00021 
00022 #include "clang/StaticAnalyzer/Frontend/ModelConsumer.h"
00023 #include "clang/AST/Decl.h"
00024 #include "clang/AST/DeclGroup.h"
00025 
00026 using namespace clang;
00027 using namespace ento;
00028 
00029 ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)
00030     : Bodies(Bodies) {}
00031 
00032 bool ModelConsumer::HandleTopLevelDecl(DeclGroupRef D) {
00033   for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
00034 
00035     // Only interested in definitions.
00036     const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I);
00037     if (func && func->hasBody()) {
00038       Bodies.insert(std::make_pair(func->getName(), func->getBody()));
00039     }
00040   }
00041   return true;
00042 }