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 
16 #include "lldb/Target/Language.h"
18 #include "lldb/lldb-private.h"
19 
20 namespace lldb_private {
21 
22 class ObjCLanguage : public Language {
24 
25 public:
26  class MethodName {
27  public:
29 
31 
32  MethodName(const char *name, bool strict)
33  : m_full(), m_class(), m_category(), m_selector(),
35  SetName(name, strict);
36  }
37  MethodName(llvm::StringRef name, bool strict)
38  : m_full(), m_class(), m_category(), m_selector(),
40  SetName(name, strict);
41  }
42 
43  void Clear();
44 
45  bool IsValid(bool strict) const {
46  // If "strict" is true, the name must have everything specified including
47  // the leading "+" or "-" on the method name
48  if (strict && m_type == eTypeUnspecified)
49  return false;
50  // Other than that, m_full will only be filled in if the objective C
51  // name is valid.
52  return (bool)m_full;
53  }
54 
55  bool HasCategory() { return !GetCategory().IsEmpty(); }
56 
57  Type GetType() const { return m_type; }
58 
59  ConstString GetFullName() const { return m_full; }
60 
61  ConstString GetFullNameWithoutCategory(bool empty_if_no_category);
62 
63  bool SetName(const char *name, bool strict);
64  bool SetName(llvm::StringRef name, bool strict);
65 
67 
69 
71 
73 
74  protected:
76  m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
77  ConstString m_class; // Class name: "NSString"
79  m_class_category; // Class with category: "NSString(my_additions)"
80  ConstString m_category; // Category: "my_additions"
81  ConstString m_selector; // Selector: "myStringWithCString:"
83  bool m_category_is_valid = false;
84  };
85 
86  ObjCLanguage() = default;
87 
88  ~ObjCLanguage() override = default;
89 
92  }
93 
94  // Get all possible names for a method. Examples:
95  // If method_name is "+[NSString(my_additions) myStringWithCString:]"
96  // variant_names[0] => "+[NSString myStringWithCString:]"
97  // If name is specified without the leading '+' or '-' like
98  // "[NSString(my_additions) myStringWithCString:]"
99  // variant_names[0] => "+[NSString(my_additions) myStringWithCString:]"
100  // variant_names[1] => "-[NSString(my_additions) myStringWithCString:]"
101  // variant_names[2] => "+[NSString myStringWithCString:]"
102  // variant_names[3] => "-[NSString myStringWithCString:]"
103  // Also returns the FunctionNameType of each possible name.
104  std::vector<Language::MethodNameVariant>
105  GetMethodNameVariants(ConstString method_name) const override;
106 
107  bool SymbolNameFitsToLanguage(Mangled mangled) const override;
108 
109  lldb::TypeCategoryImplSP GetFormatters() override;
110 
111  std::vector<ConstString>
113  lldb::DynamicValueType use_dynamic) override;
114 
115  std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
116 
117  bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint,
118  std::string &prefix,
119  std::string &suffix) override;
120 
121  bool IsNilReference(ValueObject &valobj) override;
122 
123  llvm::StringRef GetNilReferenceSummaryString() override { return "nil"; }
124 
125  bool IsSourceFile(llvm::StringRef file_path) const override;
126 
127  const Highlighter *GetHighlighter() const override { return &m_highlighter; }
128 
129  // Static Functions
130  static void Initialize();
131 
132  static void Terminate();
133 
135 
137 
138  static bool IsPossibleObjCMethodName(const char *name) {
139  if (!name)
140  return false;
141  bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';
142  bool ends_right = (name[strlen(name) - 1] == ']');
143  return (starts_right && ends_right);
144  }
145 
146  static bool IsPossibleObjCSelector(const char *name) {
147  if (!name)
148  return false;
149 
150  if (strchr(name, ':') == nullptr)
151  return true;
152  else if (name[strlen(name) - 1] == ':')
153  return true;
154  else
155  return false;
156  }
157 
158  // PluginInterface protocol
159  llvm::StringRef GetPluginName() override {
161  }
162 };
163 
164 } // namespace lldb_private
165 
166 #endif // LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H
lldb_private::ObjCLanguage::MethodName::MethodName
MethodName(const char *name, bool strict)
Definition: ObjCLanguage.h:32
lldb_private::ObjCLanguage::MethodName::HasCategory
bool HasCategory()
Definition: ObjCLanguage.h:55
lldb_private::ObjCLanguage::GetLanguageType
lldb::LanguageType GetLanguageType() const override
Definition: ObjCLanguage.h:90
lldb_private::ObjCLanguage::MethodName::GetType
Type GetType() const
Definition: ObjCLanguage.h:57
lldb_private::ObjCLanguage::MethodName::m_full
ConstString m_full
Definition: ObjCLanguage.h:76
lldb_private::ObjCLanguage::MethodName::MethodName
MethodName()
Definition: ObjCLanguage.h:30
lldb_private::ObjCLanguage::Terminate
static void Terminate()
Definition: ObjCLanguage.cpp:47
lldb_private::ObjCLanguage::MethodName::Clear
void Clear()
Definition: ObjCLanguage.cpp:67
lldb_private::ObjCLanguage::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: ObjCLanguage.cpp:51
lldb_private::ObjCLanguage::ObjCLanguage
ObjCLanguage()=default
lldb_private::ObjCLanguage::MethodName::m_category_is_valid
bool m_category_is_valid
Definition: ObjCLanguage.h:83
lldb_private::ObjCLanguage::MethodName::Type
Type
Definition: ObjCLanguage.h:28
lldb_private::ObjCLanguage::MethodName::m_class_category
ConstString m_class_category
Definition: ObjCLanguage.h:79
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::ObjCLanguage::IsPossibleObjCSelector
static bool IsPossibleObjCSelector(const char *name)
Definition: ObjCLanguage.h:146
lldb_private::ObjCLanguage::GetPossibleFormattersMatches
std::vector< ConstString > GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) override
Definition: ObjCLanguage.cpp:940
Language.h
lldb_private::ObjCLanguage::GetFormatterPrefixSuffix
bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint, std::string &prefix, std::string &suffix) override
Definition: ObjCLanguage.cpp:1070
lldb_private::ObjCLanguage::MethodName::GetFullName
ConstString GetFullName() const
Definition: ObjCLanguage.h:59
lldb_private::ObjCLanguage::MethodName::GetClassName
ConstString GetClassName()
Definition: ObjCLanguage.cpp:115
lldb_private::ObjCLanguage::~ObjCLanguage
~ObjCLanguage() override=default
lldb_private::ObjCLanguage::MethodName::GetFullNameWithoutCategory
ConstString GetFullNameWithoutCategory(bool empty_if_no_category)
Definition: ObjCLanguage.cpp:198
lldb_private::Highlighter
Annotates source code with color attributes.
Definition: Highlighter.h:90
lldb_private::ObjCLanguage::MethodName::SetName
bool SetName(const char *name, bool strict)
Definition: ObjCLanguage.cpp:111
lldb_private::ObjCLanguage::MethodName::m_category
ConstString m_category
Definition: ObjCLanguage.h:80
lldb_private::ObjCLanguage::GetTypeScavenger
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
Definition: ObjCLanguage.cpp:974
lldb_private::ObjCLanguage::GetHighlighter
const Highlighter * GetHighlighter() const override
Definition: ObjCLanguage.h:127
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::ConstString::IsEmpty
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
lldb_private::ObjCLanguage::IsSourceFile
bool IsSourceFile(llvm::StringRef file_path) const override
Definition: ObjCLanguage.cpp:1155
lldb_private::ObjCLanguage::IsNilReference
bool IsNilReference(ValueObject &valobj) override
Definition: ObjCLanguage.cpp:1144
lldb_private::ObjCLanguage::SymbolNameFitsToLanguage
bool SymbolNameFitsToLanguage(Mangled mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
Definition: ObjCLanguage.cpp:270
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::ObjCLanguage::MethodName::GetCategory
ConstString GetCategory()
Definition: ObjCLanguage.cpp:179
lldb_private::ObjCLanguage::m_highlighter
ClangHighlighter m_highlighter
Definition: ObjCLanguage.h:23
lldb_private::ObjCLanguage::MethodName::GetClassNameWithCategory
ConstString GetClassNameWithCategory()
Definition: ObjCLanguage.cpp:141
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:494
ClangHighlighter.h
lldb::eLanguageTypeObjC
@ eLanguageTypeObjC
Objective-C.
Definition: lldb-enumerations.h:453
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ObjCLanguage
Definition: ObjCLanguage.h:22
lldb_private::ObjCLanguage::MethodName::m_type
Type m_type
Definition: ObjCLanguage.h:82
lldb_private::ObjCLanguage::MethodName
Definition: ObjCLanguage.h:26
lldb_private::ObjCLanguage::MethodName::eTypeInstanceMethod
@ eTypeInstanceMethod
Definition: ObjCLanguage.h:28
lldb-private.h
lldb_private::ObjCLanguage::MethodName::GetSelector
ConstString GetSelector()
Definition: ObjCLanguage.cpp:164
lldb_private::ObjCLanguage::MethodName::eTypeClassMethod
@ eTypeClassMethod
Definition: ObjCLanguage.h:28
lldb_private::ObjCLanguage::Initialize
static void Initialize()
Definition: ObjCLanguage.cpp:42
lldb_private::ObjCLanguage::MethodName::m_selector
ConstString m_selector
Definition: ObjCLanguage.h:81
lldb_private::ObjCLanguage::CreateInstance
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
Definition: ObjCLanguage.cpp:58
lldb_private::ObjCLanguage::MethodName::m_class
ConstString m_class
Definition: ObjCLanguage.h:77
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::ObjCLanguage::GetMethodNameVariants
std::vector< Language::MethodNameVariant > GetMethodNameVariants(ConstString method_name) const override
Definition: ObjCLanguage.cpp:221
lldb_private::Language
Definition: Language.h:29
lldb_private::ObjCLanguage::MethodName::MethodName
MethodName(llvm::StringRef name, bool strict)
Definition: ObjCLanguage.h:37
lldb_private::ObjCLanguage::GetNilReferenceSummaryString
llvm::StringRef GetNilReferenceSummaryString() override
Returns the summary string for ValueObjects for which IsNilReference() is true.
Definition: ObjCLanguage.h:123
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjCLanguage::MethodName::IsValid
bool IsValid(bool strict) const
Definition: ObjCLanguage.h:45
lldb_private::ClangHighlighter
Definition: ClangHighlighter.h:19
ConstString.h
lldb_private::ObjCLanguage::GetPluginName
llvm::StringRef GetPluginName() override
Definition: ObjCLanguage.h:159
lldb_private::ObjCLanguage::IsPossibleObjCMethodName
static bool IsPossibleObjCMethodName(const char *name)
Definition: ObjCLanguage.h:138
lldb_private::ObjCLanguage::MethodName::eTypeUnspecified
@ eTypeUnspecified
Definition: ObjCLanguage.h:28
lldb_private::ObjCLanguage::GetFormatters
lldb::TypeCategoryImplSP GetFormatters() override
Definition: ObjCLanguage.cpp:924