From 8c9f13e494109426f358ef73bf873f77b1221564 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Sun, 16 Sep 2007 16:16:00 +0000 Subject: [PATCH] Fixes/tweaks that prevent "defaults-i.m" from compiling. - Allow classnames as the receiver (removing a FIXME from ParseObjCMessageExpression). - Added a FIXME to ParseObjCMessageExpression()...we need to return a message expr AST node! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42001 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/Decl.cpp | 36 ++++++++++++++++++++++++++++++++++++ Parse/ParseObjc.cpp | 9 ++++++--- Sema/Sema.h | 2 +- Sema/SemaDecl.cpp | 6 +++--- Sema/SemaExpr.cpp | 2 +- include/clang/AST/Decl.h | 4 +++- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/AST/Decl.cpp b/AST/Decl.cpp index 965ba2180a..4b464ee5e6 100644 --- a/AST/Decl.cpp +++ b/AST/Decl.cpp @@ -28,6 +28,42 @@ static unsigned nFieldDecls = 0; static unsigned nInterfaceDecls = 0; static bool StatSwitch = false; +const char *Decl::getDeclKindName() { + switch (DeclKind) { + default: assert(0 && "Unknown decl kind!"); + case Typedef: + return "Typedef"; + case Function: + return "Function"; + case BlockVariable: + return "BlockVariable"; + case FileVariable: + return "FileVariable"; + case ParmVariable: + return "ParmVariable"; + case EnumConstant: + return "EnumConstant"; + case ObjcInterface: + return "ObjcInterface"; + case ObjcClass: + return "ObjcClass"; + case ObjcMethod: + return "ObjcMethod"; + case ObjcProtoMethod: + return "ObjcProtoMethod"; + case ObjcProtocol: + return "ObjcProtocol"; + case Struct: + return "Struct"; + case Union: + return "Union"; + case Class: + return "Class"; + case Enum: + return "Enum"; + } +} + bool Decl::CollectingStats(bool enable) { if (enable) StatSwitch = true; return StatSwitch; diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 8fa071a3fe..e382974daf 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -986,8 +986,11 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() { assert(Tok.getKind() == tok::l_square && "'[' expected"); SourceLocation Loc = ConsumeBracket(); // consume '[' // Parse receiver - // FIXME: receiver as type-name/class-name - ParseAssignmentExpression(); + if (Tok.getKind() == tok::identifier && + Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) + ConsumeToken(); + else + ParseAssignmentExpression(); // Parse objc-selector IdentifierInfo *selIdent = ParseObjCSelector(); if (Tok.getKind() == tok::colon) { @@ -1024,7 +1027,7 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() { return 0; } ConsumeBracket(); // consume ']' - return 0; + return 0; // FIXME: return a message expr AST! } Parser::ExprResult Parser::ParseObjCStringLiteral() { diff --git a/Sema/Sema.h b/Sema/Sema.h index a6ce9cfbcf..95086534b5 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -182,7 +182,7 @@ private: ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc, Scope *S); ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S); - Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, + ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, Scope *S); // Decl attributes - this routine is the top level dispatcher. void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix, diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index b792b525cc..16d72130f5 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -815,8 +815,8 @@ Sema::DeclTy *Sema::ParseFunctionDefBody(DeclTy *D, StmtTy *Body) { /// ImplicitlyDefineFunction - An undeclared identifier was used in a function /// call, forming a call to an implicitly defined function (per C99 6.5.1p2). -Decl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, - Scope *S) { +ScopedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, + IdentifierInfo &II, Scope *S) { if (getLangOptions().C99) // Extension in C99. Diag(Loc, diag::ext_implicit_function_decl, II.getName()); else // Legal in C90, but warn about it. @@ -842,7 +842,7 @@ Decl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, while (S->getParent()) S = S->getParent(); - return static_cast(ActOnDeclarator(S, D, 0)); + return dyn_cast(static_cast(ActOnDeclarator(S, D, 0))); } diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index b479c0a3ba..da1981f9a0 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -60,7 +60,7 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc, IdentifierInfo &II, bool HasTrailingLParen) { // Could be enum-constant or decl. - Decl *D = LookupScopedDecl(&II, Decl::IDNS_Ordinary, Loc, S); + ScopedDecl *D = LookupScopedDecl(&II, Decl::IDNS_Ordinary, Loc, S); if (D == 0) { // Otherwise, this could be an implicitly declared function reference (legal // in C90, extension in C99). diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index c47aec3596..a920353ed9 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -68,7 +68,8 @@ protected: public: Kind getKind() const { return DeclKind; } - + const char *getDeclKindName(); + /// setInvalidDecl - Indicates the Decl had a semantic error. This /// allows for graceful error recovery. void setInvalidDecl() { InvalidDecl = 1; } @@ -83,6 +84,7 @@ public: case FileVariable: case ParmVariable: case EnumConstant: + case ObjcInterface: return IDNS_Ordinary; case Struct: case Union: -- 2.40.0