TypeSystem.h revision 309124
1292932Sdim//===-- TypeSystem.h ------------------------------------------*- C++ -*-===//
2292932Sdim//
3292932Sdim//                     The LLVM Compiler Infrastructure
4292932Sdim//
5292932Sdim// This file is distributed under the University of Illinois Open Source
6292932Sdim// License. See LICENSE.TXT for details.
7292932Sdim//
8292932Sdim//===----------------------------------------------------------------------===//
9292932Sdim
10292932Sdim#ifndef liblldb_TypeSystem_h_
11292932Sdim#define liblldb_TypeSystem_h_
12292932Sdim
13292932Sdim// C Includes
14292932Sdim// C++ Includes
15292932Sdim#include <functional>
16292932Sdim#include <map>
17309124Sdim#include <mutex>
18292932Sdim#include <string>
19292932Sdim
20292932Sdim// Other libraries and framework includes
21292932Sdim#include "llvm/ADT/APSInt.h"
22292932Sdim#include "llvm/Support/Casting.h"
23292932Sdim
24292932Sdim// Project includes
25292932Sdim#include "lldb/lldb-private.h"
26292932Sdim#include "lldb/Core/PluginInterface.h"
27292932Sdim#include "lldb/Expression/Expression.h"
28292932Sdim#include "lldb/Symbol/CompilerDecl.h"
29292932Sdim#include "lldb/Symbol/CompilerDeclContext.h"
30292932Sdim
31292932Sdimclass DWARFDIE;
32292932Sdimclass DWARFASTParser;
33292932Sdim
34292932Sdimnamespace lldb_private {
35292932Sdim
36292932Sdim//----------------------------------------------------------------------
37292932Sdim// Interface for representing the Type Systems in different languages.
38292932Sdim//----------------------------------------------------------------------
39292932Sdimclass TypeSystem : public PluginInterface
40292932Sdim{
41292932Sdimpublic:
42292932Sdim    //----------------------------------------------------------------------
43292932Sdim    // Intrusive type system that allows us to use llvm casting.
44292932Sdim    //
45292932Sdim    // To add a new type system:
46292932Sdim    //
47292932Sdim    // 1 - Add a new enumeration for llvm casting below for your TypeSystem
48292932Sdim    //     subclass, here we will use eKindFoo
49292932Sdim    //
50292932Sdim    // 2 - Your TypeSystem subclass will inherit from TypeSystem and needs
51292932Sdim    //     to implement a static classof() function that returns your
52292932Sdim    //     enumeration:
53292932Sdim    //
54292932Sdim    //    class Foo : public lldb_private::TypeSystem
55292932Sdim    //    {
56292932Sdim    //        static bool classof(const TypeSystem *ts)
57292932Sdim    //        {
58292932Sdim    //            return ts->getKind() == TypeSystem::eKindFoo;
59292932Sdim    //        }
60292932Sdim    //    };
61292932Sdim    //
62292932Sdim    // 3 - Contruct your TypeSystem subclass with the enumeration from below
63292932Sdim    //
64292932Sdim    //    Foo() :
65292932Sdim    //        TypeSystem(TypeSystem::eKindFoo),
66292932Sdim    //        ...
67292932Sdim    //    {
68292932Sdim    //    }
69292932Sdim    //
70292932Sdim    // Then you can use the llvm casting on any "TypeSystem *" to get an
71292932Sdim    // instance of your subclass.
72292932Sdim    //----------------------------------------------------------------------
73292932Sdim    enum LLVMCastKind {
74292932Sdim        eKindClang,
75292932Sdim        eKindSwift,
76292932Sdim        eKindGo,
77309124Sdim        eKindJava,
78292932Sdim        kNumKinds
79292932Sdim    };
80292932Sdim
81292932Sdim    //----------------------------------------------------------------------
82292932Sdim    // Constructors and Destructors
83292932Sdim    //----------------------------------------------------------------------
84292932Sdim    TypeSystem(LLVMCastKind kind);
85292932Sdim
86292932Sdim    ~TypeSystem() override;
87292932Sdim
88292932Sdim    LLVMCastKind getKind() const { return m_kind; }
89292932Sdim
90292932Sdim    static lldb::TypeSystemSP
91292932Sdim    CreateInstance (lldb::LanguageType language, Module *module);
92292932Sdim
93292932Sdim    static lldb::TypeSystemSP
94292932Sdim    CreateInstance (lldb::LanguageType language, Target *target);
95292932Sdim
96309124Sdim
97309124Sdim    // Free up any resources associated with this TypeSystem.  Done before removing
98309124Sdim    // all the TypeSystems from the TypeSystemMap.
99309124Sdim    virtual void
100309124Sdim    Finalize() {}
101309124Sdim
102292932Sdim    virtual DWARFASTParser *
103309124Sdim    GetDWARFParser()
104292932Sdim    {
105292932Sdim        return nullptr;
106292932Sdim    }
107292932Sdim
108292932Sdim    virtual SymbolFile *
109292932Sdim    GetSymbolFile () const
110292932Sdim    {
111292932Sdim        return m_sym_file;
112292932Sdim    }
113292932Sdim
114292932Sdim    // Returns true if the symbol file changed during the set accessor.
115292932Sdim    virtual void
116292932Sdim    SetSymbolFile (SymbolFile *sym_file)
117292932Sdim    {
118292932Sdim        m_sym_file = sym_file;
119292932Sdim    }
120292932Sdim
121292932Sdim    //----------------------------------------------------------------------
122292932Sdim    // CompilerDecl functions
123292932Sdim    //----------------------------------------------------------------------
124292932Sdim    virtual ConstString
125292932Sdim    DeclGetName (void *opaque_decl) = 0;
126292932Sdim
127292932Sdim    virtual ConstString
128292932Sdim    DeclGetMangledName (void *opaque_decl);
129292932Sdim
130292932Sdim    virtual CompilerDeclContext
131292932Sdim    DeclGetDeclContext (void *opaque_decl);
132292932Sdim
133292932Sdim    virtual CompilerType
134292932Sdim    DeclGetFunctionReturnType(void *opaque_decl);
135292932Sdim
136292932Sdim    virtual size_t
137292932Sdim    DeclGetFunctionNumArguments(void *opaque_decl);
138292932Sdim
139292932Sdim    virtual CompilerType
140292932Sdim    DeclGetFunctionArgumentType (void *opaque_decl, size_t arg_idx);
141292932Sdim
142292932Sdim    //----------------------------------------------------------------------
143292932Sdim    // CompilerDeclContext functions
144292932Sdim    //----------------------------------------------------------------------
145292932Sdim
146292932Sdim    virtual std::vector<CompilerDecl>
147309124Sdim    DeclContextFindDeclByName (void *opaque_decl_ctx,
148309124Sdim                               ConstString name,
149309124Sdim                               const bool ignore_imported_decls);
150292932Sdim
151292932Sdim    virtual bool
152292932Sdim    DeclContextIsStructUnionOrClass (void *opaque_decl_ctx) = 0;
153292932Sdim
154292932Sdim    virtual ConstString
155292932Sdim    DeclContextGetName (void *opaque_decl_ctx) = 0;
156292932Sdim
157294024Sdim    virtual ConstString
158294024Sdim    DeclContextGetScopeQualifiedName (void *opaque_decl_ctx) = 0;
159294024Sdim
160292932Sdim    virtual bool
161292932Sdim    DeclContextIsClassMethod (void *opaque_decl_ctx,
162292932Sdim                              lldb::LanguageType *language_ptr,
163292932Sdim                              bool *is_instance_method_ptr,
164292932Sdim                              ConstString *language_object_name_ptr) = 0;
165292932Sdim
166292932Sdim    //----------------------------------------------------------------------
167292932Sdim    // Tests
168292932Sdim    //----------------------------------------------------------------------
169292932Sdim
170292932Sdim    virtual bool
171292932Sdim    IsArrayType (lldb::opaque_compiler_type_t type,
172292932Sdim                 CompilerType *element_type,
173292932Sdim                 uint64_t *size,
174292932Sdim                 bool *is_incomplete) = 0;
175292932Sdim
176292932Sdim    virtual bool
177292932Sdim    IsAggregateType (lldb::opaque_compiler_type_t type) = 0;
178292932Sdim
179292932Sdim    virtual bool
180292932Sdim    IsAnonymousType (lldb::opaque_compiler_type_t type);
181292932Sdim
182292932Sdim    virtual bool
183292932Sdim    IsCharType (lldb::opaque_compiler_type_t type) = 0;
184292932Sdim
185292932Sdim    virtual bool
186292932Sdim    IsCompleteType (lldb::opaque_compiler_type_t type) = 0;
187292932Sdim
188292932Sdim    virtual bool
189292932Sdim    IsDefined(lldb::opaque_compiler_type_t type) = 0;
190292932Sdim
191292932Sdim    virtual bool
192292932Sdim    IsFloatingPointType (lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) = 0;
193292932Sdim
194292932Sdim    virtual bool
195292932Sdim    IsFunctionType (lldb::opaque_compiler_type_t type, bool *is_variadic_ptr) = 0;
196292932Sdim
197292932Sdim    virtual size_t
198292932Sdim    GetNumberOfFunctionArguments (lldb::opaque_compiler_type_t type) = 0;
199292932Sdim
200292932Sdim    virtual CompilerType
201292932Sdim    GetFunctionArgumentAtIndex (lldb::opaque_compiler_type_t type, const size_t index) = 0;
202292932Sdim
203292932Sdim    virtual bool
204292932Sdim    IsFunctionPointerType (lldb::opaque_compiler_type_t type) = 0;
205292932Sdim
206292932Sdim    virtual bool
207309124Sdim    IsBlockPointerType (lldb::opaque_compiler_type_t type, CompilerType *function_pointer_type_ptr) = 0;
208292932Sdim
209292932Sdim    virtual bool
210309124Sdim    IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed) = 0;
211309124Sdim
212309124Sdim    virtual bool
213309124Sdim    IsEnumerationType (lldb::opaque_compiler_type_t type, bool &is_signed)
214309124Sdim    {
215309124Sdim        is_signed = false;
216309124Sdim        return false;
217309124Sdim    }
218309124Sdim
219309124Sdim    virtual bool
220292932Sdim    IsPossibleDynamicType (lldb::opaque_compiler_type_t type,
221292932Sdim                           CompilerType *target_type, // Can pass NULL
222292932Sdim                           bool check_cplusplus,
223292932Sdim                           bool check_objc) = 0;
224292932Sdim
225292932Sdim    virtual bool
226292932Sdim    IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) = 0;
227292932Sdim
228292932Sdim    virtual bool
229292932Sdim    IsScalarType (lldb::opaque_compiler_type_t type) = 0;
230292932Sdim
231292932Sdim    virtual bool
232292932Sdim    IsVoidType (lldb::opaque_compiler_type_t type) = 0;
233292932Sdim
234292932Sdim    // TypeSystems can support more than one language
235292932Sdim    virtual bool
236292932Sdim    SupportsLanguage (lldb::LanguageType language) = 0;
237292932Sdim
238292932Sdim    //----------------------------------------------------------------------
239292932Sdim    // Type Completion
240292932Sdim    //----------------------------------------------------------------------
241292932Sdim
242292932Sdim    virtual bool
243292932Sdim    GetCompleteType (lldb::opaque_compiler_type_t type) = 0;
244292932Sdim
245292932Sdim    //----------------------------------------------------------------------
246292932Sdim    // AST related queries
247292932Sdim    //----------------------------------------------------------------------
248292932Sdim
249292932Sdim    virtual uint32_t
250292932Sdim    GetPointerByteSize () = 0;
251292932Sdim
252292932Sdim    //----------------------------------------------------------------------
253292932Sdim    // Accessors
254292932Sdim    //----------------------------------------------------------------------
255292932Sdim
256292932Sdim    virtual ConstString
257292932Sdim    GetTypeName (lldb::opaque_compiler_type_t type) = 0;
258292932Sdim
259292932Sdim    virtual uint32_t
260292932Sdim    GetTypeInfo (lldb::opaque_compiler_type_t type, CompilerType *pointee_or_element_compiler_type) = 0;
261292932Sdim
262292932Sdim    virtual lldb::LanguageType
263292932Sdim    GetMinimumLanguage (lldb::opaque_compiler_type_t type) = 0;
264292932Sdim
265292932Sdim    virtual lldb::TypeClass
266292932Sdim    GetTypeClass (lldb::opaque_compiler_type_t type) = 0;
267292932Sdim
268292932Sdim    //----------------------------------------------------------------------
269292932Sdim    // Creating related types
270292932Sdim    //----------------------------------------------------------------------
271292932Sdim
272292932Sdim    virtual CompilerType
273292932Sdim    GetArrayElementType (lldb::opaque_compiler_type_t type, uint64_t *stride) = 0;
274292932Sdim
275292932Sdim    virtual CompilerType
276292932Sdim    GetCanonicalType (lldb::opaque_compiler_type_t type) = 0;
277292932Sdim
278292932Sdim    // Returns -1 if this isn't a function of if the function doesn't have a prototype
279292932Sdim    // Returns a value >= 0 if there is a prototype.
280292932Sdim    virtual int
281292932Sdim    GetFunctionArgumentCount (lldb::opaque_compiler_type_t type) = 0;
282292932Sdim
283292932Sdim    virtual CompilerType
284292932Sdim    GetFunctionArgumentTypeAtIndex (lldb::opaque_compiler_type_t type, size_t idx) = 0;
285292932Sdim
286292932Sdim    virtual CompilerType
287292932Sdim    GetFunctionReturnType (lldb::opaque_compiler_type_t type) = 0;
288292932Sdim
289292932Sdim    virtual size_t
290292932Sdim    GetNumMemberFunctions (lldb::opaque_compiler_type_t type) = 0;
291292932Sdim
292292932Sdim    virtual TypeMemberFunctionImpl
293292932Sdim    GetMemberFunctionAtIndex (lldb::opaque_compiler_type_t type, size_t idx) = 0;
294292932Sdim
295292932Sdim    virtual CompilerType
296292932Sdim    GetPointeeType (lldb::opaque_compiler_type_t type) = 0;
297292932Sdim
298292932Sdim    virtual CompilerType
299292932Sdim    GetPointerType (lldb::opaque_compiler_type_t type) = 0;
300292932Sdim
301292932Sdim    virtual CompilerType
302292932Sdim    GetLValueReferenceType (lldb::opaque_compiler_type_t type);
303292932Sdim
304292932Sdim    virtual CompilerType
305292932Sdim    GetRValueReferenceType (lldb::opaque_compiler_type_t type);
306292932Sdim
307292932Sdim    virtual CompilerType
308292932Sdim    AddConstModifier (lldb::opaque_compiler_type_t type);
309292932Sdim
310292932Sdim    virtual CompilerType
311292932Sdim    AddVolatileModifier (lldb::opaque_compiler_type_t type);
312292932Sdim
313292932Sdim    virtual CompilerType
314292932Sdim    AddRestrictModifier (lldb::opaque_compiler_type_t type);
315292932Sdim
316292932Sdim    virtual CompilerType
317292932Sdim    CreateTypedef (lldb::opaque_compiler_type_t type, const char *name, const CompilerDeclContext &decl_ctx);
318292932Sdim
319292932Sdim    //----------------------------------------------------------------------
320292932Sdim    // Exploring the type
321292932Sdim    //----------------------------------------------------------------------
322292932Sdim
323292932Sdim    virtual uint64_t
324292932Sdim    GetBitSize (lldb::opaque_compiler_type_t type, ExecutionContextScope *exe_scope) = 0;
325292932Sdim
326292932Sdim    virtual lldb::Encoding
327292932Sdim    GetEncoding (lldb::opaque_compiler_type_t type, uint64_t &count) = 0;
328292932Sdim
329292932Sdim    virtual lldb::Format
330292932Sdim    GetFormat (lldb::opaque_compiler_type_t type) = 0;
331292932Sdim
332292932Sdim    virtual uint32_t
333292932Sdim    GetNumChildren (lldb::opaque_compiler_type_t type, bool omit_empty_base_classes) = 0;
334292932Sdim
335292932Sdim    virtual CompilerType
336292932Sdim    GetBuiltinTypeByName (const ConstString &name);
337292932Sdim
338292932Sdim    virtual lldb::BasicType
339292932Sdim    GetBasicTypeEnumeration (lldb::opaque_compiler_type_t type) = 0;
340292932Sdim
341292932Sdim    virtual void
342292932Sdim    ForEachEnumerator (lldb::opaque_compiler_type_t type, std::function <bool (const CompilerType &integer_type, const ConstString &name, const llvm::APSInt &value)> const &callback)
343292932Sdim    {
344292932Sdim    }
345292932Sdim
346292932Sdim    virtual uint32_t
347292932Sdim    GetNumFields (lldb::opaque_compiler_type_t type) = 0;
348292932Sdim
349292932Sdim    virtual CompilerType
350292932Sdim    GetFieldAtIndex (lldb::opaque_compiler_type_t type,
351292932Sdim                     size_t idx,
352292932Sdim                     std::string& name,
353292932Sdim                     uint64_t *bit_offset_ptr,
354292932Sdim                     uint32_t *bitfield_bit_size_ptr,
355292932Sdim                     bool *is_bitfield_ptr) = 0;
356292932Sdim
357292932Sdim    virtual uint32_t
358292932Sdim    GetNumDirectBaseClasses (lldb::opaque_compiler_type_t type) = 0;
359292932Sdim
360292932Sdim    virtual uint32_t
361292932Sdim    GetNumVirtualBaseClasses (lldb::opaque_compiler_type_t type) = 0;
362292932Sdim
363292932Sdim    virtual CompilerType
364292932Sdim    GetDirectBaseClassAtIndex (lldb::opaque_compiler_type_t type,
365292932Sdim                               size_t idx,
366292932Sdim                               uint32_t *bit_offset_ptr) = 0;
367292932Sdim
368292932Sdim    virtual CompilerType
369292932Sdim    GetVirtualBaseClassAtIndex (lldb::opaque_compiler_type_t type,
370292932Sdim                                size_t idx,
371292932Sdim                                uint32_t *bit_offset_ptr) = 0;
372292932Sdim
373292932Sdim    virtual CompilerType
374292932Sdim    GetChildCompilerTypeAtIndex (lldb::opaque_compiler_type_t type,
375292932Sdim                                 ExecutionContext *exe_ctx,
376292932Sdim                                 size_t idx,
377292932Sdim                                 bool transparent_pointers,
378292932Sdim                                 bool omit_empty_base_classes,
379292932Sdim                                 bool ignore_array_bounds,
380292932Sdim                                 std::string& child_name,
381292932Sdim                                 uint32_t &child_byte_size,
382292932Sdim                                 int32_t &child_byte_offset,
383292932Sdim                                 uint32_t &child_bitfield_bit_size,
384292932Sdim                                 uint32_t &child_bitfield_bit_offset,
385292932Sdim                                 bool &child_is_base_class,
386292932Sdim                                 bool &child_is_deref_of_parent,
387292932Sdim                                 ValueObject *valobj,
388292932Sdim                                 uint64_t &language_flags) = 0;
389292932Sdim
390292932Sdim    // Lookup a child given a name. This function will match base class names
391292932Sdim    // and member member names in "clang_type" only, not descendants.
392292932Sdim    virtual uint32_t
393292932Sdim    GetIndexOfChildWithName (lldb::opaque_compiler_type_t type,
394292932Sdim                             const char *name,
395292932Sdim                             bool omit_empty_base_classes) = 0;
396292932Sdim
397292932Sdim    // Lookup a child member given a name. This function will match member names
398292932Sdim    // only and will descend into "clang_type" children in search for the first
399292932Sdim    // member in this class, or any base class that matches "name".
400292932Sdim    // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
401292932Sdim    // so we catch all names that match a given child name, not just the first.
402292932Sdim    virtual size_t
403292932Sdim    GetIndexOfChildMemberWithName (lldb::opaque_compiler_type_t type,
404292932Sdim                                   const char *name,
405292932Sdim                                   bool omit_empty_base_classes,
406292932Sdim                                   std::vector<uint32_t>& child_indexes) = 0;
407292932Sdim
408292932Sdim    virtual size_t
409292932Sdim    GetNumTemplateArguments (lldb::opaque_compiler_type_t type) = 0;
410292932Sdim
411292932Sdim    virtual CompilerType
412292932Sdim    GetTemplateArgument (lldb::opaque_compiler_type_t type,
413292932Sdim                         size_t idx,
414292932Sdim                         lldb::TemplateArgumentKind &kind) = 0;
415292932Sdim
416292932Sdim    //----------------------------------------------------------------------
417292932Sdim    // Dumping types
418292932Sdim    //----------------------------------------------------------------------
419292932Sdim
420292932Sdim    virtual void
421292932Sdim    DumpValue (lldb::opaque_compiler_type_t type,
422292932Sdim               ExecutionContext *exe_ctx,
423292932Sdim               Stream *s,
424292932Sdim               lldb::Format format,
425292932Sdim               const DataExtractor &data,
426292932Sdim               lldb::offset_t data_offset,
427292932Sdim               size_t data_byte_size,
428292932Sdim               uint32_t bitfield_bit_size,
429292932Sdim               uint32_t bitfield_bit_offset,
430292932Sdim               bool show_types,
431292932Sdim               bool show_summary,
432292932Sdim               bool verbose,
433292932Sdim               uint32_t depth) = 0;
434292932Sdim
435292932Sdim    virtual bool
436292932Sdim    DumpTypeValue (lldb::opaque_compiler_type_t type,
437292932Sdim                   Stream *s,
438292932Sdim                   lldb::Format format,
439292932Sdim                   const DataExtractor &data,
440292932Sdim                   lldb::offset_t data_offset,
441292932Sdim                   size_t data_byte_size,
442292932Sdim                   uint32_t bitfield_bit_size,
443292932Sdim                   uint32_t bitfield_bit_offset,
444292932Sdim                   ExecutionContextScope *exe_scope) = 0;
445292932Sdim
446292932Sdim    virtual void
447292932Sdim    DumpTypeDescription (lldb::opaque_compiler_type_t type) = 0; // Dump to stdout
448292932Sdim
449292932Sdim    virtual void
450292932Sdim    DumpTypeDescription (lldb::opaque_compiler_type_t type, Stream *s) = 0;
451292932Sdim
452292932Sdim    //----------------------------------------------------------------------
453292932Sdim    // TODO: These methods appear unused. Should they be removed?
454292932Sdim    //----------------------------------------------------------------------
455292932Sdim
456292932Sdim    virtual bool
457292932Sdim    IsRuntimeGeneratedType (lldb::opaque_compiler_type_t type) = 0;
458292932Sdim
459292932Sdim    virtual void
460292932Sdim    DumpSummary (lldb::opaque_compiler_type_t type,
461292932Sdim                 ExecutionContext *exe_ctx,
462292932Sdim                 Stream *s,
463292932Sdim                 const DataExtractor &data,
464292932Sdim                 lldb::offset_t data_offset,
465292932Sdim                 size_t data_byte_size) = 0;
466292932Sdim
467292932Sdim    // Converts "s" to a floating point value and place resulting floating
468292932Sdim    // point bytes in the "dst" buffer.
469292932Sdim    virtual size_t
470292932Sdim    ConvertStringToFloatValue (lldb::opaque_compiler_type_t type,
471292932Sdim                               const char *s,
472292932Sdim                               uint8_t *dst,
473292932Sdim                               size_t dst_size) = 0;
474292932Sdim
475292932Sdim    //----------------------------------------------------------------------
476292932Sdim    // TODO: Determine if these methods should move to ClangASTContext.
477292932Sdim    //----------------------------------------------------------------------
478292932Sdim
479292932Sdim    virtual bool
480292932Sdim    IsPointerOrReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) = 0;
481292932Sdim
482292932Sdim    virtual unsigned
483292932Sdim    GetTypeQualifiers(lldb::opaque_compiler_type_t type) = 0;
484292932Sdim
485292932Sdim    virtual bool
486292932Sdim    IsCStringType (lldb::opaque_compiler_type_t type, uint32_t &length) = 0;
487292932Sdim
488292932Sdim    virtual size_t
489292932Sdim    GetTypeBitAlign (lldb::opaque_compiler_type_t type) = 0;
490292932Sdim
491292932Sdim    virtual CompilerType
492292932Sdim    GetBasicTypeFromAST (lldb::BasicType basic_type) = 0;
493292932Sdim
494292932Sdim    virtual CompilerType
495292932Sdim    GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
496292932Sdim                                        size_t bit_size) = 0;
497292932Sdim
498292932Sdim    virtual bool
499292932Sdim    IsBeingDefined (lldb::opaque_compiler_type_t type) = 0;
500292932Sdim
501292932Sdim    virtual bool
502292932Sdim    IsConst(lldb::opaque_compiler_type_t type) = 0;
503292932Sdim
504292932Sdim    virtual uint32_t
505292932Sdim    IsHomogeneousAggregate (lldb::opaque_compiler_type_t type, CompilerType* base_type_ptr) = 0;
506292932Sdim
507292932Sdim    virtual bool
508292932Sdim    IsPolymorphicClass (lldb::opaque_compiler_type_t type) = 0;
509292932Sdim
510292932Sdim    virtual bool
511292932Sdim    IsTypedefType (lldb::opaque_compiler_type_t type) = 0;
512292932Sdim
513292932Sdim    // If the current object represents a typedef type, get the underlying type
514292932Sdim    virtual CompilerType
515292932Sdim    GetTypedefedType (lldb::opaque_compiler_type_t type) = 0;
516292932Sdim
517292932Sdim    virtual bool
518292932Sdim    IsVectorType (lldb::opaque_compiler_type_t type,
519292932Sdim                  CompilerType *element_type,
520292932Sdim                  uint64_t *size) = 0;
521292932Sdim
522292932Sdim    virtual CompilerType
523292932Sdim    GetFullyUnqualifiedType (lldb::opaque_compiler_type_t type) = 0;
524292932Sdim
525292932Sdim    virtual CompilerType
526292932Sdim    GetNonReferenceType (lldb::opaque_compiler_type_t type) = 0;
527292932Sdim
528292932Sdim    virtual bool
529292932Sdim    IsReferenceType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool* is_rvalue) = 0;
530292932Sdim
531292932Sdim    virtual bool
532292932Sdim    ShouldTreatScalarValueAsAddress (lldb::opaque_compiler_type_t type)
533292932Sdim    {
534292932Sdim        return IsPointerOrReferenceType(type, nullptr);
535292932Sdim    }
536292932Sdim
537292932Sdim    virtual UserExpression *
538292932Sdim    GetUserExpression (const char *expr,
539292932Sdim                       const char *expr_prefix,
540292932Sdim                       lldb::LanguageType language,
541292932Sdim                       Expression::ResultType desired_type,
542292932Sdim                       const EvaluateExpressionOptions &options)
543292932Sdim    {
544292932Sdim        return nullptr;
545292932Sdim    }
546292932Sdim
547292932Sdim    virtual FunctionCaller *
548292932Sdim    GetFunctionCaller (const CompilerType &return_type,
549292932Sdim                       const Address& function_address,
550292932Sdim                       const ValueList &arg_value_list,
551292932Sdim                       const char *name)
552292932Sdim    {
553292932Sdim        return nullptr;
554292932Sdim    }
555292932Sdim
556292932Sdim    virtual UtilityFunction *
557292932Sdim    GetUtilityFunction(const char *text, const char *name)
558292932Sdim    {
559292932Sdim        return nullptr;
560292932Sdim    }
561292932Sdim
562292932Sdim    virtual PersistentExpressionState *
563292932Sdim    GetPersistentExpressionState()
564292932Sdim    {
565292932Sdim        return nullptr;
566292932Sdim    }
567292932Sdim
568292932Sdim    virtual CompilerType
569292932Sdim    GetTypeForFormatters (void* type);
570292932Sdim
571292932Sdim    virtual LazyBool
572292932Sdim    ShouldPrintAsOneLiner (void* type, ValueObject* valobj);
573292932Sdim
574292932Sdim    // Type systems can have types that are placeholder types, which are meant to indicate
575292932Sdim    // the presence of a type, but offer no actual information about said types, and leave
576292932Sdim    // the burden of actually figuring type information out to dynamic type resolution. For instance
577292932Sdim    // a language with a generics system, can use placeholder types to indicate "type argument goes here",
578292932Sdim    // without promising uniqueness of the placeholder, nor attaching any actually idenfiable information
579292932Sdim    // to said placeholder. This API allows type systems to tell LLDB when such a type has been encountered
580292932Sdim    // In response, the debugger can react by not using this type as a cache entry in any type-specific way
581292932Sdim    // For instance, LLDB will currently not cache any formatters that are discovered on such a type as
582292932Sdim    // attributable to the meaningless type itself, instead preferring to use the dynamic type
583292932Sdim    virtual bool
584292932Sdim    IsMeaninglessWithoutDynamicResolution (void* type);
585292932Sdim
586292932Sdimprotected:
587292932Sdim    const LLVMCastKind m_kind; // Support for llvm casting
588292932Sdim    SymbolFile *m_sym_file;
589292932Sdim
590292932Sdim};
591292932Sdim
592292932Sdim    class TypeSystemMap
593292932Sdim    {
594292932Sdim    public:
595292932Sdim        TypeSystemMap ();
596292932Sdim        ~TypeSystemMap();
597292932Sdim
598309124Sdim        // Clear calls Finalize on all the TypeSystems managed by this map, and then
599309124Sdim        // empties the map.
600292932Sdim        void
601292932Sdim        Clear ();
602292932Sdim
603292932Sdim        // Iterate through all of the type systems that are created. Return true
604292932Sdim        // from callback to keep iterating, false to stop iterating.
605292932Sdim        void
606292932Sdim        ForEach (std::function <bool(TypeSystem *)> const &callback);
607292932Sdim
608292932Sdim        TypeSystem *
609292932Sdim        GetTypeSystemForLanguage (lldb::LanguageType language, Module *module, bool can_create);
610292932Sdim
611292932Sdim        TypeSystem *
612292932Sdim        GetTypeSystemForLanguage (lldb::LanguageType language, Target *target, bool can_create);
613292932Sdim
614292932Sdim    protected:
615309124Sdim        // This function does not take the map mutex, and should only be called from
616309124Sdim        // functions that do take the mutex.
617309124Sdim        void
618309124Sdim        AddToMap (lldb::LanguageType language, lldb::TypeSystemSP const &type_system_sp);
619309124Sdim
620292932Sdim        typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> collection;
621309124Sdim        mutable std::mutex m_mutex; ///< A mutex to keep this object happy in multi-threaded environments.
622292932Sdim        collection m_map;
623309124Sdim        bool m_clear_in_progress;
624292932Sdim    };
625292932Sdim
626292932Sdim} // namespace lldb_private
627292932Sdim
628292932Sdim#endif // liblldb_TypeSystem_h_
629