aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-08-21 21:17:12 +0000
committerSteve Naroff <snaroff@apple.com>2007-08-21 21:17:12 +0000
commitddbff78fb719a645b04bd27099fa6ec8c4693b3c (patch)
tree17c750498554d405f6b50a56a2f637a4c3ee712f
parente98a11c70483b924f558ead1ae24fd6fd70c7df3 (diff)
Implement parsing for objc instance variables.
Next step, method... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41251 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Parse/ParseObjc.cpp57
-rw-r--r--include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--include/clang/Basic/TokenKinds.def1
-rw-r--r--include/clang/Parse/Parser.h2
4 files changed, 58 insertions, 4 deletions
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index e093f19c2c..94a5c8d42c 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -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:
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 979128057d..24b8fbbe72 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -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
diff --git a/include/clang/Basic/TokenKinds.def b/include/clang/Basic/TokenKinds.def
index 699b17b194..1f52c5ba2a 100644
--- a/include/clang/Basic/TokenKinds.def
+++ b/include/clang/Basic/TokenKinds.def
@@ -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?
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index cacb78fe11..02c2ee70f3 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -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();