]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/Language.h
Merge OpenSSL 1.0.2p.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / Language.h
1 //===-- Language.h ---------------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef liblldb_Language_h_
12 #define liblldb_Language_h_
13
14 // C Includes
15 // C++ Includes
16 #include <functional>
17 #include <memory>
18 #include <set>
19 #include <vector>
20
21 // Other libraries and framework includes
22 // Project includes
23 #include "lldb/Core/PluginInterface.h"
24 #include "lldb/DataFormatters/DumpValueObjectOptions.h"
25 #include "lldb/DataFormatters/FormatClasses.h"
26 #include "lldb/DataFormatters/StringPrinter.h"
27 #include "lldb/lldb-private.h"
28 #include "lldb/lldb-public.h"
29
30 namespace lldb_private {
31
32 class Language : public PluginInterface {
33 public:
34   class TypeScavenger {
35   public:
36     class Result {
37     public:
38       virtual bool IsValid() = 0;
39
40       virtual bool DumpToStream(Stream &stream,
41                                 bool print_help_if_available) = 0;
42
43       virtual ~Result() = default;
44     };
45
46     typedef std::set<std::unique_ptr<Result>> ResultSet;
47
48     virtual ~TypeScavenger() = default;
49
50     size_t Find(ExecutionContextScope *exe_scope, const char *key,
51                 ResultSet &results, bool append = true);
52
53   protected:
54     TypeScavenger() = default;
55
56     virtual bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
57                            ResultSet &results) = 0;
58   };
59
60   class ImageListTypeScavenger : public TypeScavenger {
61     class Result : public Language::TypeScavenger::Result {
62     public:
63       Result(CompilerType type)
64           : Language::TypeScavenger::Result(), m_compiler_type(type) {}
65
66       bool IsValid() override { return m_compiler_type.IsValid(); }
67
68       bool DumpToStream(Stream &stream, bool print_help_if_available) override {
69         if (IsValid()) {
70           m_compiler_type.DumpTypeDescription(&stream);
71           stream.EOL();
72           return true;
73         }
74         return false;
75       }
76
77       ~Result() override = default;
78
79     private:
80       CompilerType m_compiler_type;
81     };
82
83   protected:
84     ImageListTypeScavenger() = default;
85
86     ~ImageListTypeScavenger() override = default;
87
88     // is this type something we should accept? it's usually going to be a
89     // filter by language + maybe some sugar tweaking
90     // returning an empty type means rejecting this candidate entirely;
91     // any other result will be accepted as a valid match
92     virtual CompilerType AdjustForInclusion(CompilerType &candidate) = 0;
93
94     bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
95                    ResultSet &results) override;
96   };
97
98   template <typename... ScavengerTypes>
99   class EitherTypeScavenger : public TypeScavenger {
100   public:
101     EitherTypeScavenger() : TypeScavenger(), m_scavengers() {
102       for (std::shared_ptr<TypeScavenger> scavenger : { std::shared_ptr<TypeScavenger>(new ScavengerTypes())... }) {
103         if (scavenger)
104           m_scavengers.push_back(scavenger);
105       }
106     }
107   protected:
108     bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
109                    ResultSet &results) override {
110       const bool append = false;
111       for (auto& scavenger : m_scavengers) {
112         if (scavenger && scavenger->Find(exe_scope, key, results, append))
113           return true;
114       }
115       return false;
116     }
117   private:
118     std::vector<std::shared_ptr<TypeScavenger>> m_scavengers;
119   };
120
121   template <typename... ScavengerTypes>
122   class UnionTypeScavenger : public TypeScavenger {
123   public:
124     UnionTypeScavenger() : TypeScavenger(), m_scavengers() {
125       for (std::shared_ptr<TypeScavenger> scavenger : { std::shared_ptr<TypeScavenger>(new ScavengerTypes())... }) {
126         if (scavenger)
127           m_scavengers.push_back(scavenger);
128       }
129     }
130   protected:
131     bool Find_Impl(ExecutionContextScope *exe_scope, const char *key,
132                    ResultSet &results) override {
133       const bool append = true;
134       bool success = false;
135       for (auto& scavenger : m_scavengers) {
136         if (scavenger)
137           success = scavenger->Find(exe_scope, key, results, append) || success;
138       }
139       return success;
140     }
141   private:
142     std::vector<std::shared_ptr<TypeScavenger>> m_scavengers;
143   };
144
145   enum class FunctionNameRepresentation {
146     eName,
147     eNameWithArgs,
148     eNameWithNoArgs
149   };
150
151   ~Language() override;
152
153   static Language *FindPlugin(lldb::LanguageType language);
154
155   // return false from callback to stop iterating
156   static void ForEach(std::function<bool(Language *)> callback);
157
158   virtual lldb::LanguageType GetLanguageType() const = 0;
159
160   virtual bool IsTopLevelFunction(Function &function);
161
162   virtual lldb::TypeCategoryImplSP GetFormatters();
163
164   virtual HardcodedFormatters::HardcodedFormatFinder GetHardcodedFormats();
165
166   virtual HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries();
167
168   virtual HardcodedFormatters::HardcodedSyntheticFinder
169   GetHardcodedSynthetics();
170
171   virtual HardcodedFormatters::HardcodedValidatorFinder
172   GetHardcodedValidators();
173
174   virtual std::vector<ConstString>
175   GetPossibleFormattersMatches(ValueObject &valobj,
176                                lldb::DynamicValueType use_dynamic);
177
178   virtual lldb_private::formatters::StringPrinter::EscapingHelper
179       GetStringPrinterEscapingHelper(
180           lldb_private::formatters::StringPrinter::GetPrintableElementType);
181
182   virtual std::unique_ptr<TypeScavenger> GetTypeScavenger();
183
184   virtual const char *GetLanguageSpecificTypeLookupHelp();
185
186   // if an individual data formatter can apply to several types and cross a
187   // language boundary
188   // it makes sense for individual languages to want to customize the printing
189   // of values of that
190   // type by appending proper prefix/suffix information in language-specific
191   // ways
192   virtual bool GetFormatterPrefixSuffix(ValueObject &valobj,
193                                         ConstString type_hint,
194                                         std::string &prefix,
195                                         std::string &suffix);
196
197   // if a language has a custom format for printing variable declarations that
198   // it wants LLDB to honor
199   // it should return an appropriate closure here
200   virtual DumpValueObjectOptions::DeclPrintingHelper GetDeclPrintingHelper();
201
202   virtual LazyBool IsLogicalTrue(ValueObject &valobj, Status &error);
203
204   // for a ValueObject of some "reference type", if the value points to the
205   // nil/null object, this method returns true
206   virtual bool IsNilReference(ValueObject &valobj);
207
208   // for a ValueObject of some "reference type", if the language provides a
209   // technique
210   // to decide whether the reference has ever been assigned to some object, this
211   // method
212   // will return true if such detection is possible, and if the reference has
213   // never been assigned
214   virtual bool IsUninitializedReference(ValueObject &valobj);
215
216   virtual bool GetFunctionDisplayName(const SymbolContext *sc,
217                                       const ExecutionContext *exe_ctx,
218                                       FunctionNameRepresentation representation,
219                                       Stream &s);
220
221   virtual void GetExceptionResolverDescription(bool catch_on, bool throw_on,
222                                                Stream &s);
223
224   static void GetDefaultExceptionResolverDescription(bool catch_on,
225                                                      bool throw_on, Stream &s);
226
227   // These are accessors for general information about the Languages lldb knows
228   // about:
229
230   static lldb::LanguageType
231   GetLanguageTypeFromString(const char *string) = delete;
232   static lldb::LanguageType GetLanguageTypeFromString(llvm::StringRef string);
233
234   static const char *GetNameForLanguageType(lldb::LanguageType language);
235
236   static void PrintAllLanguages(Stream &s, const char *prefix,
237                                 const char *suffix);
238
239   // return false from callback to stop iterating
240   static void ForAllLanguages(std::function<bool(lldb::LanguageType)> callback);
241
242   static bool LanguageIsCPlusPlus(lldb::LanguageType language);
243
244   static bool LanguageIsObjC(lldb::LanguageType language);
245
246   static bool LanguageIsC(lldb::LanguageType language);
247
248   static bool LanguageIsPascal(lldb::LanguageType language);
249
250   // return the primary language, so if LanguageIsC(l), return eLanguageTypeC,
251   // etc.
252   static lldb::LanguageType GetPrimaryLanguage(lldb::LanguageType language);
253
254   static void GetLanguagesSupportingTypeSystems(
255       std::set<lldb::LanguageType> &languages,
256       std::set<lldb::LanguageType> &languages_for_expressions);
257
258   static void
259   GetLanguagesSupportingREPLs(std::set<lldb::LanguageType> &languages);
260
261 protected:
262   //------------------------------------------------------------------
263   // Classes that inherit from Language can see and modify these
264   //------------------------------------------------------------------
265
266   Language();
267
268 private:
269   DISALLOW_COPY_AND_ASSIGN(Language);
270 };
271
272 } // namespace lldb_private
273
274 #endif // liblldb_Language_h_