Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 1 | //===-- CPlusPlusLanguage.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_CPlusPlusLanguage_h_ |
| 11 | #define liblldb_CPlusPlusLanguage_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 |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
| 19 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 20 | // Project includes |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 21 | #include "lldb/Core/ConstString.h" |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Language.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | #include "lldb/lldb-private.h" |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 24 | |
| 25 | namespace lldb_private { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | |
| 27 | class CPlusPlusLanguage : public Language { |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 28 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | class MethodName { |
| 30 | public: |
| 31 | enum Type { |
| 32 | eTypeInvalid, |
| 33 | eTypeUnknownMethod, |
| 34 | eTypeClassMethod, |
| 35 | eTypeInstanceMethod |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | MethodName() |
| 39 | : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(), |
| 40 | m_type(eTypeInvalid), m_parsed(false), m_parse_error(false) {} |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | MethodName(const ConstString &s) |
| 43 | : m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(), |
| 44 | m_type(eTypeInvalid), m_parsed(false), m_parse_error(false) {} |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | void Clear(); |
| 47 | |
| 48 | bool IsValid() { |
| 49 | if (!m_parsed) |
| 50 | Parse(); |
| 51 | if (m_parse_error) |
| 52 | return false; |
| 53 | if (m_type == eTypeInvalid) |
| 54 | return false; |
| 55 | return (bool)m_full; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 56 | } |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | Type GetType() const { return m_type; } |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | const ConstString &GetFullName() const { return m_full; } |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | std::string GetScopeQualifiedName(); |
Jim Ingham | aa816b8 | 2015-09-02 01:59:14 +0000 | [diff] [blame] | 63 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | llvm::StringRef GetBasename(); |
| 65 | |
| 66 | llvm::StringRef GetContext(); |
| 67 | |
| 68 | llvm::StringRef GetArguments(); |
| 69 | |
| 70 | llvm::StringRef GetQualifiers(); |
| 71 | |
| 72 | protected: |
| 73 | void Parse(); |
| 74 | |
| 75 | ConstString m_full; // Full name: |
| 76 | // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) |
| 77 | // const" |
| 78 | llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex" |
| 79 | llvm::StringRef m_context; // Decl context: "lldb::SBTarget" |
| 80 | llvm::StringRef m_arguments; // Arguments: "(unsigned int)" |
| 81 | llvm::StringRef m_qualifiers; // Qualifiers: "const" |
| 82 | Type m_type; |
| 83 | bool m_parsed; |
| 84 | bool m_parse_error; |
| 85 | }; |
| 86 | |
| 87 | CPlusPlusLanguage() = default; |
| 88 | |
| 89 | ~CPlusPlusLanguage() override = default; |
| 90 | |
| 91 | lldb::LanguageType GetLanguageType() const override { |
| 92 | return lldb::eLanguageTypeC_plus_plus; |
| 93 | } |
| 94 | |
| 95 | lldb::TypeCategoryImplSP GetFormatters() override; |
| 96 | |
| 97 | HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override; |
| 98 | |
| 99 | HardcodedFormatters::HardcodedSyntheticFinder |
| 100 | GetHardcodedSynthetics() override; |
| 101 | |
| 102 | //------------------------------------------------------------------ |
| 103 | // Static Functions |
| 104 | //------------------------------------------------------------------ |
| 105 | static void Initialize(); |
| 106 | |
| 107 | static void Terminate(); |
| 108 | |
| 109 | static lldb_private::Language *CreateInstance(lldb::LanguageType language); |
| 110 | |
| 111 | static lldb_private::ConstString GetPluginNameStatic(); |
| 112 | |
| 113 | static bool IsCPPMangledName(const char *name); |
| 114 | |
| 115 | // Extract C++ context and identifier from a string using heuristic matching |
| 116 | // (as opposed to |
| 117 | // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name |
| 118 | // with parens and arguments. |
| 119 | // If the name is a lone C identifier (e.g. C) or a qualified C identifier |
| 120 | // (e.g. A::B::C) it will return true, |
| 121 | // and identifier will be the identifier (C and C respectively) and the |
| 122 | // context will be "" and "A::B::" respectively. |
| 123 | // If the name fails the heuristic matching for a qualified or unqualified |
| 124 | // C/C++ identifier, then it will return false |
| 125 | // and identifier and context will be unchanged. |
| 126 | |
| 127 | static bool ExtractContextAndIdentifier(const char *name, |
| 128 | llvm::StringRef &context, |
| 129 | llvm::StringRef &identifier); |
| 130 | |
| 131 | // in some cases, compilers will output different names for one same type. |
| 132 | // when that happens, it might be impossible |
| 133 | // to construct SBType objects for a valid type, because the name that is |
| 134 | // available is not the same as the name that |
| 135 | // can be used as a search key in FindTypes(). the equivalents map here is |
| 136 | // meant to return possible alternative names |
| 137 | // for a type through which a search can be conducted. Currently, this is only |
| 138 | // enabled for C++ but can be extended |
| 139 | // to ObjC or other languages if necessary |
| 140 | static uint32_t FindEquivalentNames(ConstString type_name, |
| 141 | std::vector<ConstString> &equivalents); |
| 142 | |
| 143 | //------------------------------------------------------------------ |
| 144 | // PluginInterface protocol |
| 145 | //------------------------------------------------------------------ |
| 146 | ConstString GetPluginName() override; |
| 147 | |
| 148 | uint32_t GetPluginVersion() override; |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 149 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | |
Enrico Granata | 5f9d310 | 2015-08-27 21:33:50 +0000 | [diff] [blame] | 151 | } // namespace lldb_private |
| 152 | |
Eugene Zelenko | 8d15f33 | 2015-10-20 01:10:59 +0000 | [diff] [blame] | 153 | #endif // liblldb_CPlusPlusLanguage_h_ |