]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/ClangASTContext.h
Merge clang trunk r300422 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / ClangASTContext.h
1 //===-- ClangASTContext.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_ClangASTContext_h_
11 #define liblldb_ClangASTContext_h_
12
13 // C Includes
14 #include <stdint.h>
15
16 // C++ Includes
17 #include <functional>
18 #include <initializer_list>
19 #include <map>
20 #include <memory>
21 #include <set>
22 #include <string>
23 #include <utility>
24 #include <vector>
25
26 // Other libraries and framework includes
27 #include "clang/AST/ASTContext.h"
28 #include "clang/AST/TemplateBase.h"
29 #include "llvm/ADT/SmallVector.h"
30
31 // Project includes
32 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
33 #include "lldb/Core/ClangForward.h"
34 #include "lldb/Core/ConstString.h"
35 #include "lldb/Symbol/CompilerType.h"
36 #include "lldb/Symbol/TypeSystem.h"
37 #include "lldb/lldb-enumerations.h"
38
39 class DWARFASTParserClang;
40 //class PDBASTParser;
41
42 namespace lldb_private {
43
44 class Declaration;
45
46 class ClangASTContext : public TypeSystem {
47 public:
48   typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *);
49   typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton,
50                                                     clang::ObjCInterfaceDecl *);
51
52   //------------------------------------------------------------------
53   // llvm casting support
54   //------------------------------------------------------------------
55   static bool classof(const TypeSystem *ts) {
56     return ts->getKind() == TypeSystem::eKindClang;
57   }
58
59   //------------------------------------------------------------------
60   // Constructors and Destructors
61   //------------------------------------------------------------------
62   ClangASTContext(const char *triple = nullptr);
63
64   ~ClangASTContext() override;
65
66   void Finalize() override;
67
68   //------------------------------------------------------------------
69   // PluginInterface functions
70   //------------------------------------------------------------------
71   ConstString GetPluginName() override;
72
73   uint32_t GetPluginVersion() override;
74
75   static ConstString GetPluginNameStatic();
76
77   static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
78                                            Module *module, Target *target);
79
80   static void EnumerateSupportedLanguages(
81       std::set<lldb::LanguageType> &languages_for_types,
82       std::set<lldb::LanguageType> &languages_for_expressions);
83
84   static void Initialize();
85
86   static void Terminate();
87
88   static ClangASTContext *GetASTContext(clang::ASTContext *ast_ctx);
89
90   clang::ASTContext *getASTContext();
91
92   void setASTContext(clang::ASTContext *ast_ctx);
93
94   clang::Builtin::Context *getBuiltinContext();
95
96   clang::IdentifierTable *getIdentifierTable();
97
98   clang::LangOptions *getLanguageOptions();
99
100   clang::SelectorTable *getSelectorTable();
101
102   clang::FileManager *getFileManager();
103
104   clang::SourceManager *getSourceManager();
105
106   clang::DiagnosticsEngine *getDiagnosticsEngine();
107
108   clang::DiagnosticConsumer *getDiagnosticConsumer();
109
110   clang::MangleContext *getMangleContext();
111
112   std::shared_ptr<clang::TargetOptions> &getTargetOptions();
113
114   clang::TargetInfo *getTargetInfo();
115
116   void Clear();
117
118   const char *GetTargetTriple();
119
120   void SetTargetTriple(const char *target_triple);
121
122   void SetArchitecture(const ArchSpec &arch);
123
124   bool HasExternalSource();
125
126   void SetExternalSource(
127       llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> &ast_source_ap);
128
129   void RemoveExternalSource();
130
131   bool GetCompleteDecl(clang::Decl *decl) {
132     return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
133   }
134
135   static void DumpDeclHiearchy(clang::Decl *decl);
136
137   static void DumpDeclContextHiearchy(clang::DeclContext *decl_ctx);
138
139   static bool DeclsAreEquivalent(clang::Decl *lhs_decl, clang::Decl *rhs_decl);
140
141   static bool GetCompleteDecl(clang::ASTContext *ast, clang::Decl *decl);
142
143   void SetMetadataAsUserID(const void *object, lldb::user_id_t user_id);
144
145   void SetMetadata(const void *object, ClangASTMetadata &meta_data) {
146     SetMetadata(getASTContext(), object, meta_data);
147   }
148
149   static void SetMetadata(clang::ASTContext *ast, const void *object,
150                           ClangASTMetadata &meta_data);
151
152   ClangASTMetadata *GetMetadata(const void *object) {
153     return GetMetadata(getASTContext(), object);
154   }
155
156   static ClangASTMetadata *GetMetadata(clang::ASTContext *ast,
157                                        const void *object);
158
159   //------------------------------------------------------------------
160   // Basic Types
161   //------------------------------------------------------------------
162   CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
163                                                    size_t bit_size) override;
164
165   static CompilerType GetBuiltinTypeForEncodingAndBitSize(
166       clang::ASTContext *ast, lldb::Encoding encoding, uint32_t bit_size);
167
168   CompilerType GetBasicType(lldb::BasicType type);
169
170   static CompilerType GetBasicType(clang::ASTContext *ast,
171                                    lldb::BasicType type);
172
173   static CompilerType GetBasicType(clang::ASTContext *ast,
174                                    const ConstString &name);
175
176   static lldb::BasicType GetBasicTypeEnumeration(const ConstString &name);
177
178   CompilerType GetBuiltinTypeForDWARFEncodingAndBitSize(const char *type_name,
179                                                         uint32_t dw_ate,
180                                                         uint32_t bit_size);
181
182   CompilerType GetCStringType(bool is_const);
183
184   static CompilerType GetUnknownAnyType(clang::ASTContext *ast);
185
186   CompilerType GetUnknownAnyType() {
187     return ClangASTContext::GetUnknownAnyType(getASTContext());
188   }
189
190   static clang::DeclContext *GetDeclContextForType(clang::QualType type);
191
192   static clang::DeclContext *GetDeclContextForType(const CompilerType &type);
193
194   uint32_t GetPointerByteSize() override;
195
196   static clang::DeclContext *GetTranslationUnitDecl(clang::ASTContext *ast);
197
198   clang::DeclContext *GetTranslationUnitDecl() {
199     return GetTranslationUnitDecl(getASTContext());
200   }
201
202   static clang::Decl *CopyDecl(clang::ASTContext *dest_context,
203                                clang::ASTContext *source_context,
204                                clang::Decl *source_decl);
205
206   static bool AreTypesSame(CompilerType type1, CompilerType type2,
207                            bool ignore_qualifiers = false);
208
209   static CompilerType GetTypeForDecl(clang::NamedDecl *decl);
210
211   static CompilerType GetTypeForDecl(clang::TagDecl *decl);
212
213   static CompilerType GetTypeForDecl(clang::ObjCInterfaceDecl *objc_decl);
214
215   template <typename RecordDeclType>
216   CompilerType GetTypeForIdentifier(const ConstString &type_name) {
217     CompilerType compiler_type;
218
219     if (type_name.GetLength()) {
220       clang::ASTContext *ast = getASTContext();
221       if (ast) {
222         clang::IdentifierInfo &myIdent =
223             ast->Idents.get(type_name.GetCString());
224         clang::DeclarationName myName =
225             ast->DeclarationNames.getIdentifier(&myIdent);
226
227         clang::DeclContext::lookup_result result =
228             ast->getTranslationUnitDecl()->lookup(myName);
229
230         if (!result.empty()) {
231           clang::NamedDecl *named_decl = result[0];
232           if (const RecordDeclType *record_decl =
233                   llvm::dyn_cast<RecordDeclType>(named_decl))
234             compiler_type.SetCompilerType(
235                 ast, clang::QualType(record_decl->getTypeForDecl(), 0));
236         }
237       }
238     }
239
240     return compiler_type;
241   }
242
243   CompilerType CreateStructForIdentifier(
244       const ConstString &type_name,
245       const std::initializer_list<std::pair<const char *, CompilerType>>
246           &type_fields,
247       bool packed = false);
248
249   CompilerType GetOrCreateStructForIdentifier(
250       const ConstString &type_name,
251       const std::initializer_list<std::pair<const char *, CompilerType>>
252           &type_fields,
253       bool packed = false);
254
255   //------------------------------------------------------------------
256   // Structure, Unions, Classes
257   //------------------------------------------------------------------
258
259   static clang::AccessSpecifier
260   ConvertAccessTypeToAccessSpecifier(lldb::AccessType access);
261
262   static clang::AccessSpecifier
263   UnifyAccessSpecifiers(clang::AccessSpecifier lhs, clang::AccessSpecifier rhs);
264
265   static uint32_t GetNumBaseClasses(const clang::CXXRecordDecl *cxx_record_decl,
266                                     bool omit_empty_base_classes);
267
268   CompilerType CreateRecordType(clang::DeclContext *decl_ctx,
269                                 lldb::AccessType access_type, const char *name,
270                                 int kind, lldb::LanguageType language,
271                                 ClangASTMetadata *metadata = nullptr);
272
273   class TemplateParameterInfos {
274   public:
275     bool IsValid() const {
276       if (args.empty())
277         return false;
278       return args.size() == names.size();
279     }
280
281     size_t GetSize() const {
282       if (IsValid())
283         return args.size();
284       return 0;
285     }
286
287     llvm::SmallVector<const char *, 2> names;
288     llvm::SmallVector<clang::TemplateArgument, 2> args;
289   };
290
291   clang::FunctionTemplateDecl *
292   CreateFunctionTemplateDecl(clang::DeclContext *decl_ctx,
293                              clang::FunctionDecl *func_decl, const char *name,
294                              const TemplateParameterInfos &infos);
295
296   void CreateFunctionTemplateSpecializationInfo(
297       clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template,
298       const TemplateParameterInfos &infos);
299
300   clang::ClassTemplateDecl *
301   CreateClassTemplateDecl(clang::DeclContext *decl_ctx,
302                           lldb::AccessType access_type, const char *class_name,
303                           int kind, const TemplateParameterInfos &infos);
304
305   clang::ClassTemplateSpecializationDecl *CreateClassTemplateSpecializationDecl(
306       clang::DeclContext *decl_ctx,
307       clang::ClassTemplateDecl *class_template_decl, int kind,
308       const TemplateParameterInfos &infos);
309
310   CompilerType
311   CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl *
312                                             class_template_specialization_decl);
313
314   static clang::DeclContext *
315   GetAsDeclContext(clang::CXXMethodDecl *cxx_method_decl);
316
317   static clang::DeclContext *
318   GetAsDeclContext(clang::ObjCMethodDecl *objc_method_decl);
319
320   static bool CheckOverloadedOperatorKindParameterCount(
321       bool is_method, clang::OverloadedOperatorKind op_kind,
322       uint32_t num_params);
323
324   bool FieldIsBitfield(clang::FieldDecl *field, uint32_t &bitfield_bit_size);
325
326   static bool FieldIsBitfield(clang::ASTContext *ast, clang::FieldDecl *field,
327                               uint32_t &bitfield_bit_size);
328
329   static bool RecordHasFields(const clang::RecordDecl *record_decl);
330
331   CompilerType CreateObjCClass(const char *name, clang::DeclContext *decl_ctx,
332                                bool isForwardDecl, bool isInternal,
333                                ClangASTMetadata *metadata = nullptr);
334
335   bool SetTagTypeKind(clang::QualType type, int kind) const;
336
337   bool SetDefaultAccessForRecordFields(clang::RecordDecl *record_decl,
338                                        int default_accessibility,
339                                        int *assigned_accessibilities,
340                                        size_t num_assigned_accessibilities);
341
342   // Returns a mask containing bits from the ClangASTContext::eTypeXXX
343   // enumerations
344
345   //------------------------------------------------------------------
346   // Namespace Declarations
347   //------------------------------------------------------------------
348
349   clang::NamespaceDecl *
350   GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx);
351
352   static clang::NamespaceDecl *
353   GetUniqueNamespaceDeclaration(clang::ASTContext *ast, const char *name,
354                                 clang::DeclContext *decl_ctx);
355
356   //------------------------------------------------------------------
357   // Function Types
358   //------------------------------------------------------------------
359
360   clang::FunctionDecl *
361   CreateFunctionDeclaration(clang::DeclContext *decl_ctx, const char *name,
362                             const CompilerType &function_Type, int storage,
363                             bool is_inline);
364
365   static CompilerType CreateFunctionType(clang::ASTContext *ast,
366                                          const CompilerType &result_type,
367                                          const CompilerType *args,
368                                          unsigned num_args, bool is_variadic,
369                                          unsigned type_quals);
370
371   CompilerType CreateFunctionType(const CompilerType &result_type,
372                                   const CompilerType *args, unsigned num_args,
373                                   bool is_variadic, unsigned type_quals) {
374     return ClangASTContext::CreateFunctionType(
375         getASTContext(), result_type, args, num_args, is_variadic, type_quals);
376   }
377
378   clang::ParmVarDecl *CreateParameterDeclaration(const char *name,
379                                                  const CompilerType &param_type,
380                                                  int storage);
381
382   void SetFunctionParameters(clang::FunctionDecl *function_decl,
383                              clang::ParmVarDecl **params, unsigned num_params);
384
385   CompilerType CreateBlockPointerType(const CompilerType &function_type);
386
387   //------------------------------------------------------------------
388   // Array Types
389   //------------------------------------------------------------------
390
391   CompilerType CreateArrayType(const CompilerType &element_type,
392                                size_t element_count, bool is_vector);
393
394   //------------------------------------------------------------------
395   // Enumeration Types
396   //------------------------------------------------------------------
397   CompilerType CreateEnumerationType(const char *name,
398                                      clang::DeclContext *decl_ctx,
399                                      const Declaration &decl,
400                                      const CompilerType &integer_qual_type);
401
402   //------------------------------------------------------------------
403   // Integer type functions
404   //------------------------------------------------------------------
405
406   static CompilerType GetIntTypeFromBitSize(clang::ASTContext *ast,
407                                             size_t bit_size, bool is_signed);
408
409   CompilerType GetPointerSizedIntType(bool is_signed) {
410     return GetPointerSizedIntType(getASTContext(), is_signed);
411   }
412
413   static CompilerType GetPointerSizedIntType(clang::ASTContext *ast,
414                                              bool is_signed);
415
416   //------------------------------------------------------------------
417   // Floating point functions
418   //------------------------------------------------------------------
419
420   static CompilerType GetFloatTypeFromBitSize(clang::ASTContext *ast,
421                                               size_t bit_size);
422
423   //------------------------------------------------------------------
424   // TypeSystem methods
425   //------------------------------------------------------------------
426   DWARFASTParser *GetDWARFParser() override;
427   //PDBASTParser *GetPDBParser();
428
429   //------------------------------------------------------------------
430   // ClangASTContext callbacks for external source lookups.
431   //------------------------------------------------------------------
432   static void CompleteTagDecl(void *baton, clang::TagDecl *);
433
434   static void CompleteObjCInterfaceDecl(void *baton,
435                                         clang::ObjCInterfaceDecl *);
436
437   static bool LayoutRecordType(
438       void *baton, const clang::RecordDecl *record_decl, uint64_t &size,
439       uint64_t &alignment,
440       llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
441       llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
442           &base_offsets,
443       llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
444           &vbase_offsets);
445
446   //----------------------------------------------------------------------
447   // CompilerDecl override functions
448   //----------------------------------------------------------------------
449   ConstString DeclGetName(void *opaque_decl) override;
450
451   ConstString DeclGetMangledName(void *opaque_decl) override;
452
453   CompilerDeclContext DeclGetDeclContext(void *opaque_decl) override;
454
455   CompilerType DeclGetFunctionReturnType(void *opaque_decl) override;
456
457   size_t DeclGetFunctionNumArguments(void *opaque_decl) override;
458
459   CompilerType DeclGetFunctionArgumentType(void *opaque_decl,
460                                            size_t arg_idx) override;
461
462   //----------------------------------------------------------------------
463   // CompilerDeclContext override functions
464   //----------------------------------------------------------------------
465
466   std::vector<CompilerDecl>
467   DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name,
468                             const bool ignore_using_decls) override;
469
470   bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override;
471
472   ConstString DeclContextGetName(void *opaque_decl_ctx) override;
473
474   ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override;
475
476   bool DeclContextIsClassMethod(void *opaque_decl_ctx,
477                                 lldb::LanguageType *language_ptr,
478                                 bool *is_instance_method_ptr,
479                                 ConstString *language_object_name_ptr) override;
480
481   //----------------------------------------------------------------------
482   // Clang specific clang::DeclContext functions
483   //----------------------------------------------------------------------
484
485   static clang::DeclContext *
486   DeclContextGetAsDeclContext(const CompilerDeclContext &dc);
487
488   static clang::ObjCMethodDecl *
489   DeclContextGetAsObjCMethodDecl(const CompilerDeclContext &dc);
490
491   static clang::CXXMethodDecl *
492   DeclContextGetAsCXXMethodDecl(const CompilerDeclContext &dc);
493
494   static clang::FunctionDecl *
495   DeclContextGetAsFunctionDecl(const CompilerDeclContext &dc);
496
497   static clang::NamespaceDecl *
498   DeclContextGetAsNamespaceDecl(const CompilerDeclContext &dc);
499
500   static ClangASTMetadata *DeclContextGetMetaData(const CompilerDeclContext &dc,
501                                                   const void *object);
502
503   static clang::ASTContext *
504   DeclContextGetClangASTContext(const CompilerDeclContext &dc);
505
506   //----------------------------------------------------------------------
507   // Tests
508   //----------------------------------------------------------------------
509
510   bool IsArrayType(lldb::opaque_compiler_type_t type,
511                    CompilerType *element_type, uint64_t *size,
512                    bool *is_incomplete) override;
513
514   bool IsVectorType(lldb::opaque_compiler_type_t type,
515                     CompilerType *element_type, uint64_t *size) override;
516
517   bool IsAggregateType(lldb::opaque_compiler_type_t type) override;
518
519   bool IsAnonymousType(lldb::opaque_compiler_type_t type) override;
520
521   bool IsBeingDefined(lldb::opaque_compiler_type_t type) override;
522
523   bool IsCharType(lldb::opaque_compiler_type_t type) override;
524
525   bool IsCompleteType(lldb::opaque_compiler_type_t type) override;
526
527   bool IsConst(lldb::opaque_compiler_type_t type) override;
528
529   bool IsCStringType(lldb::opaque_compiler_type_t type,
530                      uint32_t &length) override;
531
532   static bool IsCXXClassType(const CompilerType &type);
533
534   bool IsDefined(lldb::opaque_compiler_type_t type) override;
535
536   bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
537                            bool &is_complex) override;
538
539   bool IsFunctionType(lldb::opaque_compiler_type_t type,
540                       bool *is_variadic_ptr) override;
541
542   uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
543                                   CompilerType *base_type_ptr) override;
544
545   size_t
546   GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override;
547
548   CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
549                                           const size_t index) override;
550
551   bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override;
552
553   bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
554                           CompilerType *function_pointer_type_ptr) override;
555
556   bool IsIntegerType(lldb::opaque_compiler_type_t type,
557                      bool &is_signed) override;
558
559   bool IsEnumerationType(lldb::opaque_compiler_type_t type,
560                          bool &is_signed) override;
561
562   static bool IsObjCClassType(const CompilerType &type);
563
564   static bool IsObjCClassTypeAndHasIVars(const CompilerType &type,
565                                          bool check_superclass);
566
567   static bool IsObjCObjectOrInterfaceType(const CompilerType &type);
568
569   static bool IsObjCObjectPointerType(const CompilerType &type,
570                                       CompilerType *target_type = nullptr);
571
572   bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override;
573
574   static bool IsClassType(lldb::opaque_compiler_type_t type);
575
576   static bool IsEnumType(lldb::opaque_compiler_type_t type);
577
578   bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
579                              CompilerType *target_type, // Can pass nullptr
580                              bool check_cplusplus, bool check_objc) override;
581
582   bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override;
583
584   bool IsPointerType(lldb::opaque_compiler_type_t type,
585                      CompilerType *pointee_type) override;
586
587   bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type,
588                                 CompilerType *pointee_type) override;
589
590   bool IsReferenceType(lldb::opaque_compiler_type_t type,
591                        CompilerType *pointee_type, bool *is_rvalue) override;
592
593   bool IsScalarType(lldb::opaque_compiler_type_t type) override;
594
595   bool IsTypedefType(lldb::opaque_compiler_type_t type) override;
596
597   bool IsVoidType(lldb::opaque_compiler_type_t type) override;
598
599   bool SupportsLanguage(lldb::LanguageType language) override;
600
601   static bool GetCXXClassName(const CompilerType &type,
602                               std::string &class_name);
603
604   static bool GetObjCClassName(const CompilerType &type,
605                                std::string &class_name);
606
607   //----------------------------------------------------------------------
608   // Type Completion
609   //----------------------------------------------------------------------
610
611   bool GetCompleteType(lldb::opaque_compiler_type_t type) override;
612
613   //----------------------------------------------------------------------
614   // Accessors
615   //----------------------------------------------------------------------
616
617   ConstString GetTypeName(lldb::opaque_compiler_type_t type) override;
618
619   uint32_t GetTypeInfo(lldb::opaque_compiler_type_t type,
620                        CompilerType *pointee_or_element_compiler_type) override;
621
622   lldb::LanguageType
623   GetMinimumLanguage(lldb::opaque_compiler_type_t type) override;
624
625   lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override;
626
627   unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override;
628
629   //----------------------------------------------------------------------
630   // Creating related types
631   //----------------------------------------------------------------------
632
633   // Using the current type, create a new typedef to that type using
634   // "typedef_name"
635   // as the name and "decl_ctx" as the decl context.
636   static CompilerType
637   CreateTypedefType(const CompilerType &type, const char *typedef_name,
638                     const CompilerDeclContext &compiler_decl_ctx);
639
640   CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type,
641                                    uint64_t *stride) override;
642
643   CompilerType GetArrayType(lldb::opaque_compiler_type_t type,
644                             uint64_t size) override;
645
646   CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override;
647
648   CompilerType
649   GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override;
650
651   // Returns -1 if this isn't a function of if the function doesn't have a
652   // prototype
653   // Returns a value >= 0 if there is a prototype.
654   int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override;
655
656   CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type,
657                                               size_t idx) override;
658
659   CompilerType
660   GetFunctionReturnType(lldb::opaque_compiler_type_t type) override;
661
662   size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override;
663
664   TypeMemberFunctionImpl
665   GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type,
666                            size_t idx) override;
667
668   CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override;
669
670   CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override;
671
672   CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override;
673
674   CompilerType
675   GetLValueReferenceType(lldb::opaque_compiler_type_t type) override;
676
677   CompilerType
678   GetRValueReferenceType(lldb::opaque_compiler_type_t type) override;
679
680   CompilerType AddConstModifier(lldb::opaque_compiler_type_t type) override;
681
682   CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type) override;
683
684   CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type) override;
685
686   CompilerType CreateTypedef(lldb::opaque_compiler_type_t type,
687                              const char *name,
688                              const CompilerDeclContext &decl_ctx) override;
689
690   // If the current object represents a typedef type, get the underlying type
691   CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override;
692
693   //----------------------------------------------------------------------
694   // Create related types using the current type's AST
695   //----------------------------------------------------------------------
696   CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override;
697
698   //----------------------------------------------------------------------
699   // Exploring the type
700   //----------------------------------------------------------------------
701
702   uint64_t GetByteSize(lldb::opaque_compiler_type_t type,
703                        ExecutionContextScope *exe_scope) {
704     return (GetBitSize(type, exe_scope) + 7) / 8;
705   }
706
707   uint64_t GetBitSize(lldb::opaque_compiler_type_t type,
708                       ExecutionContextScope *exe_scope) override;
709
710   lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
711                              uint64_t &count) override;
712
713   lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
714
715   size_t GetTypeBitAlign(lldb::opaque_compiler_type_t type) override;
716
717   uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
718                           bool omit_empty_base_classes) override;
719
720   CompilerType GetBuiltinTypeByName(const ConstString &name) override;
721
722   lldb::BasicType
723   GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override;
724
725   static lldb::BasicType
726   GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type,
727                           const ConstString &name);
728
729   void ForEachEnumerator(
730       lldb::opaque_compiler_type_t type,
731       std::function<bool(const CompilerType &integer_type,
732                          const ConstString &name,
733                          const llvm::APSInt &value)> const &callback) override;
734
735   uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override;
736
737   CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
738                                std::string &name, uint64_t *bit_offset_ptr,
739                                uint32_t *bitfield_bit_size_ptr,
740                                bool *is_bitfield_ptr) override;
741
742   uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override;
743
744   uint32_t GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override;
745
746   CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type,
747                                          size_t idx,
748                                          uint32_t *bit_offset_ptr) override;
749
750   CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type,
751                                           size_t idx,
752                                           uint32_t *bit_offset_ptr) override;
753
754   static uint32_t GetNumPointeeChildren(clang::QualType type);
755
756   CompilerType GetChildCompilerTypeAtIndex(
757       lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
758       bool transparent_pointers, bool omit_empty_base_classes,
759       bool ignore_array_bounds, std::string &child_name,
760       uint32_t &child_byte_size, int32_t &child_byte_offset,
761       uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
762       bool &child_is_base_class, bool &child_is_deref_of_parent,
763       ValueObject *valobj, uint64_t &language_flags) override;
764
765   // Lookup a child given a name. This function will match base class names
766   // and member member names in "clang_type" only, not descendants.
767   uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
768                                    const char *name,
769                                    bool omit_empty_base_classes) override;
770
771   // Lookup a child member given a name. This function will match member names
772   // only and will descend into "clang_type" children in search for the first
773   // member in this class, or any base class that matches "name".
774   // TODO: Return all matches for a given name by returning a
775   // vector<vector<uint32_t>>
776   // so we catch all names that match a given child name, not just the first.
777   size_t
778   GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type,
779                                 const char *name, bool omit_empty_base_classes,
780                                 std::vector<uint32_t> &child_indexes) override;
781
782   size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type) override;
783
784   CompilerType GetTemplateArgument(lldb::opaque_compiler_type_t type,
785                                    size_t idx,
786                                    lldb::TemplateArgumentKind &kind) override;
787
788   CompilerType GetTypeForFormatters(void *type) override;
789
790 #define LLDB_INVALID_DECL_LEVEL UINT32_MAX
791   // LLDB_INVALID_DECL_LEVEL is returned by CountDeclLevels if
792   // child_decl_ctx could not be found in decl_ctx.
793   uint32_t CountDeclLevels(clang::DeclContext *frame_decl_ctx,
794                            clang::DeclContext *child_decl_ctx,
795                            ConstString *child_name = nullptr,
796                            CompilerType *child_type = nullptr);
797
798   //----------------------------------------------------------------------
799   // Modifying RecordType
800   //----------------------------------------------------------------------
801   static clang::FieldDecl *AddFieldToRecordType(const CompilerType &type,
802                                                 const char *name,
803                                                 const CompilerType &field_type,
804                                                 lldb::AccessType access,
805                                                 uint32_t bitfield_bit_size);
806
807   static void BuildIndirectFields(const CompilerType &type);
808
809   static void SetIsPacked(const CompilerType &type);
810
811   static clang::VarDecl *AddVariableToRecordType(const CompilerType &type,
812                                                  const char *name,
813                                                  const CompilerType &var_type,
814                                                  lldb::AccessType access);
815
816   clang::CXXMethodDecl *
817   AddMethodToCXXRecordType(lldb::opaque_compiler_type_t type, const char *name,
818                            const CompilerType &method_type,
819                            lldb::AccessType access, bool is_virtual,
820                            bool is_static, bool is_inline, bool is_explicit,
821                            bool is_attr_used, bool is_artificial);
822
823   // C++ Base Classes
824   clang::CXXBaseSpecifier *
825   CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type,
826                            lldb::AccessType access, bool is_virtual,
827                            bool base_of_class);
828
829   static void DeleteBaseClassSpecifiers(clang::CXXBaseSpecifier **base_classes,
830                                         unsigned num_base_classes);
831
832   bool
833   SetBaseClassesForClassType(lldb::opaque_compiler_type_t type,
834                              clang::CXXBaseSpecifier const *const *base_classes,
835                              unsigned num_base_classes);
836
837   static bool SetObjCSuperClass(const CompilerType &type,
838                                 const CompilerType &superclass_compiler_type);
839
840   static bool AddObjCClassProperty(const CompilerType &type,
841                                    const char *property_name,
842                                    const CompilerType &property_compiler_type,
843                                    clang::ObjCIvarDecl *ivar_decl,
844                                    const char *property_setter_name,
845                                    const char *property_getter_name,
846                                    uint32_t property_attributes,
847                                    ClangASTMetadata *metadata);
848
849   static clang::ObjCMethodDecl *AddMethodToObjCObjectType(
850       const CompilerType &type,
851       const char *name, // the full symbol name as seen in the symbol table
852                         // (lldb::opaque_compiler_type_t type, "-[NString
853                         // stringWithCString:]")
854       const CompilerType &method_compiler_type, lldb::AccessType access,
855       bool is_artificial, bool is_variadic);
856
857   static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type,
858                                     bool has_extern);
859
860   static bool GetHasExternalStorage(const CompilerType &type);
861   //------------------------------------------------------------------
862   // Tag Declarations
863   //------------------------------------------------------------------
864   static bool StartTagDeclarationDefinition(const CompilerType &type);
865
866   static bool CompleteTagDeclarationDefinition(const CompilerType &type);
867
868   //----------------------------------------------------------------------
869   // Modifying Enumeration types
870   //----------------------------------------------------------------------
871   bool AddEnumerationValueToEnumerationType(
872       lldb::opaque_compiler_type_t type,
873       const CompilerType &enumerator_qual_type, const Declaration &decl,
874       const char *name, int64_t enum_value, uint32_t enum_value_bit_size);
875
876   CompilerType GetEnumerationIntegerType(lldb::opaque_compiler_type_t type);
877
878   //------------------------------------------------------------------
879   // Pointers & References
880   //------------------------------------------------------------------
881
882   // Call this function using the class type when you want to make a
883   // member pointer type to pointee_type.
884   static CompilerType CreateMemberPointerType(const CompilerType &type,
885                                               const CompilerType &pointee_type);
886
887   // Converts "s" to a floating point value and place resulting floating
888   // point bytes in the "dst" buffer.
889   size_t ConvertStringToFloatValue(lldb::opaque_compiler_type_t type,
890                                    const char *s, uint8_t *dst,
891                                    size_t dst_size) override;
892
893   //----------------------------------------------------------------------
894   // Dumping types
895   //----------------------------------------------------------------------
896   void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
897                  Stream *s, lldb::Format format, const DataExtractor &data,
898                  lldb::offset_t data_offset, size_t data_byte_size,
899                  uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
900                  bool show_types, bool show_summary, bool verbose,
901                  uint32_t depth) override;
902
903   bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s,
904                      lldb::Format format, const DataExtractor &data,
905                      lldb::offset_t data_offset, size_t data_byte_size,
906                      uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
907                      ExecutionContextScope *exe_scope) override;
908
909   void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
910                    Stream *s, const DataExtractor &data,
911                    lldb::offset_t data_offset, size_t data_byte_size) override;
912
913   void DumpTypeDescription(
914       lldb::opaque_compiler_type_t type) override; // Dump to stdout
915
916   void DumpTypeDescription(lldb::opaque_compiler_type_t type,
917                            Stream *s) override;
918
919   static void DumpTypeName(const CompilerType &type);
920
921   static clang::EnumDecl *GetAsEnumDecl(const CompilerType &type);
922
923   static clang::RecordDecl *GetAsRecordDecl(const CompilerType &type);
924
925   static clang::TagDecl *GetAsTagDecl(const CompilerType &type);
926
927   clang::CXXRecordDecl *GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type);
928
929   static clang::ObjCInterfaceDecl *
930   GetAsObjCInterfaceDecl(const CompilerType &type);
931
932   clang::ClassTemplateDecl *ParseClassTemplateDecl(
933       clang::DeclContext *decl_ctx, lldb::AccessType access_type,
934       const char *parent_name, int tag_decl_kind,
935       const ClangASTContext::TemplateParameterInfos &template_param_infos);
936
937   clang::BlockDecl *CreateBlockDeclaration(clang::DeclContext *ctx);
938
939   clang::UsingDirectiveDecl *
940   CreateUsingDirectiveDeclaration(clang::DeclContext *decl_ctx,
941                                   clang::NamespaceDecl *ns_decl);
942
943   clang::UsingDecl *CreateUsingDeclaration(clang::DeclContext *current_decl_ctx,
944                                            clang::NamedDecl *target);
945
946   clang::VarDecl *CreateVariableDeclaration(clang::DeclContext *decl_context,
947                                             const char *name,
948                                             clang::QualType type);
949
950   static lldb::opaque_compiler_type_t
951   GetOpaqueCompilerType(clang::ASTContext *ast, lldb::BasicType basic_type);
952
953   static clang::QualType GetQualType(lldb::opaque_compiler_type_t type) {
954     if (type)
955       return clang::QualType::getFromOpaquePtr(type);
956     return clang::QualType();
957   }
958
959   static clang::QualType
960   GetCanonicalQualType(lldb::opaque_compiler_type_t type) {
961     if (type)
962       return clang::QualType::getFromOpaquePtr(type).getCanonicalType();
963     return clang::QualType();
964   }
965
966   clang::DeclarationName
967   GetDeclarationName(const char *name, const CompilerType &function_clang_type);
968
969 protected:
970   //------------------------------------------------------------------
971   // Classes that inherit from ClangASTContext can see and modify these
972   //------------------------------------------------------------------
973   // clang-format off
974     std::string                                     m_target_triple;
975     std::unique_ptr<clang::ASTContext>              m_ast_ap;
976     std::unique_ptr<clang::LangOptions>             m_language_options_ap;
977     std::unique_ptr<clang::FileManager>             m_file_manager_ap;
978     std::unique_ptr<clang::FileSystemOptions>       m_file_system_options_ap;
979     std::unique_ptr<clang::SourceManager>           m_source_manager_ap;
980     std::unique_ptr<clang::DiagnosticsEngine>       m_diagnostics_engine_ap;
981     std::unique_ptr<clang::DiagnosticConsumer>      m_diagnostic_consumer_ap;
982     std::shared_ptr<clang::TargetOptions>           m_target_options_rp;
983     std::unique_ptr<clang::TargetInfo>              m_target_info_ap;
984     std::unique_ptr<clang::IdentifierTable>         m_identifier_table_ap;
985     std::unique_ptr<clang::SelectorTable>           m_selector_table_ap;
986     std::unique_ptr<clang::Builtin::Context>        m_builtins_ap;
987     std::unique_ptr<DWARFASTParserClang>            m_dwarf_ast_parser_ap;
988 //  std::unique_ptr<PDBASTParser>                   m_pdb_ast_parser_ap;
989     std::unique_ptr<ClangASTSource>                 m_scratch_ast_source_ap;
990     std::unique_ptr<clang::MangleContext>           m_mangle_ctx_ap;
991     CompleteTagDeclCallback                         m_callback_tag_decl;
992     CompleteObjCInterfaceDeclCallback               m_callback_objc_decl;
993     void *                                          m_callback_baton;
994     uint32_t                                        m_pointer_byte_size;
995     bool                                            m_ast_owned;
996     bool                                            m_can_evaluate_expressions;
997   // clang-format on
998 private:
999   //------------------------------------------------------------------
1000   // For ClangASTContext only
1001   //------------------------------------------------------------------
1002   ClangASTContext(const ClangASTContext &);
1003   const ClangASTContext &operator=(const ClangASTContext &);
1004 };
1005
1006 class ClangASTContextForExpressions : public ClangASTContext {
1007 public:
1008   ClangASTContextForExpressions(Target &target);
1009
1010   ~ClangASTContextForExpressions() override = default;
1011
1012   UserExpression *
1013   GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
1014                     lldb::LanguageType language,
1015                     Expression::ResultType desired_type,
1016                     const EvaluateExpressionOptions &options) override;
1017
1018   FunctionCaller *GetFunctionCaller(const CompilerType &return_type,
1019                                     const Address &function_address,
1020                                     const ValueList &arg_value_list,
1021                                     const char *name) override;
1022
1023   UtilityFunction *GetUtilityFunction(const char *text,
1024                                       const char *name) override;
1025
1026   PersistentExpressionState *GetPersistentExpressionState() override;
1027
1028 private:
1029   lldb::TargetWP m_target_wp;
1030   lldb::ClangPersistentVariablesUP m_persistent_variables; ///< These are the
1031                                                            ///persistent
1032                                                            ///variables
1033                                                            ///associated with
1034                                                            ///this process for
1035                                                            ///the expression
1036                                                            ///parser.
1037 };
1038
1039 } // namespace lldb_private
1040
1041 #endif // liblldb_ClangASTContext_h_