Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 1 | //===-- ObjCLanguage.h ------------------------------------------*- C++ -*-===// |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 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 Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 17 | // Other libraries and framework includes |
| 18 | // Project includes |
| 19 | #include "lldb/lldb-private.h" |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ConstString.h" |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Language.h" |
| 22 | |
| 23 | namespace lldb_private { |
| 24 | |
| 25 | class ObjCLanguage : |
| 26 | public Language |
| 27 | { |
| 28 | public: |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 29 | 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 | { |
Jim Ingham | e90dc82 | 2015-09-03 00:03:13 +0000 | [diff] [blame] | 78 | return !GetCategory().IsEmpty(); |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 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); |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 122 | |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 123 | protected: |
| 124 | ConstString m_full; // Full name: "+[NSString(my_additions) myStringWithCString:]" |
| 125 | ConstString m_class; // Class name: "NSString" |
| 126 | ConstString m_class_category; // Class with category: "NSString(my_additions)" |
| 127 | ConstString m_category; // Category: "my_additions" |
| 128 | ConstString m_selector; // Selector: "myStringWithCString:" |
| 129 | Type m_type; |
| 130 | bool m_category_is_valid; |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 133 | ObjCLanguage() = default; |
| 134 | |
| 135 | ~ObjCLanguage() override = default; |
| 136 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 137 | lldb::LanguageType |
Enrico Granata | d3233c1 | 2015-09-09 01:10:46 +0000 | [diff] [blame] | 138 | GetLanguageType () const override |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 139 | { |
| 140 | return lldb::eLanguageTypeObjC; |
| 141 | } |
| 142 | |
Enrico Granata | 170c395 | 2015-09-14 22:18:32 +0000 | [diff] [blame] | 143 | lldb::TypeCategoryImplSP |
| 144 | GetFormatters () override; |
| 145 | |
Enrico Granata | d3233c1 | 2015-09-09 01:10:46 +0000 | [diff] [blame] | 146 | std::vector<ConstString> |
| 147 | GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic) override; |
| 148 | |
Enrico Granata | 9b0af1b | 2015-10-01 18:16:18 +0000 | [diff] [blame] | 149 | std::unique_ptr<TypeScavenger> |
| 150 | GetTypeScavenger () override; |
| 151 | |
Enrico Granata | 675f49b | 2015-10-07 18:36:53 +0000 | [diff] [blame] | 152 | bool |
| 153 | GetFormatterPrefixSuffix (ValueObject& valobj, ConstString type_hint, |
| 154 | std::string& prefix, std::string& suffix) override; |
| 155 | |
Enrico Granata | 608d67c | 2015-11-10 22:39:15 +0000 | [diff] [blame] | 156 | bool |
| 157 | IsNilReference (ValueObject& valobj) override; |
| 158 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 159 | //------------------------------------------------------------------ |
| 160 | // Static Functions |
| 161 | //------------------------------------------------------------------ |
| 162 | static void |
| 163 | Initialize(); |
| 164 | |
| 165 | static void |
| 166 | Terminate(); |
| 167 | |
| 168 | static lldb_private::Language * |
| 169 | CreateInstance (lldb::LanguageType language); |
| 170 | |
| 171 | static lldb_private::ConstString |
| 172 | GetPluginNameStatic(); |
| 173 | |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 174 | static bool |
| 175 | IsPossibleObjCMethodName (const char *name) |
| 176 | { |
| 177 | if (!name) |
| 178 | return false; |
| 179 | bool starts_right = (name[0] == '+' || name[0] == '-') && name[1] == '['; |
| 180 | bool ends_right = (name[strlen(name) - 1] == ']'); |
| 181 | return (starts_right && ends_right); |
| 182 | } |
| 183 | |
| 184 | static bool |
| 185 | IsPossibleObjCSelector (const char *name) |
| 186 | { |
| 187 | if (!name) |
| 188 | return false; |
| 189 | |
| 190 | if (strchr(name, ':') == NULL) |
| 191 | return true; |
| 192 | else if (name[strlen(name) - 1] == ':') |
| 193 | return true; |
| 194 | else |
| 195 | return false; |
| 196 | } |
| 197 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 198 | //------------------------------------------------------------------ |
| 199 | // PluginInterface protocol |
| 200 | //------------------------------------------------------------------ |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 201 | ConstString |
Enrico Granata | d3233c1 | 2015-09-09 01:10:46 +0000 | [diff] [blame] | 202 | GetPluginName() override; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 203 | |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 204 | uint32_t |
Enrico Granata | d3233c1 | 2015-09-09 01:10:46 +0000 | [diff] [blame] | 205 | GetPluginVersion() override; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | } // namespace lldb_private |
| 209 | |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 210 | #endif // liblldb_ObjCLanguage_h_ |