ClangExpressionDeclMap.h revision 82b74c85f719be67b78f9284a6a1341d47f7ac9c
1//===-- ClangExpressionDeclMap.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_ClangExpressionDeclMap_h_ 11#define liblldb_ClangExpressionDeclMap_h_ 12 13// C Includes 14#include <signal.h> 15#include <stdint.h> 16 17// C++ Includes 18#include <vector> 19 20// Other libraries and framework includes 21// Project includes 22#include "lldb/Core/ClangForward.h" 23#include "lldb/Core/Value.h" 24#include "lldb/Symbol/TaggedASTType.h" 25 26namespace llvm { 27 class Type; 28 class Value; 29} 30 31namespace lldb_private { 32 33class ClangPersistentVariable; 34class ClangPersistentVariables; 35class Error; 36class Function; 37class NameSearchContext; 38class Variable; 39 40class ClangExpressionDeclMap 41{ 42public: 43 ClangExpressionDeclMap(ExecutionContext *exe_ctx); 44 ~ClangExpressionDeclMap(); 45 46 // Interface for ClangStmtVisitor 47 bool GetIndexForDecl (uint32_t &index, 48 const clang::Decl *decl); 49 50 // Interface for IRForTarget 51 void GetPersistentResultName (std::string &name); 52 bool AddPersistentVariable (const char *name, TypeFromParser type); 53 bool AddValueToStruct (llvm::Value *value, 54 const clang::NamedDecl *decl, 55 std::string &name, 56 void *type, 57 clang::ASTContext *ast_context, 58 size_t size, 59 off_t alignment); 60 bool DoStructLayout (); 61 bool GetStructInfo (uint32_t &num_elements, 62 size_t &size, 63 off_t &alignment); 64 bool GetStructElement (const clang::NamedDecl *&decl, 65 llvm::Value *&value, 66 off_t &offset, 67 uint32_t index); 68 69 bool GetFunctionInfo (const clang::NamedDecl *decl, 70 llvm::Value**& value, 71 uint64_t &ptr); 72 bool GetFunctionAddress (const char *name, 73 uint64_t &ptr); 74 75 // Interface for DwarfExpression 76 Value *GetValueForIndex (uint32_t index); 77 78 // Interface for CommandObjectExpression 79 bool Materialize(ExecutionContext *exe_ctx, 80 lldb::addr_t &struct_address, 81 Error &error); 82 83 bool DumpMaterializedStruct(ExecutionContext *exe_ctx, 84 Stream &s, 85 Error &error); 86 87 bool Dematerialize(ExecutionContext *exe_ctx, 88 ClangPersistentVariable *&result, 89 Error &error); 90 91 // Interface for ClangASTSource 92 void GetDecls (NameSearchContext &context, 93 const char *name); 94private: 95 struct Tuple 96 { 97 const clang::NamedDecl *m_decl; 98 TypeFromParser m_parser_type; 99 TypeFromUser m_user_type; 100 lldb_private::Value *m_value; /* owned by ClangExpressionDeclMap */ 101 llvm::Value *m_llvm_value; 102 }; 103 104 struct StructMember 105 { 106 const clang::NamedDecl *m_decl; 107 llvm::Value *m_value; 108 std::string m_name; 109 TypeFromParser m_parser_type; 110 off_t m_offset; 111 size_t m_size; 112 off_t m_alignment; 113 }; 114 115 typedef std::vector<Tuple> TupleVector; 116 typedef TupleVector::iterator TupleIterator; 117 118 typedef std::vector<StructMember> StructMemberVector; 119 typedef StructMemberVector::iterator StructMemberIterator; 120 121 TupleVector m_tuples; 122 StructMemberVector m_members; 123 ExecutionContext *m_exe_ctx; 124 SymbolContext *m_sym_ctx; /* owned by ClangExpressionDeclMap */ 125 ClangPersistentVariables *m_persistent_vars; 126 off_t m_struct_alignment; 127 size_t m_struct_size; 128 bool m_struct_laid_out; 129 lldb::addr_t m_allocated_area; 130 lldb::addr_t m_materialized_location; 131 std::string m_result_name; 132 133 Variable *FindVariableInScope(const SymbolContext &sym_ctx, 134 const char *name, 135 TypeFromUser *type = NULL); 136 137 Value *GetVariableValue(ExecutionContext &exe_ctx, 138 Variable *var, 139 clang::ASTContext *parser_ast_context, 140 TypeFromUser *found_type = NULL, 141 TypeFromParser *parser_type = NULL); 142 143 void AddOneVariable(NameSearchContext &context, Variable *var); 144 void AddOneVariable(NameSearchContext &context, ClangPersistentVariable *pvar); 145 void AddOneFunction(NameSearchContext &context, Function *fun, Symbol *sym); 146 void AddOneType(NameSearchContext &context, Type *type); 147 148 bool DoMaterialize (bool dematerialize, 149 ExecutionContext *exe_ctx, 150 ClangPersistentVariable **result, /* must be non-NULL if D is set */ 151 Error &err); 152 153 bool DoMaterializeOnePersistentVariable(bool dematerialize, 154 ExecutionContext &exe_ctx, 155 const char *name, 156 lldb::addr_t addr, 157 Error &err); 158 159 bool DoMaterializeOneVariable(bool dematerialize, 160 ExecutionContext &exe_ctx, 161 const SymbolContext &sym_ctx, 162 const char *name, 163 TypeFromUser type, 164 lldb::addr_t addr, 165 Error &err); 166}; 167 168} // namespace lldb_private 169 170#endif // liblldb_ClangExpressionDeclMap_h_ 171