]> granicus.if.org Git - clang/commitdiff
- Use Tok.isObjCAtKeyword instead of Tok.getIdentifierInfo()->getObjCKeywordID().
authorChris Lattner <sabre@nondot.org>
Thu, 27 Dec 2007 19:57:00 +0000 (19:57 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 27 Dec 2007 19:57:00 +0000 (19:57 +0000)
   The later fails if the token is not an identifier.
 - Replace tabs with spaces.
 - Various other cleanups.

Patch by Nico Weber!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45368 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseObjc.cpp
Parse/Parser.cpp
test/Parser/objc-try-catch-1.m

index a701d2fffb7188f9ea5a03c7af3fd7b63dd66e3c..5dcbde1d59f96c59aa49e6bee55b3916b60db14d 100644 (file)
@@ -192,7 +192,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
       return 0;
   }
   DeclTy *ClsType = Actions.ActOnStartClassInterface(
-                     atLoc, nameId, nameLoc, 
+                      atLoc, nameId, nameLoc, 
                       superClassId, superClassLoc, &ProtocolRefs[0], 
                       ProtocolRefs.size(), endProtoLoc, attrList);
             
@@ -223,7 +223,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
 ///     @optional
 ///
 void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
-                                       tok::ObjCKeywordKind contextKey) {
+                                        tok::ObjCKeywordKind contextKey) {
   llvm::SmallVector<DeclTy*, 32>  allMethods;
   llvm::SmallVector<DeclTy*, 16> allProperties;
   tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
@@ -239,14 +239,14 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
         break;
       } else if (ocKind == tok::objc_required) { // protocols only
         ConsumeToken();
-       MethodImplKind = ocKind;
-       if (contextKey != tok::objc_protocol)
-         Diag(AtLoc, diag::err_objc_protocol_required);
+        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);
+        MethodImplKind = ocKind;
+        if (contextKey != tok::objc_protocol)
+          Diag(AtLoc, diag::err_objc_protocol_optional);
       } else if (ocKind == tok::objc_property) {
         allProperties.push_back(ParseObjCPropertyDecl(interfaceDecl, AtLoc));
         continue;
@@ -327,9 +327,9 @@ void Parser::ParseObjCPropertyAttribute (ObjcDeclSpec &DS) {
         }
         else {
           Diag(loc, diag::err_expected_ident);
-         SkipUntil(tok::r_paren,true,true);
-         break;
-       }
+          SkipUntil(tok::r_paren,true,true);
+          break;
+        }
       }
       else {
         Diag(loc, diag::err_objc_expected_equal);    
@@ -409,7 +409,7 @@ Parser::DeclTy *Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl,
 ///     __attribute__((deprecated))
 ///
 Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, 
-                         tok::ObjCKeywordKind MethodImplKind) {
+                          tok::ObjCKeywordKind MethodImplKind) {
   assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
 
   tok::TokenKind methodType = Tok.getKind();  
@@ -501,7 +501,7 @@ bool Parser::isObjCPropertyAttribute() {
 ///
 void Parser::ParseObjcTypeQualifierList(ObjcDeclSpec &DS) {
   while (1) {
-    if (!Tok.is(tok::identifier))
+    if (Tok.isNot(tok::identifier))
       return;
     
     const IdentifierInfo *II = Tok.getIdentifierInfo();
@@ -587,7 +587,7 @@ Parser::TypeTy *Parser::ParseObjCTypeName(ObjcDeclSpec &DS) {
 Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
                                             tok::TokenKind mType,
                                             DeclTy *IDecl,
-                                           tok::ObjCKeywordKind MethodImplKind)
+                                            tok::ObjCKeywordKind MethodImplKind)
 {
   // Parse the return type.
   TypeTy *ReturnType = 0;
@@ -796,8 +796,8 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl,
     }
     ParseStructDeclaration(interfaceDecl, IvarDecls);
     for (unsigned i = 0; i < IvarDecls.size(); i++) {
-       AllIvarDecls.push_back(IvarDecls[i]);
-       AllVisibilities.push_back(visibility);
+      AllIvarDecls.push_back(IvarDecls[i]);
+      AllVisibilities.push_back(visibility);
     }
     IvarDecls.clear();
     
@@ -967,7 +967,7 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration(
     superClassLoc = ConsumeToken(); // Consume super class name
   }
   DeclTy *ImplClsType = Actions.ActOnStartClassImplementation(
-                                 atLoc, nameId, nameLoc,
+                                  atLoc, nameId, nameLoc,
                                   superClassId, superClassLoc);
   
   if (Tok.is(tok::l_brace)) // we have ivars
@@ -1127,7 +1127,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
     TryBody = Actions.ActOnNullStmt(Tok.getLocation());
   while (Tok.is(tok::at)) {
     SourceLocation AtCatchFinallyLoc = ConsumeToken();
-    if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_catch) {
+    if (Tok.isObjCAtKeyword(tok::objc_catch)) {
       StmtTy *FirstPart = 0;
       ConsumeToken(); // consume catch
       if (Tok.is(tok::l_paren)) {
@@ -1161,7 +1161,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
       }
       catch_or_finally_seen = true;
     }
-    else if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_finally) {
+    else if (Tok.isObjCAtKeyword(tok::objc_finally)) {
        ConsumeToken(); // consume finally
       StmtResult FinallyBody = ParseCompoundStatementBody();
       if (FinallyBody.isInvalid)
@@ -1478,7 +1478,7 @@ Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc)
         Diag(Tok, diag::err_expected_colon);
         break;
       }
-         nColons++;
+      nColons++;
       ConsumeToken(); // Eat the ':'.
       if (Tok.is(tok::r_paren))
         break;
index 732311d6c2d2df1bec73e5ad8264e7ca24fe6a16..2e15cbde04b2ac1c62132fb61fc8cc207bd1fef8 100644 (file)
@@ -374,8 +374,12 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() {
   // ObjC2 allows prefix attributes on class interfaces.
   if (getLang().ObjC2 && Tok.is(tok::at)) {
     SourceLocation AtLoc = ConsumeToken(); // the "@"
-    if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_interface)
-      return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()); 
+    if (!Tok.isObjCAtKeyword(tok::objc_interface)) {
+      Diag(Tok, diag::err_objc_expected_property_attr);//FIXME:better diagnostic
+      SkipUntil(tok::semi); // FIXME: better skip?
+      return 0;
+    }
+    return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()); 
   }
   
   // Parse the first declarator.
index 6a0acd13dcb3219d0ea5aae76db77db605d6828e..d6ad8d38ef7130685d92029413080f5c92fde304 100644 (file)
@@ -10,29 +10,43 @@ void * proc();
 
 void * foo()
 {
-        @try {
-                return proc();
-        }
-        @catch (Frob* ex) {
-                @throw;
-        }
-        @catch (Frob1* ex) {
-                @throw proc();
-        }
-        @finally {
-         @try {
-                return proc();
-          }
-          @catch (Frob* ex) {
-                @throw 1,2;
-          }
-         @catch(...) {
-           @throw (4,3,proc());
-         }
-        }
-
-       @try {  // expected-error {{@try statment without a @catch and @finally clause}}
-                return proc();
-        }
+  @try {
+    return proc();
+  }
+  @catch (Frob* ex) {
+    @throw;
+  }
+  @catch (Frob1* ex) {
+    @throw proc();
+  }
+  @finally {
+    @try {
+      return proc();
+    }
+    @catch (Frob* ex) {
+      @throw 1,2;
+    }
+    @catch(...) {
+      @throw (4,3,proc());
+    }
+  }
+
+  @try {  // expected-error {{@try statment without a @catch and @finally clause}}
+    return proc();
+  }
+}
+
+
+void bar()
+{
+  @try {}// expected-error {{@try statment without a @catch and @finally clause}}
+  @"s" {} //  expected-warning {{result unused}} expected-error {{expected ';'}}
+}
+
+void baz()
+{
+  @try {}// expected-error {{@try statment without a @catch and @finally clause}}
+  @try {}// expected-error {{undeclared identifier}}
+  @finally {}
 }