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