1 //===-- Language.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_Language_h_
11 #define liblldb_Language_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <functional>
16 #include <memory>
17 #include <set>
18 #include <vector>
19 
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/lldb-public.h"
23 #include "lldb/lldb-private.h"
24 #include "lldb/Core/PluginInterface.h"
25 #include "lldb/DataFormatters/DumpValueObjectOptions.h"
26 #include "lldb/DataFormatters/FormatClasses.h"
27 #include "lldb/DataFormatters/StringPrinter.h"
28 
29 namespace lldb_private {
30 
31 class Language :
32 public PluginInterface
33 {
34 public:
35     class TypeScavenger
36     {
37     public:
38         class Result
39         {
40         public:
41             virtual bool
42             IsValid () = 0;
43 
44             virtual bool
45             DumpToStream (Stream& stream,
46                           bool print_help_if_available) = 0;
47 
48             virtual ~Result() = default;
49         };
50 
51         typedef std::set<std::unique_ptr<Result>> ResultSet;
52 
53         virtual ~TypeScavenger () = default;
54 
55         size_t
56         Find (ExecutionContextScope *exe_scope,
57               const char *key,
58               ResultSet &results,
59               bool append = true);
60 
61     protected:
62         TypeScavenger () = default;
63 
64         virtual bool
65         Find_Impl (ExecutionContextScope *exe_scope,
66                    const char *key,
67                    ResultSet &results) = 0;
68     };
69 
70     enum class FunctionNameRepresentation
71     {
72         eName,
73         eNameWithArgs,
74         eNameWithNoArgs
75     };
76 
77     ~Language() override;
78 
79     static Language*
80     FindPlugin (lldb::LanguageType language);
81 
82     // return false from callback to stop iterating
83     static void
84     ForEach (std::function<bool(Language*)> callback);
85 
86     virtual lldb::LanguageType
87     GetLanguageType () const = 0;
88 
89     virtual bool
90     IsTopLevelFunction (Function& function);
91 
92     virtual lldb::TypeCategoryImplSP
93     GetFormatters ();
94 
95     virtual HardcodedFormatters::HardcodedFormatFinder
96     GetHardcodedFormats ();
97 
98     virtual HardcodedFormatters::HardcodedSummaryFinder
99     GetHardcodedSummaries ();
100 
101     virtual HardcodedFormatters::HardcodedSyntheticFinder
102     GetHardcodedSynthetics ();
103 
104     virtual HardcodedFormatters::HardcodedValidatorFinder
105     GetHardcodedValidators ();
106 
107     virtual std::vector<ConstString>
108     GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic);
109 
110     virtual lldb_private::formatters::StringPrinter::EscapingHelper
111     GetStringPrinterEscapingHelper (lldb_private::formatters::StringPrinter::GetPrintableElementType);
112 
113     virtual std::unique_ptr<TypeScavenger>
114     GetTypeScavenger ();
115 
116     // if an individual data formatter can apply to several types and cross a language boundary
117     // it makes sense for individual languages to want to customize the printing of values of that
118     // type by appending proper prefix/suffix information in language-specific ways
119     virtual bool
120     GetFormatterPrefixSuffix (ValueObject& valobj, ConstString type_hint,
121                               std::string& prefix, std::string& suffix);
122 
123     // if a language has a custom format for printing variable declarations that it wants LLDB to honor
124     // it should return an appropriate closure here
125     virtual DumpValueObjectOptions::DeclPrintingHelper
126     GetDeclPrintingHelper ();
127 
128     virtual LazyBool
129     IsLogicalTrue (ValueObject& valobj,
130                    Error& error);
131 
132     // for a ValueObject of some "reference type", if the value points to the
133     // nil/null object, this method returns true
134     virtual bool
135     IsNilReference (ValueObject& valobj);
136 
137     // for a ValueObject of some "reference type", if the language provides a technique
138     // to decide whether the reference has ever been assigned to some object, this method
139     // will return true if such detection is possible, and if the reference has never been assigned
140     virtual bool
141     IsUninitializedReference (ValueObject& valobj);
142 
143     virtual bool
144     GetFunctionDisplayName (const SymbolContext *sc,
145                             const ExecutionContext *exe_ctx,
146                             FunctionNameRepresentation representation,
147                             Stream& s);
148 
149     virtual void
150     GetExceptionResolverDescription(bool catch_on, bool throw_on, Stream &s);
151 
152     static void
153     GetDefaultExceptionResolverDescription(bool catch_on, bool throw_on, Stream &s);
154 
155     // These are accessors for general information about the Languages lldb knows about:
156 
157     static lldb::LanguageType
158     GetLanguageTypeFromString (const char *string);
159 
160     static const char *
161     GetNameForLanguageType (lldb::LanguageType language);
162 
163     static void
164     PrintAllLanguages (Stream &s, const char *prefix, const char *suffix);
165 
166     // return false from callback to stop iterating
167     static void
168     ForAllLanguages (std::function<bool(lldb::LanguageType)> callback);
169 
170     static bool
171     LanguageIsCPlusPlus (lldb::LanguageType language);
172 
173     static bool
174     LanguageIsObjC (lldb::LanguageType language);
175 
176     static bool
177     LanguageIsC (lldb::LanguageType language);
178 
179     static bool
180     LanguageIsPascal (lldb::LanguageType language);
181 
182     // return the primary language, so if LanguageIsC(l), return eLanguageTypeC, etc.
183     static lldb::LanguageType
184     GetPrimaryLanguage (lldb::LanguageType language);
185 
186     static void
187     GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
188                                        std::set<lldb::LanguageType> &languages_for_expressions);
189 
190     static void
191     GetLanguagesSupportingREPLs (std::set<lldb::LanguageType> &languages);
192 
193 protected:
194     //------------------------------------------------------------------
195     // Classes that inherit from Language can see and modify these
196     //------------------------------------------------------------------
197 
198     Language();
199 private:
200 
201     DISALLOW_COPY_AND_ASSIGN (Language);
202 };
203 
204 } // namespace lldb_private
205 
206 #endif // liblldb_Language_h_
207