1 //===-- CompilerDeclContext.cpp ---------------------------------*- 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 #include "lldb/Symbol/CompilerDeclContext.h"
10 #include "lldb/Symbol/ClangASTContext.h"
11 #include "lldb/Symbol/CompilerDecl.h"
12 #include "lldb/Symbol/TypeSystem.h"
13 #include <vector>
14 
15 using namespace lldb_private;
16 
17 std::vector<CompilerDecl>
18 CompilerDeclContext::FindDeclByName(ConstString name,
19                                     const bool ignore_using_decls) {
20   if (IsValid())
21     return m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name,
22                                                     ignore_using_decls);
23   else
24     return std::vector<CompilerDecl>();
25 }
26 
27 bool CompilerDeclContext::IsClang() const {
28   return IsValid() && llvm::isa<ClangASTContext>(m_type_system);
29 }
30 
31 ConstString CompilerDeclContext::GetName() const {
32   if (IsValid())
33     return m_type_system->DeclContextGetName(m_opaque_decl_ctx);
34   else
35     return ConstString();
36 }
37 
38 ConstString CompilerDeclContext::GetScopeQualifiedName() const {
39   if (IsValid())
40     return m_type_system->DeclContextGetScopeQualifiedName(m_opaque_decl_ctx);
41   else
42     return ConstString();
43 }
44 
45 bool CompilerDeclContext::IsStructUnionOrClass() const {
46   if (IsValid())
47     return m_type_system->DeclContextIsStructUnionOrClass(m_opaque_decl_ctx);
48   else
49     return false;
50 }
51 
52 bool CompilerDeclContext::IsClassMethod(lldb::LanguageType *language_ptr,
53                                         bool *is_instance_method_ptr,
54                                         ConstString *language_object_name_ptr) {
55   if (IsValid())
56     return m_type_system->DeclContextIsClassMethod(
57         m_opaque_decl_ctx, language_ptr, is_instance_method_ptr,
58         language_object_name_ptr);
59   else
60     return false;
61 }
62 
63 bool CompilerDeclContext::IsContainedInLookup(CompilerDeclContext other) const {
64   if (!IsValid())
65     return false;
66 
67   // If the other context is just the current context, we don't need to go
68   // over the type system to know that the lookup is identical.
69   if (this == &other)
70     return true;
71 
72   return m_type_system->DeclContextIsContainedInLookup(m_opaque_decl_ctx,
73                                                        other.m_opaque_decl_ctx);
74 }
75 
76 bool lldb_private::operator==(const lldb_private::CompilerDeclContext &lhs,
77                               const lldb_private::CompilerDeclContext &rhs) {
78   return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
79          lhs.GetOpaqueDeclContext() == rhs.GetOpaqueDeclContext();
80 }
81 
82 bool lldb_private::operator!=(const lldb_private::CompilerDeclContext &lhs,
83                               const lldb_private::CompilerDeclContext &rhs) {
84   return lhs.GetTypeSystem() != rhs.GetTypeSystem() ||
85          lhs.GetOpaqueDeclContext() != rhs.GetOpaqueDeclContext();
86 }
87