ClangASTContext.h revision 3525576f2cddc2a7b82b2bec3fd885ef6b1b5a52
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    clang::VarDecl *
340    AddVariableToRecordType (lldb::clang_type_t record_opaque_type,
341                             const char *name,
342                             lldb::clang_type_t var_opaque_type,
343                             lldb::AccessType access)
344    {
345        return ClangASTContext::AddVariableToRecordType (getASTContext(),
346                                                         record_opaque_type,
347                                                         name,
348                                                         var_opaque_type,
349                                                         access);
350    }
351
352    static clang::VarDecl *
353    AddVariableToRecordType (clang::ASTContext *ast,
354                             lldb::clang_type_t record_opaque_type,
355                             const char *name,
356                             lldb::clang_type_t var_opaque_type,
357                             lldb::AccessType access);
358
359    static void
360    BuildIndirectFields (clang::ASTContext *ast,
361                         lldb::clang_type_t record_qual_type);
362
363    void
364    BuildIndirectFields (lldb::clang_type_t record_qual_type)
365    {
366        ClangASTContext::BuildIndirectFields(getASTContext(),
367                                             record_qual_type);
368    }
369
370    static clang::CXXMethodDecl *
371    AddMethodToCXXRecordType (clang::ASTContext *ast,
372                              lldb::clang_type_t record_opaque_type,
373                              const char *name,
374                              lldb::clang_type_t method_type,
375                              lldb::AccessType access,
376                              bool is_virtual,
377                              bool is_static,
378                              bool is_inline,
379                              bool is_explicit,
380                              bool is_attr_used,
381                              bool is_artificial);
382
383    clang::CXXMethodDecl *
384    AddMethodToCXXRecordType (lldb::clang_type_t record_opaque_type,
385                              const char *name,
386                              lldb::clang_type_t method_type,
387                              lldb::AccessType access,
388                              bool is_virtual,
389                              bool is_static,
390                              bool is_inline,
391                              bool is_explicit,
392                              bool is_attr_used,
393                              bool is_artificial)
394
395    {
396        return ClangASTContext::AddMethodToCXXRecordType (getASTContext(),
397                                                          record_opaque_type,
398                                                          name,
399                                                          method_type,
400                                                          access,
401                                                          is_virtual,
402                                                          is_static,
403                                                          is_inline,
404                                                          is_explicit,
405                                                          is_attr_used,
406                                                          is_artificial);
407    }
408
409    class TemplateParameterInfos
410    {
411    public:
412        bool
413        IsValid() const
414        {
415            if (args.empty())
416                return false;
417            return args.size() == names.size();
418        }
419
420        size_t
421        GetSize () const
422        {
423            if (IsValid())
424                return args.size();
425            return 0;
426        }
427
428        llvm::SmallVector<const char *, 8> names;
429        llvm::SmallVector<clang::TemplateArgument, 8> args;
430    };
431
432    clang::FunctionTemplateDecl *
433    CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx,
434                                clang::FunctionDecl *func_decl,
435                                const char *name,
436                                const TemplateParameterInfos &infos);
437
438    void
439    CreateFunctionTemplateSpecializationInfo (clang::FunctionDecl *func_decl,
440                                              clang::FunctionTemplateDecl *Template,
441                                              const TemplateParameterInfos &infos);
442
443    clang::ClassTemplateDecl *
444    CreateClassTemplateDecl (clang::DeclContext *decl_ctx,
445                             lldb::AccessType access_type,
446                             const char *class_name,
447                             int kind,
448                             const TemplateParameterInfos &infos);
449
450    clang::ClassTemplateSpecializationDecl *
451    CreateClassTemplateSpecializationDecl (clang::DeclContext *decl_ctx,
452                                           clang::ClassTemplateDecl *class_template_decl,
453                                           int kind,
454                                           const TemplateParameterInfos &infos);
455
456    lldb::clang_type_t
457    CreateClassTemplateSpecializationType (clang::ClassTemplateSpecializationDecl *class_template_specialization_decl);
458
459    static clang::DeclContext *
460    GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl);
461
462    static clang::DeclContext *
463    GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl);
464
465
466    static bool
467    CheckOverloadedOperatorKindParameterCount (uint32_t op_kind,
468                                               uint32_t num_params);
469
470    bool
471    FieldIsBitfield (clang::FieldDecl* field,
472                     uint32_t& bitfield_bit_size);
473
474    static bool
475    FieldIsBitfield (clang::ASTContext *ast,
476                     clang::FieldDecl* field,
477                     uint32_t& bitfield_bit_size);
478
479    static bool
480    RecordHasFields (const clang::RecordDecl *record_decl);
481
482    void
483    SetDefaultAccessForRecordFields (lldb::clang_type_t clang_type,
484                                     int default_accessibility,
485                                     int *assigned_accessibilities,
486                                     size_t num_assigned_accessibilities);
487
488    lldb::clang_type_t
489    CreateObjCClass (const char *name,
490                     clang::DeclContext *decl_ctx,
491                     bool isForwardDecl,
492                     bool isInternal,
493                     ClangASTMetadata *metadata = NULL);
494
495    static clang::FieldDecl *
496    AddObjCClassIVar (clang::ASTContext *ast,
497                      lldb::clang_type_t class_opaque_type,
498                      const char *name,
499                      lldb::clang_type_t ivar_opaque_type,
500                      lldb::AccessType access,
501                      uint32_t bitfield_bit_size,
502                      bool isSynthesized);
503
504    clang::FieldDecl *
505    AddObjCClassIVar (lldb::clang_type_t class_opaque_type,
506                      const char *name,
507                      lldb::clang_type_t ivar_opaque_type,
508                      lldb::AccessType access,
509                      uint32_t bitfield_bit_size,
510                      bool isSynthesized)
511    {
512        return ClangASTContext::AddObjCClassIVar (getASTContext(),
513                                                  class_opaque_type,
514                                                  name,
515                                                  ivar_opaque_type,
516                                                  access,
517                                                  bitfield_bit_size,
518                                                  isSynthesized);
519    }
520
521    static bool
522    AddObjCClassProperty
523    (
524        clang::ASTContext *ast,
525        lldb::clang_type_t class_opaque_type,
526        const char *property_name,
527        lldb::clang_type_t property_opaque_type,  // The property type is only required if you don't have an ivar decl
528        clang::ObjCIvarDecl *ivar_decl,
529        const char *property_setter_name,
530        const char *property_getter_name,
531        uint32_t property_attributes,
532        ClangASTMetadata *metadata = NULL
533    );
534
535    bool
536    AddObjCClassProperty
537    (
538        lldb::clang_type_t class_opaque_type,
539        const char *property_name,
540        lldb::clang_type_t property_opaque_type,
541        clang::ObjCIvarDecl *ivar_decl,
542        const char *property_setter_name,
543        const char *property_getter_name,
544        uint32_t property_attributes,
545        ClangASTMetadata *metadata = NULL
546    )
547    {
548        return ClangASTContext::AddObjCClassProperty (getASTContext(),
549                                                      class_opaque_type,
550                                                      property_name,
551                                                      property_opaque_type,
552                                                      ivar_decl,
553                                                      property_setter_name,
554                                                      property_getter_name,
555                                                      property_attributes,
556                                                      metadata);
557    }
558
559    bool
560    SetObjCSuperClass (lldb::clang_type_t class_clang_type,
561                       lldb::clang_type_t superclass_clang_type);
562
563    static bool
564    ObjCTypeHasIVars (lldb::clang_type_t class_clang_type, bool check_superclass);
565
566    static bool
567    ObjCDeclHasIVars (clang::ObjCInterfaceDecl *class_interface_decl,
568                      bool check_superclass);
569
570
571    static clang::ObjCMethodDecl *
572    AddMethodToObjCObjectType (clang::ASTContext *ast,
573                               lldb::clang_type_t class_opaque_type,
574                               const char *name,  // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
575                               lldb::clang_type_t method_opaque_type,
576                               lldb::AccessType access,
577                               bool is_artificial);
578
579    clang::ObjCMethodDecl *
580    AddMethodToObjCObjectType (lldb::clang_type_t class_opaque_type,
581                               const char *name,  // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]")
582                               lldb::clang_type_t method_opaque_type,
583                               lldb::AccessType access,
584                               bool is_artificial)
585    {
586        return AddMethodToObjCObjectType (getASTContext(),
587                                          class_opaque_type,
588                                          name,
589                                          method_opaque_type,
590                                          access, is_artificial);
591    }
592
593    static bool
594    SetHasExternalStorage (lldb::clang_type_t clang_type, bool has_extern);
595
596    //------------------------------------------------------------------
597    // Aggregate Types
598    //------------------------------------------------------------------
599    static bool
600    IsAggregateType (lldb::clang_type_t clang_type);
601
602    // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations
603    static uint32_t
604    GetTypeInfo (lldb::clang_type_t clang_type,
605                 clang::ASTContext *ast,                // The AST for clang_type (can be NULL)
606                 lldb::clang_type_t *pointee_or_element_type);  // (can be NULL)
607
608    static uint32_t
609    GetNumChildren (clang::ASTContext *ast,
610                    lldb::clang_type_t clang_type,
611                    bool omit_empty_base_classes);
612
613    static uint32_t
614    GetNumDirectBaseClasses (clang::ASTContext *ast,
615                             lldb::clang_type_t clang_type);
616
617    static uint32_t
618    GetNumVirtualBaseClasses (clang::ASTContext *ast,
619                              lldb::clang_type_t clang_type);
620
621    static uint32_t
622    GetNumFields (clang::ASTContext *ast,
623                  lldb::clang_type_t clang_type);
624
625    static lldb::clang_type_t
626    GetDirectBaseClassAtIndex (clang::ASTContext *ast,
627                               lldb::clang_type_t clang_type,
628                               size_t idx,
629                               uint32_t *bit_offset_ptr);
630
631    static lldb::clang_type_t
632    GetVirtualBaseClassAtIndex (clang::ASTContext *ast,
633                                lldb::clang_type_t clang_type,
634                                size_t idx,
635                                uint32_t *bit_offset_ptr);
636
637    static lldb::clang_type_t
638    GetFieldAtIndex (clang::ASTContext *ast,
639                     lldb::clang_type_t clang_type,
640                     size_t idx,
641                     std::string& name,
642                     uint64_t *bit_offset_ptr,
643                     uint32_t *bitfield_bit_size_ptr,
644                     bool *is_bitfield_ptr);
645
646    static size_t
647    GetIndexOfFieldWithName (clang::ASTContext *ast,
648                             lldb::clang_type_t clang_type,
649                             const char* name,
650                             lldb::clang_type_t* field_clang_type = NULL,
651                             uint64_t *bit_offset_ptr = NULL,
652                             uint32_t *bitfield_bit_size_ptr = NULL,
653                             bool *is_bitfield_ptr = NULL);
654
655    static uint32_t
656    GetNumPointeeChildren (lldb::clang_type_t clang_type);
657
658    lldb::clang_type_t
659    GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
660                              const char *parent_name,
661                              lldb::clang_type_t  parent_clang_type,
662                              size_t idx,
663                              bool transparent_pointers,
664                              bool omit_empty_base_classes,
665                              bool ignore_array_bounds,
666                              std::string& child_name,
667                              uint32_t &child_byte_size,
668                              int32_t &child_byte_offset,
669                              uint32_t &child_bitfield_bit_size,
670                              uint32_t &child_bitfield_bit_offset,
671                              bool &child_is_base_class,
672                              bool &child_is_deref_of_parent);
673
674    static lldb::clang_type_t
675    GetChildClangTypeAtIndex (ExecutionContext *exe_ctx,
676                              clang::ASTContext *ast,
677                              const char *parent_name,
678                              lldb::clang_type_t  parent_clang_type,
679                              size_t idx,
680                              bool transparent_pointers,
681                              bool omit_empty_base_classes,
682                              bool ignore_array_bounds,
683                              std::string& child_name,
684                              uint32_t &child_byte_size,
685                              int32_t &child_byte_offset,
686                              uint32_t &child_bitfield_bit_size,
687                              uint32_t &child_bitfield_bit_offset,
688                              bool &child_is_base_class,
689                              bool &child_is_deref_of_parent);
690
691    // Lookup a child given a name. This function will match base class names
692    // and member member names in "clang_type" only, not descendants.
693    static uint32_t
694    GetIndexOfChildWithName (clang::ASTContext *ast,
695                             lldb::clang_type_t clang_type,
696                             const char *name,
697                             bool omit_empty_base_classes);
698
699    // Lookup a child member given a name. This function will match member names
700    // only and will descend into "clang_type" children in search for the first
701    // member in this class, or any base class that matches "name".
702    // TODO: Return all matches for a given name by returning a vector<vector<uint32_t>>
703    // so we catch all names that match a given child name, not just the first.
704    static size_t
705    GetIndexOfChildMemberWithName (clang::ASTContext *ast,
706                                   lldb::clang_type_t clang_type,
707                                   const char *name,
708                                   bool omit_empty_base_classes,
709                                   std::vector<uint32_t>& child_indexes);
710
711    size_t
712    GetNumTemplateArguments (lldb::clang_type_t clang_type)
713    {
714        return GetNumTemplateArguments(getASTContext(), clang_type);
715    }
716
717    lldb::clang_type_t
718    GetTemplateArgument (lldb::clang_type_t clang_type,
719                         size_t idx,
720                         lldb::TemplateArgumentKind &kind)
721    {
722        return GetTemplateArgument(getASTContext(), clang_type, idx, kind);
723    }
724
725    static size_t
726    GetNumTemplateArguments (clang::ASTContext *ast,
727                             lldb::clang_type_t clang_type);
728
729    static lldb::clang_type_t
730    GetTemplateArgument (clang::ASTContext *ast,
731                         lldb::clang_type_t clang_type,
732                         size_t idx,
733                         lldb::TemplateArgumentKind &kind);
734
735    //------------------------------------------------------------------
736    // clang::TagType
737    //------------------------------------------------------------------
738
739    bool
740    SetTagTypeKind (lldb::clang_type_t  tag_qual_type,
741                    int kind);
742
743    //------------------------------------------------------------------
744    // C++ Base Classes
745    //------------------------------------------------------------------
746
747    clang::CXXBaseSpecifier *
748    CreateBaseClassSpecifier (lldb::clang_type_t  base_class_type,
749                              lldb::AccessType access,
750                              bool is_virtual,
751                              bool base_of_class);
752
753    static void
754    DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes,
755                               unsigned num_base_classes);
756
757    bool
758    SetBaseClassesForClassType (lldb::clang_type_t  class_clang_type,
759                                clang::CXXBaseSpecifier const * const *base_classes,
760                                unsigned num_base_classes);
761
762    //------------------------------------------------------------------
763    // DeclContext Functions
764    //------------------------------------------------------------------
765
766    static clang::DeclContext *
767    GetDeclContextForType (lldb::clang_type_t  qual_type);
768
769    //------------------------------------------------------------------
770    // Namespace Declarations
771    //------------------------------------------------------------------
772
773    clang::NamespaceDecl *
774    GetUniqueNamespaceDeclaration (const char *name,
775                                   clang::DeclContext *decl_ctx);
776
777    //------------------------------------------------------------------
778    // Function Types
779    //------------------------------------------------------------------
780
781    clang::FunctionDecl *
782    CreateFunctionDeclaration (clang::DeclContext *decl_ctx,
783                               const char *name,
784                               lldb::clang_type_t  function_Type,
785                               int storage,
786                               bool is_inline);
787
788    static lldb::clang_type_t
789    CreateFunctionType (clang::ASTContext *ast,
790                        lldb::clang_type_t result_type,
791                        lldb::clang_type_t *args,
792                        unsigned num_args,
793                        bool is_variadic,
794                        unsigned type_quals);
795
796    lldb::clang_type_t
797    CreateFunctionType (lldb::clang_type_t result_type,
798                        lldb::clang_type_t *args,
799                        unsigned num_args,
800                        bool is_variadic,
801                        unsigned type_quals)
802    {
803        return ClangASTContext::CreateFunctionType(getASTContext(),
804                                                   result_type,
805                                                   args,
806                                                   num_args,
807                                                   is_variadic,
808                                                   type_quals);
809    }
810
811    clang::ParmVarDecl *
812    CreateParameterDeclaration (const char *name,
813                               lldb::clang_type_t param_type,
814                               int storage);
815
816    void
817    SetFunctionParameters (clang::FunctionDecl *function_decl,
818                           clang::ParmVarDecl **params,
819                           unsigned num_params);
820
821    //------------------------------------------------------------------
822    // Array Types
823    //------------------------------------------------------------------
824
825    lldb::clang_type_t
826    CreateArrayType (lldb::clang_type_t element_type,
827                     size_t element_count,
828                     bool is_vector);
829
830    //------------------------------------------------------------------
831    // Tag Declarations
832    //------------------------------------------------------------------
833    bool
834    StartTagDeclarationDefinition (lldb::clang_type_t  qual_type);
835
836    bool
837    CompleteTagDeclarationDefinition (lldb::clang_type_t  qual_type);
838
839    //------------------------------------------------------------------
840    // Enumeration Types
841    //------------------------------------------------------------------
842    lldb::clang_type_t
843    CreateEnumerationType (const char *name,
844                           clang::DeclContext *decl_ctx,
845                           const Declaration &decl,
846                           lldb::clang_type_t integer_qual_type);
847
848    static lldb::clang_type_t
849    GetEnumerationIntegerType (lldb::clang_type_t enum_clang_type);
850
851    bool
852    AddEnumerationValueToEnumerationType (lldb::clang_type_t  enum_qual_type,
853                                          lldb::clang_type_t  enumerator_qual_type,
854                                          const Declaration &decl,
855                                          const char *name,
856                                          int64_t enum_value,
857                                          uint32_t enum_value_bit_size);
858
859    //------------------------------------------------------------------
860    // Pointers & References
861    //------------------------------------------------------------------
862    lldb::clang_type_t
863    CreatePointerType (lldb::clang_type_t clang_type);
864
865    static lldb::clang_type_t
866    CreatePointerType (clang::ASTContext *ast,
867                       lldb::clang_type_t clang_type);
868
869    static lldb::clang_type_t
870    CreateLValueReferenceType (clang::ASTContext *ast_context,
871                               lldb::clang_type_t clang_type);
872
873    static lldb::clang_type_t
874    CreateRValueReferenceType (clang::ASTContext *ast_context,
875                               lldb::clang_type_t clang_type);
876
877    lldb::clang_type_t
878    CreateLValueReferenceType (lldb::clang_type_t clang_type)
879    {
880        return ClangASTContext::CreateLValueReferenceType(getASTContext(), clang_type);
881    }
882
883    lldb::clang_type_t
884    CreateRValueReferenceType (lldb::clang_type_t clang_type)
885    {
886        return ClangASTContext::CreateRValueReferenceType(getASTContext(), clang_type);
887    }
888
889    lldb::clang_type_t
890    CreateMemberPointerType (lldb::clang_type_t  clang_pointee_type,
891                             lldb::clang_type_t  clang_class_type);
892
893    uint64_t
894    GetPointerBitSize ();
895
896    static bool
897    IsIntegerType (lldb::clang_type_t clang_type, bool &is_signed);
898
899    static bool
900    IsPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL);
901
902    static bool
903    IsReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL);
904
905    static bool
906    IsPointerOrReferenceType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type = NULL);
907
908    static bool
909    IsPossibleCPlusPlusDynamicType (clang::ASTContext *ast,
910                                    lldb::clang_type_t clang_type,
911                                    lldb::clang_type_t *target_type = NULL);
912
913    static bool
914    IsPossibleDynamicType (clang::ASTContext *ast,
915                           lldb::clang_type_t clang_type,
916                           lldb::clang_type_t *dynamic_pointee_type, // Can pass NULL
917                           bool check_cplusplus,
918                           bool check_objc);
919
920    static bool
921    IsCStringType (lldb::clang_type_t clang_type, uint32_t &length);
922
923    static bool
924    IsFunctionPointerType (lldb::clang_type_t clang_type);
925
926    static lldb::clang_type_t
927    GetAsArrayType (lldb::clang_type_t clang_type,
928                    lldb::clang_type_t *member_type,
929                    uint64_t *size,
930                    bool *is_incomplete);
931
932    static bool
933    IsArrayType (lldb::clang_type_t clang_type,
934                 lldb::clang_type_t *member_type,
935                 uint64_t *size,
936                 bool *is_incomplete)
937    {
938        return GetAsArrayType(clang_type, member_type, size, is_incomplete) != 0;
939    }
940
941    //------------------------------------------------------------------
942    // Typedefs
943    //------------------------------------------------------------------
944    lldb::clang_type_t
945    CreateTypedefType (const char *name,
946                       lldb::clang_type_t clang_type,
947                       clang::DeclContext *decl_ctx);
948
949    //------------------------------------------------------------------
950    // Type names
951    //------------------------------------------------------------------
952    static bool
953    IsFloatingPointType (lldb::clang_type_t clang_type, uint32_t &count, bool &is_complex);
954
955    // true iff this is one of the types that can "fit"
956    // in a Scalar object
957    static bool
958    IsScalarType (lldb::clang_type_t clang_type);
959
960    static bool
961    IsPointerToScalarType (lldb::clang_type_t clang_type);
962
963    static bool
964    IsArrayOfScalarType (lldb::clang_type_t clang_type);
965
966    static bool
967    GetCXXClassName (lldb::clang_type_t clang_type,
968                     std::string &class_name);
969
970    static bool
971    IsCXXClassType (lldb::clang_type_t clang_type);
972
973    static bool
974    IsBeingDefined (lldb::clang_type_t clang_type);
975
976    static bool
977    IsObjCClassType (lldb::clang_type_t clang_type);
978
979    static bool
980    IsObjCObjectPointerType (lldb::clang_type_t clang_type, lldb::clang_type_t *target_type);
981
982    static bool
983    GetObjCClassName (lldb::clang_type_t clang_type,
984                      std::string &class_name);
985
986    static bool
987    IsCharType (lldb::clang_type_t clang_type);
988
989    static size_t
990    GetArraySize (lldb::clang_type_t clang_type);
991
992    //static bool
993    //ConvertFloatValueToString (clang::ASTContext *ast,
994    //                           lldb::clang_type_t clang_type,
995    //                           const uint8_t* bytes,
996    //                           size_t byte_size,
997    //                           int apint_byte_order,
998    //                           std::string &float_str);
999
1000    static size_t
1001    ConvertStringToFloatValue (clang::ASTContext *ast,
1002                               lldb::clang_type_t clang_type,
1003                               const char *s,
1004                               uint8_t *dst,
1005                               size_t dst_size);
1006
1007    //------------------------------------------------------------------
1008    // Qualifiers
1009    //------------------------------------------------------------------
1010    static unsigned
1011    GetTypeQualifiers(lldb::clang_type_t clang_type);
1012protected:
1013    //------------------------------------------------------------------
1014    // Classes that inherit from ClangASTContext can see and modify these
1015    //------------------------------------------------------------------
1016    std::string                             m_target_triple;
1017    std::auto_ptr<clang::ASTContext>        m_ast_ap;
1018    std::auto_ptr<clang::LangOptions>       m_language_options_ap;
1019    std::auto_ptr<clang::FileManager>       m_file_manager_ap;
1020    std::auto_ptr<clang::FileSystemOptions> m_file_system_options_ap;
1021    std::auto_ptr<clang::SourceManager>     m_source_manager_ap;
1022    std::auto_ptr<clang::DiagnosticsEngine>  m_diagnostics_engine_ap;
1023    std::auto_ptr<clang::DiagnosticConsumer> m_diagnostic_consumer_ap;
1024    llvm::IntrusiveRefCntPtr<clang::TargetOptions>  m_target_options_rp;
1025    std::auto_ptr<clang::TargetInfo>        m_target_info_ap;
1026    std::auto_ptr<clang::IdentifierTable>   m_identifier_table_ap;
1027    std::auto_ptr<clang::SelectorTable>     m_selector_table_ap;
1028    std::auto_ptr<clang::Builtin::Context>  m_builtins_ap;
1029    CompleteTagDeclCallback                 m_callback_tag_decl;
1030    CompleteObjCInterfaceDeclCallback       m_callback_objc_decl;
1031    void *                                  m_callback_baton;
1032private:
1033    //------------------------------------------------------------------
1034    // For ClangASTContext only
1035    //------------------------------------------------------------------
1036    ClangASTContext(const ClangASTContext&);
1037    const ClangASTContext& operator=(const ClangASTContext&);
1038};
1039
1040} // namespace lldb_private
1041
1042#endif  // liblldb_ClangASTContext_h_
1043