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   enum class FunctionNameRepresentation {
61     eName,
62     eNameWithArgs,
63     eNameWithNoArgs
64   };
65 
66   ~Language() override;
67 
68   static Language *FindPlugin(lldb::LanguageType language);
69 
70   // return false from callback to stop iterating
71   static void ForEach(std::function<bool(Language *)> callback);
72 
73   virtual lldb::LanguageType GetLanguageType() const = 0;
74 
75   virtual bool IsTopLevelFunction(Function &function);
76 
77   virtual lldb::TypeCategoryImplSP GetFormatters();
78 
79   virtual HardcodedFormatters::HardcodedFormatFinder GetHardcodedFormats();
80 
81   virtual HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries();
82 
83   virtual HardcodedFormatters::HardcodedSyntheticFinder
84   GetHardcodedSynthetics();
85 
86   virtual HardcodedFormatters::HardcodedValidatorFinder
87   GetHardcodedValidators();
88 
89   virtual std::vector<ConstString>
90   GetPossibleFormattersMatches(ValueObject &valobj,
91                                lldb::DynamicValueType use_dynamic);
92 
93   virtual lldb_private::formatters::StringPrinter::EscapingHelper
94       GetStringPrinterEscapingHelper(
95           lldb_private::formatters::StringPrinter::GetPrintableElementType);
96 
97   virtual std::unique_ptr<TypeScavenger> GetTypeScavenger();
98 
99   virtual const char *GetLanguageSpecificTypeLookupHelp();
100 
101   // if an individual data formatter can apply to several types and cross a
102   // language boundary
103   // it makes sense for individual languages to want to customize the printing
104   // of values of that
105   // type by appending proper prefix/suffix information in language-specific
106   // ways
107   virtual bool GetFormatterPrefixSuffix(ValueObject &valobj,
108                                         ConstString type_hint,
109                                         std::string &prefix,
110                                         std::string &suffix);
111 
112   // if a language has a custom format for printing variable declarations that
113   // it wants LLDB to honor
114   // it should return an appropriate closure here
115   virtual DumpValueObjectOptions::DeclPrintingHelper GetDeclPrintingHelper();
116 
117   virtual LazyBool IsLogicalTrue(ValueObject &valobj, Error &error);
118 
119   // for a ValueObject of some "reference type", if the value points to the
120   // nil/null object, this method returns true
121   virtual bool IsNilReference(ValueObject &valobj);
122 
123   // for a ValueObject of some "reference type", if the language provides a
124   // technique
125   // to decide whether the reference has ever been assigned to some object, this
126   // method
127   // will return true if such detection is possible, and if the reference has
128   // never been assigned
129   virtual bool IsUninitializedReference(ValueObject &valobj);
130 
131   virtual bool GetFunctionDisplayName(const SymbolContext *sc,
132                                       const ExecutionContext *exe_ctx,
133                                       FunctionNameRepresentation representation,
134                                       Stream &s);
135 
136   virtual void GetExceptionResolverDescription(bool catch_on, bool throw_on,
137                                                Stream &s);
138 
139   static void GetDefaultExceptionResolverDescription(bool catch_on,
140                                                      bool throw_on, Stream &s);
141 
142   // These are accessors for general information about the Languages lldb knows
143   // about:
144 
145   static lldb::LanguageType
146   GetLanguageTypeFromString(const char *string) = delete;
147   static lldb::LanguageType GetLanguageTypeFromString(llvm::StringRef string);
148 
149   static const char *GetNameForLanguageType(lldb::LanguageType language);
150 
151   static void PrintAllLanguages(Stream &s, const char *prefix,
152                                 const char *suffix);
153 
154   // return false from callback to stop iterating
155   static void ForAllLanguages(std::function<bool(lldb::LanguageType)> callback);
156 
157   static bool LanguageIsCPlusPlus(lldb::LanguageType language);
158 
159   static bool LanguageIsObjC(lldb::LanguageType language);
160 
161   static bool LanguageIsC(lldb::LanguageType language);
162 
163   static bool LanguageIsPascal(lldb::LanguageType language);
164 
165   // return the primary language, so if LanguageIsC(l), return eLanguageTypeC,
166   // etc.
167   static lldb::LanguageType GetPrimaryLanguage(lldb::LanguageType language);
168 
169   static void GetLanguagesSupportingTypeSystems(
170       std::set<lldb::LanguageType> &languages,
171       std::set<lldb::LanguageType> &languages_for_expressions);
172 
173   static void
174   GetLanguagesSupportingREPLs(std::set<lldb::LanguageType> &languages);
175 
176 protected:
177   //------------------------------------------------------------------
178   // Classes that inherit from Language can see and modify these
179   //------------------------------------------------------------------
180 
181   Language();
182 
183 private:
184   DISALLOW_COPY_AND_ASSIGN(Language);
185 };
186 
187 } // namespace lldb_private
188 
189 #endif // liblldb_Language_h_
190