From: Chris Lattner Date: Mon, 20 Oct 2008 05:46:22 +0000 (+0000) Subject: restructure the body of the ParseObjCInterfaceDeclList loop X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e82a10fbba9e33b253119c7c1e0a9801caef486d;p=clang restructure the body of the ParseObjCInterfaceDeclList loop to make it easier to understand. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57797 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 0222b0401a..16fab37e48 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -249,68 +249,7 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, SourceLocation AtEndLoc; while (1) { - if (Tok.is(tok::at)) { - SourceLocation AtLoc = ConsumeToken(); // the "@" - tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID(); - - if (ocKind == tok::objc_end) { // terminate list - AtEndLoc = AtLoc; - break; - } else if (ocKind == tok::objc_required) { // protocols only - ConsumeToken(); - MethodImplKind = ocKind; - if (contextKey != tok::objc_protocol) - Diag(AtLoc, diag::err_objc_protocol_required); - } else if (ocKind == tok::objc_optional) { // protocols only - ConsumeToken(); - MethodImplKind = ocKind; - if (contextKey != tok::objc_protocol) - Diag(AtLoc, diag::err_objc_protocol_optional); - } else if (ocKind == tok::objc_property) { - ObjCDeclSpec OCDS; - ConsumeToken(); // the "property" identifier - // Parse property attribute list, if any. - if (Tok.is(tok::l_paren)) { - // property has attribute list. - ParseObjCPropertyAttribute(OCDS); - } - // Parse all the comma separated declarators. - DeclSpec DS; - llvm::SmallVector FieldDeclarators; - ParseStructDeclaration(DS, FieldDeclarators); - - if (Tok.is(tok::semi)) - ConsumeToken(); - else { - Diag(Tok, diag::err_expected_semi_decl_list); - SkipUntil(tok::r_brace, true, true); - } - // Convert them all to property declarations. - for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { - FieldDeclarator &FD = FieldDeclarators[i]; - // Install the property declarator into interfaceDecl. - Selector GetterSel = - PP.getSelectorTable().getNullarySelector(OCDS.getGetterName() - ? OCDS.getGetterName() - : FD.D.getIdentifier()); - IdentifierInfo *SetterName = OCDS.getSetterName(); - if (!SetterName) - SetterName = constructSetterName(PP.getIdentifierTable(), - FD.D.getIdentifier()); - Selector SetterSel = - PP.getSelectorTable().getUnarySelector(SetterName); - DeclTy *Property = Actions.ActOnProperty(CurScope, - AtLoc, FD, OCDS, - GetterSel, SetterSel, - MethodImplKind); - allProperties.push_back(Property); - } - continue; - } else { - Diag(Tok, diag::err_objc_illegal_interface_qual); - ConsumeToken(); - } - } + // If this is a method prototype, parse it. if (Tok.is(tok::minus) || Tok.is(tok::plus)) { DeclTy *methodPrototype = ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); @@ -320,17 +259,88 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, ExpectAndConsume(tok::semi, diag::err_expected_semi_after,"method proto"); continue; } - else if (Tok.is(tok::at)) - continue; - if (Tok.is(tok::semi)) + // Ignore excess semicolons. + if (Tok.is(tok::semi)) { ConsumeToken(); - else if (Tok.is(tok::eof)) + continue; + } + + // If we got to the end of the file, pretend that we saw an @end. + // FIXME: Should this be a warning? + if (Tok.is(tok::eof)) break; - else { + + // If we don't have an @ directive, parse it as a function definition. + if (Tok.isNot(tok::at)) { // FIXME: as the name implies, this rule allows function definitions. // We could pass a flag or check for functions during semantic analysis. ParseDeclarationOrFunctionDefinition(); + continue; + } + + // Otherwise, we have an @ directive, eat the @. + SourceLocation AtLoc = ConsumeToken(); // the "@" + tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID(); + + if (ocKind == tok::objc_end) { // @end -> terminate list + AtEndLoc = AtLoc; + break; + } + + if (ocKind == tok::objc_required) { // protocols only + ConsumeToken(); + MethodImplKind = ocKind; + if (contextKey != tok::objc_protocol) + Diag(AtLoc, diag::err_objc_protocol_required); + } else if (ocKind == tok::objc_optional) { // protocols only + ConsumeToken(); + MethodImplKind = ocKind; + if (contextKey != tok::objc_protocol) + Diag(AtLoc, diag::err_objc_protocol_optional); + } else if (ocKind == tok::objc_property) { + ObjCDeclSpec OCDS; + ConsumeToken(); // the "property" identifier + // Parse property attribute list, if any. + if (Tok.is(tok::l_paren)) { + // property has attribute list. + ParseObjCPropertyAttribute(OCDS); + } + // Parse all the comma separated declarators. + DeclSpec DS; + llvm::SmallVector FieldDeclarators; + ParseStructDeclaration(DS, FieldDeclarators); + + if (Tok.is(tok::semi)) + ConsumeToken(); + else { + Diag(Tok, diag::err_expected_semi_decl_list); + SkipUntil(tok::r_brace, true, true); + } + // Convert them all to property declarations. + for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { + FieldDeclarator &FD = FieldDeclarators[i]; + // Install the property declarator into interfaceDecl. + Selector GetterSel = + PP.getSelectorTable().getNullarySelector(OCDS.getGetterName() + ? OCDS.getGetterName() + : FD.D.getIdentifier()); + IdentifierInfo *SetterName = OCDS.getSetterName(); + if (!SetterName) + SetterName = constructSetterName(PP.getIdentifierTable(), + FD.D.getIdentifier()); + Selector SetterSel = + PP.getSelectorTable().getUnarySelector(SetterName); + DeclTy *Property = Actions.ActOnProperty(CurScope, + AtLoc, FD, OCDS, + GetterSel, SetterSel, + MethodImplKind); + allProperties.push_back(Property); + } + continue; + } else { + Diag(Tok, diag::err_objc_illegal_interface_qual); + ConsumeToken(); } } /// Insert collected methods declarations into the @interface object.