From 44b4321feab46299d3f5cfd404680884752a0fcf Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 11 Dec 2008 16:49:14 +0000 Subject: Unifies the name-lookup mechanisms used in various parts of the AST and separates lexical name lookup from qualified name lookup. In particular: * Make DeclContext the central data structure for storing and looking up declarations within existing declarations, e.g., members of structs/unions/classes, enumerators in C++0x enums, members of C++ namespaces, and (later) members of Objective-C interfaces/implementations. DeclContext uses a lazily-constructed data structure optimized for fast lookup (array for small contexts, hash table for larger contexts). * Implement C++ qualified name lookup in terms of lookup into DeclContext. * Implement C++ unqualified name lookup in terms of qualified+unqualified name lookup (since unqualified lookup is not purely lexical in C++!) * Limit the use of the chains of declarations stored in IdentifierInfo to those names declared lexically. * Eliminate CXXFieldDecl, collapsing its behavior into FieldDecl. (FieldDecl is now a ScopedDecl). * Make RecordDecl into a DeclContext and eliminates its Members/NumMembers fields (since one can just iterate through the DeclContext to get the fields). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60878 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'lib/CodeGen/CodeGenTypes.cpp') diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 85b10399a4..8918671332 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -392,7 +392,7 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { } else if (TD->isUnion()) { // Just use the largest element of the union, breaking ties with the // highest aligned member. - if (RD->getNumMembers() != 0) { + if (RD->field_begin() != RD->field_end()) { RecordOrganizer RO(*this, *RD); RO.layoutUnionFields(Context.getASTRecordLayout(RD)); @@ -478,16 +478,17 @@ void RecordOrganizer::layoutStructFields(const ASTRecordLayout &RL) { uint64_t llvmSize = 0; // FIXME: Make this a SmallVector std::vector LLVMFields; - int NumMembers = RD.getNumMembers(); - for (int curField = 0; curField < NumMembers; curField++) { - const FieldDecl *FD = RD.getMember(curField); + unsigned curField = 0; + for (RecordDecl::field_iterator Field = RD.field_begin(), + FieldEnd = RD.field_end(); + Field != FieldEnd; ++Field) { uint64_t offset = RL.getFieldOffset(curField); - const llvm::Type *Ty = CGT.ConvertTypeRecursive(FD->getType()); + const llvm::Type *Ty = CGT.ConvertTypeRecursive(Field->getType()); uint64_t size = CGT.getTargetData().getABITypeSizeInBits(Ty); - if (FD->isBitField()) { - Expr *BitWidth = FD->getBitWidth(); + if (Field->isBitField()) { + Expr *BitWidth = Field->getBitWidth(); llvm::APSInt FieldSize(32); bool isBitField = BitWidth->isIntegerConstantExpr(FieldSize, CGT.getContext()); @@ -498,8 +499,8 @@ void RecordOrganizer::layoutStructFields(const ASTRecordLayout &RL) { // Bitfield field info is different from other field info; // it actually ignores the underlying LLVM struct because // there isn't any convenient mapping. - CGT.addFieldInfo(FD, offset / size); - CGT.addBitFieldInfo(FD, offset % size, BitFieldSize); + CGT.addFieldInfo(*Field, offset / size); + CGT.addBitFieldInfo(*Field, offset % size, BitFieldSize); } else { // Put the element into the struct. This would be simpler // if we didn't bother, but it seems a bit too strange to @@ -510,9 +511,10 @@ void RecordOrganizer::layoutStructFields(const ASTRecordLayout &RL) { } llvmSize += size; - CGT.addFieldInfo(FD, LLVMFields.size()); + CGT.addFieldInfo(*Field, LLVMFields.size()); LLVMFields.push_back(Ty); } + ++curField; } while (llvmSize < RL.getSize()) { @@ -528,21 +530,24 @@ void RecordOrganizer::layoutStructFields(const ASTRecordLayout &RL) { /// corresponding llvm struct type. This should be invoked only after /// all fields are added. void RecordOrganizer::layoutUnionFields(const ASTRecordLayout &RL) { - for (int curField = 0; curField < RD.getNumMembers(); curField++) { - const FieldDecl *FD = RD.getMember(curField); + unsigned curField = 0; + for (RecordDecl::field_iterator Field = RD.field_begin(), + FieldEnd = RD.field_end(); + Field != FieldEnd; ++Field) { // The offset should usually be zero, but bitfields could be strange uint64_t offset = RL.getFieldOffset(curField); - if (FD->isBitField()) { - Expr *BitWidth = FD->getBitWidth(); + if (Field->isBitField()) { + Expr *BitWidth = Field->getBitWidth(); uint64_t BitFieldSize = BitWidth->getIntegerConstantExprValue(CGT.getContext()).getZExtValue(); - CGT.addFieldInfo(FD, 0); - CGT.addBitFieldInfo(FD, offset, BitFieldSize); + CGT.addFieldInfo(*Field, 0); + CGT.addBitFieldInfo(*Field, offset, BitFieldSize); } else { - CGT.addFieldInfo(FD, 0); + CGT.addFieldInfo(*Field, 0); } + ++curField; } // This looks stupid, but it is correct in the sense that -- cgit v1.2.3-70-g09d2