Patch for collecting ivars before running action on them.

llvm-svn: 41932
This commit is contained in:
Fariborz Jahanian 2007-09-13 20:56:13 +00:00
parent 9324db12b2
commit 6812cbb230
5 changed files with 44 additions and 28 deletions

View File

@ -606,9 +606,12 @@ bool Parser::ParseObjCProtocolReferences(
void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
assert(Tok.getKind() == tok::l_brace && "expected {");
llvm::SmallVector<DeclTy*, 16> IvarDecls;
llvm::SmallVector<DeclTy*, 32> AllIvarDecls;
llvm::SmallVector<tok::ObjCKeywordKind, 32> AllVisibilities;
SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
tok::ObjCKeywordKind visibility = tok::objc_private;
// While we still have something to read, read the instance variables.
while (Tok.getKind() != tok::r_brace &&
Tok.getKind() != tok::eof) {
@ -621,7 +624,6 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
continue;
}
// Set the default visibility to private.
tok::ObjCKeywordKind visibility = tok::objc_private;
if (Tok.getKind() == tok::at) { // parse objc-visibility-spec
ConsumeToken(); // eat the @ sign
switch (Tok.getObjCKeywordID()) {
@ -639,8 +641,10 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
}
}
ParseStructDeclaration(interfaceDecl, IvarDecls);
for (unsigned i = 0; i < IvarDecls.size(); i++)
Actions.ObjcAddInstanceVariable(interfaceDecl, IvarDecls[i], visibility);
for (unsigned i = 0; i < IvarDecls.size(); i++) {
AllIvarDecls.push_back(IvarDecls[i]);
AllVisibilities.push_back(visibility);
}
IvarDecls.clear();
if (Tok.getKind() == tok::semi) {
@ -654,6 +658,10 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
SkipUntil(tok::r_brace, true, true);
}
}
if (AllIvarDecls.size()) { // Check for {} - no ivars in braces
Actions.ObjcAddInstanceVariable(interfaceDecl,
&AllIvarDecls[0], AllIvarDecls.size(), &AllVisibilities[0]);
}
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
return;
}

View File

@ -369,8 +369,9 @@ public:
tok::TokenKind MethodType, TypeTy *ReturnType,
IdentifierInfo *SelectorName, AttributeList *AttrList);
virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy *Ivar,
tok::ObjCKeywordKind visibility);
virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy **Ivar,
unsigned numIvars,
tok::ObjCKeywordKind *visibility);
private:
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
// functions and arrays to their respective pointers (C99 6.3.2.1).

View File

@ -875,31 +875,36 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(SourceLocation AtInterfaceLoc,
return IDecl;
}
void Sema::ObjcAddInstanceVariable(DeclTy *ClassDecl, DeclTy *Ivar,
tok::ObjCKeywordKind visibility) {
assert((ClassDecl && Ivar) && "missing class or instance variable");
void Sema::ObjcAddInstanceVariable(DeclTy *ClassDecl, DeclTy **Ivar,
unsigned numIvars,
tok::ObjCKeywordKind *visibility) {
assert((ClassDecl && numIvars) && "missing class or instance variable");
ObjcInterfaceDecl *OInterface = dyn_cast<ObjcInterfaceDecl>(
static_cast<Decl *>(ClassDecl));
ObjcIvarDecl *OIvar = dyn_cast<ObjcIvarDecl>(static_cast<Decl *>(Ivar));
assert (OInterface && "mistyped class");
for (unsigned i = 0; i != numIvars; ++i) {
ObjcIvarDecl *OIvar = dyn_cast<ObjcIvarDecl>(static_cast<Decl *>(Ivar[i]));
tok::ObjCKeywordKind ivarVisibility = visibility[i];
assert((OInterface && OIvar) && "mistyped class or instance variable");
assert(OIvar && "mistyped instance variable");
switch (visibility) {
case tok::objc_private:
OIvar->setAccessControl(ObjcIvarDecl::Private);
break;
case tok::objc_public:
OIvar->setAccessControl(ObjcIvarDecl::Public);
break;
case tok::objc_protected:
OIvar->setAccessControl(ObjcIvarDecl::Protected);
break;
case tok::objc_package:
OIvar->setAccessControl(ObjcIvarDecl::Package);
break;
default:
OIvar->setAccessControl(ObjcIvarDecl::None);
break;
switch (ivarVisibility) {
case tok::objc_private:
OIvar->setAccessControl(ObjcIvarDecl::Private);
break;
case tok::objc_public:
OIvar->setAccessControl(ObjcIvarDecl::Public);
break;
case tok::objc_protected:
OIvar->setAccessControl(ObjcIvarDecl::Protected);
break;
case tok::objc_package:
OIvar->setAccessControl(ObjcIvarDecl::Package);
break;
default:
OIvar->setAccessControl(ObjcIvarDecl::None);
break;
}
}
// FIXME: add to the class...
}

View File

@ -675,6 +675,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";

View File

@ -449,8 +449,9 @@ public:
AttributeList *AttrList) {
return 0;
}
virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy *Ivars,
tok::ObjCKeywordKind visibility) {
virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy **Ivars,
unsigned numIvars,
tok::ObjCKeywordKind *visibility) {
return;
}
virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,