xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/StaticAnalyzer/Frontend/ModelConsumer.cpp (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1*7330f729Sjoerg //===--- ModelConsumer.cpp - ASTConsumer for consuming model files --------===//
2*7330f729Sjoerg //
3*7330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*7330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
5*7330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*7330f729Sjoerg //
7*7330f729Sjoerg //===----------------------------------------------------------------------===//
8*7330f729Sjoerg ///
9*7330f729Sjoerg /// \file
10*7330f729Sjoerg /// This file implements an ASTConsumer for consuming model files.
11*7330f729Sjoerg ///
12*7330f729Sjoerg /// This ASTConsumer handles the AST of a parsed model file. All top level
13*7330f729Sjoerg /// function definitions will be collected from that model file for later
14*7330f729Sjoerg /// retrieval during the static analysis. The body of these functions will not
15*7330f729Sjoerg /// be injected into the ASTUnit of the analyzed translation unit. It will be
16*7330f729Sjoerg /// available through the BodyFarm which is utilized by the AnalysisDeclContext
17*7330f729Sjoerg /// class.
18*7330f729Sjoerg ///
19*7330f729Sjoerg //===----------------------------------------------------------------------===//
20*7330f729Sjoerg 
21*7330f729Sjoerg #include "clang/StaticAnalyzer/Frontend/ModelConsumer.h"
22*7330f729Sjoerg #include "clang/AST/Decl.h"
23*7330f729Sjoerg #include "clang/AST/DeclGroup.h"
24*7330f729Sjoerg 
25*7330f729Sjoerg using namespace clang;
26*7330f729Sjoerg using namespace ento;
27*7330f729Sjoerg 
ModelConsumer(llvm::StringMap<Stmt * > & Bodies)28*7330f729Sjoerg ModelConsumer::ModelConsumer(llvm::StringMap<Stmt *> &Bodies)
29*7330f729Sjoerg     : Bodies(Bodies) {}
30*7330f729Sjoerg 
HandleTopLevelDecl(DeclGroupRef D)31*7330f729Sjoerg bool ModelConsumer::HandleTopLevelDecl(DeclGroupRef D) {
32*7330f729Sjoerg   for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) {
33*7330f729Sjoerg 
34*7330f729Sjoerg     // Only interested in definitions.
35*7330f729Sjoerg     const FunctionDecl *func = llvm::dyn_cast<FunctionDecl>(*I);
36*7330f729Sjoerg     if (func && func->hasBody()) {
37*7330f729Sjoerg       Bodies.insert(std::make_pair(func->getName(), func->getBody()));
38*7330f729Sjoerg     }
39*7330f729Sjoerg   }
40*7330f729Sjoerg   return true;
41*7330f729Sjoerg }
42