}
/// getRecordLayoutInfo - Return record layout info.
-RecordLayoutInfo *CodeGenFunction::getRecordLayoutInfo(CodeGenTypes &CGT,
+const RecordLayoutInfo *CodeGenFunction::getRecordLayoutInfo(CodeGenTypes &CGT,
QualType RTy) {
assert (isa<RecordType>(RTy)
&& "Unexpected type. RecordType expected here.");
void StartBlock(const char *N);
/// getRecordLayoutInfo - Return record layout info.
- RecordLayoutInfo *getRecordLayoutInfo(CodeGenTypes &CGT, QualType RTy);
+ const RecordLayoutInfo *getRecordLayoutInfo(CodeGenTypes &CGT, QualType RTy);
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//
RecordTypesToResolve[RD] = OpaqueTy;
// Layout fields.
- RecordOrganizer *RO = new RecordOrganizer();
+ RecordOrganizer RO;
for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
- RO->addField(RD->getMember(i));
- RO->layoutFields(*this);
+ RO.addField(RD->getMember(i));
+ RO.layoutFields(*this);
// Get llvm::StructType.
- RecordLayoutInfo *RLI = new RecordLayoutInfo(RO);
+ RecordLayoutInfo *RLI = new RecordLayoutInfo(&RO);
ResultType = RLI->getLLVMType();
RecordLayouts[ResultType] = RLI;
&& "Expected RecordDecl in RecordTypesToResolve");
RecordTypesToResolve.erase(OpaqueI);
- delete RO;
+ RO.clear();
} else if (TD->getKind() == Decl::Union) {
const RecordDecl *RD = cast<const RecordDecl>(TD);
// Just use the largest element of the union, breaking ties with the
return I->second;
}
- /// addFieldInfo - Assign field number to field FD.
+/// addFieldInfo - Assign field number to field FD.
void CodeGenTypes::addFieldInfo(const FieldDecl *FD, unsigned No) {
FieldInfo[FD] = No;
}
/// getRecordLayoutInfo - Return record layout info for the given llvm::Type.
-RecordLayoutInfo *CodeGenTypes::getRecordLayoutInfo(const llvm::Type* Ty) {
+const RecordLayoutInfo *
+CodeGenTypes::getRecordLayoutInfo(const llvm::Type* Ty) const {
llvm::DenseMap<const llvm::Type*, RecordLayoutInfo *>::iterator I
= RecordLayouts.find(Ty);
assert (I != RecordLayouts.end()
}
STy = llvm::StructType::get(Fields);
}
+
+/// Clear private data so that this object can be reused.
+void RecordOrganizer::clear() {
+ STy = NULL;
+ FieldDecls.clear();
+}
/// getLLVMType - Return associated llvm struct type. This may be NULL
/// if fields are not laid out.
- llvm::Type *getLLVMType() {
+ llvm::Type *getLLVMType() const {
return STy;
}
+ /// Clear private data so that this object can be reused.
+ void clear();
private:
llvm::Type *STy;
llvm::SmallVector<const FieldDecl *, 8> FieldDecls;
RecordLayoutInfo(RecordOrganizer *RO);
/// getLLVMType - Return llvm type associated with this record.
- llvm::Type *getLLVMType() {
+ llvm::Type *getLLVMType() const {
return STy;
}
void DecodeArgumentTypes(const FunctionTypeProto &FTP,
std::vector<const llvm::Type*> &ArgTys);
- RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*);
+ const RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*) const;
/// getLLVMFieldNo - Return llvm::StructType element number
/// that corresponds to the field FD.