15ffd83dbSDimitry Andric //===-- CompilerDeclContext.cpp -------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/Symbol/CompilerDeclContext.h"
100b57cec5SDimitry Andric #include "lldb/Symbol/CompilerDecl.h"
110b57cec5SDimitry Andric #include "lldb/Symbol/TypeSystem.h"
120b57cec5SDimitry Andric #include <vector>
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric using namespace lldb_private;
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric std::vector<CompilerDecl>
FindDeclByName(ConstString name,const bool ignore_using_decls)170b57cec5SDimitry Andric CompilerDeclContext::FindDeclByName(ConstString name,
180b57cec5SDimitry Andric                                     const bool ignore_using_decls) {
190b57cec5SDimitry Andric   if (IsValid())
200b57cec5SDimitry Andric     return m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name,
210b57cec5SDimitry Andric                                                     ignore_using_decls);
220b57cec5SDimitry Andric   return std::vector<CompilerDecl>();
230b57cec5SDimitry Andric }
240b57cec5SDimitry Andric 
GetName() const250b57cec5SDimitry Andric ConstString CompilerDeclContext::GetName() const {
260b57cec5SDimitry Andric   if (IsValid())
270b57cec5SDimitry Andric     return m_type_system->DeclContextGetName(m_opaque_decl_ctx);
280b57cec5SDimitry Andric   return ConstString();
290b57cec5SDimitry Andric }
300b57cec5SDimitry Andric 
GetScopeQualifiedName() const310b57cec5SDimitry Andric ConstString CompilerDeclContext::GetScopeQualifiedName() const {
320b57cec5SDimitry Andric   if (IsValid())
330b57cec5SDimitry Andric     return m_type_system->DeclContextGetScopeQualifiedName(m_opaque_decl_ctx);
340b57cec5SDimitry Andric   return ConstString();
350b57cec5SDimitry Andric }
360b57cec5SDimitry Andric 
IsClassMethod()37fe013be4SDimitry Andric bool CompilerDeclContext::IsClassMethod() {
380b57cec5SDimitry Andric   if (IsValid())
39fe013be4SDimitry Andric     return m_type_system->DeclContextIsClassMethod(m_opaque_decl_ctx);
400b57cec5SDimitry Andric   return false;
410b57cec5SDimitry Andric }
420b57cec5SDimitry Andric 
GetLanguage()43fe013be4SDimitry Andric lldb::LanguageType CompilerDeclContext::GetLanguage() {
44fe013be4SDimitry Andric   if (IsValid())
45fe013be4SDimitry Andric     return m_type_system->DeclContextGetLanguage(m_opaque_decl_ctx);
46fe013be4SDimitry Andric   return {};
47fe013be4SDimitry Andric }
48fe013be4SDimitry Andric 
IsContainedInLookup(CompilerDeclContext other) const490b57cec5SDimitry Andric bool CompilerDeclContext::IsContainedInLookup(CompilerDeclContext other) const {
500b57cec5SDimitry Andric   if (!IsValid())
510b57cec5SDimitry Andric     return false;
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   // If the other context is just the current context, we don't need to go
540b57cec5SDimitry Andric   // over the type system to know that the lookup is identical.
550b57cec5SDimitry Andric   if (this == &other)
560b57cec5SDimitry Andric     return true;
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   return m_type_system->DeclContextIsContainedInLookup(m_opaque_decl_ctx,
590b57cec5SDimitry Andric                                                        other.m_opaque_decl_ctx);
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric 
62*c9157d92SDimitry Andric std::vector<lldb_private::CompilerContext>
GetCompilerContext() const63*c9157d92SDimitry Andric CompilerDeclContext::GetCompilerContext() const {
64*c9157d92SDimitry Andric   if (IsValid())
65*c9157d92SDimitry Andric     return m_type_system->DeclContextGetCompilerContext(m_opaque_decl_ctx);
66*c9157d92SDimitry Andric   return {};
67*c9157d92SDimitry Andric }
68*c9157d92SDimitry Andric 
operator ==(const lldb_private::CompilerDeclContext & lhs,const lldb_private::CompilerDeclContext & rhs)690b57cec5SDimitry Andric bool lldb_private::operator==(const lldb_private::CompilerDeclContext &lhs,
700b57cec5SDimitry Andric                               const lldb_private::CompilerDeclContext &rhs) {
710b57cec5SDimitry Andric   return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
720b57cec5SDimitry Andric          lhs.GetOpaqueDeclContext() == rhs.GetOpaqueDeclContext();
730b57cec5SDimitry Andric }
740b57cec5SDimitry Andric 
operator !=(const lldb_private::CompilerDeclContext & lhs,const lldb_private::CompilerDeclContext & rhs)750b57cec5SDimitry Andric bool lldb_private::operator!=(const lldb_private::CompilerDeclContext &lhs,
760b57cec5SDimitry Andric                               const lldb_private::CompilerDeclContext &rhs) {
770b57cec5SDimitry Andric   return lhs.GetTypeSystem() != rhs.GetTypeSystem() ||
780b57cec5SDimitry Andric          lhs.GetOpaqueDeclContext() != rhs.GetOpaqueDeclContext();
790b57cec5SDimitry Andric }
80