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 liblldb_ObjCLanguage_h_
10 #define liblldb_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 {
23  ClangHighlighter m_highlighter;
24 
25 public:
26  class MethodName {
27  public:
29 
31  : m_full(), m_class(), m_category(), m_selector(),
33 
34  MethodName(const char *name, bool strict)
35  : m_full(), m_class(), m_category(), m_selector(),
37  SetName(name, strict);
38  }
39  MethodName(llvm::StringRef name, bool strict)
40  : m_full(), m_class(), m_category(), m_selector(),
42  SetName(name, strict);
43  }
44 
45  void Clear();
46 
47  bool IsValid(bool strict) const {
48  // If "strict" is true, the name must have everything specified including
49  // the leading "+" or "-" on the method name
50  if (strict && m_type == eTypeUnspecified)
51  return false;
52  // Other than that, m_full will only be filled in if the objective C
53  // name is valid.
54  return (bool)m_full;
55  }
56 
57  bool HasCategory() { return !GetCategory().IsEmpty(); }
58 
59  Type GetType() const { return m_type; }
60 
61  ConstString GetFullName() const { return m_full; }
62 
63  ConstString GetFullNameWithoutCategory(bool empty_if_no_category);
64 
65  bool SetName(const char *name, bool strict);
66  bool SetName(llvm::StringRef name, bool strict);
67 
69 
71 
73 
75 
76  // Get all possible names for a method. Examples:
77  // If name is "+[NSString(my_additions) myStringWithCString:]"
78  // names[0] => "+[NSString(my_additions) myStringWithCString:]"
79  // names[1] => "+[NSString myStringWithCString:]"
80  // If name is specified without the leading '+' or '-' like
81  // "[NSString(my_additions) myStringWithCString:]"
82  // names[0] => "+[NSString(my_additions) myStringWithCString:]"
83  // names[1] => "-[NSString(my_additions) myStringWithCString:]"
84  // names[2] => "+[NSString myStringWithCString:]"
85  // names[3] => "-[NSString myStringWithCString:]"
86  size_t GetFullNames(std::vector<ConstString> &names, bool append);
87 
88  protected:
90  m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
91  ConstString m_class; // Class name: "NSString"
93  m_class_category; // Class with category: "NSString(my_additions)"
94  ConstString m_category; // Category: "my_additions"
95  ConstString m_selector; // Selector: "myStringWithCString:"
98  };
99 
100  ObjCLanguage() = default;
101 
102  ~ObjCLanguage() override = default;
103 
106  }
107 
108  lldb::TypeCategoryImplSP GetFormatters() override;
109 
110  std::vector<ConstString>
112  lldb::DynamicValueType use_dynamic) override;
113 
114  std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
115 
116  bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint,
117  std::string &prefix,
118  std::string &suffix) override;
119 
120  bool IsNilReference(ValueObject &valobj) override;
121 
122  bool IsSourceFile(llvm::StringRef file_path) const override;
123 
124  const Highlighter *GetHighlighter() const override { return &m_highlighter; }
125 
126  // Static Functions
127  static void Initialize();
128 
129  static void Terminate();
130 
132 
134 
135  static bool IsPossibleObjCMethodName(const char *name) {
136  if (!name)
137  return false;
138  bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';
139  bool ends_right = (name[strlen(name) - 1] == ']');
140  return (starts_right && ends_right);
141  }
142 
143  static bool IsPossibleObjCSelector(const char *name) {
144  if (!name)
145  return false;
146 
147  if (strchr(name, ':') == nullptr)
148  return true;
149  else if (name[strlen(name) - 1] == ':')
150  return true;
151  else
152  return false;
153  }
154 
155  // PluginInterface protocol
156  ConstString GetPluginName() override;
157 
158  uint32_t GetPluginVersion() override;
159 };
160 
161 } // namespace lldb_private
162 
163 #endif // liblldb_ObjCLanguage_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
bool IsSourceFile(llvm::StringRef file_path) const override
MethodName(llvm::StringRef name, bool strict)
Definition: ObjCLanguage.h:39
bool SetName(const char *name, bool strict)
static bool IsPossibleObjCSelector(const char *name)
Definition: ObjCLanguage.h:143
size_t GetFullNames(std::vector< ConstString > &names, bool append)
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
uint32_t GetPluginVersion() override
ConstString GetFullNameWithoutCategory(bool empty_if_no_category)
LanguageType
Programming language type.
static bool IsPossibleObjCMethodName(const char *name)
Definition: ObjCLanguage.h:135
ConstString GetPluginName() override
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
lldb::LanguageType GetLanguageType() const override
Definition: ObjCLanguage.h:104
std::vector< ConstString > GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) override
Annotates source code with color attributes.
Definition: Highlighter.h:92
A uniqued constant string class.
Definition: ConstString.h:38
const Highlighter * GetHighlighter() const override
Definition: ObjCLanguage.h:124
~ObjCLanguage() override=default
MethodName(const char *name, bool strict)
Definition: ObjCLanguage.h:34
bool IsNilReference(ValueObject &valobj) override
lldb::TypeCategoryImplSP GetFormatters() override
static lldb_private::ConstString GetPluginNameStatic()
bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint, std::string &prefix, std::string &suffix) override
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:340
bool IsValid(bool strict) const
Definition: ObjCLanguage.h:47