ModelConsumer.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "clang/StaticAnalyzer/Frontend/ModelConsumer.h"
  22. #include "clang/AST/Decl.h"
  23. #include "clang/AST/DeclGroup.h"
  24. using namespace clang;
  25. using namespace ento;
  26. ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)
  27. : Bodies(Bodies) {}
  28. bool ModelConsumer::HandleTopLevelDecl(DeclGroupRef D) {
  29. for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
  30. // Only interested in definitions.
  31. const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I);
  32. if (func && func->hasBody()) {
  33. Bodies.insert(std::make_pair(func->getName(), func->getBody()));
  34. }
  35. }
  36. return true;
  37. }