1 //===-- CPlusPlusLanguage.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_CPlusPlusLanguage_h_ 11 #define liblldb_CPlusPlusLanguage_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <vector> 16 17 // Other libraries and framework includes 18 #include "llvm/ADT/StringRef.h" 19 20 // Project includes 21 #include "lldb/lldb-private.h" 22 #include "lldb/Core/ConstString.h" 23 #include "lldb/Target/Language.h" 24 25 namespace lldb_private { 26 27 class CPlusPlusLanguage : 28 public Language 29 { 30 public: 31 class MethodName 32 { 33 public: 34 enum Type 35 { 36 eTypeInvalid, 37 eTypeUnknownMethod, 38 eTypeClassMethod, 39 eTypeInstanceMethod 40 }; 41 42 MethodName () : 43 m_full(), 44 m_basename(), 45 m_context(), 46 m_arguments(), 47 m_qualifiers(), 48 m_type (eTypeInvalid), 49 m_parsed (false), 50 m_parse_error (false) 51 { 52 } 53 54 MethodName (const ConstString &s) : 55 m_full(s), 56 m_basename(), 57 m_context(), 58 m_arguments(), 59 m_qualifiers(), 60 m_type (eTypeInvalid), 61 m_parsed (false), 62 m_parse_error (false) 63 { 64 } 65 66 void 67 Clear(); 68 69 bool 70 IsValid () 71 { 72 if (!m_parsed) 73 Parse(); 74 if (m_parse_error) 75 return false; 76 if (m_type == eTypeInvalid) 77 return false; 78 return (bool)m_full; 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 std::string 94 GetScopeQualifiedName (); 95 96 llvm::StringRef 97 GetBasename (); 98 99 llvm::StringRef 100 GetContext (); 101 102 llvm::StringRef 103 GetArguments (); 104 105 llvm::StringRef 106 GetQualifiers (); 107 108 protected: 109 void 110 Parse(); 111 112 ConstString m_full; // Full name: "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) const" 113 llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex" 114 llvm::StringRef m_context; // Decl context: "lldb::SBTarget" 115 llvm::StringRef m_arguments; // Arguments: "(unsigned int)" 116 llvm::StringRef m_qualifiers; // Qualifiers: "const" 117 Type m_type; 118 bool m_parsed; 119 bool m_parse_error; 120 }; 121 122 CPlusPlusLanguage() = default; 123 124 ~CPlusPlusLanguage() override = default; 125 126 lldb::LanguageType 127 GetLanguageType () const override 128 { 129 return lldb::eLanguageTypeC_plus_plus; 130 } 131 132 lldb::TypeCategoryImplSP 133 GetFormatters () override; 134 135 HardcodedFormatters::HardcodedSummaryFinder 136 GetHardcodedSummaries () override; 137 138 HardcodedFormatters::HardcodedSyntheticFinder 139 GetHardcodedSynthetics () override; 140 141 //------------------------------------------------------------------ 142 // Static Functions 143 //------------------------------------------------------------------ 144 static void 145 Initialize(); 146 147 static void 148 Terminate(); 149 150 static lldb_private::Language * 151 CreateInstance (lldb::LanguageType language); 152 153 static lldb_private::ConstString 154 GetPluginNameStatic(); 155 156 static bool 157 IsCPPMangledName(const char *name); 158 159 // Extract C++ context and identifier from a string using heuristic matching (as opposed to 160 // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name with parens and arguments. 161 // If the name is a lone C identifier (e.g. C) or a qualified C identifier (e.g. A::B::C) it will return true, 162 // and identifier will be the identifier (C and C respectively) and the context will be "" and "A::B::" respectively. 163 // If the name fails the heuristic matching for a qualified or unqualified C/C++ identifier, then it will return false 164 // and identifier and context will be unchanged. 165 166 static bool 167 ExtractContextAndIdentifier (const char *name, llvm::StringRef &context, llvm::StringRef &identifier); 168 169 // in some cases, compilers will output different names for one same type. when that happens, it might be impossible 170 // to construct SBType objects for a valid type, because the name that is available is not the same as the name that 171 // can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names 172 // for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended 173 // to ObjC or other languages if necessary 174 static uint32_t 175 FindEquivalentNames(ConstString type_name, std::vector<ConstString>& equivalents); 176 177 //------------------------------------------------------------------ 178 // PluginInterface protocol 179 //------------------------------------------------------------------ 180 ConstString 181 GetPluginName() override; 182 183 uint32_t 184 GetPluginVersion() override; 185 }; 186 187 } // namespace lldb_private 188 189 #endif // liblldb_CPlusPlusLanguage_h_ 190