ClangExpressionDeclMap.h revision 32824aa43fdc8393d829c16f126f32ca8d3582ad
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 Value;
28}
29
30namespace lldb_private {
31
32//----------------------------------------------------------------------
33// For cases in which there are multiple classes of types that are not
34// interchangeable, to allow static type checking.
35//----------------------------------------------------------------------
36template <unsigned int C> class TaggedClangASTType : public ClangASTType
37{
38public:
39    TaggedClangASTType (void *type, clang::ASTContext *ast_context) :
40        ClangASTType(type, ast_context) { }
41
42    TaggedClangASTType (const TaggedClangASTType<C> &tw) :
43        ClangASTType(tw) { }
44
45    TaggedClangASTType () :
46        ClangASTType() { }
47
48    ~TaggedClangASTType() { }
49
50    const TaggedClangASTType<C> &
51    operator= (const TaggedClangASTType<C> &tw)
52    {
53        ClangASTType::operator= (tw);
54        return *this;
55    }
56};
57
58
59class Error;
60class Function;
61class NameSearchContext;
62class Variable;
63
64class ClangExpressionDeclMap
65{
66public:
67    ClangExpressionDeclMap(ExecutionContext *exe_ctx);
68    ~ClangExpressionDeclMap();
69
70    // Interface for ClangStmtVisitor
71    bool GetIndexForDecl (uint32_t &index,
72                          const clang::Decl *decl);
73
74    // Interface for IRForTarget
75    bool AddValueToStruct (llvm::Value *value,
76                           const clang::NamedDecl *decl,
77                           std::string &name,
78                           void *type,
79                           clang::ASTContext *ast_context,
80                           size_t size,
81                           off_t alignment);
82    bool DoStructLayout ();
83    bool GetStructInfo (uint32_t &num_elements,
84                        size_t &size,
85                        off_t &alignment);
86    bool GetStructElement (const clang::NamedDecl *&decl,
87                           llvm::Value *&value,
88                           off_t &offset,
89                           uint32_t index);
90
91    // Interface for DwarfExpression
92    Value *GetValueForIndex (uint32_t index);
93
94    // Interface for CommandObjectExpression
95    bool Materialize(ExecutionContext *exe_ctx,
96                     lldb::addr_t &struct_address,
97                     Error &error);
98
99    bool DumpMaterializedStruct(ExecutionContext *exe_ctx,
100                                Stream &s,
101                                Error &error);
102
103    bool Dematerialize(ExecutionContext *exe_ctx,
104                       lldb_private::Value &result_value,
105                       Error &error);
106
107    // Interface for ClangASTSource
108    void GetDecls (NameSearchContext &context,
109                   const char *name);
110private:
111    typedef TaggedClangASTType<0> TypeFromParser;
112    typedef TaggedClangASTType<1> TypeFromUser;
113
114    struct Tuple
115    {
116        const clang::NamedDecl  *m_decl;
117        TypeFromParser          m_parser_type;
118        TypeFromUser            m_user_type;
119        lldb_private::Value     *m_value; /* owned by ClangExpressionDeclMap */
120    };
121
122    struct StructMember
123    {
124        const clang::NamedDecl *m_decl;
125        llvm::Value            *m_value;
126        std::string             m_name;
127        TypeFromParser          m_parser_type;
128        off_t                   m_offset;
129        size_t                  m_size;
130        off_t                   m_alignment;
131    };
132
133    typedef std::vector<Tuple> TupleVector;
134    typedef TupleVector::iterator TupleIterator;
135
136    typedef std::vector<StructMember> StructMemberVector;
137    typedef StructMemberVector::iterator StructMemberIterator;
138
139    TupleVector         m_tuples;
140    StructMemberVector  m_members;
141    ExecutionContext   *m_exe_ctx;
142    SymbolContext      *m_sym_ctx; /* owned by ClangExpressionDeclMap */
143    off_t               m_struct_alignment;
144    size_t              m_struct_size;
145    bool                m_struct_laid_out;
146    lldb::addr_t        m_allocated_area;
147    lldb::addr_t        m_materialized_location;
148
149    Variable *FindVariableInScope(const SymbolContext &sym_ctx,
150                                  const char *name,
151                                  TypeFromUser *type = NULL);
152
153    Value *GetVariableValue(ExecutionContext &exe_ctx,
154                            Variable *var,
155                            clang::ASTContext *parser_ast_context,
156                            TypeFromUser *found_type = NULL,
157                            TypeFromParser *parser_type = NULL);
158
159    void AddOneVariable(NameSearchContext &context, Variable *var);
160    void AddOneFunction(NameSearchContext &context, Function *fun);
161
162    bool DoMaterialize (bool dematerialize,
163                        ExecutionContext *exe_ctx,
164                        lldb_private::Value *result_value, /* must be non-NULL if D is set */
165                        Error &err);
166
167    bool DoMaterializeOneVariable(bool dematerialize,
168                                  ExecutionContext &exe_ctx,
169                                  const SymbolContext &sym_ctx,
170                                  const char *name,
171                                  TypeFromUser type,
172                                  lldb::addr_t addr,
173                                  Error &err);
174};
175
176} // namespace lldb_private
177
178#endif  // liblldb_ClangExpressionDeclMap_h_
179