aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-08-26 06:07:48 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-08-26 06:07:48 +0000
commit451318c08a6342c10b8986060386fd9274418437 (patch)
tree3b58d20357e5346f1d98294d5118ff5976f3578d
parent9f0afd4e79601d9982072ff9318e6f9a982c770e (diff)
Move implicit Obj-C param creation into ObjCMethodDecl.
- Add ObjCMethodDecl::createImplicitParams. - Remove ObjCMethodDecl::set{Self,Cmd}Decl - Remove Sema::CreateImplicitParameter No (intended) functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55356 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclObjC.h14
-rw-r--r--lib/Sema/Sema.h2
-rw-r--r--lib/Sema/SemaDecl.cpp15
-rw-r--r--lib/Sema/SemaDeclObjC.cpp22
4 files changed, 14 insertions, 39 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index 7d16b54f63..0cbe4241f9 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -131,8 +131,12 @@ private:
// The following are only used for method definitions, null otherwise.
// FIXME: space savings opportunity, consider a sub-class.
Stmt *Body;
- // Decls for implicit parameters
+
+ /// SelfDecl - Decl for the implicit self parameter. This is lazily
+ /// constructed by createImplicitParams.
ImplicitParamDecl *SelfDecl;
+ /// CmdDecl - Decl for the implicit _cmd parameter. This is lazily
+ /// constructed by createImplicitParams.
ImplicitParamDecl *CmdDecl;
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
@@ -207,10 +211,14 @@ public:
}
void setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams);
+ /// createImplicitParams - Used to lazily create the self and cmd
+ /// implict parameters. This must be called prior to using getSelfDecl()
+ /// or getCmdDecl(). The call is ignored if the implicit paramters
+ /// have already been created.
+ void createImplicitParams(ASTContext &Context);
+
ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
- void setSelfDecl(ImplicitParamDecl *decl) { SelfDecl = decl; }
ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
- void setCmdDecl(ImplicitParamDecl *decl) { CmdDecl = decl; }
bool isInstance() const { return IsInstance; }
bool isVariadic() const { return IsVariadic; }
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 4bfbcb9939..1ce4d804c0 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -299,8 +299,6 @@ private:
/// Helpers for dealing with function parameters
bool CheckParmsForFunctionDef(FunctionDecl *FD);
- ImplicitParamDecl *CreateImplicitParameter(Scope *S, IdentifierInfo *Id,
- SourceLocation IdLoc, QualType Type);
void CheckCXXDefaultArguments(FunctionDecl *FD);
void CheckExtraCXXDefaultArguments(Declarator &D);
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index ad83908e45..c6f8c22b08 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -493,21 +493,6 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) {
return HasInvalidParm;
}
-/// CreateImplicitParameter - Creates an implicit function parameter
-/// in the scope S and with the given type. This routine is used, for
-/// example, to create the implicit "self" parameter in an Objective-C
-/// method.
-ImplicitParamDecl *
-Sema::CreateImplicitParameter(Scope *S, IdentifierInfo *Id,
- SourceLocation IdLoc, QualType Type) {
- ImplicitParamDecl *New = ImplicitParamDecl::Create(Context, CurContext,
- IdLoc, Id, Type, 0);
- if (Id)
- PushOnScopeChains(New, S);
-
- return New;
-}
-
/// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
/// no declarator (e.g. "struct foo;") is parsed.
Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index b02df056c8..d98c3065f5 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -40,28 +40,12 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
// Create Decl objects for each parameter, entrring them in the scope for
// binding to their use.
- struct DeclaratorChunk::ParamInfo PI;
// Insert the invisible arguments, self and _cmd!
- PI.Ident = &Context.Idents.get("self");
- PI.IdentLoc = SourceLocation(); // synthesized vars have a null location.
- QualType selfTy;
- if (MDecl->isInstance()) {
- selfTy = Context.getObjCIdType();
- if (ObjCInterfaceDecl *OID = MDecl->getClassInterface()) {
- // There may be no interface context due to error in declaration of the
- // interface (which has been reported). Recover gracefully
- selfTy = Context.getObjCInterfaceType(OID);
- selfTy = Context.getPointerType(selfTy);
- }
- } else // we have a factory method.
- selfTy = Context.getObjCClassType();
- getCurMethodDecl()->setSelfDecl(CreateImplicitParameter(FnBodyScope,
- PI.Ident, PI.IdentLoc, selfTy));
+ MDecl->createImplicitParams(Context);
- PI.Ident = &Context.Idents.get("_cmd");
- getCurMethodDecl()->setCmdDecl(CreateImplicitParameter(FnBodyScope,
- PI.Ident, PI.IdentLoc, Context.getObjCSelType()));
+ PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
+ PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
// Introduce all of the other parameters into this scope.
for (unsigned i = 0, e = MDecl->getNumParams(); i != e; ++i) {