clang 17.0.0git
ModelInjector.h
Go to the documentation of this file.
1//===-- ModelInjector.h -----------------------------------------*- C++ -*-===//
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 defines the clang::ento::ModelInjector class which implements the
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
27#include "llvm/ADT/StringMap.h"
28
29namespace clang {
30
31class CompilerInstance;
32class NamedDecl;
33
34namespace ento {
36public:
38 Stmt *getBody(const FunctionDecl *D) override;
39 Stmt *getBody(const ObjCMethodDecl *D) override;
40
41private:
42 /// Synthesize a body for a declaration
43 ///
44 /// This method first looks up the appropriate model file based on the
45 /// model-path configuration option and the name of the declaration that is
46 /// looked up. If no model were synthesized yet for a function with that name
47 /// it will create a new compiler instance to parse the model file using the
48 /// ASTContext, Preprocessor, SourceManager of the original compiler instance.
49 /// The former resources are shared between the two compiler instance, so the
50 /// newly created instance have to "leak" these objects, since they are owned
51 /// by the original instance.
52 ///
53 /// The model-path should be either an absolute path or relative to the
54 /// working directory of the compiler.
55 void onBodySynthesis(const NamedDecl *D);
56
58
59 // FIXME: double memoization is redundant, with memoization both here and in
60 // BodyFarm.
61 llvm::StringMap<Stmt *> Bodies;
62};
63}
64}
65
66#endif
Defines the clang::CodeInjector interface which is responsible for injecting AST of function definiti...
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
Definition: CodeInjector.h:35
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Represents a function declaration or definition.
Definition: Decl.h:1919
This represents a decl that may have a name.
Definition: Decl.h:247
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
Stmt - This represents one statement.
Definition: Stmt.h:72
Stmt * getBody(const FunctionDecl *D) override