From 4e6c0d19b7c072758922cf80525a81aeefc6e64b Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 23 Apr 2010 23:01:43 +0000 Subject: [PATCH] Rework Parser-Sema interface for Objective-C @catch exception object arguments. Rather than having the parser call ActOnParamDeclarator (which is a bit of a hack), call a new ActOnObjCExceptionDecl action. We'll be moving more functionality into this handler to perform earlier checking of @catch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102222 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Action.h | 6 +++++- lib/Parse/ParseObjc.cpp | 6 ++---- lib/Sema/Sema.h | 2 +- lib/Sema/SemaDecl.cpp | 5 ----- lib/Sema/SemaDeclObjC.cpp | 7 +++++++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index dd12fdfe3e..6b16522848 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -468,7 +468,11 @@ public: virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D) { return DeclPtrTy(); } - virtual void ActOnObjCCatchParam(DeclPtrTy D) { + + /// \brief Parsed an exception object declaration within an Objective-C + /// @catch statement. + virtual DeclPtrTy ActOnObjCExceptionDecl(Scope *S, Declarator &D) { + return DeclPtrTy(); } /// AddInitializerToDecl - This action is called immediately after diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 4846dad7b0..e30ec83d84 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1542,11 +1542,9 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { Declarator ParmDecl(DS, Declarator::PrototypeContext); ParseDeclarator(ParmDecl); - // Inform the actions module about the parameter declarator, so it + // Inform the actions module about the declarator, so it // gets added to the current scope. - // FIXME. Probably can build a VarDecl and avoid setting DeclContext. - FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl); - Actions.ActOnObjCCatchParam(FirstPart); + FirstPart = Actions.ActOnObjCExceptionDecl(CurScope, ParmDecl); } else ConsumeToken(); // consume '...' diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index e9cd6ca7d6..64afd56a40 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -812,7 +812,7 @@ public: SourceLocation NameLoc, VarDecl::StorageClass StorageClass, VarDecl::StorageClass StorageClassAsWritten); - virtual void ActOnObjCCatchParam(DeclPtrTy D); + virtual DeclPtrTy ActOnObjCExceptionDecl(Scope *S, Declarator &D); virtual void ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4800337383..83796ba65f 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4258,11 +4258,6 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, return New; } -void Sema::ActOnObjCCatchParam(DeclPtrTy D) { - ParmVarDecl *Param = cast(D.getAs()); - Param->setDeclContext(CurContext); -} - void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, SourceLocation LocAfterDecls) { assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function && diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index e1973fa5c2..9a223e91dc 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1707,3 +1707,10 @@ void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, } } +Sema::DeclPtrTy Sema::ActOnObjCExceptionDecl(Scope *S, Declarator &D) { + // FIXME: Perform checking on the declaration here. + DeclPtrTy Dcl = ActOnParamDeclarator(S, D); + if (Dcl.get()) + cast(Dcl.getAs())->setDeclContext(CurContext); + return Dcl; +} -- 2.40.0