1 //===-- ClangASTContext.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ClangASTContext_h_
11 #define liblldb_ClangASTContext_h_
20 // Other libraries and framework includes
21 #include "llvm/ADT/SmallVector.h"
22 #include "clang/AST/TemplateBase.h"
26 #include "lldb/lldb-enumerations.h"
27 #include "lldb/Core/ClangForward.h"
28 #include "lldb/Symbol/ClangASTType.h"
30 namespace lldb_private {
37 typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *);
38 typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *);
40 //------------------------------------------------------------------
41 // Constructors and Destructors
42 //------------------------------------------------------------------
43 ClangASTContext (const char *triple = NULL);
47 static ClangASTContext*
48 GetASTContext (clang::ASTContext* ast_ctx);
53 clang::Builtin::Context *
56 clang::IdentifierTable *
62 clang::SelectorTable *
68 clang::SourceManager *
71 clang::DiagnosticsEngine *
72 getDiagnosticsEngine();
74 clang::DiagnosticConsumer *
75 getDiagnosticConsumer();
77 std::shared_ptr<clang::TargetOptions> &getTargetOptions();
89 SetTargetTriple (const char *target_triple);
92 SetArchitecture (const ArchSpec &arch);
98 SetExternalSource (llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> &ast_source_ap);
101 RemoveExternalSource ();
104 GetCompleteDecl (clang::Decl *decl)
106 return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
110 GetCompleteDecl (clang::ASTContext *ast,
113 void SetMetadataAsUserID (const void *object,
114 lldb::user_id_t user_id);
116 void SetMetadata (const void *object,
117 ClangASTMetadata &meta_data)
119 SetMetadata(getASTContext(), object, meta_data);
123 SetMetadata (clang::ASTContext *ast,
125 ClangASTMetadata &meta_data);
128 GetMetadata (const void *object)
130 return GetMetadata(getASTContext(), object);
133 static ClangASTMetadata *
134 GetMetadata (clang::ASTContext *ast,
137 //------------------------------------------------------------------
139 //------------------------------------------------------------------
141 GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
145 GetBuiltinTypeForEncodingAndBitSize (clang::ASTContext *ast,
146 lldb::Encoding encoding,
150 GetBasicType (lldb::BasicType type);
153 GetBasicType (clang::ASTContext *ast, lldb::BasicType type);
156 GetBasicType (clang::ASTContext *ast, const ConstString &name);
158 static lldb::BasicType
159 GetBasicTypeEnumeration (const ConstString &name);
162 GetBuiltinTypeForDWARFEncodingAndBitSize (
163 const char *type_name,
168 GetCStringType(bool is_const);
171 GetUnknownAnyType(clang::ASTContext *ast);
176 return ClangASTContext::GetUnknownAnyType(getASTContext());
180 GetPointerByteSize ();
182 static clang::DeclContext *
183 GetTranslationUnitDecl (clang::ASTContext *ast);
186 GetTranslationUnitDecl ()
188 return GetTranslationUnitDecl (getASTContext());
192 GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx,
193 lldb::LanguageType &language,
194 bool &is_instance_method,
195 ConstString &language_object_name);
198 CopyType(clang::ASTContext *dest_context,
199 ClangASTType source_type);
202 CopyDecl (clang::ASTContext *dest_context,
203 clang::ASTContext *source_context,
204 clang::Decl *source_decl);
207 AreTypesSame(ClangASTType type1,
209 bool ignore_qualifiers = false);
212 GetTypeForDecl (clang::TagDecl *decl);
215 GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
217 //------------------------------------------------------------------
218 // Structure, Unions, Classes
219 //------------------------------------------------------------------
221 static clang::AccessSpecifier
222 ConvertAccessTypeToAccessSpecifier (lldb::AccessType access);
224 static clang::AccessSpecifier
225 UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs);
228 GetNumBaseClasses (const clang::CXXRecordDecl *cxx_record_decl,
229 bool omit_empty_base_classes);
232 GetIndexForRecordBase (const clang::RecordDecl *record_decl,
233 const clang::CXXBaseSpecifier *base_spec,
234 bool omit_empty_base_classes);
237 CreateRecordType (clang::DeclContext *decl_ctx,
238 lldb::AccessType access_type,
241 lldb::LanguageType language,
242 ClangASTMetadata *metadata = NULL);
244 class TemplateParameterInfos
252 return args.size() == names.size();
263 llvm::SmallVector<const char *, 2> names;
264 llvm::SmallVector<clang::TemplateArgument, 2> args;
267 clang::FunctionTemplateDecl *
268 CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx,
269 clang::FunctionDecl *func_decl,
271 const TemplateParameterInfos &infos);
274 CreateFunctionTemplateSpecializationInfo (clang::FunctionDecl *func_decl,
275 clang::FunctionTemplateDecl *Template,
276 const TemplateParameterInfos &infos);
278 clang::ClassTemplateDecl *
279 CreateClassTemplateDecl (clang::DeclContext *decl_ctx,
280 lldb::AccessType access_type,
281 const char *class_name,
283 const TemplateParameterInfos &infos);
285 clang::ClassTemplateSpecializationDecl *
286 CreateClassTemplateSpecializationDecl (clang::DeclContext *decl_ctx,
287 clang::ClassTemplateDecl *class_template_decl,
289 const TemplateParameterInfos &infos);
292 CreateClassTemplateSpecializationType (clang::ClassTemplateSpecializationDecl *class_template_specialization_decl);
294 static clang::DeclContext *
295 GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl);
297 static clang::DeclContext *
298 GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl);
302 CheckOverloadedOperatorKindParameterCount (uint32_t op_kind,
303 uint32_t num_params);
306 FieldIsBitfield (clang::FieldDecl* field,
307 uint32_t& bitfield_bit_size);
310 FieldIsBitfield (clang::ASTContext *ast,
311 clang::FieldDecl* field,
312 uint32_t& bitfield_bit_size);
315 RecordHasFields (const clang::RecordDecl *record_decl);
319 CreateObjCClass (const char *name,
320 clang::DeclContext *decl_ctx,
323 ClangASTMetadata *metadata = NULL);
325 // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations
328 //------------------------------------------------------------------
329 // Namespace Declarations
330 //------------------------------------------------------------------
332 clang::NamespaceDecl *
333 GetUniqueNamespaceDeclaration (const char *name,
334 clang::DeclContext *decl_ctx);
336 //------------------------------------------------------------------
338 //------------------------------------------------------------------
340 clang::FunctionDecl *
341 CreateFunctionDeclaration (clang::DeclContext *decl_ctx,
343 const ClangASTType &function_Type,
348 CreateFunctionType (clang::ASTContext *ast,
349 const ClangASTType &result_type,
350 const ClangASTType *args,
353 unsigned type_quals);
356 CreateFunctionType (const ClangASTType &result_type,
357 const ClangASTType *args,
362 return ClangASTContext::CreateFunctionType(getASTContext(),
371 CreateParameterDeclaration (const char *name,
372 const ClangASTType ¶m_type,
376 SetFunctionParameters (clang::FunctionDecl *function_decl,
377 clang::ParmVarDecl **params,
378 unsigned num_params);
380 //------------------------------------------------------------------
382 //------------------------------------------------------------------
385 CreateArrayType (const ClangASTType &element_type,
386 size_t element_count,
389 //------------------------------------------------------------------
391 //------------------------------------------------------------------
393 CreateEnumerationType (const char *name,
394 clang::DeclContext *decl_ctx,
395 const Declaration &decl,
396 const ClangASTType &integer_qual_type);
398 //------------------------------------------------------------------
399 // Integer type functions
400 //------------------------------------------------------------------
403 GetIntTypeFromBitSize (size_t bit_size, bool is_signed)
405 return GetIntTypeFromBitSize (getASTContext(), bit_size, is_signed);
409 GetIntTypeFromBitSize (clang::ASTContext *ast,
410 size_t bit_size, bool is_signed);
413 GetPointerSizedIntType (bool is_signed)
415 return GetPointerSizedIntType (getASTContext(), is_signed);
419 GetPointerSizedIntType (clang::ASTContext *ast, bool is_signed);
421 //------------------------------------------------------------------
422 // Floating point functions
423 //------------------------------------------------------------------
426 GetFloatTypeFromBitSize (size_t bit_size)
428 return GetFloatTypeFromBitSize (getASTContext(), bit_size);
432 GetFloatTypeFromBitSize (clang::ASTContext *ast,
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;
456 //------------------------------------------------------------------
457 // For ClangASTContext only
458 //------------------------------------------------------------------
459 ClangASTContext(const ClangASTContext&);
460 const ClangASTContext& operator=(const ClangASTContext&);
463 } // namespace lldb_private
465 #endif // liblldb_ClangASTContext_h_