ClangExpression.h revision 1cf3da8b0fb0cabf2431b5fe521842929fca69a3
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 use when registering 97 /// local variables. May be NULL if the Expression doesn't care. 98 //------------------------------------------------------------------ 99 virtual ClangExpressionVariableList * 100 LocalVariables () = 0; 101 102 //------------------------------------------------------------------ 103 /// Return the object that the parser should allow to access ASTs. 104 /// May be NULL if the ASTs do not need to be transformed. 105 /// 106 /// @param[in] passthrough 107 /// The ASTConsumer that the returned transformer should send 108 /// the ASTs to after transformation. 109 //------------------------------------------------------------------ 110 virtual clang::ASTConsumer * 111 ASTTransformer (clang::ASTConsumer *passthrough) = 0; 112 113 //------------------------------------------------------------------ 114 /// Return the desired result type of the function, or 115 /// eResultTypeAny if indifferent. 116 //------------------------------------------------------------------ 117 virtual ResultType 118 DesiredResultType () 119 { 120 return eResultTypeAny; 121 } 122 123 //------------------------------------------------------------------ 124 /// Flags 125 //------------------------------------------------------------------ 126 127 //------------------------------------------------------------------ 128 /// Return true if validation code should be inserted into the 129 /// expression. 130 //------------------------------------------------------------------ 131 virtual bool 132 NeedsValidation () = 0; 133 134 //------------------------------------------------------------------ 135 /// Return true if external variables in the expression should be 136 /// resolved. 137 //------------------------------------------------------------------ 138 virtual bool 139 NeedsVariableResolution () = 0; 140 141 //------------------------------------------------------------------ 142 /// Return the address of the function's JIT-compiled code, or 143 /// LLDB_INVALID_ADDRESS if the function is not JIT compiled 144 //------------------------------------------------------------------ 145 lldb::addr_t 146 StartAddress () 147 { 148 return m_jit_start_addr; 149 } 150 151protected: 152 153 lldb::ProcessWP m_jit_process_wp; 154 lldb::addr_t m_jit_start_addr; ///< The address of the JITted function within the JIT allocation. LLDB_INVALID_ADDRESS if invalid. 155 lldb::addr_t m_jit_end_addr; ///< The address of the JITted function within the JIT allocation. LLDB_INVALID_ADDRESS if invalid. 156 157}; 158 159} // namespace lldb_private 160 161#endif // liblldb_ClangExpression_h_ 162