xref: /src/contrib/llvm-project/lldb/source/Symbol/CompilerDeclContext.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1cfca06d7SDimitry Andric //===-- CompilerDeclContext.cpp -------------------------------------------===//
2e81d9d49SDimitry Andric //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e81d9d49SDimitry Andric //
7e81d9d49SDimitry Andric //===----------------------------------------------------------------------===//
8e81d9d49SDimitry Andric 
9e81d9d49SDimitry Andric #include "lldb/Symbol/CompilerDeclContext.h"
10e81d9d49SDimitry Andric #include "lldb/Symbol/CompilerDecl.h"
11e81d9d49SDimitry Andric #include "lldb/Symbol/TypeSystem.h"
12e81d9d49SDimitry Andric #include <vector>
13e81d9d49SDimitry Andric 
14e81d9d49SDimitry Andric using namespace lldb_private;
15e81d9d49SDimitry Andric 
16e81d9d49SDimitry Andric std::vector<CompilerDecl>
FindDeclByName(ConstString name,const bool ignore_using_decls)1714f1b3e8SDimitry Andric CompilerDeclContext::FindDeclByName(ConstString name,
1814f1b3e8SDimitry Andric                                     const bool ignore_using_decls) {
19e81d9d49SDimitry Andric   if (IsValid())
2014f1b3e8SDimitry Andric     return m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name,
2114f1b3e8SDimitry Andric                                                     ignore_using_decls);
22e81d9d49SDimitry Andric   return std::vector<CompilerDecl>();
23e81d9d49SDimitry Andric }
24e81d9d49SDimitry Andric 
GetName() const2514f1b3e8SDimitry Andric ConstString CompilerDeclContext::GetName() const {
26e81d9d49SDimitry Andric   if (IsValid())
27e81d9d49SDimitry Andric     return m_type_system->DeclContextGetName(m_opaque_decl_ctx);
28e81d9d49SDimitry Andric   return ConstString();
29e81d9d49SDimitry Andric }
30e81d9d49SDimitry Andric 
GetScopeQualifiedName() const3114f1b3e8SDimitry Andric ConstString CompilerDeclContext::GetScopeQualifiedName() const {
327fed546dSDimitry Andric   if (IsValid())
337fed546dSDimitry Andric     return m_type_system->DeclContextGetScopeQualifiedName(m_opaque_decl_ctx);
347fed546dSDimitry Andric   return ConstString();
357fed546dSDimitry Andric }
367fed546dSDimitry Andric 
IsClassMethod()377fa27ce4SDimitry Andric bool CompilerDeclContext::IsClassMethod() {
38e81d9d49SDimitry Andric   if (IsValid())
397fa27ce4SDimitry Andric     return m_type_system->DeclContextIsClassMethod(m_opaque_decl_ctx);
40e81d9d49SDimitry Andric   return false;
41e81d9d49SDimitry Andric }
42e81d9d49SDimitry Andric 
GetLanguage()437fa27ce4SDimitry Andric lldb::LanguageType CompilerDeclContext::GetLanguage() {
447fa27ce4SDimitry Andric   if (IsValid())
457fa27ce4SDimitry Andric     return m_type_system->DeclContextGetLanguage(m_opaque_decl_ctx);
467fa27ce4SDimitry Andric   return {};
477fa27ce4SDimitry Andric }
487fa27ce4SDimitry Andric 
IsContainedInLookup(CompilerDeclContext other) const495f29bb8aSDimitry Andric bool CompilerDeclContext::IsContainedInLookup(CompilerDeclContext other) const {
505f29bb8aSDimitry Andric   if (!IsValid())
515f29bb8aSDimitry Andric     return false;
525f29bb8aSDimitry Andric 
535f29bb8aSDimitry Andric   // If the other context is just the current context, we don't need to go
545f29bb8aSDimitry Andric   // over the type system to know that the lookup is identical.
555f29bb8aSDimitry Andric   if (this == &other)
565f29bb8aSDimitry Andric     return true;
575f29bb8aSDimitry Andric 
585f29bb8aSDimitry Andric   return m_type_system->DeclContextIsContainedInLookup(m_opaque_decl_ctx,
595f29bb8aSDimitry Andric                                                        other.m_opaque_decl_ctx);
605f29bb8aSDimitry Andric }
615f29bb8aSDimitry Andric 
62312c0ed1SDimitry Andric std::vector<lldb_private::CompilerContext>
GetCompilerContext() const63312c0ed1SDimitry Andric CompilerDeclContext::GetCompilerContext() const {
64312c0ed1SDimitry Andric   if (IsValid())
65312c0ed1SDimitry Andric     return m_type_system->DeclContextGetCompilerContext(m_opaque_decl_ctx);
66312c0ed1SDimitry Andric   return {};
67312c0ed1SDimitry Andric }
68312c0ed1SDimitry Andric 
operator ==(const lldb_private::CompilerDeclContext & lhs,const lldb_private::CompilerDeclContext & rhs)6914f1b3e8SDimitry Andric bool lldb_private::operator==(const lldb_private::CompilerDeclContext &lhs,
7014f1b3e8SDimitry Andric                               const lldb_private::CompilerDeclContext &rhs) {
7114f1b3e8SDimitry Andric   return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
7214f1b3e8SDimitry Andric          lhs.GetOpaqueDeclContext() == rhs.GetOpaqueDeclContext();
73e81d9d49SDimitry Andric }
74e81d9d49SDimitry Andric 
operator !=(const lldb_private::CompilerDeclContext & lhs,const lldb_private::CompilerDeclContext & rhs)7514f1b3e8SDimitry Andric bool lldb_private::operator!=(const lldb_private::CompilerDeclContext &lhs,
7614f1b3e8SDimitry Andric                               const lldb_private::CompilerDeclContext &rhs) {
7714f1b3e8SDimitry Andric   return lhs.GetTypeSystem() != rhs.GetTypeSystem() ||
7814f1b3e8SDimitry Andric          lhs.GetOpaqueDeclContext() != rhs.GetOpaqueDeclContext();
79e81d9d49SDimitry Andric }
80