Home | History | Annotate | Download | only in Expression
      1 //===-- ClangExpression.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 #ifndef liblldb_ClangExpression_h_
     11 #define liblldb_ClangExpression_h_
     12 
     13 // C Includes
     14 // C++ Includes
     15 #include <string>
     16 #include <map>
     17 #include <vector>
     18 
     19 // Other libraries and framework includes
     20 // Project includes
     21 
     22 #include "lldb/lldb-forward.h"
     23 #include "lldb/lldb-private.h"
     24 #include "lldb/Core/ClangForward.h"
     25 #include "lldb/Target/Process.h"
     26 
     27 namespace lldb_private {
     28 
     29 class RecordingMemoryManager;
     30 
     31 //----------------------------------------------------------------------
     32 /// @class ClangExpression ClangExpression.h "lldb/Expression/ClangExpression.h"
     33 /// @brief Encapsulates a single expression for use with Clang
     34 ///
     35 /// LLDB uses expressions for various purposes, notably to call functions
     36 /// and as a backend for the expr command.  ClangExpression encapsulates
     37 /// the objects needed to parse and interpret or JIT an expression.  It
     38 /// uses the Clang parser to produce LLVM IR from the expression.
     39 //----------------------------------------------------------------------
     40 class ClangExpression
     41 {
     42 public:
     43     enum ResultType {
     44         eResultTypeAny,
     45         eResultTypeId
     46     };
     47 
     48     ClangExpression () :
     49         m_jit_process_wp(),
     50         m_jit_start_addr (LLDB_INVALID_ADDRESS),
     51         m_jit_end_addr (LLDB_INVALID_ADDRESS)
     52     {
     53     }
     54 
     55     //------------------------------------------------------------------
     56     /// Destructor
     57     //------------------------------------------------------------------
     58     virtual ~ClangExpression ()
     59     {
     60     }
     61 
     62     //------------------------------------------------------------------
     63     /// Return the string that the parser should parse.  Must be a full
     64     /// translation unit.
     65     //------------------------------------------------------------------
     66     virtual const char *
     67     Text () = 0;
     68 
     69     //------------------------------------------------------------------
     70     /// Return the function name that should be used for executing the
     71     /// expression.  Text() should contain the definition of this
     72     /// function.
     73     //------------------------------------------------------------------
     74     virtual const char *
     75     FunctionName () = 0;
     76 
     77     //------------------------------------------------------------------
     78     /// Return the language that should be used when parsing.  To use
     79     /// the default, return eLanguageTypeUnknown.
     80     //------------------------------------------------------------------
     81     virtual lldb::LanguageType
     82     Language ()
     83     {
     84         return lldb::eLanguageTypeUnknown;
     85     }
     86 
     87     //------------------------------------------------------------------
     88     /// Return the object that the parser should use when resolving external
     89     /// values.  May be NULL if everything should be self-contained.
     90     //------------------------------------------------------------------
     91     virtual ClangExpressionDeclMap *
     92     DeclMap () = 0;
     93 
     94     //------------------------------------------------------------------
     95     /// Return the object that the parser should allow to access ASTs.
     96     /// May be NULL if the ASTs do not need to be transformed.
     97     ///
     98     /// @param[in] passthrough
     99     ///     The ASTConsumer that the returned transformer should send
    100     ///     the ASTs to after transformation.
    101     //------------------------------------------------------------------
    102     virtual clang::ASTConsumer *
    103     ASTTransformer (clang::ASTConsumer *passthrough) = 0;
    104 
    105     //------------------------------------------------------------------
    106     /// Return the desired result type of the function, or
    107     /// eResultTypeAny if indifferent.
    108     //------------------------------------------------------------------
    109     virtual ResultType
    110     DesiredResultType ()
    111     {
    112         return eResultTypeAny;
    113     }
    114 
    115     //------------------------------------------------------------------
    116     /// Flags
    117     //------------------------------------------------------------------
    118 
    119     //------------------------------------------------------------------
    120     /// Return true if validation code should be inserted into the
    121     /// expression.
    122     //------------------------------------------------------------------
    123     virtual bool
    124     NeedsValidation () = 0;
    125 
    126     //------------------------------------------------------------------
    127     /// Return true if external variables in the expression should be
    128     /// resolved.
    129     //------------------------------------------------------------------
    130     virtual bool
    131     NeedsVariableResolution () = 0;
    132 
    133     //------------------------------------------------------------------
    134     /// Return the address of the function's JIT-compiled code, or
    135     /// LLDB_INVALID_ADDRESS if the function is not JIT compiled
    136     //------------------------------------------------------------------
    137     lldb::addr_t
    138     StartAddress ()
    139     {
    140         return m_jit_start_addr;
    141     }
    142 
    143 protected:
    144 
    145     lldb::ProcessWP m_jit_process_wp;
    146     lldb::addr_t    m_jit_start_addr;       ///< The address of the JITted function within the JIT allocation.  LLDB_INVALID_ADDRESS if invalid.
    147     lldb::addr_t    m_jit_end_addr;         ///< The address of the JITted function within the JIT allocation.  LLDB_INVALID_ADDRESS if invalid.
    148 
    149 };
    150 
    151 } // namespace lldb_private
    152 
    153 #endif  // liblldb_ClangExpression_h_
    154