- Added Sema::AddFactoryMethodToGlobalPool and Sema::AddInstanceMethodToGlobalPool and DenseMaps. This will allow us to efficiently lookup a method from a selector given no type information (for the "id" data type).
- Fixed some funky "}
else {" indentation in Sema::ActOnAddMethodsToObjcDecl(). I'd prefer we stay away from this style...it wastes space and isn't any easier to read (from my perspective, at least:-)
- Changed Parser::ParseObjCInterfaceDeclList() to only call Action::ActOnAddMethodsToObjcDecl() when it actually has methods to add (since most interface have methods, this is a very minor cleanup).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42957 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 511b43a..94d22f0 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -120,6 +120,27 @@
/// ObjcIdTypedef - built-in typedef for "id".
TypedefDecl *ObjcIdTypedef;
+
+ /// ObjCMethodList - a linked list of methods with different signatures.
+ struct ObjcMethodList {
+ ObjcMethodDecl *Method;
+ ObjcMethodList *Next;
+
+ ObjcMethodList() {
+ Method = 0;
+ Next = 0;
+ }
+ ObjcMethodList(ObjcMethodDecl *M, ObjcMethodList *C) {
+ Method = M;
+ Next = C;
+ }
+ };
+ /// Instance/Factory Method Pools - allows efficient lookup when typechecking
+ /// messages to "id". We need to maintain a list, since selectors can have
+ /// differing signatures across classes. In Cocoa, this happens to be
+ /// extremely uncommon (only 1% of selectors are "overloaded").
+ llvm::DenseMap<Selector, ObjcMethodList> InstanceMethodPool;
+ llvm::DenseMap<Selector, ObjcMethodList> FactoryMethodPool;
public:
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
@@ -259,6 +280,14 @@
/// GetObjcIdType - Getter for the build-in "id" type.
QualType GetObjcIdType(SourceLocation Loc = SourceLocation());
+ /// AddInstanceMethodToGlobalPool - All instance methods in a translation
+ /// unit are added to a global pool. This allows us to efficiently associate
+ /// a selector with a method declaraation for purposes of typechecking
+ /// messages sent to "id" (where the class of the object is unknown).
+ void AddInstanceMethodToGlobalPool(ObjcMethodDecl *Method);
+
+ /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
+ void AddFactoryMethodToGlobalPool(ObjcMethodDecl *Method);
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks: SemaStmt.cpp.
public: