[cfe-commits] r42050 - in /cfe/trunk: Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/Parse/Action.h include/clang/Parse/DeclSpec.h
Steve Naroff
snaroff at apple.com
Mon Sep 17 13:25:27 PDT 2007
Author: snaroff
Date: Mon Sep 17 15:25:27 2007
New Revision: 42050
URL: http://llvm.org/viewvc/llvm-project?rev=42050&view=rev
Log:
- Refactored ObjcKeywordInfo into ObjcKeywordInfo, ObjcKeywordDecl, and ObjcKeywordMessage.
- Removed helper ObjcGetSelectorInfo(), moving the code directly into ObjcBuildMethodDeclaration().
- Many refinements to ParseObjCMessageExpression().
- Add ActOnMessageExpression().
Next step, finish the message actions and (finally) create/instantiate an ObjcMessageExpr AST.
Modified:
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/DeclSpec.h
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=42050&r1=42049&r2=42050&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Mon Sep 17 15:25:27 2007
@@ -486,12 +486,12 @@
ReturnType = ParseObjCTypeName();
IdentifierInfo *selIdent = ParseObjCSelector();
- llvm::SmallVector<ObjcKeywordInfo, 12> KeyInfo;
+ llvm::SmallVector<ObjcKeywordDecl, 12> KeyInfo;
if (Tok.getKind() == tok::colon) {
while (1) {
- ObjcKeywordInfo KeyInfoDecl;
+ ObjcKeywordDecl KeyInfoDecl;
KeyInfoDecl.SelectorName = selIdent;
// Each iteration parses a single keyword argument.
@@ -514,11 +514,11 @@
KeyInfoDecl.ArgumentName = Tok.getIdentifierInfo();
ConsumeToken(); // Eat the identifier.
- // Rather than call out to the actions, try packaging up the info
- // locally, like we do for Declarator.
- // FIXME: add Actions.BuildObjCKeyword()
-
+ // Rather than call out to the actions, package up the info locally,
+ // like we do for Declarator.
KeyInfo.push_back(KeyInfoDecl);
+
+ // Check for another keyword selector.
selIdent = ParseObjCSelector();
if (!selIdent && Tok.getKind() != tok::colon)
break;
@@ -984,28 +984,52 @@
Parser::ExprResult Parser::ParseObjCMessageExpression() {
assert(Tok.getKind() == tok::l_square && "'[' expected");
SourceLocation Loc = ConsumeBracket(); // consume '['
+ IdentifierInfo *ReceiverName = 0;
+ ExprTy *ReceiverExpr = 0;
// Parse receiver
if (Tok.getKind() == tok::identifier &&
- Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope))
+ Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) {
+ ReceiverName = Tok.getIdentifierInfo();
ConsumeToken();
- else
- ParseAssignmentExpression();
+ } else {
+ ExprResult Res = ParseAssignmentExpression();
+ if (Res.isInvalid) {
+ SkipUntil(tok::identifier);
+ return Res;
+ }
+ ReceiverExpr = Res.Val;
+ }
// Parse objc-selector
IdentifierInfo *selIdent = ParseObjCSelector();
+ llvm::SmallVector<ObjcKeywordMessage, 12> KeyInfo;
if (Tok.getKind() == tok::colon) {
while (1) {
// Each iteration parses a single keyword argument.
+ ObjcKeywordMessage KeyInfoMess;
+ KeyInfoMess.SelectorName = selIdent;
+
if (Tok.getKind() != tok::colon) {
Diag(Tok, diag::err_expected_colon);
SkipUntil(tok::semi);
- return 0;
+ return true;
}
- ConsumeToken(); // Eat the ':'.
+ KeyInfoMess.ColonLoc = ConsumeToken(); // Eat the ':'.
/// Parse the expression after ':'
- ParseAssignmentExpression();
- IdentifierInfo *keywordSelector = ParseObjCSelector();
+ ExprResult Res = ParseAssignmentExpression();
+ if (Res.isInvalid) {
+ SkipUntil(tok::identifier);
+ return Res;
+ }
+ // We have a valid expression.
+ KeyInfoMess.KeywordExpr = Res.Val;
+
+ // Rather than call out to the actions, package up the info locally,
+ // like we do for Declarator.
+ KeyInfo.push_back(KeyInfoMess);
- if (!keywordSelector && Tok.getKind() != tok::colon)
+ // Check for another keyword selector.
+ selIdent = ParseObjCSelector();
+ if (!selIdent && Tok.getKind() != tok::colon)
break;
// We have a selector or a colon, continue parsing.
}
@@ -1026,7 +1050,12 @@
return 0;
}
ConsumeBracket(); // consume ']'
- return 0; // FIXME: return a message expr AST!
+
+ if (ReceiverName)
+ return Actions.ActOnMessageExpression(ReceiverName,
+ &KeyInfo[0], KeyInfo.size());
+ return Actions.ActOnMessageExpression(ReceiverExpr,
+ &KeyInfo[0], KeyInfo.size());
}
Parser::ExprResult Parser::ParseObjCStringLiteral() {
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42050&r1=42049&r2=42050&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Mon Sep 17 15:25:27 2007
@@ -366,7 +366,7 @@
DeclTy **allMethods, unsigned allNum);
virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
tok::TokenKind MethodType, TypeTy *ReturnType,
- ObjcKeywordInfo *Keywords, unsigned NumKeywords,
+ ObjcKeywordDecl *Keywords, unsigned NumKeywords,
AttributeList *AttrList);
virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
tok::TokenKind MethodType, TypeTy *ReturnType,
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42050&r1=42049&r2=42050&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Sep 17 15:25:27 2007
@@ -1239,41 +1239,33 @@
return;
}
-/// Build objective-c style method name.
-static SelectorInfo &
- ObjcGetSelectorInfo(ObjcKeywordInfo* KeyInfo, unsigned numKeyInfo,
- ASTContext &Context)
-{
+Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
+ tok::TokenKind MethodType, TypeTy *ReturnType,
+ ObjcKeywordDecl *Keywords, unsigned NumKeywords,
+ AttributeList *AttrList) {
+ assert(NumKeywords && "Selector must be specified");
+
+ // Derive the selector name from the keyword declarations.
int len=0;
char *methodName;
- for (unsigned int i = 0; i < numKeyInfo; i++) {
- IdentifierInfo *selectorName = KeyInfo[i].SelectorName;
- if (selectorName)
- len += strlen(selectorName->getName());
+ for (unsigned int i = 0; i < NumKeywords; i++) {
+ if (Keywords[i].SelectorName)
+ len += strlen(Keywords[i].SelectorName->getName());
len++;
}
methodName = (char *) alloca (len + 1);
methodName[0] = '\0';
- for (unsigned int i = 0; i < numKeyInfo; i++) {
- IdentifierInfo *selectorName = KeyInfo[i].SelectorName;
- if (selectorName)
- strcat(methodName, selectorName->getName());
+ for (unsigned int i = 0; i < NumKeywords; i++) {
+ if (Keywords[i].SelectorName)
+ strcat(methodName, Keywords[i].SelectorName->getName());
strcat(methodName, ":");
}
- return Context.getSelectorInfo(methodName, methodName+len);
-}
+ SelectorInfo &SelName = Context.getSelectorInfo(methodName, methodName+len);
-
-Sema::DeclTy *Sema::ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
- tok::TokenKind MethodType, TypeTy *ReturnType,
- ObjcKeywordInfo *Keywords, unsigned NumKeywords,
- AttributeList *AttrList) {
- assert(NumKeywords && "Selector must be specified");
- SelectorInfo &SelName = ObjcGetSelectorInfo(Keywords, NumKeywords, Context);
llvm::SmallVector<ParmVarDecl*, 16> Params;
for (unsigned i = 0; i < NumKeywords; i++) {
- ObjcKeywordInfo *arg = &Keywords[i];
+ ObjcKeywordDecl *arg = &Keywords[i];
// FIXME: arg->AttrList must be stored too!
ParmVarDecl* Param = new ParmVarDecl(arg->ColonLoc, arg->ArgumentName,
QualType::getFromOpaquePtr(arg->TypeInfo),
@@ -1284,9 +1276,9 @@
Params.push_back(Param);
}
QualType resultDeclType = QualType::getFromOpaquePtr(ReturnType);
- ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc,
- SelName, resultDeclType,
- 0, -1, AttrList, MethodType == tok::minus);
+ ObjcMethodDecl* ObjcMethod;
+ ObjcMethod = new ObjcMethodDecl(MethodLoc, SelName, resultDeclType,
+ 0, -1, AttrList, MethodType == tok::minus);
ObjcMethod->setMethodParams(&Params[0], NumKeywords);
return ObjcMethod;
}
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42050&r1=42049&r2=42050&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Mon Sep 17 15:25:27 2007
@@ -708,7 +708,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=42050&r1=42049&r2=42050&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Mon Sep 17 15:25:27 2007
@@ -21,7 +21,8 @@
// Semantic.
class DeclSpec;
class Declarator;
- struct ObjcKeywordInfo;
+ struct ObjcKeywordDecl;
+ struct ObjcKeywordMessage;
class AttributeList;
// Parse.
class Scope;
@@ -145,12 +146,6 @@
return 0;
}
- virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
- IdentifierInfo **IdentList,
- unsigned NumElts) {
- return 0;
- }
-
//===--------------------------------------------------------------------===//
// Type Parsing Callbacks.
//===--------------------------------------------------------------------===//
@@ -455,7 +450,7 @@
}
virtual DeclTy *ObjcBuildMethodDeclaration(
SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType,
- ObjcKeywordInfo *Keywords, unsigned NumKeywords,
+ ObjcKeywordDecl *Keywords, unsigned NumKeywords,
AttributeList *AttrList) {
return 0;
}
@@ -464,6 +459,21 @@
IdentifierInfo *SelectorName, AttributeList *AttrList) {
return 0;
}
+ // This actions handles keyword message to classes.
+ virtual DeclTy *ActOnMessageExpression(IdentifierInfo *receivingClassName,
+ ObjcKeywordMessage *Keywords, unsigned NumKeywords) {
+ return 0;
+ }
+ // This action handles keyword messages to instances.
+ virtual DeclTy *ActOnMessageExpression(ExprTy *receiver,
+ ObjcKeywordMessage *Keywords, unsigned NumKeywords) {
+ return 0;
+ }
+ virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
+ IdentifierInfo **IdentList,
+ unsigned NumElts) {
+ return 0;
+ }
virtual void ObjCStartCategoryInterface() { // FIXME
return;
}
Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=42050&r1=42049&r2=42050&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Mon Sep 17 15:25:27 2007
@@ -566,20 +566,37 @@
IdentifierInfo *SelectorName; // optional
SourceLocation SelectorLoc;
SourceLocation ColonLoc;
+
+ ObjcKeywordInfo() {}
+ ObjcKeywordInfo(IdentifierInfo *selName, SourceLocation sLoc,
+ SourceLocation cLoc)
+ : SelectorName(selName), SelectorLoc(sLoc), ColonLoc(cLoc) {}
+};
+
+struct ObjcKeywordDecl : ObjcKeywordInfo {
Action::TypeTy *TypeInfo; // optional
- bool InvalidType;
IdentifierInfo *ArgumentName;
AttributeList *AttrList;
+ bool InvalidType; // FIXME: is this used?
- ObjcKeywordInfo() {}
- ObjcKeywordInfo(IdentifierInfo *selName, SourceLocation sLoc,
+ ObjcKeywordDecl() {}
+ ObjcKeywordDecl(IdentifierInfo *selName, SourceLocation sLoc,
SourceLocation cLoc, Action::TypeTy *tInfo,
IdentifierInfo *argName, AttributeList *aList)
- : SelectorName(selName), SelectorLoc(sLoc), ColonLoc(cLoc), TypeInfo(tInfo),
- ArgumentName(argName), AttrList(aList) {
+ : ObjcKeywordInfo(selName, sLoc, cLoc),
+ TypeInfo(tInfo), ArgumentName(argName), AttrList(aList) {
}
};
+
+struct ObjcKeywordMessage : ObjcKeywordInfo {
+ Action::ExprTy *KeywordExpr;
+
+ ObjcKeywordMessage() {}
+ ObjcKeywordMessage(IdentifierInfo *selName, SourceLocation sLoc,
+ SourceLocation cLoc, Action::ExprTy *expr)
+ : ObjcKeywordInfo(selName, sLoc, cLoc), KeywordExpr(expr) {}
+};
-} // end namespace clang
+} // end namespace clang
#endif
More information about the cfe-commits
mailing list