]> granicus.if.org Git - clang/commitdiff
Implement parsing for objc instance variables.
authorSteve Naroff <snaroff@apple.com>
Tue, 21 Aug 2007 21:17:12 +0000 (21:17 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 21 Aug 2007 21:17:12 +0000 (21:17 +0000)
Next step, method...

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

Parse/ParseObjc.cpp
include/clang/Basic/DiagnosticKinds.def
include/clang/Basic/TokenKinds.def
include/clang/Parse/Parser.h

index e093f19c2c92686d5ce784ec5daa3f45ce0c972b..94a5c8d42cb0138dab8a6f9f6ff9ed7e734ab7b3 100644 (file)
@@ -179,8 +179,9 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
     if (ParseObjCProtocolReferences())
       return 0;
   }
+  // FIXME: add Actions.StartObjCClassInterface(nameId, superClassId, ...)
   if (Tok.getKind() == tok::l_brace)
-    ParseObjCClassInstanceVariables();
+    ParseObjCClassInstanceVariables(0/*FIXME*/);
 
   //ParseObjCInterfaceDeclList();
   
@@ -249,12 +250,62 @@ bool Parser::ParseObjCProtocolReferences() {
 ///     @private
 ///     @protected
 ///     @public
+///     @package [OBJC2]
 ///
 ///   objc-instance-variable-decl:
 ///     struct-declaration 
 ///
-void Parser::ParseObjCClassInstanceVariables() {
-  assert(0 && "Unimp");
+void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
+  assert(Tok.getKind() == tok::l_brace && "expected {");
+  
+  SourceLocation LBraceLoc = ConsumeBrace(); // the "{"
+  llvm::SmallVector<DeclTy*, 32> IvarDecls;
+  
+  // While we still have something to read, read the instance variables.
+  while (Tok.getKind() != tok::r_brace && 
+         Tok.getKind() != tok::eof) {
+    // Each iteration of this loop reads one objc-instance-variable-decl.
+    
+    // Check for extraneous top-level semicolon.
+    if (Tok.getKind() == tok::semi) {
+      Diag(Tok, diag::ext_extra_struct_semi);
+      ConsumeToken();
+      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
+      IdentifierInfo *specId = Tok.getIdentifierInfo();
+      switch (specId->getObjCKeywordID()) {
+      case tok::objc_private:
+      case tok::objc_public:
+      case tok::objc_protected:
+      case tok::objc_package:
+        visibility = specId->getObjCKeywordID();
+        ConsumeToken();
+        continue; 
+      default:
+        Diag(Tok, diag::err_objc_illegal_visibility_spec);
+        ConsumeToken();
+        continue;
+      }
+    }
+    ParseStructDeclaration(interfaceDecl, IvarDecls);
+
+    if (Tok.getKind() == tok::semi) {
+      ConsumeToken();
+    } else if (Tok.getKind() == tok::r_brace) {
+      Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list);
+      break;
+    } else {
+      Diag(Tok, diag::err_expected_semi_decl_list);
+      // Skip to end of block or statement
+      SkipUntil(tok::r_brace, true, true);
+    }
+  }
+  MatchRHSPunctuation(tok::r_brace, LBraceLoc);
+  return;
 }
 
 ///   objc-protocol-declaration:
index 979128057d276311eaf9e4725ae014c82e29281c..24b8fbbe72223cb79889ddb9a66895426a9bd0ac 100644 (file)
@@ -382,6 +382,8 @@ DIAG(err_objc_no_attributes_on_category, ERROR,
      "attributes may not be specified on a category")
 DIAG(err_objc_missing_end, ERROR,
      "missing @end")
+DIAG(err_objc_illegal_visibility_spec, ERROR,
+     "illegal visibility specification")
 
 //===----------------------------------------------------------------------===//
 // Semantic Analysis
index 699b17b1947eb7a3b33090219476b3329ad3680d..1f52c5ba2a6eb99f055299430644da0010c5dce5 100644 (file)
@@ -349,6 +349,7 @@ OBJC1_AT_KEYWORD(synchronized)
 
 // I'm guessing this is an objc2 keyword, what are the others?
 OBJC2_AT_KEYWORD(property)
+OBJC2_AT_KEYWORD(package)
 
 // TODO: What to do about context-sensitive keywords like:
 //       bycopy/byref/in/inout/oneway/out?
index cacb78fe11f2e76828ba40d6608e2e0a3a31697e..02c2ee70f38608fdcffa3534720e82fb2d3e9036 100644 (file)
@@ -258,7 +258,7 @@ private:
   DeclTy *ParseObjCAtClassDeclaration(SourceLocation atLoc);
   DeclTy *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, 
                                           AttributeList *prefixAttrs = 0);
-  void ParseObjCClassInstanceVariables();
+  void ParseObjCClassInstanceVariables(DeclTy *interfaceDecl);
   bool ParseObjCProtocolReferences();
   void ParseObjCInterfaceDeclList();
   DeclTy *ParseObjCAtProtocolDeclaration();