diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-01-16 23:00:23 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-01-16 23:00:23 +0000 |
commit | d329724745b49f894b768d47275b7c2713106e89 (patch) | |
tree | 54fc9308cb83f0062cdccb86488b9c96a58fa36a /lib/Serialization | |
parent | 804381d8ce78f60c40dd59f5a0b468a7de78b025 (diff) |
Rework the traversal of Objective-C categories and extensions to
consider (sub)module visibility.
The bulk of this change replaces myriad hand-rolled loops over the
linked list of Objective-C categories/extensions attached to an
interface declaration with loops using one of the four new category
iterator kinds:
visible_categories_iterator: Iterates over all visible categories
and extensions, hiding any that have their "hidden" bit set. This is
by far the most commonly used iterator.
known_categories_iterator: Iterates over all categories and
extensions, ignoring the "hidden" bit. This tends to be used for
redeclaration-like traversals.
visible_extensions_iterator: Iterates over all visible extensions,
hiding any that have their "hidden" bit set.
known_extensions_iterator: Iterates over all extensions, whether
they are visible to normal name lookup or not.
The effect of this change is that any uses of the visible_ iterators
will respect module-import visibility. See the new tests for examples.
Note that the old accessors for categories and extensions are gone;
there are *Raw() forms for some of them, for those (few) areas of the
compiler that have to manipulate the linked list of categories
directly. This is generally discouraged.
Part two of <rdar://problem/10634711>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172665 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 12 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 10 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterDecl.cpp | 5 |
3 files changed, 16 insertions, 11 deletions
diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 32179798ea..9f8268adee 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -2404,7 +2404,7 @@ namespace { if (Tail) ASTDeclReader::setNextObjCCategory(Tail, Cat); else - Interface->setCategoryList(Cat); + Interface->setCategoryListRaw(Cat); Tail = Cat; } @@ -2419,13 +2419,15 @@ namespace { Tail(0) { // Populate the name -> category map with the set of known categories. - for (ObjCCategoryDecl *Cat = Interface->getCategoryList(); Cat; - Cat = Cat->getNextClassCategory()) { + for (ObjCInterfaceDecl::known_categories_iterator + Cat = Interface->known_categories_begin(), + CatEnd = Interface->known_categories_end(); + Cat != CatEnd; ++Cat) { if (Cat->getDeclName()) - NameCategoryMap[Cat->getDeclName()] = Cat; + NameCategoryMap[Cat->getDeclName()] = *Cat; // Keep track of the tail of the category list. - Tail = Cat; + Tail = *Cat; } } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 67e03c2334..8c14b5f395 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3238,10 +3238,12 @@ void ASTWriter::WriteObjCCategories() { Categories.push_back(0); // Add the categories. - for (ObjCCategoryDecl *Cat = Class->getCategoryList(); - Cat; Cat = Cat->getNextClassCategory(), ++Size) { - assert(getDeclID(Cat) != 0 && "Bogus category"); - AddDeclRef(Cat, Categories); + for (ObjCInterfaceDecl::known_categories_iterator + Cat = Class->known_categories_begin(), + CatEnd = Class->known_categories_end(); + Cat != CatEnd; ++Cat, ++Size) { + assert(getDeclID(*Cat) != 0 && "Bogus category"); + AddDeclRef(*Cat, Categories); } // Update the size. diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index bc92fb714a..7a57bad736 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -491,13 +491,14 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { PEnd = Data.AllReferencedProtocols.end(); P != PEnd; ++P) Writer.AddDeclRef(*P, Record); + - if (ObjCCategoryDecl *Cat = D->getCategoryList()) { + if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) { // Ensure that we write out the set of categories for this class. Writer.ObjCClassesWithCategories.insert(D); // Make sure that the categories get serialized. - for (; Cat; Cat = Cat->getNextClassCategory()) + for (; Cat; Cat = Cat->getNextClassCategoryRaw()) (void)Writer.GetDeclRef(Cat); } } |