LLDB mainline
ObjCLanguage.h
Go to the documentation of this file.
1//===-- ObjCLanguage.h ------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H
10#define LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H
11
12#include <cstring>
13#include <vector>
14
17#include "lldb/lldb-private.h"
18
19namespace lldb_private {
20
21class ObjCLanguage : public Language {
22public:
24 public:
25 /// The static factory method for creating a ObjCMethodName.
26 ///
27 /// \param[in] name
28 /// The name of the method.
29 ///
30 /// \param[in] strict
31 /// Control whether or not the name parser is strict about +/- in the
32 /// front of the name.
33 ///
34 /// \return If the name failed to parse as a valid Objective-C method name,
35 /// returns std::nullopt. Otherwise returns a const ObjCMethodName.
36 static std::optional<const ObjCMethodName> Create(llvm::StringRef name,
37 bool strict);
38
39 /// Determines if this method is a class method
40 ///
41 /// \return Returns true if the method is a class method. False otherwise.
42 bool IsClassMethod() const { return m_type == eTypeClassMethod; }
43
44 /// Determines if this method is an instance method
45 ///
46 /// \return Returns true if the method is an instance method. False
47 /// otherwise.
48 bool IsInstanceMethod() const { return m_type == eTypeInstanceMethod; }
49
50 /// Returns the full name of the method.
51 ///
52 /// This includes the class name, the category name (if applicable), and the
53 /// selector name.
54 ///
55 /// \return The name of the method in the form of a const std::string
56 /// reference.
57 const std::string &GetFullName() const { return m_full; }
58
59 /// Creates a variation of this method without the category.
60 /// If this method has no category, it returns an empty string.
61 ///
62 /// Example:
63 /// Full name: "+[NSString(my_additions) myStringWithCString:]"
64 /// becomes "+[NSString myStringWithCString:]"
65 ///
66 /// \return The method name without the category or an empty string if there
67 /// was no category to begin with.
68 std::string GetFullNameWithoutCategory() const;
69
70 /// Returns a reference to the class name.
71 ///
72 /// Example:
73 /// Full name: "+[NSString(my_additions) myStringWithCString:]"
74 /// will give you "NSString"
75 ///
76 /// \return A StringRef to the class name of this method.
77 llvm::StringRef GetClassName() const;
78
79 /// Returns a reference to the class name with the category.
80 ///
81 /// Example:
82 /// Full name: "+[NSString(my_additions) myStringWithCString:]"
83 /// will give you "NSString(my_additions)"
84 ///
85 /// Note: If your method has no category, this will give the same output as
86 /// `GetClassName`.
87 ///
88 /// \return A StringRef to the class name (including the category) of this
89 /// method. If there was no category, returns the same as `GetClassName`.
90 llvm::StringRef GetClassNameWithCategory() const;
91
92 /// Returns a reference to the category name.
93 ///
94 /// Example:
95 /// Full name: "+[NSString(my_additions) myStringWithCString:]"
96 /// will give you "my_additions"
97 /// \return A StringRef to the category name of this method. If no category
98 /// is present, the StringRef is empty.
99 llvm::StringRef GetCategory() const;
100
101 /// Returns a reference to the selector name.
102 ///
103 /// Example:
104 /// Full name: "+[NSString(my_additions) myStringWithCString:]"
105 /// will give you "myStringWithCString:"
106 /// \return A StringRef to the selector of this method.
107 llvm::StringRef GetSelector() const;
108
109 protected:
111
112 ObjCMethodName(llvm::StringRef name, Type type)
113 : m_full(name.str()), m_type(type) {}
114
115 const std::string m_full;
117 };
118
119 ObjCLanguage() = default;
120
121 ~ObjCLanguage() override = default;
122
125 }
126
127 llvm::StringRef GetUserEntryPointName() const override { return "main"; }
128
129 // Get all possible names for a method. Examples:
130 // If method_name is "+[NSString(my_additions) myStringWithCString:]"
131 // variant_names[0] => "+[NSString myStringWithCString:]"
132 // If name is specified without the leading '+' or '-' like
133 // "[NSString(my_additions) myStringWithCString:]"
134 // variant_names[0] => "+[NSString(my_additions) myStringWithCString:]"
135 // variant_names[1] => "-[NSString(my_additions) myStringWithCString:]"
136 // variant_names[2] => "+[NSString myStringWithCString:]"
137 // variant_names[3] => "-[NSString myStringWithCString:]"
138 // Also returns the FunctionNameType of each possible name.
139 std::vector<Language::MethodNameVariant>
140 GetMethodNameVariants(ConstString method_name) const override;
141
142 std::pair<lldb::FunctionNameType, std::optional<ConstString>>
143 GetFunctionNameInfo(ConstString name) const override;
144
145 bool SymbolNameFitsToLanguage(const Mangled &mangled) const override;
146
148
149 std::vector<FormattersMatchCandidate>
151 lldb::DynamicValueType use_dynamic) override;
152
153 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
154
155 std::pair<llvm::StringRef, llvm::StringRef>
156 GetFormatterPrefixSuffix(llvm::StringRef type_hint) override;
157
158 bool IsNilReference(ValueObject &valobj) override;
159
160 llvm::StringRef GetNilReferenceSummaryString() override { return "nil"; }
161
162 bool IsSourceFile(llvm::StringRef file_path) const override;
163
164 // Static Functions
165 static void Initialize();
166
167 static void Terminate();
168
170
171 static llvm::StringRef GetPluginNameStatic() { return "objc"; }
172
173 static bool IsPossibleObjCMethodName(llvm::StringRef name);
174
175 static bool IsPossibleObjCSelector(const char *name) {
176 if (!name)
177 return false;
178
179 if (strchr(name, ':') == nullptr)
180 return true;
181 else if (name[strlen(name) - 1] == ':')
182 return true;
183 else
184 return false;
185 }
186
187 llvm::StringRef GetInstanceVariableName() override { return "self"; }
188
189 virtual std::optional<bool>
190 GetBooleanFromString(llvm::StringRef str) const override;
191
192 bool SupportsExceptionBreakpointsOnThrow() const override { return true; }
193
194 // PluginInterface protocol
195 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
196};
197
198} // namespace lldb_private
199
200#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H
A uniqued constant string class.
Definition ConstString.h:40
A class that handles mangled names.
Definition Mangled.h:34
llvm::StringRef GetClassNameWithCategory() const
Returns a reference to the class name with the category.
llvm::StringRef GetSelector() const
Returns a reference to the selector name.
static std::optional< const ObjCMethodName > Create(llvm::StringRef name, bool strict)
The static factory method for creating a ObjCMethodName.
llvm::StringRef GetCategory() const
Returns a reference to the category name.
bool IsInstanceMethod() const
Determines if this method is an instance method.
bool IsClassMethod() const
Determines if this method is a class method.
ObjCMethodName(llvm::StringRef name, Type type)
const std::string & GetFullName() const
Returns the full name of the method.
llvm::StringRef GetClassName() const
Returns a reference to the class name.
std::string GetFullNameWithoutCategory() const
Creates a variation of this method without the category.
llvm::StringRef GetPluginName() override
std::pair< llvm::StringRef, llvm::StringRef > GetFormatterPrefixSuffix(llvm::StringRef type_hint) override
An individual data formatter may apply to several types and cross language boundaries.
static bool IsPossibleObjCSelector(const char *name)
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
lldb::TypeCategoryImplSP GetFormatters() override
std::pair< lldb::FunctionNameType, std::optional< ConstString > > GetFunctionNameInfo(ConstString name) const override
bool SymbolNameFitsToLanguage(const Mangled &mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
bool IsSourceFile(llvm::StringRef file_path) const override
llvm::StringRef GetNilReferenceSummaryString() override
Returns the summary string for ValueObjects for which IsNilReference() is true.
llvm::StringRef GetInstanceVariableName() override
static bool IsPossibleObjCMethodName(llvm::StringRef name)
~ObjCLanguage() override=default
lldb::LanguageType GetLanguageType() const override
virtual std::optional< bool > GetBooleanFromString(llvm::StringRef str) const override
static llvm::StringRef GetPluginNameStatic()
std::vector< FormattersMatchCandidate > GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) override
std::vector< Language::MethodNameVariant > GetMethodNameVariants(ConstString method_name) const override
bool IsNilReference(ValueObject &valobj) override
llvm::StringRef GetUserEntryPointName() const override
bool SupportsExceptionBreakpointsOnThrow() const override
Returns true if this Language supports exception breakpoints on throw via a corresponding LanguageRun...
A class that represents a running process on the host machine.
LanguageType
Programming language type.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP