ClangASTContext.h revision f95fc9e09fa0a32de0a3904a1517266df37e8bff
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// C++ Includes
15#include <string>
16#include <vector>
17#include <memory>
18#include <stdint.h>
19
20// Other libraries and framework includes
21#include "llvm/ADT/OwningPtr.h"
22#include "llvm/ADT/SmallVector.h"
23#include "clang/AST/TemplateBase.h"
24
25
26// Project includes
27#include "lldb/lldb-enumerations.h"
28#include "lldb/Core/ClangForward.h"
29#include "lldb/Symbol/ClangASTType.h"
30
31namespace lldb_private {
32
33class Declaration;
34
35class ClangASTContext
36{
37public:
38    enum {
39        eTypeHasChildren        = (1u <<  0),
40        eTypeHasValue           = (1u <<  1),
41        eTypeIsArray            = (1u <<  2),
42        eTypeIsBlock            = (1u <<  3),
43        eTypeIsBuiltIn          = (1u <<  4),
44        eTypeIsClass            = (1u <<  5),
45        eTypeIsCPlusPlus        = (1u <<  6),
46        eTypeIsEnumeration      = (1u <<  7),
47        eTypeIsFuncPrototype    = (1u <<  8),
48        eTypeIsMember           = (1u <<  9),
49        eTypeIsObjC             = (1u << 10),
50        eTypeIsPointer          = (1u << 11),
51        eTypeIsReference        = (1u << 12),
52        eTypeIsStructUnion      = (1u << 13),
53        eTypeIsTemplate         = (1u << 14),
54        eTypeIsTypedef          = (1u << 15),
55        eTypeIsVector           = (1u << 16),
56        eTypeIsScalar           = (1u << 17),
57        eTypeIsInteger          = (1u << 18),
58        eTypeIsFloat            = (1u << 19),
59        eTypeIsComplex          = (1u << 20),
60        eTypeIsSigned           = (1u << 21)
61    };
62
63    typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *);
64    typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *);
65
66    //------------------------------------------------------------------
67    // Constructors and Destructors
68    //------------------------------------------------------------------
69    ClangASTContext (const char *triple = NULL);
70
71    ~ClangASTContext();
72
73    clang::ASTContext *
74    getASTContext();
75
76    clang::Builtin::Context *
77    getBuiltinContext();
78
79    clang::IdentifierTable *
80    getIdentifierTable();
81
82    clang::LangOptions *
83    getLanguageOptions();
84
85    clang::SelectorTable *
86    getSelectorTable();
87
88    clang::FileManager *
89    getFileManager();
90
91    clang::SourceManager *
92    getSourceManager();
93
94    clang::DiagnosticsEngine *
95    getDiagnosticsEngine();
96
97    clang::DiagnosticConsumer *
98    getDiagnosticConsumer();
99
100    clang::TargetOptions *
101    getTargetOptions();
102
103    clang::TargetInfo *
104    getTargetInfo();
105
106    void
107    Clear();
108
109    const char *
110    GetTargetTriple ();
111
112    void
113    SetTargetTriple (const char *target_triple);
114
115    void
116    SetArchitecture (const ArchSpec &arch);
117
118    bool
119    HasExternalSource ();
120
121    void
122    SetExternalSource (llvm::OwningPtr<clang::ExternalASTSource> &ast_source_ap);
123
124    void
125    RemoveExternalSource ();
126
127    bool
128    GetCompleteType (lldb::clang_type_t clang_type);
129
130    static bool
131    GetCompleteType (clang::ASTContext *ast,
132                     lldb::clang_type_t clang_type);
133
134    bool
135    IsCompleteType (lldb::clang_type_t clang_type);
136
137    static bool
138    IsCompleteType (clang::ASTContext *ast,
139                    lldb::clang_type_t clang_type);
140
141    bool
142    GetCompleteDecl (clang::Decl *decl)
143    {
144        return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
145    }
146
147    static bool
148    GetCompleteDecl (clang::ASTContext *ast,
149                     clang::Decl *decl);
150
151    void SetMetadataAsUserID (const void *object,
152                              lldb::user_id_t user_id);
153
154    void SetMetadata (const void *object,
155                      ClangASTMetadata &meta_data)
156    {
157        SetMetadata(getASTContext(), object, meta_data);
158    }
159
160    static void
161    SetMetadata (clang::ASTContext *ast,
162                 const void *object,
163                 ClangASTMetadata &meta_data);
164
165    ClangASTMetadata *
166    GetMetadata (const void *object)
167    {
168        return GetMetadata(getASTContext(), object);
169    }
170
171    static ClangASTMetadata *
172    GetMetadata (clang::ASTContext *ast,
173                 const void *object);
174
175    //------------------------------------------------------------------
176    // Basic Types
177    //------------------------------------------------------------------
178
179    lldb::clang_type_t
180    GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
181                                          uint32_t bit_size);
182
183    static lldb::clang_type_t
184    GetBuiltinTypeForEncodingAndBitSize (clang::ASTContext *ast,
185                                         lldb::Encoding encoding,
186                                         uint32_t bit_size);
187
188    lldb::clang_type_t
189    GetBuiltinTypeForDWARFEncodingAndBitSize (
190        const char *type_name,
191        uint32_t dw_ate,
192        uint32_t bit_size);
193
194    static lldb::clang_type_t
195    GetBuiltInType_void(clang::ASTContext *ast);
196
197    lldb::clang_type_t
198    GetBuiltInType_void()
199    {
200        return GetBuiltInType_void(getASTContext());
201    }
202
203    lldb::clang_type_t
204    GetBuiltInType_bool();
205
206    lldb::clang_type_t
207    GetBuiltInType_objc_id();
208
209    static lldb::clang_type_t
210    GetBuiltInType_objc_id(clang::ASTContext *ast);
211
212    lldb::clang_type_t
213    GetBuiltInType_objc_Class();
214
215    static lldb::clang_type_t
216    GetUnknownAnyType(clang::ASTContext *ast);
217
218    lldb::clang_type_t
219    GetUnknownAnyType()
220    {
221        return ClangASTContext::GetUnknownAnyType(getASTContext());
222    }
223
224    lldb::clang_type_t
225    GetBuiltInType_objc_selector();
226
227    lldb::clang_type_t
228    GetCStringType(bool is_const);
229
230    lldb::clang_type_t
231    GetVoidType();
232
233    lldb::clang_type_t
234    GetVoidType(clang::ASTContext *ast);
235
236    lldb::clang_type_t
237    GetVoidPtrType(bool is_const);
238
239    static lldb::clang_type_t
240    GetVoidPtrType(clang::ASTContext *ast, bool is_const);
241
242    static clang::DeclContext *
243    GetTranslationUnitDecl (clang::ASTContext *ast);
244
245    clang::DeclContext *
246    GetTranslationUnitDecl ()
247    {
248        return GetTranslationUnitDecl (getASTContext());
249    }
250
251    static bool
252    GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx,
253                                      lldb::LanguageType &language,
254                                      bool &is_instance_method,
255                                      ConstString &language_object_name);
256
257    static lldb::clang_type_t
258    CopyType(clang::ASTContext *dest_context,
259             clang::ASTContext *source_context,
260             lldb::clang_type_t clang_type);
261
262    static clang::Decl *
263    CopyDecl (clang::ASTContext *dest_context,
264              clang::ASTContext *source_context,
265              clang::Decl *source_decl);
266
267    static bool
268    AreTypesSame(clang::ASTContext *ast,
269                 lldb::clang_type_t type1,
270                 lldb::clang_type_t type2,
271                 bool ignore_qualifiers = false);
272
273    bool
274    AreTypesSame(lldb::clang_type_t type1,
275                 lldb::clang_type_t type2,
276                 bool ignore_qualifiers = false)
277    {
278        return ClangASTContext::AreTypesSame(getASTContext(), type1, type2, ignore_qualifiers);
279    }
280
281
282    lldb::clang_type_t
283    GetTypeForDecl (clang::TagDecl *decl);
284
285    lldb::clang_type_t
286    GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
287
288    static lldb::BasicType
289    GetLLDBBasicTypeEnumeration (lldb::clang_type_t clang_type);
290
291    //------------------------------------------------------------------
292    // CVR modifiers
293    //------------------------------------------------------------------
294
295    static lldb::clang_type_t
296    AddConstModifier (lldb::clang_type_t clang_type);
297
298    static lldb::clang_type_t
299    AddRestrictModifier (lldb::clang_type_t clang_type);
300
301    static lldb::clang_type_t
302    AddVolatileModifier (lldb::clang_type_t clang_type);
303
304    //------------------------------------------------------------------
305    // Structure, Unions, Classes
306    //------------------------------------------------------------------
307
308    lldb::clang_type_t
309    CreateRecordType (clang::DeclContext *decl_ctx,
310                      lldb::AccessType access_type,
311                      const char *name,
312                      int kind,
313                      lldb::LanguageType language,
314                      ClangASTMetadata *metadata = NULL);
315
316    static clang::FieldDecl *
317    AddFieldToRecordType (clang::ASTContext *ast,
318                          lldb::clang_type_t record_qual_type,
319                          const char *name,
320                          lldb::clang_type_t field_type,
321                          lldb::AccessType access,
322                          uint32_t bitfield_bit_size);
323
324    clang::FieldDecl *
325    AddFieldToRecordType (lldb::clang_type_t record_qual_type,
326                          const char *name,
327                          lldb::clang_type_t field_type,
328                          lldb::AccessType access,
329                          uint32_t bitfield_bit_size)
330    {
331        return ClangASTContext::AddFieldToRecordType (getASTContext(),
332                                                      record_qual_type,
333                                                      name,
334                                                      field_type,
335                                                      access,
336                                                      bitfield_bit_size);
337    }
338
339    static void
340    BuildIndirectFields (clang::ASTContext *ast,
341                         lldb::clang_type_t record_qual_type);
342
343    void
344    BuildIndirectFields (lldb::clang_type_t record_qual_type)
345    {
346        ClangASTContext::BuildIndirectFields(getASTContext(),
347                                             record_qual_type);
348    }
349
350    static clang::CXXMethodDecl *
351    AddMethodToCXXRecordType (clang::ASTContext *ast,
352                              lldb::clang_type_t record_opaque_type,
353                              const char *name,
354                              lldb::clang_type_t method_type,
355                              lldb::AccessType access,
356                              bool is_virtual,
357                              bool is_static,
358                              bool is_inline,
359                              bool is_explicit,
360                              bool is_attr_used,
361                              bool is_artificial);
362
363    clang::CXXMethodDecl *
364    AddMethodToCXXRecordType (lldb::clang_type_t record_opaque_type,
365                              const char *name,
366                              lldb::clang_type_t method_type,
367                              lldb::AccessType access,
368                              bool is_virtual,
369                              bool is_static,
370                              bool is_inline,
371                              bool is_explicit,
372                              bool is_attr_used,
373                              bool is_artificial)
374
375    {
376        return ClangASTContext::AddMethodToCXXRecordType (getASTContext(),
377                                                          record_opaque_type,
378                                                          name,
379                                                          method_type,
380                                                          access,
381                                                          is_virtual,
382                                                          is_static,
383                                                          is_inline,
384                                                          is_explicit,
385                                                          is_attr_used,
386                                                          is_artificial);
387    }
388
389    class TemplateParameterInfos
390    {
391    public:
392        bool
393        IsValid() const
394        {
395            if (args.empty())
396                return false;
397            return args.size() == names.size();
398        }
399
400        size_t
401        GetSize () const
402        {
403            if (IsValid())
404                return args.size();
405            return 0;
406        }
407
408        llvm::SmallVector<const char *, 8> names;
409        llvm::SmallVector<clang::TemplateArgument, 8> args;
410    };
411
412    clang::FunctionTemplateDecl *
413    CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx,
414                                clang::FunctionDecl *func_decl,
415                                const char *name,
416                                const TemplateParameterInfos &infos);
417
418    void
419    CreateFunctionTemplateSpecializationInfo (clang::FunctionDecl *func_decl,
420                                              clang::FunctionTemplateDecl *Template,
421                                              const TemplateParameterInfos &infos);
422
423    clang::ClassTemplateDecl *
424    CreateClassTemplateDecl (clang::DeclContext *decl_ctx,
425                             lldb::AccessType access_type,
426                             const char *class_name,
427                             int kind,
428                             const TemplateParameterInfos &infos);
429
430    clang::ClassTemplateSpecializationDecl *
431    CreateClassTemplateSpecializationDecl (clang::DeclContext *decl_ctx,
432                                           clang::ClassTemplateDecl *class_template_decl,
433                                           int kind,
434                                           const TemplateParameterInfos &infos);
435
436    lldb::clang_type_t
437    CreateClassTemplateSpecializationType (clang::ClassTemplateSpecializationDecl *class_template_specialization_decl);
438
439    static clang::DeclContext *
440    GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl);
441
442    static clang::DeclContext *
443    GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl);
444
445
446    static bool
447    CheckOverloadedOperatorKindParameterCount (uint32_t op_kind,
448                                               uint32_t num_params);
449
450    bool
451    FieldIsBitfield (clang::FieldDecl* field,
452                     uint32_t& bitfield_bit_size);
453
454    static bool
455    FieldIsBitfield (clang::ASTContext *ast,
456                     clang::FieldDecl* field,
457                     uint32_t& bitfield_bit_size);
458
459    static bool
460    RecordHasFields (const clang::RecordDecl *record_decl);
461
462    void
463    SetDefaultAccessForRecordFields (lldb::clang_type_t clang_type,
464                                     int default_accessibility,
465                                     int *assigned_accessibilities,
466                                     size_t num_assigned_accessibilities);
467
468    lldb::clang_type_t
469    CreateObjCClass (const char *name,
470                     clang::DeclContext *decl_ctx,
471                     bool isForwardDecl,
472                     bool isInternal,
473                     ClangASTMetadata *metadata = NULL);
474
475    static clang::FieldDecl *
476    AddObjCClassIVar (clang::ASTContext *ast,
477                      lldb::clang_type_t class_opaque_type,
478                      const char *name,
479                      lldb::clang_type_t ivar_opaque_type,
480                      lldb::AccessType access,
481                      uint32_t bitfield_bit_size,
482                      bool isSynthesized);
483
484    clang::FieldDecl *
485    AddObjCClassIVar (lldb::clang_type_t class_opaque_type,
486                      const char *name,
487                      lldb::clang_type_t ivar_opaque_type,
488                      lldb::AccessType access,
489                      uint32_t bitfield_bit_size,
490                      bool isSynthesized)
491    {
492        return ClangASTContext::AddObjCClassIVar (getASTContext(),
493                                                  class_opaque_type,
494                                                  name,
495                                                  ivar_opaque_type,
496                                                  access,
497                                                  bitfield_bit_size,
498                                                  isSynthesized);
499    }
500
501    static bool
502    AddObjCClassProperty
503    (
504        clang::ASTContext *ast,
505        lldb::clang_type_t class_opaque_type,
506        const char *property_name,
507        lldb::clang_type_t property_opaque_type,  // The property type is only required if you don't have an ivar decl
508        clang::ObjCIvarDecl *ivar_decl,
509        const char *property_setter_name,
510        const char *property_getter_name,
511        uint32_t property_attributes,
512        ClangASTMetadata *metadata = NULL
513    );
514
515    bool
516    AddObjCClassProperty
517    (
518        lldb::clang_type_t class_opaque_type,
519        const char *property_name,
520        lldb::clang_type_t property_opaque_type,
521        clang::ObjCIvarDecl *ivar_decl,
522        const char *property_setter_name,
523        const char *property_getter_name,
524        uint32_t property_attributes,
525        ClangASTMetadata *metadata = NULL
526    )
527    {
528        return ClangASTContext::AddObjCClassProperty (getASTContext(),
529                                                      class_opaque_type,
530                                                      property_name,
531                                                      property_opaque_type,
532                                                      ivar_decl,
533                                                      property_setter_name,
534                                                      property_getter_name,
535                                                      property_attributes,
536                                                      metadata);
537    }
538
539    bool
540    SetObjCSuperClass (lldb::clang_type_t class_clang_type,
541                       lldb::clang_type_t superclass_clang_type);
542
543    static bool
544    ObjCTypeHasIVars (lldb::clang_type_t class_clang_type, bool check_superclass);
545
546    static bool
547    ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl,
548                      bool check_superclass);
549
550
551    static clang::ObjCMethodDecl *
552    AddMethodToObjCObjectType (clang::ASTContext *ast,
553                               lldb::clang_type_t class_opaque_type,
554                               const char *name,  // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
555                               lldb::clang_type_t method_opaque_type,
556                               lldb::AccessType access,
557                               bool is_artificial);
558
559    clang::ObjCMethodDecl *
560    AddMethodToObjCObjectType (lldb::clang_type_t class_opaque_type,
561                               const char *name,  // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
562                               lldb::clang_type_t method_opaque_type,
563                               lldb::AccessType access,
564                               bool is_artificial)
565    {
566        return AddMethodToObjCObjectType (getASTContext(),
567                                          class_opaque_type,
568                                          name,
569                                          method_opaque_type,
570                                          access, is_artificial);
571    }
572
573    static bool
574    SetHasExternalStorage (lldb::clang_type_t clang_type, bool has_extern);
575
576    //------------------------------------------------------------------
577    // Aggregate Types
578    //------------------------------------------------------------------
579    static bool
580    IsAggregateType (lldb::clang_type_t clang_type);
581
582    // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations
583    static uint32_t
584    GetTypeInfo (lldb::clang_type_t clang_type,
585                 clang::ASTContext *ast,                // The AST for clang_type (can be NULL)
586                 lldb::clang_type_t *pointee_or_element_type);  // (can be NULL)
587
588    static uint32_t
589    GetNumChildren (clang::ASTContext *ast,
590                    lldb::clang_type_t clang_type,
591                    bool omit_empty_base_classes);
592
593    static uint32_t
594    GetNumDirectBaseClasses (clang::ASTContext *ast,
595                             lldb::clang_type_t clang_type);
596
597    static uint32_t
598    GetNumVirtualBaseClasses (clang::ASTContext *ast,
599                              lldb::clang_type_t clang_type);
600
601    static uint32_t
602    GetNumFields (clang::ASTContext *ast,
603                  lldb::clang_type_t clang_type);
604
605    static lldb::clang_type_t
606    GetDirectBaseClassAtIndex (clang::ASTContext *ast,
607                               lldb::clang_type_t clang_type,
608                               size_t idx,
609                               uint32_t *bit_offset_ptr);
610
611    static lldb::clang_type_t
612    GetVirtualBaseClassAtIndex (clang::ASTContext *ast,
613                                lldb::clang_type_t clang_type,
614                                size_t idx,
615                                uint32_t *bit_offset_ptr);
616
617    static lldb::clang_type_t
618    GetFieldAtIndex (clang::ASTContext *ast,
619                     lldb::clang_type_t clang_type,
620                     size_t idx,
621                     std::string& name,
622                     uint64_t *bit_offset_ptr,
623                     uint32_t *bitfield_bit_size_ptr,
624                     bool *is_bitfield_ptr);
625
626    static size_t
627    GetIndexOfFieldWithName (clang::ASTContext *ast,
628                             lldb::clang_type_t clang_type,
629                             const char* name,
630                             lldb::clang_type_t* field_clang_type = NULL,
631                             uint64_t *bit_offset_ptr = NULL,
632                             uint32_t *bitfield_bit_size_ptr = NULL,
633                             bool *is_bitfield_ptr = NULL);
634
635    static uint32_t
636    GetNumPointeeChildren (lldb::clang_type_t clang_type);
637
638    lldb::clang_type_t
639    GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
640                              const char *parent_name,
641                              lldb::clang_type_t  parent_clang_type,
642                              size_t idx,
643                              bool transparent_pointers,
644                              bool omit_empty_base_classes,
645                              bool ignore_array_bounds,
646                              std::string& child_name,
647                              uint32_t &child_byte_size,
648                              int32_t &child_byte_offset,
649                              uint32_t &child_bitfield_bit_size,
650                              uint32_t &child_bitfield_bit_offset,
651                              bool &child_is_base_class,
652                              bool &child_is_deref_of_parent);
653
654    static lldb::clang_type_t
655    GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
656                              clang::ASTContext *ast,
657                              const char *parent_name,
658                              lldb::clang_type_t  parent_clang_type,
659                              size_t idx,
660                              bool transparent_pointers,
661                              bool omit_empty_base_classes,
662                              bool ignore_array_bounds,
663                              std::string& child_name,
664                              uint32_t &child_byte_size,
665                              int32_t &child_byte_offset,
666                              uint32_t &child_bitfield_bit_size,
667                              uint32_t &child_bitfield_bit_offset,
668                              bool &child_is_base_class,
669                              bool &child_is_deref_of_parent);
670
671    // Lookup a child given a name. This function will match base class names
672    // and member member names in "clang_type" only, not descendants.
673    static uint32_t
674    GetIndexOfChildWithName (clang::ASTContext *ast,
675                             lldb::clang_type_t clang_type,
676                             const char *name,
677                             bool omit_empty_base_classes);
678
679    // Lookup a child member given a name. This function will match member names
680    // only and will descend into "clang_type" children in search for the first
681    // member in this class, or any base class that matches "name".
682    // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
683    // so we catch all names that match a given child name, not just the first.
684    static size_t
685    GetIndexOfChildMemberWithName (clang::ASTContext *ast,
686                                   lldb::clang_type_t clang_type,
687                                   const char *name,
688                                   bool omit_empty_base_classes,
689                                   std::vector<uint32_t>& child_indexes);
690
691    size_t
692    GetNumTemplateArguments (lldb::clang_type_t clang_type)
693    {
694        return GetNumTemplateArguments(getASTContext(), clang_type);
695    }
696
697    lldb::clang_type_t
698    GetTemplateArgument (lldb::clang_type_t clang_type,
699                         size_t idx,
700                         lldb::TemplateArgumentKind &kind)
701    {
702        return GetTemplateArgument(getASTContext(), clang_type, idx, kind);
703    }
704
705    static size_t
706    GetNumTemplateArguments (clang::ASTContext *ast,
707                             lldb::clang_type_t clang_type);
708
709    static lldb::clang_type_t
710    GetTemplateArgument (clang::ASTContext *ast,
711                         lldb::clang_type_t clang_type,
712                         size_t idx,
713                         lldb::TemplateArgumentKind &kind);
714
715    //------------------------------------------------------------------
716    // clang::TagType
717    //------------------------------------------------------------------
718
719    bool
720    SetTagTypeKind (lldb::clang_type_t  tag_qual_type,
721                    int kind);
722
723    //------------------------------------------------------------------
724    // C++ Base Classes
725    //------------------------------------------------------------------
726
727    clang::CXXBaseSpecifier *
728    CreateBaseClassSpecifier (lldb::clang_type_t  base_class_type,
729                              lldb::AccessType access,
730                              bool is_virtual,
731                              bool base_of_class);
732
733    static void
734    DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes,
735                               unsigned num_base_classes);
736
737    bool
738    SetBaseClassesForClassType (lldb::clang_type_t  class_clang_type,
739                                clang::CXXBaseSpecifier const * const *base_classes,
740                                unsigned num_base_classes);
741
742    //------------------------------------------------------------------
743    // DeclContext Functions
744    //------------------------------------------------------------------
745
746    static clang::DeclContext *
747    GetDeclContextForType (lldb::clang_type_t  qual_type);
748
749    //------------------------------------------------------------------
750    // Namespace Declarations
751    //------------------------------------------------------------------
752
753    clang::NamespaceDecl *
754    GetUniqueNamespaceDeclaration (const char *name,
755                                   clang::DeclContext *decl_ctx);
756
757    //------------------------------------------------------------------
758    // Function Types
759    //------------------------------------------------------------------
760
761    clang::FunctionDecl *
762    CreateFunctionDeclaration (clang::DeclContext *decl_ctx,
763                               const char *name,
764                               lldb::clang_type_t  function_Type,
765                               int storage,
766                               bool is_inline);
767
768    static lldb::clang_type_t
769    CreateFunctionType (clang::ASTContext *ast,
770                        lldb::clang_type_t result_type,
771                        lldb::clang_type_t *args,
772                        unsigned num_args,
773                        bool is_variadic,
774                        unsigned type_quals);
775
776    lldb::clang_type_t
777    CreateFunctionType (lldb::clang_type_t result_type,
778                        lldb::clang_type_t *args,
779                        unsigned num_args,
780                        bool is_variadic,
781                        unsigned type_quals)
782    {
783        return ClangASTContext::CreateFunctionType(getASTContext(),
784                                                   result_type,
785                                                   args,
786                                                   num_args,
787                                                   is_variadic,
788                                                   type_quals);
789    }
790
791    clang::ParmVarDecl *
792    CreateParameterDeclaration (const char *name,
793                               lldb::clang_type_t param_type,
794                               int storage);
795
796    void
797    SetFunctionParameters (clang::FunctionDecl *function_decl,
798                           clang::ParmVarDecl **params,
799                           unsigned num_params);
800
801    //------------------------------------------------------------------
802    // Array Types
803    //------------------------------------------------------------------
804
805    lldb::clang_type_t
806    CreateArrayType (lldb::clang_type_t element_type,
807                     size_t element_count,
808                     bool is_vector);
809
810    //------------------------------------------------------------------
811    // Tag Declarations
812    //------------------------------------------------------------------
813    bool
814    StartTagDeclarationDefinition (lldb::clang_type_t  qual_type);
815
816    bool
817    CompleteTagDeclarationDefinition (lldb::clang_type_t  qual_type);
818
819    //------------------------------------------------------------------
820    // Enumeration Types
821    //------------------------------------------------------------------
822    lldb::clang_type_t
823    CreateEnumerationType (const char *name,
824                           clang::DeclContext *decl_ctx,
825                           const Declaration &decl,
826                           lldb::clang_type_t integer_qual_type);
827
828    static lldb::clang_type_t
829    GetEnumerationIntegerType (lldb::clang_type_t enum_clang_type);
830
831    bool
832    AddEnumerationValueToEnumerationType (lldb::clang_type_t  enum_qual_type,
833                                          lldb::clang_type_t  enumerator_qual_type,
834                                          const Declaration &decl,
835                                          const char *name,
836                                          int64_t enum_value,
837                                          uint32_t enum_value_bit_size);
838
839    //------------------------------------------------------------------
840    // Pointers & References
841    //------------------------------------------------------------------
842    lldb::clang_type_t
843    CreatePointerType (lldb::clang_type_t clang_type);
844
845    static lldb::clang_type_t
846    CreatePointerType (clang::ASTContext *ast,
847                       lldb::clang_type_t clang_type);
848
849    static lldb::clang_type_t
850    CreateLValueReferenceType (clang::ASTContext *ast_context,
851                               lldb::clang_type_t clang_type);
852
853    static lldb::clang_type_t
854    CreateRValueReferenceType (clang::ASTContext *ast_context,
855                               lldb::clang_type_t clang_type);
856
857    lldb::clang_type_t
858    CreateLValueReferenceType (lldb::clang_type_t clang_type)
859    {
860        return ClangASTContext::CreateLValueReferenceType(getASTContext(), clang_type);
861    }
862
863    lldb::clang_type_t
864    CreateRValueReferenceType (lldb::clang_type_t clang_type)
865    {
866        return ClangASTContext::CreateRValueReferenceType(getASTContext(), clang_type);
867    }
868
869    lldb::clang_type_t
870    CreateMemberPointerType (lldb::clang_type_t  clang_pointee_type,
871                             lldb::clang_type_t  clang_class_type);
872
873    uint64_t
874    GetPointerBitSize ();
875
876    static bool
877    IsIntegerType (lldb::clang_type_t clang_type, bool &is_signed);
878
879    static bool
880    IsPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL);
881
882    static bool
883    IsReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL);
884
885    static bool
886    IsPointerOrReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL);
887
888    static bool
889    IsPossibleCPlusPlusDynamicType (clang::ASTContext *ast,
890                                    lldb::clang_type_t clang_type,
891                                    lldb::clang_type_t *target_type = NULL);
892
893    static bool
894    IsPossibleDynamicType (clang::ASTContext *ast,
895                           lldb::clang_type_t clang_type,
896                           lldb::clang_type_t *dynamic_pointee_type, // Can pass NULL
897                           bool check_cplusplus,
898                           bool check_objc);
899
900    static bool
901    IsCStringType (lldb::clang_type_t clang_type, uint32_t &length);
902
903    static bool
904    IsFunctionPointerType (lldb::clang_type_t clang_type);
905
906    static lldb::clang_type_t
907    GetAsArrayType (lldb::clang_type_t clang_type,
908                    lldb::clang_type_t *member_type,
909                    uint64_t *size,
910                    bool *is_incomplete);
911
912    static bool
913    IsArrayType (lldb::clang_type_t clang_type,
914                 lldb::clang_type_t *member_type,
915                 uint64_t *size,
916                 bool *is_incomplete)
917    {
918        return GetAsArrayType(clang_type, member_type, size, is_incomplete) != 0;
919    }
920
921    //------------------------------------------------------------------
922    // Typedefs
923    //------------------------------------------------------------------
924    lldb::clang_type_t
925    CreateTypedefType (const char *name,
926                       lldb::clang_type_t clang_type,
927                       clang::DeclContext *decl_ctx);
928
929    //------------------------------------------------------------------
930    // Type names
931    //------------------------------------------------------------------
932    static bool
933    IsFloatingPointType (lldb::clang_type_t clang_type, uint32_t &count, bool &is_complex);
934
935    // true iff this is one of the types that can "fit"
936    // in a Scalar object
937    static bool
938    IsScalarType (lldb::clang_type_t clang_type);
939
940    static bool
941    IsPointerToScalarType (lldb::clang_type_t clang_type);
942
943    static bool
944    IsArrayOfScalarType (lldb::clang_type_t clang_type);
945
946    static bool
947    GetCXXClassName (lldb::clang_type_t clang_type,
948                     std::string &class_name);
949
950    static bool
951    IsCXXClassType (lldb::clang_type_t clang_type);
952
953    static bool
954    IsBeingDefined (lldb::clang_type_t clang_type);
955
956    static bool
957    IsObjCClassType (lldb::clang_type_t clang_type);
958
959    static bool
960    IsObjCObjectPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type);
961
962    static bool
963    GetObjCClassName (lldb::clang_type_t clang_type,
964                      std::string &class_name);
965
966    static bool
967    IsCharType (lldb::clang_type_t clang_type);
968
969    static size_t
970    GetArraySize (lldb::clang_type_t clang_type);
971
972    //static bool
973    //ConvertFloatValueToString (clang::ASTContext *ast,
974    //                           lldb::clang_type_t clang_type,
975    //                           const uint8_t* bytes,
976    //                           size_t byte_size,
977    //                           int apint_byte_order,
978    //                           std::string &float_str);
979
980    static size_t
981    ConvertStringToFloatValue (clang::ASTContext *ast,
982                               lldb::clang_type_t clang_type,
983                               const char *s,
984                               uint8_t *dst,
985                               size_t dst_size);
986
987    //------------------------------------------------------------------
988    // Qualifiers
989    //------------------------------------------------------------------
990    static unsigned
991    GetTypeQualifiers(lldb::clang_type_t clang_type);
992protected:
993    //------------------------------------------------------------------
994    // Classes that inherit from ClangASTContext can see and modify these
995    //------------------------------------------------------------------
996    std::string                             m_target_triple;
997    std::auto_ptr<clang::ASTContext>        m_ast_ap;
998    std::auto_ptr<clang::LangOptions>       m_language_options_ap;
999    std::auto_ptr<clang::FileManager>       m_file_manager_ap;
1000    std::auto_ptr<clang::FileSystemOptions> m_file_system_options_ap;
1001    std::auto_ptr<clang::SourceManager>     m_source_manager_ap;
1002    std::auto_ptr<clang::DiagnosticsEngine>  m_diagnostics_engine_ap;
1003    std::auto_ptr<clang::DiagnosticConsumer> m_diagnostic_consumer_ap;
1004    llvm::IntrusiveRefCntPtr<clang::TargetOptions>  m_target_options_rp;
1005    std::auto_ptr<clang::TargetInfo>        m_target_info_ap;
1006    std::auto_ptr<clang::IdentifierTable>   m_identifier_table_ap;
1007    std::auto_ptr<clang::SelectorTable>     m_selector_table_ap;
1008    std::auto_ptr<clang::Builtin::Context>  m_builtins_ap;
1009    CompleteTagDeclCallback                 m_callback_tag_decl;
1010    CompleteObjCInterfaceDeclCallback       m_callback_objc_decl;
1011    void *                                  m_callback_baton;
1012private:
1013    //------------------------------------------------------------------
1014    // For ClangASTContext only
1015    //------------------------------------------------------------------
1016    ClangASTContext(const ClangASTContext&);
1017    const ClangASTContext& operator=(const ClangASTContext&);
1018};
1019
1020} // namespace lldb_private
1021
1022#endif  // liblldb_ClangASTContext_h_
1023