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