CompilerDecl.h revision 292932
1//===-- CompilerDecl.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_CompilerDecl_h_
11#define liblldb_CompilerDecl_h_
12
13#include "lldb/lldb-private.h"
14#include "lldb/Core/ConstString.h"
15#include "lldb/Symbol/CompilerType.h"
16
17namespace lldb_private {
18
19class CompilerDecl
20{
21public:
22    //----------------------------------------------------------------------
23    // Constructors and Destructors
24    //----------------------------------------------------------------------
25    CompilerDecl () :
26        m_type_system  (nullptr),
27        m_opaque_decl (nullptr)
28    {
29    }
30
31    CompilerDecl (TypeSystem *type_system, void *decl) :
32        m_type_system (type_system),
33        m_opaque_decl (decl)
34    {
35    }
36
37    ~CompilerDecl ()
38    {
39    }
40
41    //----------------------------------------------------------------------
42    // Tests
43    //----------------------------------------------------------------------
44
45    explicit operator bool () const
46    {
47        return IsValid ();
48    }
49
50    bool
51    operator < (const CompilerDecl &rhs) const
52    {
53        if (m_type_system == rhs.m_type_system)
54            return m_opaque_decl < rhs.m_opaque_decl;
55        return m_type_system < rhs.m_type_system;
56    }
57
58    bool
59    IsValid () const
60    {
61        return m_type_system != nullptr && m_opaque_decl != nullptr;
62    }
63
64    bool
65    IsClang () const;
66
67    //----------------------------------------------------------------------
68    // Object linked to the decl
69    //----------------------------------------------------------------------
70    lldb::VariableSP
71    GetAsVariable ();
72
73    //----------------------------------------------------------------------
74    // Accessors
75    //----------------------------------------------------------------------
76
77    TypeSystem *
78    GetTypeSystem() const
79    {
80        return m_type_system;
81    }
82
83    void *
84    GetOpaqueDecl() const
85    {
86        return m_opaque_decl;
87    }
88
89    void
90    SetDecl (TypeSystem* type_system, void* decl)
91    {
92        m_type_system = type_system;
93        m_opaque_decl = decl;
94    }
95
96    void
97    Clear()
98    {
99        m_type_system = nullptr;
100        m_opaque_decl = nullptr;
101    }
102
103    ConstString
104    GetName () const;
105
106    ConstString
107    GetMangledName () const;
108
109    CompilerDeclContext
110    GetDeclContext() const;
111
112    // If this decl represents a function, return the return type
113    CompilerType
114    GetFunctionReturnType() const;
115
116    // If this decl represents a function, return the number of arguments for the function
117    size_t
118    GetNumFunctionArguments() const;
119
120    // If this decl represents a function, return the argument type given a zero based argument index
121    CompilerType
122    GetFunctionArgumentType (size_t arg_idx) const;
123
124private:
125    TypeSystem *m_type_system;
126    void *m_opaque_decl;
127};
128
129bool operator == (const CompilerDecl &lhs, const CompilerDecl &rhs);
130bool operator != (const CompilerDecl &lhs, const CompilerDecl &rhs);
131
132
133} // namespace lldb_private
134
135#endif // #ifndef liblldb_CompilerDecl_h_
136