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