forked from OSchip/llvm-project
[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
This commit is contained in:
parent
b472512a77
commit
1639c6bbb1
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue