CompilerDecl.h revision 314564
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/Core/ConstString.h"
14#include "lldb/Symbol/CompilerType.h"
15#include "lldb/lldb-private.h"
16
17namespace lldb_private {
18
19class CompilerDecl {
20public:
21  //----------------------------------------------------------------------
22  // Constructors and Destructors
23  //----------------------------------------------------------------------
24  CompilerDecl() : m_type_system(nullptr), m_opaque_decl(nullptr) {}
25
26  CompilerDecl(TypeSystem *type_system, void *decl)
27      : m_type_system(type_system), m_opaque_decl(decl) {}
28
29  ~CompilerDecl() {}
30
31  //----------------------------------------------------------------------
32  // Tests
33  //----------------------------------------------------------------------
34
35  explicit operator bool() const { return IsValid(); }
36
37  bool operator<(const CompilerDecl &rhs) const {
38    if (m_type_system == rhs.m_type_system)
39      return m_opaque_decl < rhs.m_opaque_decl;
40    return m_type_system < rhs.m_type_system;
41  }
42
43  bool IsValid() const {
44    return m_type_system != nullptr && m_opaque_decl != nullptr;
45  }
46
47  bool IsClang() const;
48
49  //----------------------------------------------------------------------
50  // Accessors
51  //----------------------------------------------------------------------
52
53  TypeSystem *GetTypeSystem() const { return m_type_system; }
54
55  void *GetOpaqueDecl() const { return m_opaque_decl; }
56
57  void SetDecl(TypeSystem *type_system, void *decl) {
58    m_type_system = type_system;
59    m_opaque_decl = decl;
60  }
61
62  void Clear() {
63    m_type_system = nullptr;
64    m_opaque_decl = nullptr;
65  }
66
67  ConstString GetName() const;
68
69  ConstString GetMangledName() const;
70
71  CompilerDeclContext GetDeclContext() const;
72
73  // If this decl represents a function, return the return type
74  CompilerType GetFunctionReturnType() const;
75
76  // If this decl represents a function, return the number of arguments for the
77  // function
78  size_t GetNumFunctionArguments() const;
79
80  // If this decl represents a function, return the argument type given a zero
81  // based argument index
82  CompilerType GetFunctionArgumentType(size_t arg_idx) const;
83
84private:
85  TypeSystem *m_type_system;
86  void *m_opaque_decl;
87};
88
89bool operator==(const CompilerDecl &lhs, const CompilerDecl &rhs);
90bool operator!=(const CompilerDecl &lhs, const CompilerDecl &rhs);
91
92} // namespace lldb_private
93
94#endif // #ifndef liblldb_CompilerDecl_h_
95