]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/ClangASTContext.h
Merge ^/head r275715 through r275748.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / ClangASTContext.h
1 //===-- ClangASTContext.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ClangASTContext_h_
11 #define liblldb_ClangASTContext_h_
12
13 // C Includes
14 #include <stdint.h>
15
16 // C++ Includes
17 #include <string>
18 #include <vector>
19
20 // Other libraries and framework includes
21 #include "llvm/ADT/SmallVector.h"
22 #include "clang/AST/TemplateBase.h"
23
24
25 // Project includes
26 #include "lldb/lldb-enumerations.h"
27 #include "lldb/Core/ClangForward.h"
28 #include "lldb/Symbol/ClangASTType.h"
29
30 namespace lldb_private {
31
32 class Declaration;
33
34 class ClangASTContext
35 {
36 public:
37     typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *);
38     typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *);
39     
40     //------------------------------------------------------------------
41     // Constructors and Destructors
42     //------------------------------------------------------------------
43     ClangASTContext (const char *triple = NULL);
44
45     ~ClangASTContext();
46     
47     static ClangASTContext*
48     GetASTContext (clang::ASTContext* ast_ctx);
49
50     clang::ASTContext *
51     getASTContext();
52
53     clang::Builtin::Context *
54     getBuiltinContext();
55
56     clang::IdentifierTable *
57     getIdentifierTable();
58
59     clang::LangOptions *
60     getLanguageOptions();
61
62     clang::SelectorTable *
63     getSelectorTable();
64
65     clang::FileManager *
66     getFileManager();
67     
68     clang::SourceManager *
69     getSourceManager();
70
71     clang::DiagnosticsEngine *
72     getDiagnosticsEngine();
73     
74     clang::DiagnosticConsumer *
75     getDiagnosticConsumer();
76
77     std::shared_ptr<clang::TargetOptions> &getTargetOptions();
78
79     clang::TargetInfo *
80     getTargetInfo();
81
82     void
83     Clear();
84
85     const char *
86     GetTargetTriple ();
87
88     void
89     SetTargetTriple (const char *target_triple);
90
91     void
92     SetArchitecture (const ArchSpec &arch);
93
94     bool
95     HasExternalSource ();
96
97     void
98     SetExternalSource (llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> &ast_source_ap);
99
100     void
101     RemoveExternalSource ();
102     
103     bool
104     GetCompleteDecl (clang::Decl *decl)
105     {
106         return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
107     }
108     
109     static bool
110     GetCompleteDecl (clang::ASTContext *ast,
111                      clang::Decl *decl);
112
113     void SetMetadataAsUserID (const void *object,
114                               lldb::user_id_t user_id);
115
116     void SetMetadata (const void *object,
117                       ClangASTMetadata &meta_data)
118     {
119         SetMetadata(getASTContext(), object, meta_data);
120     }
121     
122     static void
123     SetMetadata (clang::ASTContext *ast,
124                  const void *object,
125                  ClangASTMetadata &meta_data);
126     
127     ClangASTMetadata *
128     GetMetadata (const void *object)
129     {
130         return GetMetadata(getASTContext(), object);
131     }
132     
133     static ClangASTMetadata *
134     GetMetadata (clang::ASTContext *ast,
135                  const void *object);
136     
137     //------------------------------------------------------------------
138     // Basic Types
139     //------------------------------------------------------------------
140     ClangASTType
141     GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
142                                           uint32_t bit_size);
143
144     static ClangASTType
145     GetBuiltinTypeForEncodingAndBitSize (clang::ASTContext *ast,
146                                          lldb::Encoding encoding,
147                                          uint32_t bit_size);
148
149     ClangASTType
150     GetBasicType (lldb::BasicType type);
151
152     static ClangASTType
153     GetBasicType (clang::ASTContext *ast, lldb::BasicType type);
154     
155     static ClangASTType
156     GetBasicType (clang::ASTContext *ast, const ConstString &name);
157     
158     static lldb::BasicType
159     GetBasicTypeEnumeration (const ConstString &name);
160
161     ClangASTType
162     GetBuiltinTypeForDWARFEncodingAndBitSize (
163         const char *type_name,
164         uint32_t dw_ate,
165         uint32_t bit_size);
166
167     ClangASTType
168     GetCStringType(bool is_const);
169     
170     static ClangASTType
171     GetUnknownAnyType(clang::ASTContext *ast);
172     
173     ClangASTType
174     GetUnknownAnyType()
175     {
176         return ClangASTContext::GetUnknownAnyType(getASTContext());
177     }
178     
179     uint32_t
180     GetPointerByteSize ();
181
182     static clang::DeclContext *
183     GetTranslationUnitDecl (clang::ASTContext *ast);
184     
185     clang::DeclContext *
186     GetTranslationUnitDecl ()
187     {
188         return GetTranslationUnitDecl (getASTContext());
189     }
190     
191     static bool
192     GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx,
193                                       lldb::LanguageType &language,
194                                       bool &is_instance_method,
195                                       ConstString &language_object_name);
196     
197     static ClangASTType
198     CopyType(clang::ASTContext *dest_context, 
199              ClangASTType source_type);
200     
201     static clang::Decl *
202     CopyDecl (clang::ASTContext *dest_context, 
203               clang::ASTContext *source_context,
204               clang::Decl *source_decl);
205
206     static bool
207     AreTypesSame(ClangASTType type1,
208                  ClangASTType type2,
209                  bool ignore_qualifiers = false);
210     
211     ClangASTType
212     GetTypeForDecl (clang::TagDecl *decl);
213     
214     ClangASTType
215     GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
216
217     //------------------------------------------------------------------
218     // Structure, Unions, Classes
219     //------------------------------------------------------------------
220
221     static clang::AccessSpecifier
222     ConvertAccessTypeToAccessSpecifier (lldb::AccessType access);
223
224     static clang::AccessSpecifier
225     UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs);
226
227     static uint32_t
228     GetNumBaseClasses (const clang::CXXRecordDecl *cxx_record_decl,
229                        bool omit_empty_base_classes);
230
231     static uint32_t
232     GetIndexForRecordBase (const clang::RecordDecl *record_decl,
233                            const clang::CXXBaseSpecifier *base_spec,
234                            bool omit_empty_base_classes);
235
236     ClangASTType
237     CreateRecordType (clang::DeclContext *decl_ctx,
238                       lldb::AccessType access_type,
239                       const char *name,
240                       int kind,
241                       lldb::LanguageType language,
242                       ClangASTMetadata *metadata = NULL);
243     
244     class TemplateParameterInfos
245     {
246     public:
247         bool
248         IsValid() const
249         {
250             if (args.empty())
251                 return false;
252             return args.size() == names.size();
253         }
254
255         size_t
256         GetSize () const
257         {
258             if (IsValid())
259                 return args.size();
260             return 0;
261         }
262
263         llvm::SmallVector<const char *, 2> names;
264         llvm::SmallVector<clang::TemplateArgument, 2> args;
265     };
266
267     clang::FunctionTemplateDecl *
268     CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx,
269                                 clang::FunctionDecl *func_decl,
270                                 const char *name, 
271                                 const TemplateParameterInfos &infos);
272     
273     void
274     CreateFunctionTemplateSpecializationInfo (clang::FunctionDecl *func_decl, 
275                                               clang::FunctionTemplateDecl *Template,
276                                               const TemplateParameterInfos &infos);
277
278     clang::ClassTemplateDecl *
279     CreateClassTemplateDecl (clang::DeclContext *decl_ctx,
280                              lldb::AccessType access_type,
281                              const char *class_name, 
282                              int kind, 
283                              const TemplateParameterInfos &infos);
284
285     clang::ClassTemplateSpecializationDecl *
286     CreateClassTemplateSpecializationDecl (clang::DeclContext *decl_ctx,
287                                            clang::ClassTemplateDecl *class_template_decl,
288                                            int kind,
289                                            const TemplateParameterInfos &infos);
290
291     ClangASTType
292     CreateClassTemplateSpecializationType (clang::ClassTemplateSpecializationDecl *class_template_specialization_decl);
293
294     static clang::DeclContext *
295     GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl);
296
297     static clang::DeclContext *
298     GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl);
299
300     
301     static bool
302     CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, 
303                                                uint32_t num_params);
304
305     bool
306     FieldIsBitfield (clang::FieldDecl* field,
307                      uint32_t& bitfield_bit_size);
308
309     static bool
310     FieldIsBitfield (clang::ASTContext *ast,
311                      clang::FieldDecl* field,
312                      uint32_t& bitfield_bit_size);
313
314     static bool
315     RecordHasFields (const clang::RecordDecl *record_decl);
316
317
318     ClangASTType
319     CreateObjCClass (const char *name, 
320                      clang::DeclContext *decl_ctx, 
321                      bool isForwardDecl, 
322                      bool isInternal,
323                      ClangASTMetadata *metadata = NULL);
324
325     // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations
326
327
328     //------------------------------------------------------------------
329     // Namespace Declarations
330     //------------------------------------------------------------------
331
332     clang::NamespaceDecl *
333     GetUniqueNamespaceDeclaration (const char *name,
334                                    clang::DeclContext *decl_ctx);
335
336     //------------------------------------------------------------------
337     // Function Types
338     //------------------------------------------------------------------
339
340     clang::FunctionDecl *
341     CreateFunctionDeclaration (clang::DeclContext *decl_ctx,
342                                const char *name,
343                                const ClangASTType &function_Type,
344                                int storage,
345                                bool is_inline);
346     
347     static ClangASTType
348     CreateFunctionType (clang::ASTContext *ast,
349                         const ClangASTType &result_type,
350                         const ClangASTType *args,
351                         unsigned num_args,
352                         bool is_variadic,
353                         unsigned type_quals);
354     
355     ClangASTType
356     CreateFunctionType (const ClangASTType &result_type,
357                         const ClangASTType *args,
358                         unsigned num_args,
359                         bool is_variadic,
360                         unsigned type_quals)
361     {
362         return ClangASTContext::CreateFunctionType(getASTContext(),
363                                                    result_type,
364                                                    args,
365                                                    num_args,
366                                                    is_variadic,
367                                                    type_quals);
368     }
369     
370     clang::ParmVarDecl *
371     CreateParameterDeclaration (const char *name,
372                                 const ClangASTType &param_type,
373                                 int storage);
374
375     void
376     SetFunctionParameters (clang::FunctionDecl *function_decl,
377                            clang::ParmVarDecl **params,
378                            unsigned num_params);
379
380     //------------------------------------------------------------------
381     // Array Types
382     //------------------------------------------------------------------
383
384     ClangASTType
385     CreateArrayType (const ClangASTType &element_type,
386                      size_t element_count,
387                      bool is_vector);
388
389     //------------------------------------------------------------------
390     // Enumeration Types
391     //------------------------------------------------------------------
392     ClangASTType
393     CreateEnumerationType (const char *name, 
394                            clang::DeclContext *decl_ctx, 
395                            const Declaration &decl, 
396                            const ClangASTType &integer_qual_type);
397     
398     //------------------------------------------------------------------
399     // Integer type functions
400     //------------------------------------------------------------------
401     
402     ClangASTType
403     GetIntTypeFromBitSize (size_t bit_size, bool is_signed)
404     {
405         return GetIntTypeFromBitSize (getASTContext(), bit_size, is_signed);
406     }
407     
408     static ClangASTType
409     GetIntTypeFromBitSize (clang::ASTContext *ast,
410                            size_t bit_size, bool is_signed);
411     
412     ClangASTType
413     GetPointerSizedIntType (bool is_signed)
414     {
415         return GetPointerSizedIntType (getASTContext(), is_signed);
416     }
417     
418     static ClangASTType
419     GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed);
420     
421     //------------------------------------------------------------------
422     // Floating point functions
423     //------------------------------------------------------------------
424     
425     ClangASTType
426     GetFloatTypeFromBitSize (size_t bit_size)
427     {
428         return GetFloatTypeFromBitSize (getASTContext(), bit_size);
429     }
430
431     static ClangASTType
432     GetFloatTypeFromBitSize (clang::ASTContext *ast,
433                              size_t bit_size);
434 protected:
435     //------------------------------------------------------------------
436     // Classes that inherit from ClangASTContext can see and modify these
437     //------------------------------------------------------------------
438     std::string                                     m_target_triple;
439     std::unique_ptr<clang::ASTContext>              m_ast_ap;
440     std::unique_ptr<clang::LangOptions>             m_language_options_ap;
441     std::unique_ptr<clang::FileManager>             m_file_manager_ap;
442     std::unique_ptr<clang::FileSystemOptions>       m_file_system_options_ap;
443     std::unique_ptr<clang::SourceManager>           m_source_manager_ap;
444     std::unique_ptr<clang::DiagnosticsEngine>       m_diagnostics_engine_ap;
445     std::unique_ptr<clang::DiagnosticConsumer>      m_diagnostic_consumer_ap;
446     std::shared_ptr<clang::TargetOptions>           m_target_options_rp;
447     std::unique_ptr<clang::TargetInfo>              m_target_info_ap;
448     std::unique_ptr<clang::IdentifierTable>         m_identifier_table_ap;
449     std::unique_ptr<clang::SelectorTable>           m_selector_table_ap;
450     std::unique_ptr<clang::Builtin::Context>        m_builtins_ap;
451     CompleteTagDeclCallback                         m_callback_tag_decl;
452     CompleteObjCInterfaceDeclCallback               m_callback_objc_decl;
453     void *                                          m_callback_baton;
454     uint32_t                                        m_pointer_byte_size;
455 private:
456     //------------------------------------------------------------------
457     // For ClangASTContext only
458     //------------------------------------------------------------------
459     ClangASTContext(const ClangASTContext&);
460     const ClangASTContext& operator=(const ClangASTContext&);
461 };
462
463 } // namespace lldb_private
464
465 #endif  // liblldb_ClangASTContext_h_