From: Anders Carlsson Date: Thu, 23 Aug 2007 15:25:28 +0000 (+0000) Subject: Parse ObjC @protocol expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29b2cb1ff1a3dd78edd38e2f43ee7041d3e4ec3c;p=clang Parse ObjC @protocol expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41320 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 4f4bdfe012..b1c5366197 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -634,9 +634,15 @@ Parser::ExprResult Parser::ParseObjCExpression() { case tok::string_literal: // primary-expression: string-literal case tok::wide_string_literal: return ParseObjCStringLiteral(); + default: + break; + } + + switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { case tok::objc_encode: return ParseObjCEncodeExpression(); - break; + case tok::objc_protocol: + return ParseObjCProtocolExpression(); default: Diag(AtLoc, diag::err_unexpected_at); SkipUntil(tok::semi); @@ -679,3 +685,36 @@ Parser::ExprResult Parser::ParseObjCEncodeExpression() { return Actions.ParseObjCEncodeExpression(EncLoc, LParenLoc, Ty, ConsumeParen()); } + +/// objc-protocol-expression +/// @protocol ( protocol-name ) + +Parser::ExprResult Parser::ParseObjCProtocolExpression() +{ + SourceLocation ProtoLoc = ConsumeToken(); + + if (Tok.getKind() != tok::l_paren) { + Diag(Tok, diag::err_expected_lparen_after, "@protocol"); + return true; + } + + SourceLocation LParenLoc = ConsumeParen(); + + if (Tok.getKind() != tok::identifier) { + Diag(Tok, diag::err_expected_ident); + return true; + } + + // FIXME: Do something with the protocol name + ConsumeToken(); + + if (Tok.getKind() != tok::r_paren) { + Diag(Tok, diag::err_expected_rparen); + return true; + } + + ConsumeParen(); + + // FIXME + return 0; +} diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 19e984ce33..7e38e051dd 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -206,7 +206,7 @@ 1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGBuiltin.cpp; path = CodeGen/CGBuiltin.cpp; sourceTree = ""; }; 84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = ""; }; 84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = ""; }; - 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; + 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = ""; }; DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = ""; }; DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = ""; }; diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 90988791de..97c0ca1d45 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -336,6 +336,7 @@ private: ExprResult ParseObjCExpression(); ExprResult ParseObjCStringLiteral(); ExprResult ParseObjCEncodeExpression(); + ExprResult ParseObjCProtocolExpression(); //===--------------------------------------------------------------------===// // C99 6.8: Statements and Blocks.