Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions lldb/include/lldb/Symbol/CompilerDeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,13 @@ class CompilerDeclContext {

/// Checks if this decl context represents a method of a class.
///
/// \param[out] language_ptr
/// If non NULL and \b true is returned from this function,
/// this will indicate if the language that respresents the method.
///
/// \param[out] is_instance_method_ptr
/// If non NULL and \b true is returned from this function,
/// this will indicate if the method is an instance function (true)
/// or a class method (false indicating the function is static, or
/// doesn't require an instance of the class to be called).
///
/// \param[out] language_object_name_ptr
/// If non NULL and \b true is returned from this function,
/// this will indicate if implicit object name for the language
/// like "this" for C++, and "self" for Objective C.
///
/// \return
/// Returns true if this is a decl context that represents a method
/// in a struct, union or class.
bool IsClassMethod(lldb::LanguageType *language_ptr,
bool *is_instance_method_ptr,
ConstString *language_object_name_ptr);
bool IsClassMethod();

/// Determines the original language of the decl context.
lldb::LanguageType GetLanguage();

/// Check if the given other decl context is contained in the lookup
/// of this decl context (for example because the other context is a nested
Expand Down
21 changes: 4 additions & 17 deletions lldb/include/lldb/Symbol/SymbolContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,13 @@ class SymbolContext {
/// represented by this symbol context object, nullptr otherwise.
Block *GetFunctionBlock();

/// If this symbol context represents a function that is a method, return
/// true and provide information about the method.
/// Determines the name of the instance variable for the this decl context.
///
/// \param[out] language
/// If \b true is returned, the language for the method.
///
/// \param[out] is_instance_method
/// If \b true is returned, \b true if this is a instance method,
/// \b false if this is a static/class function.
///
/// \param[out] language_object_name
/// If \b true is returned, the name of the artificial variable
/// for the language ("this" for C++, "self" for ObjC).
/// For C++ the name is "this", for Objective-C the name is "self".
///
/// \return
/// \b True if this symbol context represents a function that
/// is a method of a class, \b false otherwise.
bool GetFunctionMethodInfo(lldb::LanguageType &language,
bool &is_instance_method,
ConstString &language_object_name);
/// Returns a string for the name of the instance variable.
ConstString GetInstanceVariableName();

/// Sorts the types in TypeMap according to SymbolContext to TypeList
///
Expand Down
6 changes: 3 additions & 3 deletions lldb/include/lldb/Symbol/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class TypeSystem : public PluginInterface,
virtual ConstString
DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) = 0;

virtual bool DeclContextIsClassMethod(
void *opaque_decl_ctx, lldb::LanguageType *language_ptr,
bool *is_instance_method_ptr, ConstString *language_object_name_ptr) = 0;
virtual bool DeclContextIsClassMethod(void *opaque_decl_ctx) = 0;

virtual bool DeclContextIsContainedInLookup(void *opaque_decl_ctx,
void *other_opaque_decl_ctx) = 0;

virtual lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) = 0;

// Tests
#ifndef NDEBUG
/// Verify the integrity of the type to catch CompilerTypes that mix
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ class Language : public PluginInterface {
return ConstString();
}

virtual ConstString GetInstanceVariableName() { return {}; }

