1*0b57cec5SDimitry Andric //===-- CompilerDeclContext.cpp ---------------------------------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "lldb/Symbol/CompilerDeclContext.h" 10*0b57cec5SDimitry Andric #include "lldb/Symbol/CompilerDecl.h" 11*0b57cec5SDimitry Andric #include "lldb/Symbol/TypeSystem.h" 12*0b57cec5SDimitry Andric #include <vector> 13*0b57cec5SDimitry Andric 14*0b57cec5SDimitry Andric using namespace lldb_private; 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric std::vector<CompilerDecl> 17*0b57cec5SDimitry Andric CompilerDeclContext::FindDeclByName(ConstString name, 18*0b57cec5SDimitry Andric const bool ignore_using_decls) { 19*0b57cec5SDimitry Andric if (IsValid()) 20*0b57cec5SDimitry Andric return m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name, 21*0b57cec5SDimitry Andric ignore_using_decls); 22*0b57cec5SDimitry Andric else 23*0b57cec5SDimitry Andric return std::vector<CompilerDecl>(); 24*0b57cec5SDimitry Andric } 25*0b57cec5SDimitry Andric 26*0b57cec5SDimitry Andric bool CompilerDeclContext::IsClang() const { 27*0b57cec5SDimitry Andric return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang; 28*0b57cec5SDimitry Andric } 29*0b57cec5SDimitry Andric 30*0b57cec5SDimitry Andric ConstString CompilerDeclContext::GetName() const { 31*0b57cec5SDimitry Andric if (IsValid()) 32*0b57cec5SDimitry Andric return m_type_system->DeclContextGetName(m_opaque_decl_ctx); 33*0b57cec5SDimitry Andric else 34*0b57cec5SDimitry Andric return ConstString(); 35*0b57cec5SDimitry Andric } 36*0b57cec5SDimitry Andric 37*0b57cec5SDimitry Andric ConstString CompilerDeclContext::GetScopeQualifiedName() const { 38*0b57cec5SDimitry Andric if (IsValid()) 39*0b57cec5SDimitry Andric return m_type_system->DeclContextGetScopeQualifiedName(m_opaque_decl_ctx); 40*0b57cec5SDimitry Andric else 41*0b57cec5SDimitry Andric return ConstString(); 42*0b57cec5SDimitry Andric } 43*0b57cec5SDimitry Andric 44*0b57cec5SDimitry Andric bool CompilerDeclContext::IsStructUnionOrClass() const { 45*0b57cec5SDimitry Andric if (IsValid()) 46*0b57cec5SDimitry Andric return m_type_system->DeclContextIsStructUnionOrClass(m_opaque_decl_ctx); 47*0b57cec5SDimitry Andric else 48*0b57cec5SDimitry Andric return false; 49*0b57cec5SDimitry Andric } 50*0b57cec5SDimitry Andric 51*0b57cec5SDimitry Andric bool CompilerDeclContext::IsClassMethod(lldb::LanguageType *language_ptr, 52*0b57cec5SDimitry Andric bool *is_instance_method_ptr, 53*0b57cec5SDimitry Andric ConstString *language_object_name_ptr) { 54*0b57cec5SDimitry Andric if (IsValid()) 55*0b57cec5SDimitry Andric return m_type_system->DeclContextIsClassMethod( 56*0b57cec5SDimitry Andric m_opaque_decl_ctx, language_ptr, is_instance_method_ptr, 57*0b57cec5SDimitry Andric language_object_name_ptr); 58*0b57cec5SDimitry Andric else 59*0b57cec5SDimitry Andric return false; 60*0b57cec5SDimitry Andric } 61*0b57cec5SDimitry Andric 62*0b57cec5SDimitry Andric bool CompilerDeclContext::IsContainedInLookup(CompilerDeclContext other) const { 63*0b57cec5SDimitry Andric if (!IsValid()) 64*0b57cec5SDimitry Andric return false; 65*0b57cec5SDimitry Andric 66*0b57cec5SDimitry Andric // If the other context is just the current context, we don't need to go 67*0b57cec5SDimitry Andric // over the type system to know that the lookup is identical. 68*0b57cec5SDimitry Andric if (this == &other) 69*0b57cec5SDimitry Andric return true; 70*0b57cec5SDimitry Andric 71*0b57cec5SDimitry Andric return m_type_system->DeclContextIsContainedInLookup(m_opaque_decl_ctx, 72*0b57cec5SDimitry Andric other.m_opaque_decl_ctx); 73*0b57cec5SDimitry Andric } 74*0b57cec5SDimitry Andric 75*0b57cec5SDimitry Andric bool lldb_private::operator==(const lldb_private::CompilerDeclContext &lhs, 76*0b57cec5SDimitry Andric const lldb_private::CompilerDeclContext &rhs) { 77*0b57cec5SDimitry Andric return lhs.GetTypeSystem() == rhs.GetTypeSystem() && 78*0b57cec5SDimitry Andric lhs.GetOpaqueDeclContext() == rhs.GetOpaqueDeclContext(); 79*0b57cec5SDimitry Andric } 80*0b57cec5SDimitry Andric 81*0b57cec5SDimitry Andric bool lldb_private::operator!=(const lldb_private::CompilerDeclContext &lhs, 82*0b57cec5SDimitry Andric const lldb_private::CompilerDeclContext &rhs) { 83*0b57cec5SDimitry Andric return lhs.GetTypeSystem() != rhs.GetTypeSystem() || 84*0b57cec5SDimitry Andric lhs.GetOpaqueDeclContext() != rhs.GetOpaqueDeclContext(); 85*0b57cec5SDimitry Andric } 86