diff options
| author | Zachary Turner <zturner@google.com> | 2018-12-17 16:15:13 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2018-12-17 16:15:13 +0000 |
| commit | 1639c6bbb186c733ffb4f54c9f77522f262fe2ba (patch) | |
| tree | 35af036db10a9a2c44fda9485e1019e60ad1c374 /lldb | |
| parent | b472512a77884a1f9a89bcec80f4a4709d0a6ecf (diff) | |
| download | bcm5719-llvm-1639c6bbb186c733ffb4f54c9f77522f262fe2ba.tar.gz bcm5719-llvm-1639c6bbb186c733ffb4f54c9f77522f262fe2ba.zip | |
[Clang AST Context] Add a few helper functions.
The first one allows us to add an enumerator to an enum if we
already have an APSInt, since ultimately the implementation just
constructs one anyway. The second is just a general utility
function to covert a CompilerType to a clang::TagDecl.
llvm-svn: 349360
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/include/lldb/Symbol/ClangASTContext.h | 4 | ||||
| -rw-r--r-- | lldb/include/lldb/Symbol/ClangUtil.h | 6 | ||||
| -rw-r--r-- | lldb/source/Symbol/ClangASTContext.cpp | 31 | ||||
| -rw-r--r-- | lldb/source/Symbol/ClangUtil.cpp | 8 |
4 files changed, 35 insertions, 14 deletions
diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 9302ddc437e..4cff9b25657 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -24,6 +24,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ExternalASTMerger.h" #include "clang/AST/TemplateBase.h" +#include "llvm/ADT/APSInt.h" #include "llvm/ADT/SmallVector.h" #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" @@ -902,6 +903,9 @@ public: clang::EnumConstantDecl *AddEnumerationValueToEnumerationType( const CompilerType &enum_type, const Declaration &decl, const char *name, int64_t enum_value, uint32_t enum_value_bit_size); + clang::EnumConstantDecl *AddEnumerationValueToEnumerationType( + const CompilerType &enum_type, const Declaration &decl, const char *name, + const llvm::APSInt &value); CompilerType GetEnumerationIntegerType(lldb::opaque_compiler_type_t type); diff --git a/lldb/include/lldb/Symbol/ClangUtil.h b/lldb/include/lldb/Symbol/ClangUtil.h index cb380221152..c8638f78254 100644 --- a/lldb/include/lldb/Symbol/ClangUtil.h +++ b/lldb/include/lldb/Symbol/ClangUtil.h @@ -16,6 +16,10 @@ #include "lldb/Symbol/CompilerType.h" +namespace clang { +class TagDecl; +} + namespace lldb_private { struct ClangUtil { static bool IsClangType(const CompilerType &ct); @@ -25,6 +29,8 @@ struct ClangUtil { static clang::QualType GetCanonicalQualType(const CompilerType &ct); static CompilerType RemoveFastQualifiers(const CompilerType &ct); + + static clang::TagDecl *GetAsTagDecl(const CompilerType &type); }; } diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 67e27f26e5b..0fb4699ac35 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -7827,11 +7827,7 @@ clang::RecordDecl *ClangASTContext::GetAsRecordDecl(const CompilerType &type) { } clang::TagDecl *ClangASTContext::GetAsTagDecl(const CompilerType &type) { - clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type); - if (qual_type.isNull()) - return nullptr; - else - return qual_type->getAsTagDecl(); + return ClangUtil::GetAsTagDecl(type); } clang::TypedefNameDecl * @@ -8937,7 +8933,7 @@ bool ClangASTContext::CompleteTagDeclarationDefinition( clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( const CompilerType &enum_type, const Declaration &decl, const char *name, - int64_t enum_value, uint32_t enum_value_bit_size) { + const llvm::APSInt &value) { if (!enum_type || ConstString(name).IsEmpty()) return nullptr; @@ -8950,14 +8946,9 @@ clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( if (!enum_opaque_compiler_type) return nullptr; - CompilerType underlying_type = - GetEnumerationIntegerType(enum_type.GetOpaqueQualType()); - clang::QualType enum_qual_type( GetCanonicalQualType(enum_opaque_compiler_type)); - bool is_signed = false; - underlying_type.IsIntegerType(is_signed); const clang::Type *clang_type = enum_qual_type.getTypePtr(); if (!clang_type) @@ -8968,12 +8959,10 @@ clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( if (!enutype) return nullptr; - llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed); - enum_llvm_apsint = enum_value; clang::EnumConstantDecl *enumerator_decl = clang::EnumConstantDecl::Create( *getASTContext(), enutype->getDecl(), clang::SourceLocation(), name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier - clang::QualType(enutype, 0), nullptr, enum_llvm_apsint); + clang::QualType(enutype, 0), nullptr, value); if (!enumerator_decl) return nullptr; @@ -8987,6 +8976,20 @@ clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( return enumerator_decl; } +clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType( + const CompilerType &enum_type, const Declaration &decl, const char *name, + int64_t enum_value, uint32_t enum_value_bit_size) { + CompilerType underlying_type = + GetEnumerationIntegerType(enum_type.GetOpaqueQualType()); + bool is_signed = false; + underlying_type.IsIntegerType(is_signed); + + llvm::APSInt value(enum_value_bit_size, is_signed); + value = enum_value; + + return AddEnumerationValueToEnumerationType(enum_type, decl, name, value); +} + CompilerType ClangASTContext::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) { clang::QualType enum_qual_type(GetCanonicalQualType(type)); diff --git a/lldb/source/Symbol/ClangUtil.cpp b/lldb/source/Symbol/ClangUtil.cpp index 7a67df48ee6..687fba7c7c3 100644 --- a/lldb/source/Symbol/ClangUtil.cpp +++ b/lldb/source/Symbol/ClangUtil.cpp @@ -48,3 +48,11 @@ CompilerType ClangUtil::RemoveFastQualifiers(const CompilerType &ct) { qual_type.removeLocalFastQualifiers(); return CompilerType(ct.GetTypeSystem(), qual_type.getAsOpaquePtr()); } + +clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) { + clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type); + if (qual_type.isNull()) + return nullptr; + + return qual_type->getAsTagDecl(); +} |