protected:
// Classes that inherit from Language can see and modify these

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,7 @@ SymbolContextList ClangExpressionDeclMap::SearchFunctionsInSymbolContexts(
// class/instance methods, since they'll be skipped in the code that
// follows anyway.
CompilerDeclContext func_decl_context = function->GetDeclContext();
if (!func_decl_context ||
func_decl_context.IsClassMethod(nullptr, nullptr, nullptr))
if (!func_decl_context || func_decl_context.IsClassMethod())
continue;
// We can only prune functions for which we can copy the type.
CompilerType func_clang_type = function->GetType()->GetFullCompilerType();
Expand Down Expand Up @@ -1308,7 +1307,7 @@ void ClangExpressionDeclMap::LookupFunction(
continue;

// Filter out class/instance methods.
if (decl_ctx.IsClassMethod(nullptr, nullptr, nullptr))
if (decl_ctx.IsClassMethod())
continue;

AddOneFunction(context, sym_ctx.function, nullptr);
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class CPlusPlusLanguage : public Language {
ConstString FindBestAlternateFunctionMangledName(
const Mangled mangled, const SymbolContext &sym_ctx) const override;

ConstString GetInstanceVariableName() override { return ConstString("this"); }

// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class ObjCLanguage : public Language {
return false;
}

ConstString GetInstanceVariableName() override { return ConstString("self"); }

// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ObjCPlusPlusLanguage : public Language {

static lldb_private::Language *CreateInstance(lldb::LanguageType language);

ConstString GetInstanceVariableName() override { return ConstString("self"); }

static llvm::StringRef GetPluginNameStatic() { return "objcplusplus"; }

// PluginInterface protocol
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Target/Language.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-private.h"

namespace lldb_private {
Expand Down Expand Up @@ -88,6 +89,8 @@ class SwiftLanguage : public Language {

bool SymbolNameFitsToLanguage(Mangled mangled) const override;

ConstString GetInstanceVariableName() override { return ConstString("self"); }

//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
Expand Down
70 changes: 34 additions & 36 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "TypeSystemClang.h"

#include "clang/AST/DeclBase.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/FormatAdapters.h"
#include "llvm/Support/FormatVariadic.h"

Expand Down Expand Up @@ -9721,43 +9723,21 @@ TypeSystemClang::DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) {
return ConstString();
}

bool TypeSystemClang::DeclContextIsClassMethod(
void *opaque_decl_ctx, lldb::LanguageType *language_ptr,
bool *is_instance_method_ptr, ConstString *language_object_name_ptr) {
if (opaque_decl_ctx) {
clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
if (ObjCMethodDecl *objc_method =
llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) {
if (is_instance_method_ptr)
*is_instance_method_ptr = objc_method->isInstanceMethod();
if (language_ptr)
*language_ptr = eLanguageTypeObjC;
if (language_object_name_ptr)
language_object_name_ptr->SetCString("self");
return true;
} else if (CXXMethodDecl *cxx_method =
llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) {
if (is_instance_method_ptr)
*is_instance_method_ptr = cxx_method->isInstance();
if (language_ptr)
*language_ptr = eLanguageTypeC_plus_plus;
if (language_object_name_ptr)
language_object_name_ptr->SetCString("this");
return true;
} else if (clang::FunctionDecl *function_decl =
llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
ClangASTMetadata *metadata = GetMetadata(function_decl);
if (metadata && metadata->HasObjectPtr()) {
if (is_instance_method_ptr)
*is_instance_method_ptr = true;
if (language_ptr)
*language_ptr = eLanguageTypeObjC;
if (language_object_name_ptr)
language_object_name_ptr->SetCString(metadata->GetObjectPtrName());
return true;
}
}
bool TypeSystemClang::DeclContextIsClassMethod(void *opaque_decl_ctx) {
if (!opaque_decl_ctx)
return false;

clang::DeclContext *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
return true;
} else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
return true;
} else if (clang::FunctionDecl *fun_decl =
llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
if (ClangASTMetadata *metadata = GetMetadata(fun_decl))
return metadata->HasObjectPtr();
}

return false;
}

Expand All @@ -9778,6 +9758,24 @@ bool TypeSystemClang::DeclContextIsContainedInLookup(
return false;
}

lldb::LanguageType
TypeSystemClang::DeclContextGetLanguage(void *opaque_decl_ctx) {
if (!opaque_decl_ctx)
return eLanguageTypeUnknown;

auto *decl_ctx = (clang::DeclContext *)opaque_decl_ctx;
if (llvm::isa<clang::ObjCMethodDecl>(decl_ctx)) {
return eLanguageTypeObjC;
} else if (llvm::isa<clang::CXXMethodDecl>(decl_ctx)) {
return eLanguageTypeC_plus_plus;
} else if (auto *fun_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) {
if (ClangASTMetadata *metadata = GetMetadata(fun_decl))
return metadata->GetObjectPtrLanguage();
}

return eLanguageTypeUnknown;
}

static bool IsClangDeclContext(const CompilerDeclContext &dc) {
return dc.IsValid() && isa<TypeSystemClang>(dc.GetTypeSystem());
}
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,13 @@ class TypeSystemClang : public TypeSystem {

ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override;

bool DeclContextIsClassMethod(void *opaque_decl_ctx,
lldb::LanguageType *language_ptr,
bool *is_instance_method_ptr,
ConstString *language_object_name_ptr) override;
bool DeclContextIsClassMethod(void *opaque_decl_ctx) override;

bool DeclContextIsContainedInLookup(void *opaque_decl_ctx,
void *other_opaque_decl_ctx) override;

lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) override;

// Clang specific clang::DeclContext functions

static clang::DeclContext *
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Flags.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-private.h"

namespace clang {
Expand Down Expand Up @@ -198,13 +199,12 @@ class TypeSystemSwift : public TypeSystem {
ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override {
return {};
}
bool
DeclContextIsClassMethod(void *opaque_decl_ctx,
lldb::LanguageType *language_ptr,
bool *is_instance_method_ptr,
ConstString *language_object_name_ptr) override {
bool DeclContextIsClassMethod(void *opaque_decl_ctx) override {
return false;
}
lldb::LanguageType DeclContextGetLanguage(void *) override {
return lldb::eLanguageTypeSwift;
}
bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override {
return false;
}
Expand Down
14 changes: 8 additions & 6 deletions lldb/source/Symbol/CompilerDeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ ConstString CompilerDeclContext::GetScopeQualifiedName() const {
return ConstString();
}

bool CompilerDeclContext::IsClassMethod(lldb::LanguageType *language_ptr,
bool *is_instance_method_ptr,
ConstString *language_object_name_ptr) {
bool CompilerDeclContext::IsClassMethod() {
if (IsValid())
return m_type_system->DeclContextIsClassMethod(
m_opaque_decl_ctx, language_ptr, is_instance_method_ptr,
language_object_name_ptr);
return m_type_system->DeclContextIsClassMethod(m_opaque_decl_ctx);
return false;
}

lldb::LanguageType CompilerDeclContext::GetLanguage() {
if (IsValid())
return m_type_system->DeclContextGetLanguage(m_opaque_decl_ctx);
return {};
}

bool CompilerDeclContext::IsContainedInLookup(CompilerDeclContext other) const {
if (!IsValid())
return false;
Expand Down
29 changes: 16 additions & 13 deletions lldb/source/Symbol/SymbolContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/lldb-enumerations.h"

using namespace lldb;
using namespace lldb_private;
Expand Down Expand Up @@ -539,19 +541,20 @@ Block *SymbolContext::GetFunctionBlock() {
return nullptr;
}

bool SymbolContext::GetFunctionMethodInfo(lldb::LanguageType &language,
bool &is_instance_method,
ConstString &language_object_name)

{
Block *function_block = GetFunctionBlock();
if (function_block) {
CompilerDeclContext decl_ctx = function_block->GetDeclContext();
if (decl_ctx)
return decl_ctx.IsClassMethod(&language, &is_instance_method,
&language_object_name);
}
return false;
ConstString SymbolContext::GetInstanceVariableName() {
LanguageType lang_type = eLanguageTypeUnknown;

if (Block *function_block = GetFunctionBlock())
if (CompilerDeclContext decl_ctx = function_block->GetDeclContext())
lang_type = decl_ctx.GetLanguage();

if (lang_type == eLanguageTypeUnknown)
lang_type = GetLanguage();

if (auto *lang = Language::FindPlugin(lang_type))
return lang->GetInstanceVariableName();

return {};
}

void SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list) const {
Expand Down
Loading