ModelConsumer.cpp 1.5 KB

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