Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
39642 views
//===-- ObjCLanguage.h ------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H9#define LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H1011#include <cstring>12#include <vector>1314#include "Plugins/Language/ClangCommon/ClangHighlighter.h"15#include "lldb/Target/Language.h"16#include "lldb/Utility/ConstString.h"17#include "lldb/lldb-private.h"1819namespace lldb_private {2021class ObjCLanguage : public Language {22ClangHighlighter m_highlighter;2324public:25class MethodName {26public:27/// The static factory method for creating a MethodName.28///29/// \param[in] name30/// The name of the method.31///32/// \param[in] strict33/// Control whether or not the name parser is strict about +/- in the34/// front of the name.35///36/// \return If the name failed to parse as a valid Objective-C method name,37/// returns std::nullopt. Otherwise returns a const MethodName.38static std::optional<const MethodName> Create(llvm::StringRef name,39bool strict);4041/// Determines if this method is a class method42///43/// \return Returns true if the method is a class method. False otherwise.44bool IsClassMethod() const { return m_type == eTypeClassMethod; }4546/// Determines if this method is an instance method47///48/// \return Returns true if the method is an instance method. False49/// otherwise.50bool IsInstanceMethod() const { return m_type == eTypeInstanceMethod; }5152/// Returns the full name of the method.53///54/// This includes the class name, the category name (if applicable), and the55/// selector name.56///57/// \return The name of the method in the form of a const std::string58/// reference.59const std::string &GetFullName() const { return m_full; }6061/// Creates a variation of this method without the category.62/// If this method has no category, it returns an empty string.63///64/// Example:65/// Full name: "+[NSString(my_additions) myStringWithCString:]"66/// becomes "+[NSString myStringWithCString:]"67///68/// \return The method name without the category or an empty string if there69/// was no category to begin with.70std::string GetFullNameWithoutCategory() const;7172/// Returns a reference to the class name.73///74/// Example:75/// Full name: "+[NSString(my_additions) myStringWithCString:]"76/// will give you "NSString"77///78/// \return A StringRef to the class name of this method.79llvm::StringRef GetClassName() const;8081/// Returns a reference to the class name with the category.82///83/// Example:84/// Full name: "+[NSString(my_additions) myStringWithCString:]"85/// will give you "NSString(my_additions)"86///87/// Note: If your method has no category, this will give the same output as88/// `GetClassName`.89///90/// \return A StringRef to the class name (including the category) of this91/// method. If there was no category, returns the same as `GetClassName`.92llvm::StringRef GetClassNameWithCategory() const;9394/// Returns a reference to the category name.95///96/// Example:97/// Full name: "+[NSString(my_additions) myStringWithCString:]"98/// will give you "my_additions"99/// \return A StringRef to the category name of this method. If no category100/// is present, the StringRef is empty.101llvm::StringRef GetCategory() const;102103/// Returns a reference to the selector name.104///105/// Example:106/// Full name: "+[NSString(my_additions) myStringWithCString:]"107/// will give you "myStringWithCString:"108/// \return A StringRef to the selector of this method.109llvm::StringRef GetSelector() const;110111protected:112enum Type { eTypeUnspecified, eTypeClassMethod, eTypeInstanceMethod };113114MethodName(llvm::StringRef name, Type type)115: m_full(name.str()), m_type(type) {}116117const std::string m_full;118Type m_type;119};120121ObjCLanguage() = default;122123~ObjCLanguage() override = default;124125lldb::LanguageType GetLanguageType() const override {126return lldb::eLanguageTypeObjC;127}128129llvm::StringRef GetUserEntryPointName() const override { return "main"; }130131// Get all possible names for a method. Examples:132// If method_name is "+[NSString(my_additions) myStringWithCString:]"133// variant_names[0] => "+[NSString myStringWithCString:]"134// If name is specified without the leading '+' or '-' like135// "[NSString(my_additions) myStringWithCString:]"136// variant_names[0] => "+[NSString(my_additions) myStringWithCString:]"137// variant_names[1] => "-[NSString(my_additions) myStringWithCString:]"138// variant_names[2] => "+[NSString myStringWithCString:]"139// variant_names[3] => "-[NSString myStringWithCString:]"140// Also returns the FunctionNameType of each possible name.141std::vector<Language::MethodNameVariant>142GetMethodNameVariants(ConstString method_name) const override;143144bool SymbolNameFitsToLanguage(Mangled mangled) const override;145146lldb::TypeCategoryImplSP GetFormatters() override;147148std::vector<FormattersMatchCandidate>149GetPossibleFormattersMatches(ValueObject &valobj,150lldb::DynamicValueType use_dynamic) override;151152std::unique_ptr<TypeScavenger> GetTypeScavenger() override;153154std::pair<llvm::StringRef, llvm::StringRef>155GetFormatterPrefixSuffix(llvm::StringRef type_hint) override;156157bool IsNilReference(ValueObject &valobj) override;158159llvm::StringRef GetNilReferenceSummaryString() override { return "nil"; }160161bool IsSourceFile(llvm::StringRef file_path) const override;162163const Highlighter *GetHighlighter() const override { return &m_highlighter; }164165// Static Functions166static void Initialize();167168static void Terminate();169170static lldb_private::Language *CreateInstance(lldb::LanguageType language);171172static llvm::StringRef GetPluginNameStatic() { return "objc"; }173174static bool IsPossibleObjCMethodName(const char *name) {175if (!name)176return false;177bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';178bool ends_right = (name[strlen(name) - 1] == ']');179return (starts_right && ends_right);180}181182static bool IsPossibleObjCSelector(const char *name) {183if (!name)184return false;185186if (strchr(name, ':') == nullptr)187return true;188else if (name[strlen(name) - 1] == ':')189return true;190else191return false;192}193194llvm::StringRef GetInstanceVariableName() override { return "self"; }195196bool SupportsExceptionBreakpointsOnThrow() const override { return true; }197198// PluginInterface protocol199llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }200};201202} // namespace lldb_private203204#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H205206207