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