199558cc4SGreg Clayton //===-- CompilerDeclContext.cpp ---------------------------------*- C++ -*-===//
299558cc4SGreg Clayton //
399558cc4SGreg Clayton //                     The LLVM Compiler Infrastructure
499558cc4SGreg Clayton //
599558cc4SGreg Clayton // This file is distributed under the University of Illinois Open Source
699558cc4SGreg Clayton // License. See LICENSE.TXT for details.
799558cc4SGreg Clayton //
899558cc4SGreg Clayton //===----------------------------------------------------------------------===//
999558cc4SGreg Clayton 
1099558cc4SGreg Clayton #include "lldb/Symbol/CompilerDeclContext.h"
11*d628cbb9SPaul Herman #include "lldb/Symbol/CompilerDecl.h"
1299558cc4SGreg Clayton #include "lldb/Symbol/TypeSystem.h"
13*d628cbb9SPaul Herman #include <vector>
1499558cc4SGreg Clayton 
1599558cc4SGreg Clayton using namespace lldb_private;
1699558cc4SGreg Clayton 
17*d628cbb9SPaul Herman std::vector<CompilerDecl>
18*d628cbb9SPaul Herman CompilerDeclContext::FindDeclByName (ConstString name)
19*d628cbb9SPaul Herman {
20*d628cbb9SPaul Herman     std::vector<CompilerDecl> found_decls;
21*d628cbb9SPaul Herman     if (IsValid())
22*d628cbb9SPaul Herman     {
23*d628cbb9SPaul Herman         std::vector<void *> found_opaque_decls = m_type_system->DeclContextFindDeclByName(m_opaque_decl_ctx, name);
24*d628cbb9SPaul Herman         for (void *opaque_decl : found_opaque_decls)
25*d628cbb9SPaul Herman             found_decls.push_back(CompilerDecl(m_type_system, opaque_decl));
26*d628cbb9SPaul Herman     }
27*d628cbb9SPaul Herman     return found_decls;
28*d628cbb9SPaul Herman }
29*d628cbb9SPaul Herman 
3099558cc4SGreg Clayton bool
3199558cc4SGreg Clayton CompilerDeclContext::IsClang () const
3299558cc4SGreg Clayton {
33f73034f9SGreg Clayton     return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang;
3499558cc4SGreg Clayton }
3599558cc4SGreg Clayton 
3699558cc4SGreg Clayton ConstString
3799558cc4SGreg Clayton CompilerDeclContext::GetName () const
3899558cc4SGreg Clayton {
3999558cc4SGreg Clayton     if (IsValid())
4099558cc4SGreg Clayton         return m_type_system->DeclContextGetName(m_opaque_decl_ctx);
4199558cc4SGreg Clayton     else
4299558cc4SGreg Clayton         return ConstString();
4399558cc4SGreg Clayton }
4499558cc4SGreg Clayton 
4599558cc4SGreg Clayton bool
4699558cc4SGreg Clayton CompilerDeclContext::IsStructUnionOrClass () const
4799558cc4SGreg Clayton {
4899558cc4SGreg Clayton     if (IsValid())
4999558cc4SGreg Clayton         return m_type_system->DeclContextIsStructUnionOrClass(m_opaque_decl_ctx);
5099558cc4SGreg Clayton     else
5199558cc4SGreg Clayton         return false;
5299558cc4SGreg Clayton }
5399558cc4SGreg Clayton 
5499558cc4SGreg Clayton bool
5599558cc4SGreg Clayton CompilerDeclContext::IsClassMethod (lldb::LanguageType *language_ptr,
5699558cc4SGreg Clayton                                     bool *is_instance_method_ptr,
5799558cc4SGreg Clayton                                     ConstString *language_object_name_ptr)
5899558cc4SGreg Clayton {
5999558cc4SGreg Clayton     if (IsValid())
6099558cc4SGreg Clayton         return m_type_system->DeclContextIsClassMethod (m_opaque_decl_ctx,
6199558cc4SGreg Clayton                                                         language_ptr,
6299558cc4SGreg Clayton                                                         is_instance_method_ptr,
6399558cc4SGreg Clayton                                                         language_object_name_ptr);
6499558cc4SGreg Clayton     else
6599558cc4SGreg Clayton         return false;
6699558cc4SGreg Clayton }
6799558cc4SGreg Clayton 
6899558cc4SGreg Clayton bool
6999558cc4SGreg Clayton lldb_private::operator == (const lldb_private::CompilerDeclContext &lhs, const lldb_private::CompilerDeclContext &rhs)
7099558cc4SGreg Clayton {
7199558cc4SGreg Clayton     return lhs.GetTypeSystem() == rhs.GetTypeSystem() && lhs.GetOpaqueDeclContext() == rhs.GetOpaqueDeclContext();
7299558cc4SGreg Clayton }
7399558cc4SGreg Clayton 
7499558cc4SGreg Clayton 
7599558cc4SGreg Clayton bool
7699558cc4SGreg Clayton lldb_private::operator != (const lldb_private::CompilerDeclContext &lhs, const lldb_private::CompilerDeclContext &rhs)
7799558cc4SGreg Clayton {
7899558cc4SGreg Clayton     return lhs.GetTypeSystem() != rhs.GetTypeSystem() || lhs.GetOpaqueDeclContext() != rhs.GetOpaqueDeclContext();
7999558cc4SGreg Clayton }
80