blob: af60957cf638520b095c9be1320d94781ee30417 [file] [log] [blame]
Eugene Zelenko8d15f332015-10-20 01:10:59 +00001//===-- CPlusPlusLanguage.h -------------------------------------*- C++ -*-===//
Enrico Granata5f9d3102015-08-27 21:33:50 +00002//
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 Inghamaa816b82015-09-02 01:59:14 +000015#include <vector>
16
Enrico Granata5f9d3102015-08-27 21:33:50 +000017// Other libraries and framework includes
Jim Inghamaa816b82015-09-02 01:59:14 +000018#include "llvm/ADT/StringRef.h"
19
Enrico Granata5f9d3102015-08-27 21:33:50 +000020// Project includes
Jim Inghamaa816b82015-09-02 01:59:14 +000021#include "lldb/Core/ConstString.h"
Enrico Granata5f9d3102015-08-27 21:33:50 +000022#include "lldb/Target/Language.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#include "lldb/lldb-private.h"
Enrico Granata5f9d3102015-08-27 21:33:50 +000024
25namespace lldb_private {
Kate Stoneb9c1b512016-09-06 20:57:50 +000026
27class CPlusPlusLanguage : public Language {
Enrico Granata5f9d3102015-08-27 21:33:50 +000028public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 class MethodName {
30 public:
31 enum Type {
32 eTypeInvalid,
33 eTypeUnknownMethod,
34 eTypeClassMethod,
35 eTypeInstanceMethod
Jim Inghamaa816b82015-09-02 01:59:14 +000036 };
37
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 MethodName()
39 : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(),
40 m_type(eTypeInvalid), m_parsed(false), m_parse_error(false) {}
Eugene Zelenko8d15f332015-10-20 01:10:59 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 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 Zelenko8d15f332015-10-20 01:10:59 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 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 Granata5f9d3102015-08-27 21:33:50 +000056 }
Jim Inghamaa816b82015-09-02 01:59:14 +000057
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 Type GetType() const { return m_type; }
Jim Inghamaa816b82015-09-02 01:59:14 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 const ConstString &GetFullName() const { return m_full; }
Jim Inghamaa816b82015-09-02 01:59:14 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 std::string GetScopeQualifiedName();
Jim Inghamaa816b82015-09-02 01:59:14 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 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
Enrico Granatac0464972016-10-27 18:44:45 +000095 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
96
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 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
145 //------------------------------------------------------------------
146 // PluginInterface protocol
147 //------------------------------------------------------------------
148 ConstString GetPluginName() override;
149
150 uint32_t GetPluginVersion() override;
Enrico Granata5f9d3102015-08-27 21:33:50 +0000151};
Kate Stoneb9c1b512016-09-06 20:57:50 +0000152
Enrico Granata5f9d3102015-08-27 21:33:50 +0000153} // namespace lldb_private
154
Eugene Zelenko8d15f332015-10-20 01:10:59 +0000155#endif // liblldb_CPlusPlusLanguage_h_