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 #include <set> 14 #include <vector> 15 16 #include "llvm/ADT/StringRef.h" 17 18 #include "Plugins/Language/ClangCommon/ClangHighlighter.h" 19 #include "lldb/Target/Language.h" 20 #include "lldb/Utility/ConstString.h" 21 #include "lldb/lldb-private.h" 22 23 namespace lldb_private { 24 25 class CPlusPlusLanguage : public Language { 26 ClangHighlighter m_highlighter; 27 28 public: 29 class MethodName { 30 public: 31 MethodName() 32 : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(), 33 m_parsed(false), m_parse_error(false) {} 34 35 MethodName(const ConstString &s) 36 : m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(), 37 m_parsed(false), m_parse_error(false) {} 38 39 void Clear(); 40 41 bool IsValid() { 42 if (!m_parsed) 43 Parse(); 44 if (m_parse_error) 45 return false; 46 return (bool)m_full; 47 } 48 49 const ConstString &GetFullName() const { return m_full; } 50 51 std::string GetScopeQualifiedName(); 52 53 llvm::StringRef GetBasename(); 54 55 llvm::StringRef GetContext(); 56 57 llvm::StringRef GetArguments(); 58 59 llvm::StringRef GetQualifiers(); 60 61 protected: 62 void Parse(); 63 bool TrySimplifiedParse(); 64 65 ConstString m_full; // Full name: 66 // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) 67 // const" 68 llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex" 69 llvm::StringRef m_context; // Decl context: "lldb::SBTarget" 70 llvm::StringRef m_arguments; // Arguments: "(unsigned int)" 71 llvm::StringRef m_qualifiers; // Qualifiers: "const" 72 bool m_parsed; 73 bool m_parse_error; 74 }; 75 76 CPlusPlusLanguage() = default; 77 78 ~CPlusPlusLanguage() override = default; 79 80 lldb::LanguageType GetLanguageType() const override { 81 return lldb::eLanguageTypeC_plus_plus; 82 } 83 84 std::unique_ptr<TypeScavenger> GetTypeScavenger() override; 85 lldb::TypeCategoryImplSP GetFormatters() override; 86 87 HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override; 88 89 HardcodedFormatters::HardcodedSyntheticFinder 90 GetHardcodedSynthetics() override; 91 92 bool IsSourceFile(llvm::StringRef file_path) const override; 93 94 const Highlighter *GetHighlighter() const override { return &m_highlighter; } 95 96 //------------------------------------------------------------------ 97 // Static Functions 98 //------------------------------------------------------------------ 99 static void Initialize(); 100 101 static void Terminate(); 102 103 static lldb_private::Language *CreateInstance(lldb::LanguageType language); 104 105 static lldb_private::ConstString GetPluginNameStatic(); 106 107 static bool IsCPPMangledName(const char *name); 108 109 // Extract C++ context and identifier from a string using heuristic matching 110 // (as opposed to 111 // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name 112 // with parens and arguments. 113 // If the name is a lone C identifier (e.g. C) or a qualified C identifier 114 // (e.g. A::B::C) it will return true, 115 // and identifier will be the identifier (C and C respectively) and the 116 // context will be "" and "A::B" respectively. 117 // If the name fails the heuristic matching for a qualified or unqualified 118 // C/C++ identifier, then it will return false 119 // and identifier and context will be unchanged. 120 121 static bool ExtractContextAndIdentifier(const char *name, 122 llvm::StringRef &context, 123 llvm::StringRef &identifier); 124 125 // Given a mangled function name, calculates some alternative manglings since 126 // the compiler mangling may not line up with the symbol we are expecting 127 static uint32_t 128 FindAlternateFunctionManglings(const ConstString mangled, 129 std::set<ConstString> &candidates); 130 131 //------------------------------------------------------------------ 132 // PluginInterface protocol 133 //------------------------------------------------------------------ 134 ConstString GetPluginName() override; 135 136 uint32_t GetPluginVersion() override; 137 }; 138 139 } // namespace lldb_private 140 141 #endif // liblldb_CPlusPlusLanguage_h_ 142