blob: b1b6de9ef9d9a7fe3087e65dd24c6607954cbfce [file] [log] [blame]
Ted Kremenekeeccb302014-08-27 15:14:15 +00001//===-- 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011/// This file defines the clang::ento::ModelInjector class which implements the
Ted Kremenekeeccb302014-08-27 15:14:15 +000012/// 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
Ted Kremenekeeccb302014-08-27 15:14:15 +000027#include "clang/Analysis/CodeInjector.h"
Ted Kremenekeeccb302014-08-27 15:14:15 +000028#include "llvm/ADT/StringMap.h"
29
30namespace clang {
31
32class CompilerInstance;
33class ASTUnit;
34class ASTReader;
35class NamedDecl;
36class Module;
37
38namespace ento {
39class ModelInjector : public CodeInjector {
40public:
41 ModelInjector(CompilerInstance &CI);
Alexander Kornienko34eb2072015-04-11 02:00:23 +000042 Stmt *getBody(const FunctionDecl *D) override;
43 Stmt *getBody(const ObjCMethodDecl *D) override;
Ted Kremenekeeccb302014-08-27 15:14:15 +000044
45private:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000046 /// Synthesize a body for a declaration
Ted Kremenekeeccb302014-08-27 15:14:15 +000047 ///
48 /// This method first looks up the appropriate model file based on the
49 /// model-path configuration option and the name of the declaration that is
50 /// looked up. If no model were synthesized yet for a function with that name
51 /// it will create a new compiler instance to parse the model file using the
52 /// ASTContext, Preprocessor, SourceManager of the original compiler instance.
53 /// The former resources are shared between the two compiler instance, so the
54 /// newly created instance have to "leak" these objects, since they are owned
55 /// by the original instance.
56 ///
57 /// The model-path should be either an absolute path or relative to the
58 /// working directory of the compiler.
59 void onBodySynthesis(const NamedDecl *D);
60
61 CompilerInstance &CI;
62
63 // FIXME: double memoization is redundant, with memoization both here and in
64 // BodyFarm.
65 llvm::StringMap<Stmt *> Bodies;
66};
Alexander Kornienkoab9db512015-06-22 23:07:51 +000067}
68}
Ted Kremenekeeccb302014-08-27 15:14:15 +000069
Daniel Dunbar214671f2014-10-09 20:34:45 +000070#endif