Path: blob/main/contrib/llvm-project/clang/lib/StaticAnalyzer/Frontend/ModelInjector.h
35269 views
//===-- ModelInjector.h -----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file defines the clang::ento::ModelInjector class which implements the10/// clang::CodeInjector interface. This class is responsible for injecting11/// function definitions that were synthesized from model files.12///13/// Model files allow definitions of functions to be lazily constituted for functions14/// which lack bodies in the original source code. This allows the analyzer15/// to more precisely analyze code that calls such functions, analyzing the16/// artificial definitions (which typically approximate the semantics of the17/// called function) when called by client code. These definitions are18/// reconstituted lazily, on-demand, by the static analyzer engine.19///20//===----------------------------------------------------------------------===//2122#ifndef LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H23#define LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H2425#include "clang/Analysis/CodeInjector.h"26#include "llvm/ADT/StringMap.h"2728namespace clang {2930class CompilerInstance;31class NamedDecl;3233namespace ento {34class ModelInjector : public CodeInjector {35public:36ModelInjector(CompilerInstance &CI);37Stmt *getBody(const FunctionDecl *D) override;38Stmt *getBody(const ObjCMethodDecl *D) override;3940private:41/// Synthesize a body for a declaration42///43/// This method first looks up the appropriate model file based on the44/// model-path configuration option and the name of the declaration that is45/// looked up. If no model were synthesized yet for a function with that name46/// it will create a new compiler instance to parse the model file using the47/// ASTContext, Preprocessor, SourceManager of the original compiler instance.48/// The former resources are shared between the two compiler instance, so the49/// newly created instance have to "leak" these objects, since they are owned50/// by the original instance.51///52/// The model-path should be either an absolute path or relative to the53/// working directory of the compiler.54void onBodySynthesis(const NamedDecl *D);5556CompilerInstance &CI;5758// FIXME: double memoization is redundant, with memoization both here and in59// BodyFarm.60llvm::StringMap<Stmt *> Bodies;61};62}63}6465#endif666768