LLDB  mainline
CompilerDecl.h
Go to the documentation of this file.
1 //===-- CompilerDecl.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SYMBOL_COMPILERDECL_H
10 #define LLDB_SYMBOL_COMPILERDECL_H
11 
14 #include "lldb/lldb-private.h"
15 
16 namespace lldb_private {
17 
18 /// Represents a generic declaration such as a function declaration.
19 ///
20 /// This class serves as an abstraction for a declaration inside one of the
21 /// TypeSystems implemented by the language plugins. It does not have any actual
22 /// logic in it but only stores an opaque pointer and a pointer to the
23 /// TypeSystem that gives meaning to this opaque pointer. All methods of this
24 /// class should call their respective method in the TypeSystem interface and
25 /// pass the opaque pointer along.
26 ///
27 /// \see lldb_private::TypeSystem
28 class CompilerDecl {
29 public:
30  // Constructors and Destructors
31  CompilerDecl() = default;
32 
33  /// Creates a CompilerDecl with the given TypeSystem and opaque pointer.
34  ///
35  /// This constructor should only be called from the respective TypeSystem
36  /// implementation.
37  CompilerDecl(TypeSystem *type_system, void *decl)
38  : m_type_system(type_system), m_opaque_decl(decl) {}
39 
40  // Tests
41 
42  explicit operator bool() const { return IsValid(); }
43 
44  bool operator<(const CompilerDecl &rhs) const {
45  if (m_type_system == rhs.m_type_system)
46  return m_opaque_decl < rhs.m_opaque_decl;
47  return m_type_system < rhs.m_type_system;
48  }
49 
50  bool IsValid() const {
51  return m_type_system != nullptr && m_opaque_decl != nullptr;
52  }
53 
54  // Accessors
55 
56  TypeSystem *GetTypeSystem() const { return m_type_system; }
57 
58  void *GetOpaqueDecl() const { return m_opaque_decl; }
59 
60  void SetDecl(TypeSystem *type_system, void *decl) {
61  m_type_system = type_system;
62  m_opaque_decl = decl;
63  }
64 
65  void Clear() {
66  m_type_system = nullptr;
67  m_opaque_decl = nullptr;
68  }
69 
70  ConstString GetName() const;
71 
73 
75 
76  // If this decl represents a function, return the return type
78 
79  // If this decl represents a function, return the number of arguments for the
80  // function
81  size_t GetNumFunctionArguments() const;
82 
83  // If this decl represents a function, return the argument type given a zero
84  // based argument index
85  CompilerType GetFunctionArgumentType(size_t arg_idx) const;
86 
87 private:
89  void *m_opaque_decl = nullptr;
90 };
91 
92 bool operator==(const CompilerDecl &lhs, const CompilerDecl &rhs);
93 bool operator!=(const CompilerDecl &lhs, const CompilerDecl &rhs);
94 
95 } // namespace lldb_private
96 
97 #endif // LLDB_SYMBOL_COMPILERDECL_H
lldb_private::CompilerDecl::CompilerDecl
CompilerDecl()=default
lldb_private::CompilerDecl::IsValid
bool IsValid() const
Definition: CompilerDecl.h:50
lldb_private::CompilerDecl::SetDecl
void SetDecl(TypeSystem *type_system, void *decl)
Definition: CompilerDecl.h:60
lldb_private::CompilerDecl::CompilerDecl
CompilerDecl(TypeSystem *type_system, void *decl)
Creates a CompilerDecl with the given TypeSystem and opaque pointer.
Definition: CompilerDecl.h:37
lldb_private::CompilerDecl::GetNumFunctionArguments
size_t GetNumFunctionArguments() const
Definition: CompilerDecl.cpp:31
lldb_private::CompilerDecl::GetOpaqueDecl
void * GetOpaqueDecl() const
Definition: CompilerDecl.h:58
lldb_private::CompilerDecl
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
lldb_private::CompilerDecl::operator<
bool operator<(const CompilerDecl &rhs) const
Definition: CompilerDecl.h:44
lldb_private::CompilerDecl::m_type_system
TypeSystem * m_type_system
Definition: CompilerDecl.h:88
lldb_private::operator==
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:999
lldb_private::CompilerDecl::GetName
ConstString GetName() const
Definition: CompilerDecl.cpp:15
lldb_private::CompilerDecl::GetFunctionReturnType
CompilerType GetFunctionReturnType() const
Definition: CompilerDecl.cpp:27
lldb_private::CompilerDecl::GetTypeSystem
TypeSystem * GetTypeSystem() const
Definition: CompilerDecl.h:56
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::CompilerDecl::GetDeclContext
CompilerDeclContext GetDeclContext() const
Definition: CompilerDecl.cpp:23
CompilerType.h
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::operator!=
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1005
lldb-private.h
lldb_private::CompilerDecl::m_opaque_decl
void * m_opaque_decl
Definition: CompilerDecl.h:89
lldb_private::CompilerDecl::GetFunctionArgumentType
CompilerType GetFunctionArgumentType(size_t arg_idx) const
Definition: CompilerDecl.cpp:35
lldb_private::CompilerDecl::GetMangledName
ConstString GetMangledName() const
Definition: CompilerDecl.cpp:19
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::CompilerDecl::Clear
void Clear()
Definition: CompilerDecl.h:65
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::TypeSystem
Interface for representing a type system.
Definition: TypeSystem.h:71
ConstString.h