зеркало из https://github.com/microsoft/clang-1.git
Move the creation of the record type for the state of Objective-C fast
enumerations from the ASTContext into CodeGen, so that we don't need to serialize it to AST files. This appears to be the last of the low-hanging fruit for SpecialTypes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137124 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
5c0d3d66bf
Коммит
0815b579b3
|
@ -198,8 +198,6 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
|
|||
QualType ObjCConstantStringType;
|
||||
mutable RecordDecl *CFConstantStringTypeDecl;
|
||||
|
||||
mutable RecordDecl *ObjCFastEnumerationStateTypeDecl;
|
||||
|
||||
/// \brief The type for the C FILE type.
|
||||
TypeDecl *FILEDecl;
|
||||
|
||||
|
@ -823,19 +821,6 @@ public:
|
|||
return ObjCConstantStringType;
|
||||
}
|
||||
|
||||
//// This gets the struct used to keep track of fast enumerations.
|
||||
QualType getObjCFastEnumerationStateType() const;
|
||||
|
||||
/// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet
|
||||
/// been built.
|
||||
QualType getRawObjCFastEnumerationStateType() const {
|
||||
if (ObjCFastEnumerationStateTypeDecl)
|
||||
return getTagDeclType(ObjCFastEnumerationStateTypeDecl);
|
||||
return QualType();
|
||||
}
|
||||
|
||||
void setObjCFastEnumerationStateType(QualType T);
|
||||
|
||||
/// \brief Set the type for the C FILE type.
|
||||
void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
|
||||
|
||||
|
|
|
@ -650,22 +650,20 @@ namespace clang {
|
|||
SPECIAL_TYPE_OBJC_CLASS = 4,
|
||||
/// \brief CFConstantString type
|
||||
SPECIAL_TYPE_CF_CONSTANT_STRING = 5,
|
||||
/// \brief Objective-C fast enumeration state type
|
||||
SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE = 6,
|
||||
/// \brief C FILE typedef type
|
||||
SPECIAL_TYPE_FILE = 7,
|
||||
SPECIAL_TYPE_FILE = 6,
|
||||
/// \brief C jmp_buf typedef type
|
||||
SPECIAL_TYPE_jmp_buf = 8,
|
||||
SPECIAL_TYPE_jmp_buf = 7,
|
||||
/// \brief C sigjmp_buf typedef type
|
||||
SPECIAL_TYPE_sigjmp_buf = 9,
|
||||
SPECIAL_TYPE_sigjmp_buf = 8,
|
||||
/// \brief Objective-C "id" redefinition type
|
||||
SPECIAL_TYPE_OBJC_ID_REDEFINITION = 10,
|
||||
SPECIAL_TYPE_OBJC_ID_REDEFINITION = 9,
|
||||
/// \brief Objective-C "Class" redefinition type
|
||||
SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 11,
|
||||
SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 10,
|
||||
/// \brief Objective-C "SEL" redefinition type
|
||||
SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 12,
|
||||
SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 11,
|
||||
/// \brief Whether __[u]int128_t identifier is installed.
|
||||
SPECIAL_TYPE_INT128_INSTALLED = 13
|
||||
SPECIAL_TYPE_INT128_INSTALLED = 12
|
||||
};
|
||||
|
||||
/// \brief Predefined declaration IDs.
|
||||
|
|
|
@ -223,7 +223,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
|
|||
SubstTemplateTemplateParmPacks(this_()),
|
||||
GlobalNestedNameSpecifier(0), IsInt128Installed(false),
|
||||
CFConstantStringTypeDecl(0),
|
||||
ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0),
|
||||
FILEDecl(0),
|
||||
jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0),
|
||||
BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0),
|
||||
NullTypeSourceInfo(QualType()),
|
||||
|
@ -3639,40 +3639,6 @@ void ASTContext::setCFConstantStringType(QualType T) {
|
|||
CFConstantStringTypeDecl = Rec->getDecl();
|
||||
}
|
||||
|
||||
QualType ASTContext::getObjCFastEnumerationStateType() const {
|
||||
if (!ObjCFastEnumerationStateTypeDecl) {
|
||||
ObjCFastEnumerationStateTypeDecl =
|
||||
CreateRecordDecl(*this, TTK_Struct, TUDecl,
|
||||
&Idents.get("__objcFastEnumerationState"));
|
||||
ObjCFastEnumerationStateTypeDecl->startDefinition();
|
||||
|
||||
QualType FieldTypes[] = {
|
||||
UnsignedLongTy,
|
||||
getPointerType(ObjCIdTypedefType),
|
||||
getPointerType(UnsignedLongTy),
|
||||
getConstantArrayType(UnsignedLongTy,
|
||||
llvm::APInt(32, 5), ArrayType::Normal, 0)
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
FieldDecl *Field = FieldDecl::Create(*this,
|
||||
ObjCFastEnumerationStateTypeDecl,
|
||||
SourceLocation(),
|
||||
SourceLocation(), 0,
|
||||
FieldTypes[i], /*TInfo=*/0,
|
||||
/*BitWidth=*/0,
|
||||
/*Mutable=*/false,
|
||||
/*HasInit=*/false);
|
||||
Field->setAccess(AS_public);
|
||||
ObjCFastEnumerationStateTypeDecl->addDecl(Field);
|
||||
}
|
||||
|
||||
ObjCFastEnumerationStateTypeDecl->completeDefinition();
|
||||
}
|
||||
|
||||
return getTagDeclType(ObjCFastEnumerationStateTypeDecl);
|
||||
}
|
||||
|
||||
QualType ASTContext::getBlockDescriptorType() const {
|
||||
if (BlockDescriptorType)
|
||||
return getTagDeclType(BlockDescriptorType);
|
||||
|
@ -3829,12 +3795,6 @@ ASTContext::BuildByRefType(StringRef DeclName, QualType Ty) const {
|
|||
return getPointerType(getTagDeclType(T));
|
||||
}
|
||||
|
||||
void ASTContext::setObjCFastEnumerationStateType(QualType T) {
|
||||
const RecordType *Rec = T->getAs<RecordType>();
|
||||
assert(Rec && "Invalid ObjCFAstEnumerationStateType");
|
||||
ObjCFastEnumerationStateTypeDecl = Rec->getDecl();
|
||||
}
|
||||
|
||||
// This returns true if a type has been typedefed to BOOL:
|
||||
// typedef <type> BOOL;
|
||||
static bool isTypeTypedefedAsBOOL(QualType T) {
|
||||
|
|
|
@ -997,7 +997,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
|
|||
JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end");
|
||||
|
||||
// Fast enumeration state.
|
||||
QualType StateTy = getContext().getObjCFastEnumerationStateType();
|
||||
QualType StateTy = CGM.getObjCFastEnumerationStateType();
|
||||
llvm::Value *StatePtr = CreateMemTemp(StateTy, "state.ptr");
|
||||
EmitNullInitialization(StatePtr, StateTy);
|
||||
|
||||
|
|
|
@ -1925,6 +1925,41 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) {
|
|||
return GV;
|
||||
}
|
||||
|
||||
QualType CodeGenModule::getObjCFastEnumerationStateType() {
|
||||
if (ObjCFastEnumerationStateType.isNull()) {
|
||||
RecordDecl *D = CreateRecordDecl(Context, TTK_Struct,
|
||||
Context.getTranslationUnitDecl(),
|
||||
&Context.Idents.get("__objcFastEnumerationState"));
|
||||
D->startDefinition();
|
||||
|
||||
QualType FieldTypes[] = {
|
||||
Context.UnsignedLongTy,
|
||||
Context.getPointerType(Context.getObjCIdType()),
|
||||
Context.getPointerType(Context.UnsignedLongTy),
|
||||
Context.getConstantArrayType(Context.UnsignedLongTy,
|
||||
llvm::APInt(32, 5), ArrayType::Normal, 0)
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
FieldDecl *Field = FieldDecl::Create(Context,
|
||||
D,
|
||||
SourceLocation(),
|
||||
SourceLocation(), 0,
|
||||
FieldTypes[i], /*TInfo=*/0,
|
||||
/*BitWidth=*/0,
|
||||
/*Mutable=*/false,
|
||||
/*HasInit=*/false);
|
||||
Field->setAccess(AS_public);
|
||||
D->addDecl(Field);
|
||||
}
|
||||
|
||||
D->completeDefinition();
|
||||
ObjCFastEnumerationStateType = Context.getTagDeclType(D);
|
||||
}
|
||||
|
||||
return ObjCFastEnumerationStateType;
|
||||
}
|
||||
|
||||
/// GetStringForStringLiteral - Return the appropriate bytes for a
|
||||
/// string literal, properly padded to match the literal type.
|
||||
std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) {
|
||||
|
|
|
@ -300,6 +300,10 @@ class CodeGenModule : public CodeGenTypeCache {
|
|||
/// \brief The LLVM type corresponding to NSConstantString.
|
||||
llvm::StructType *NSConstantStringType;
|
||||
|
||||
/// \brief The type used to describe the state of a fast enumeration in
|
||||
/// Objective-C's for..in loop.
|
||||
QualType ObjCFastEnumerationStateType;
|
||||
|
||||
/// @}
|
||||
|
||||
/// Lazily create the Objective-C runtime
|
||||
|
@ -566,6 +570,10 @@ public:
|
|||
const char *GlobalName=0,
|
||||
unsigned Alignment=1);
|
||||
|
||||
/// \brief Retrieve the record type that describes the state of an
|
||||
/// Objective-C fast enumeration loop (for..in).
|
||||
QualType getObjCFastEnumerationStateType();
|
||||
|
||||
/// GetAddrOfCXXConstructor - Return the address of the constructor of the
|
||||
/// given type.
|
||||
llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor,
|
||||
|
|
|
@ -2976,9 +2976,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) {
|
|||
|
||||
if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING])
|
||||
Context->setCFConstantStringType(GetType(String));
|
||||
if (unsigned FastEnum
|
||||
= SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE])
|
||||
Context->setObjCFastEnumerationStateType(GetType(FastEnum));
|
||||
if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
|
||||
QualType FileType = GetType(File);
|
||||
if (FileType.isNull()) {
|
||||
|
|
|
@ -2934,7 +2934,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
|
|||
AddTypeRef(Context.getObjCProtoType(), SpecialTypes);
|
||||
AddTypeRef(Context.getObjCClassType(), SpecialTypes);
|
||||
AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
|
||||
AddTypeRef(Context.getRawObjCFastEnumerationStateType(), SpecialTypes);
|
||||
AddTypeRef(Context.getFILEType(), SpecialTypes);
|
||||
AddTypeRef(Context.getjmp_bufType(), SpecialTypes);
|
||||
AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);
|
||||
|
|
Загрузка…
Ссылка в новой задаче