clang API Documentation

ModelInjector.h
Go to the documentation of this file.
00001 //===-- ModelInjector.h -----------------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief This file defines the clang::ento::ModelInjector class which implements the
00012 /// clang::CodeInjector interface. This class is responsible for injecting
00013 /// function definitions that were synthesized from model files.
00014 ///
00015 /// Model files allow definitions of functions to be lazily constituted for functions
00016 /// which lack bodies in the original source code.  This allows the analyzer
00017 /// to more precisely analyze code that calls such functions, analyzing the
00018 /// artificial definitions (which typically approximate the semantics of the
00019 /// called function) when called by client code.  These definitions are
00020 /// reconstituted lazily, on-demand, by the static analyzer engine.
00021 ///
00022 //===----------------------------------------------------------------------===//
00023 
00024 #ifndef LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H
00025 #define LLVM_CLANG_SA_FRONTEND_MODELINJECTOR_H
00026 
00027 #include <map>
00028 #include <vector>
00029 #include <memory>
00030 
00031 #include "clang/Analysis/CodeInjector.h"
00032 #include "llvm/ADT/IntrusiveRefCntPtr.h"
00033 #include "llvm/ADT/StringMap.h"
00034 
00035 namespace clang {
00036 
00037 class CompilerInstance;
00038 class ASTUnit;
00039 class ASTReader;
00040 class NamedDecl;
00041 class Module;
00042 
00043 namespace ento {
00044 class ModelInjector : public CodeInjector {
00045 public:
00046   ModelInjector(CompilerInstance &CI);
00047   Stmt *getBody(const FunctionDecl *D);
00048   Stmt *getBody(const ObjCMethodDecl *D);
00049 
00050 private:
00051   /// \brief Synthesize a body for a declaration
00052   ///
00053   /// This method first looks up the appropriate model file based on the
00054   /// model-path configuration option and the name of the declaration that is
00055   /// looked up. If no model were synthesized yet for a function with that name
00056   /// it will create a new compiler instance to parse the model file using the
00057   /// ASTContext, Preprocessor, SourceManager of the original compiler instance.
00058   /// The former resources are shared between the two compiler instance, so the
00059   /// newly created instance have to "leak" these objects, since they are owned
00060   /// by the original instance.
00061   ///
00062   /// The model-path should be either an absolute path or relative to the
00063   /// working directory of the compiler.
00064   void onBodySynthesis(const NamedDecl *D);
00065 
00066   CompilerInstance &CI;
00067 
00068   // FIXME: double memoization is redundant, with memoization both here and in
00069   // BodyFarm.
00070   llvm::StringMap<Stmt *> Bodies;
00071 };
00072 }
00073 }
00074 
00075 #endif