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/OwningPtr.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "clang/AST/TemplateBase.h"
27 #include "lldb/lldb-enumerations.h"
28 #include "lldb/Core/ClangForward.h"
29 #include "lldb/Symbol/ClangASTType.h"
31 namespace lldb_private {
38 typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *);
39 typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *);
41 //------------------------------------------------------------------
42 // Constructors and Destructors
43 //------------------------------------------------------------------
44 ClangASTContext (const char *triple = NULL);
51 clang::Builtin::Context *
54 clang::IdentifierTable *
60 clang::SelectorTable *
66 clang::SourceManager *
69 clang::DiagnosticsEngine *
70 getDiagnosticsEngine();
72 clang::DiagnosticConsumer *
73 getDiagnosticConsumer();
75 clang::TargetOptions *
88 SetTargetTriple (const char *target_triple);
91 SetArchitecture (const ArchSpec &arch);
97 SetExternalSource (llvm::OwningPtr<clang::ExternalASTSource> &ast_source_ap);
100 RemoveExternalSource ();
103 GetCompleteDecl (clang::Decl *decl)
105 return ClangASTContext::GetCompleteDecl(getASTContext(), decl);
109 GetCompleteDecl (clang::ASTContext *ast,
112 void SetMetadataAsUserID (const void *object,
113 lldb::user_id_t user_id);
115 void SetMetadata (const void *object,
116 ClangASTMetadata &meta_data)
118 SetMetadata(getASTContext(), object, meta_data);
122 SetMetadata (clang::ASTContext *ast,
124 ClangASTMetadata &meta_data);
127 GetMetadata (const void *object)
129 return GetMetadata(getASTContext(), object);
132 static ClangASTMetadata *
133 GetMetadata (clang::ASTContext *ast,
136 //------------------------------------------------------------------
138 //------------------------------------------------------------------
140 GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
144 GetBuiltinTypeForEncodingAndBitSize (clang::ASTContext *ast,
145 lldb::Encoding encoding,
149 GetBasicType (lldb::BasicType type);
152 GetBasicType (clang::ASTContext *ast, lldb::BasicType type);
155 GetBasicType (clang::ASTContext *ast, const ConstString &name);
157 static lldb::BasicType
158 GetBasicTypeEnumeration (const ConstString &name);
161 GetBuiltinTypeForDWARFEncodingAndBitSize (
162 const char *type_name,
167 GetCStringType(bool is_const);
170 GetUnknownAnyType(clang::ASTContext *ast);
175 return ClangASTContext::GetUnknownAnyType(getASTContext());
179 GetPointerByteSize ();
181 static clang::DeclContext *
182 GetTranslationUnitDecl (clang::ASTContext *ast);
185 GetTranslationUnitDecl ()
187 return GetTranslationUnitDecl (getASTContext());
191 GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx,
192 lldb::LanguageType &language,
193 bool &is_instance_method,
194 ConstString &language_object_name);
197 CopyType(clang::ASTContext *dest_context,
198 ClangASTType source_type);
201 CopyDecl (clang::ASTContext *dest_context,
202 clang::ASTContext *source_context,
203 clang::Decl *source_decl);
206 AreTypesSame(ClangASTType type1,
208 bool ignore_qualifiers = false);
211 GetTypeForDecl (clang::TagDecl *decl);
214 GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
216 //------------------------------------------------------------------
217 // Structure, Unions, Classes
218 //------------------------------------------------------------------
220 static clang::AccessSpecifier
221 ConvertAccessTypeToAccessSpecifier (lldb::AccessType access);
223 static clang::AccessSpecifier
224 UnifyAccessSpecifiers (clang::AccessSpecifier lhs, clang::AccessSpecifier rhs);
227 GetNumBaseClasses (const clang::CXXRecordDecl *cxx_record_decl,
228 bool omit_empty_base_classes);
231 GetIndexForRecordBase (const clang::RecordDecl *record_decl,
232 const clang::CXXBaseSpecifier *base_spec,
233 bool omit_empty_base_classes);
236 CreateRecordType (clang::DeclContext *decl_ctx,
237 lldb::AccessType access_type,
240 lldb::LanguageType language,
241 ClangASTMetadata *metadata = NULL);
243 class TemplateParameterInfos
251 return args.size() == names.size();
262 llvm::SmallVector<const char *, 8> names;
263 llvm::SmallVector<clang::TemplateArgument, 8> args;
266 clang::FunctionTemplateDecl *
267 CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx,
268 clang::FunctionDecl *func_decl,
270 const TemplateParameterInfos &infos);
273 CreateFunctionTemplateSpecializationInfo (clang::FunctionDecl *func_decl,
274 clang::FunctionTemplateDecl *Template,
275 const TemplateParameterInfos &infos);
277 clang::ClassTemplateDecl *
278 CreateClassTemplateDecl (clang::DeclContext *decl_ctx,
279 lldb::AccessType access_type,
280 const char *class_name,
282 const TemplateParameterInfos &infos);
284 clang::ClassTemplateSpecializationDecl *
285 CreateClassTemplateSpecializationDecl (clang::DeclContext *decl_ctx,
286 clang::ClassTemplateDecl *class_template_decl,
288 const TemplateParameterInfos &infos);
291 CreateClassTemplateSpecializationType (clang::ClassTemplateSpecializationDecl *class_template_specialization_decl);
293 static clang::DeclContext *
294 GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl);
296 static clang::DeclContext *
297 GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl);
301 CheckOverloadedOperatorKindParameterCount (uint32_t op_kind,
302 uint32_t num_params);
305 FieldIsBitfield (clang::FieldDecl* field,
306 uint32_t& bitfield_bit_size);
309 FieldIsBitfield (clang::ASTContext *ast,
310 clang::FieldDecl* field,
311 uint32_t& bitfield_bit_size);
314 RecordHasFields (const clang::RecordDecl *record_decl);
318 CreateObjCClass (const char *name,
319 clang::DeclContext *decl_ctx,
322 ClangASTMetadata *metadata = NULL);
324 // Returns a mask containing bits from the ClangASTContext::eTypeXXX enumerations
327 //------------------------------------------------------------------
328 // Namespace Declarations
329 //------------------------------------------------------------------
331 clang::NamespaceDecl *
332 GetUniqueNamespaceDeclaration (const char *name,
333 clang::DeclContext *decl_ctx);
335 //------------------------------------------------------------------
337 //------------------------------------------------------------------
339 clang::FunctionDecl *
340 CreateFunctionDeclaration (clang::DeclContext *decl_ctx,
342 const ClangASTType &function_Type,
347 CreateFunctionType (clang::ASTContext *ast,
348 const ClangASTType &result_type,
349 const ClangASTType *args,
352 unsigned type_quals);
355 CreateFunctionType (const ClangASTType &result_type,
356 const ClangASTType *args,
361 return ClangASTContext::CreateFunctionType(getASTContext(),
370 CreateParameterDeclaration (const char *name,
371 const ClangASTType ¶m_type,
375 SetFunctionParameters (clang::FunctionDecl *function_decl,
376 clang::ParmVarDecl **params,
377 unsigned num_params);
379 //------------------------------------------------------------------
381 //------------------------------------------------------------------
384 CreateArrayType (const ClangASTType &element_type,
385 size_t element_count,
388 //------------------------------------------------------------------
390 //------------------------------------------------------------------
392 CreateEnumerationType (const char *name,
393 clang::DeclContext *decl_ctx,
394 const Declaration &decl,
395 const ClangASTType &integer_qual_type);
397 //------------------------------------------------------------------
398 // Floating point functions
399 //------------------------------------------------------------------
402 GetFloatTypeFromBitSize (size_t bit_size)
404 return GetFloatTypeFromBitSize (getASTContext(), bit_size);
408 GetFloatTypeFromBitSize (clang::ASTContext *ast,
411 //------------------------------------------------------------------
412 // Classes that inherit from ClangASTContext can see and modify these
413 //------------------------------------------------------------------
414 std::string m_target_triple;
415 std::unique_ptr<clang::ASTContext> m_ast_ap;
416 std::unique_ptr<clang::LangOptions> m_language_options_ap;
417 std::unique_ptr<clang::FileManager> m_file_manager_ap;
418 std::unique_ptr<clang::FileSystemOptions> m_file_system_options_ap;
419 std::unique_ptr<clang::SourceManager> m_source_manager_ap;
420 std::unique_ptr<clang::DiagnosticsEngine> m_diagnostics_engine_ap;
421 std::unique_ptr<clang::DiagnosticConsumer> m_diagnostic_consumer_ap;
422 llvm::IntrusiveRefCntPtr<clang::TargetOptions> m_target_options_rp;
423 std::unique_ptr<clang::TargetInfo> m_target_info_ap;
424 std::unique_ptr<clang::IdentifierTable> m_identifier_table_ap;
425 std::unique_ptr<clang::SelectorTable> m_selector_table_ap;
426 std::unique_ptr<clang::Builtin::Context> m_builtins_ap;
427 CompleteTagDeclCallback m_callback_tag_decl;
428 CompleteObjCInterfaceDeclCallback m_callback_objc_decl;
429 void * m_callback_baton;
430 uint32_t m_pointer_byte_size;
432 //------------------------------------------------------------------
433 // For ClangASTContext only
434 //------------------------------------------------------------------
435 ClangASTContext(const ClangASTContext&);
436 const ClangASTContext& operator=(const ClangASTContext&);
439 } // namespace lldb_private
441 #endif // liblldb_ClangASTContext_h_