Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 1 | //===-- ModelInjector.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10 | /// This file defines the clang::ento::ModelInjector class which implements the |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 11 | /// clang::CodeInjector interface. This class is responsible for injecting |
| 12 | /// function definitions that were synthesized from model files. |
| 13 | /// |
| 14 | /// Model files allow definitions of functions to be lazily constituted for functions |
| 15 | /// which lack bodies in the original source code. This allows the analyzer |
| 16 | /// to more precisely analyze code that calls such functions, analyzing the |
| 17 | /// artificial definitions (which typically approximate the semantics of the |
| 18 | /// called function) when called by client code. These definitions are |
| 19 | /// reconstituted lazily, on-demand, by the static analyzer engine. |
| 20 | /// |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
| 23 | #ifndef LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H |
| 24 | #define LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H |
| 25 | |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 26 | #include "clang/Analysis/CodeInjector.h" |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringMap.h" |
| 28 | |
| 29 | namespace clang { |
| 30 | |
| 31 | class CompilerInstance; |
| 32 | class ASTUnit; |
| 33 | class ASTReader; |
| 34 | class NamedDecl; |
| 35 | class Module; |
| 36 | |
| 37 | namespace ento { |
| 38 | class ModelInjector : public CodeInjector { |
| 39 | public: |
| 40 | ModelInjector(CompilerInstance &CI); |
Alexander Kornienko | 34eb207 | 2015-04-11 02:00:23 +0000 | [diff] [blame] | 41 | Stmt *getBody(const FunctionDecl *D) override; |
| 42 | Stmt *getBody(const ObjCMethodDecl *D) override; |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 43 | |
| 44 | private: |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 45 | /// Synthesize a body for a declaration |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 46 | /// |
| 47 | /// This method first looks up the appropriate model file based on the |
| 48 | /// model-path configuration option and the name of the declaration that is |
| 49 | /// looked up. If no model were synthesized yet for a function with that name |
| 50 | /// it will create a new compiler instance to parse the model file using the |
| 51 | /// ASTContext, Preprocessor, SourceManager of the original compiler instance. |
| 52 | /// The former resources are shared between the two compiler instance, so the |
| 53 | /// newly created instance have to "leak" these objects, since they are owned |
| 54 | /// by the original instance. |
| 55 | /// |
| 56 | /// The model-path should be either an absolute path or relative to the |
| 57 | /// working directory of the compiler. |
| 58 | void onBodySynthesis(const NamedDecl *D); |
| 59 | |
| 60 | CompilerInstance &CI; |
| 61 | |
| 62 | // FIXME: double memoization is redundant, with memoization both here and in |
| 63 | // BodyFarm. |
| 64 | llvm::StringMap<Stmt *> Bodies; |
| 65 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
Ted Kremenek | eeccb30 | 2014-08-27 15:14:15 +0000 | [diff] [blame] | 68 | |
Daniel Dunbar | 214671f | 2014-10-09 20:34:45 +0000 | [diff] [blame] | 69 | #endif |