blob: 70ecf90ae3976382fa7551a62a11fc5ad8fb8bcd [file] [log] [blame]
Enrico Granata5f9d3102015-08-27 21:33:50 +00001//===-- ObjCLanguage.h ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ObjCLanguage_h_
11#define liblldb_ObjCLanguage_h_
12
13// C Includes
14// C++ Includes
Jim Inghamaa816b82015-09-02 01:59:14 +000015#include <vector>
16
Enrico Granata5f9d3102015-08-27 21:33:50 +000017// Other libraries and framework includes
18// Project includes
19#include "lldb/lldb-private.h"
Jim Inghamaa816b82015-09-02 01:59:14 +000020#include "lldb/Core/ConstString.h"
Enrico Granata5f9d3102015-08-27 21:33:50 +000021#include "lldb/Target/Language.h"
22
23namespace lldb_private {
24
25class ObjCLanguage :
26 public Language
27{
28public:
Jim Inghamaa816b82015-09-02 01:59:14 +000029 class MethodName
30 {
31 public:
32 enum Type
33 {
34 eTypeUnspecified,
35 eTypeClassMethod,
36 eTypeInstanceMethod
37 };
38
39 MethodName () :
40 m_full(),
41 m_class(),
42 m_category(),
43 m_selector(),
44 m_type (eTypeUnspecified),
45 m_category_is_valid (false)
46 {
47 }
48
49 MethodName (const char *name, bool strict) :
50 m_full(),
51 m_class(),
52 m_category(),
53 m_selector(),
54 m_type (eTypeUnspecified),
55 m_category_is_valid (false)
56 {
57 SetName (name, strict);
58 }
59
60 void
61 Clear();
62
63 bool
64 IsValid (bool strict) const
65 {
66 // If "strict" is true, the name must have everything specified including
67 // the leading "+" or "-" on the method name
68 if (strict && m_type == eTypeUnspecified)
69 return false;
70 // Other than that, m_full will only be filled in if the objective C
71 // name is valid.
72 return (bool)m_full;
73 }
74
75 bool
76 HasCategory()
77 {
78 return !GetCategory();
79 }
80
81 Type
82 GetType () const
83 {
84 return m_type;
85 }
86
87 const ConstString &
88 GetFullName () const
89 {
90 return m_full;
91 }
92
93 ConstString
94 GetFullNameWithoutCategory (bool empty_if_no_category);
95
96 bool
97 SetName (const char *name, bool strict);
98
99 const ConstString &
100 GetClassName ();
101
102 const ConstString &
103 GetClassNameWithCategory ();
104
105 const ConstString &
106 GetCategory ();
107
108 const ConstString &
109 GetSelector ();
110
111 // Get all possible names for a method. Examples:
112 // If name is "+[NSString(my_additions) myStringWithCString:]"
113 // names[0] => "+[NSString(my_additions) myStringWithCString:]"
114 // names[1] => "+[NSString myStringWithCString:]"
115 // If name is specified without the leading '+' or '-' like "[NSString(my_additions) myStringWithCString:]"
116 // names[0] => "+[NSString(my_additions) myStringWithCString:]"
117 // names[1] => "-[NSString(my_additions) myStringWithCString:]"
118 // names[2] => "+[NSString myStringWithCString:]"
119 // names[3] => "-[NSString myStringWithCString:]"
120 size_t
121 GetFullNames (std::vector<ConstString> &names, bool append);
122 protected:
123 ConstString m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]"
124 ConstString m_class; // Class name: "NSString"
125 ConstString m_class_category; // Class with category: "NSString(my_additions)"
126 ConstString m_category; // Category: "my_additions"
127 ConstString m_selector; // Selector: "myStringWithCString:"
128 Type m_type;
129 bool m_category_is_valid;
130
131 };
132
Enrico Granata5f9d3102015-08-27 21:33:50 +0000133 virtual ~ObjCLanguage() = default;
134
135 ObjCLanguage () = default;
136
137 lldb::LanguageType
138 GetLanguageType () const
139 {
140 return lldb::eLanguageTypeObjC;
141 }
142
143 //------------------------------------------------------------------
144 // Static Functions
145 //------------------------------------------------------------------
146 static void
147 Initialize();
148
149 static void
150 Terminate();
151
152 static lldb_private::Language *
153 CreateInstance (lldb::LanguageType language);
154
155 static lldb_private::ConstString
156 GetPluginNameStatic();
157
Jim Inghamaa816b82015-09-02 01:59:14 +0000158 static bool
159 IsPossibleObjCMethodName (const char *name)
160 {
161 if (!name)
162 return false;
163 bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '[';
164 bool ends_right = (name[strlen(name) - 1] == ']');
165 return (starts_right && ends_right);
166 }
167
168 static bool
169 IsPossibleObjCSelector (const char *name)
170 {
171 if (!name)
172 return false;
173
174 if (strchr(name, ':') == NULL)
175 return true;
176 else if (name[strlen(name) - 1] == ':')
177 return true;
178 else
179 return false;
180 }
181
Enrico Granata5f9d3102015-08-27 21:33:50 +0000182 //------------------------------------------------------------------
183 // PluginInterface protocol
184 //------------------------------------------------------------------
185 virtual ConstString
186 GetPluginName();
187
188 virtual uint32_t
189 GetPluginVersion();
190};
191
192} // namespace lldb_private
193
194#endif // liblldb_ObjCLanguage_h_