blob: fd24e32f3a3d60b6cbcc57d4a3f22becb90b0002 [file] [log] [blame]
Stephen Hines176edba2014-12-01 14:53:08 -08001//===-- ModelInjector.h -----------------------------------------*- C++ -*-===//
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 defines the clang::ento::ModelInjector class which implements the
12/// clang::CodeInjector interface. This class is responsible for injecting
13/// function definitions that were synthesized from model files.
14///
15/// Model files allow definitions of functions to be lazily constituted for functions
16/// which lack bodies in the original source code. This allows the analyzer
17/// to more precisely analyze code that calls such functions, analyzing the
18/// artificial definitions (which typically approximate the semantics of the
19/// called function) when called by client code. These definitions are
20/// reconstituted lazily, on-demand, by the static analyzer engine.
21///
22//===----------------------------------------------------------------------===//
23
24#ifndef LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H
25#define LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H
26
Stephen Hines176edba2014-12-01 14:53:08 -080027#include "clang/Analysis/CodeInjector.h"
28#include "llvm/ADT/IntrusiveRefCntPtr.h"
29#include "llvm/ADT/StringMap.h"
Stephen Hines0e2c34f2015-03-23 12:09:02 -070030#include <map>
31#include <memory>
32#include <vector>
Stephen Hines176edba2014-12-01 14:53:08 -080033
34namespace clang {
35
36class CompilerInstance;
37class ASTUnit;
38class ASTReader;
39class NamedDecl;
40class Module;
41
42namespace ento {
43class ModelInjector : public CodeInjector {
44public:
45 ModelInjector(CompilerInstance &CI);
46 Stmt *getBody(const FunctionDecl *D);
47 Stmt *getBody(const ObjCMethodDecl *D);
48
49private:
50 /// \brief Synthesize a body for a declaration
51 ///
52 /// This method first looks up the appropriate model file based on the
53 /// model-path configuration option and the name of the declaration that is
54 /// looked up. If no model were synthesized yet for a function with that name
55 /// it will create a new compiler instance to parse the model file using the
56 /// ASTContext, Preprocessor, SourceManager of the original compiler instance.
57 /// The former resources are shared between the two compiler instance, so the
58 /// newly created instance have to "leak" these objects, since they are owned
59 /// by the original instance.
60 ///
61 /// The model-path should be either an absolute path or relative to the
62 /// working directory of the compiler.
63 void onBodySynthesis(const NamedDecl *D);
64
65 CompilerInstance &CI;
66
67 // FIXME: double memoization is redundant, with memoization both here and in
68 // BodyFarm.
69 llvm::StringMap<Stmt *> Bodies;
70};
71}
72}
73
74#endif