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