Some code clean up in the form of name changes for functions which
process method definitions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43967 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.h b/Sema/Sema.h
index 50a6046..9816e81 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -172,7 +172,7 @@
//
QualType GetTypeForDeclarator(Declarator &D, Scope *S);
- QualType ObjcGetTypeForDeclarator(DeclTy *D, Scope *S);
+ QualType ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S);
virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
@@ -184,12 +184,13 @@
//
virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
- virtual DeclTy *ObjcActOnDeclarator(Scope *S, DeclTy *D, DeclTy *LastInGroup);
+ virtual DeclTy *ObjcActOnMethodDefinition(Scope *S, DeclTy *D,
+ DeclTy *LastInGroup);
void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
- virtual DeclTy *ObjcActOnStartOfFunctionDef(Scope *S, DeclTy *D);
+ virtual DeclTy *ObjcActOnStartOfMethodDef(Scope *S, DeclTy *D);
virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body);
/// Scope actions.
@@ -231,7 +232,7 @@
/// More parsing and symbol table subroutines...
ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
Scope *FnBodyScope);
- ParmVarDecl *ObjcParseParamDeclarator(ParmVarDecl *param, Scope *FnBodyScope);
+ ParmVarDecl *ObjcBuildMethodParameter(ParmVarDecl *param, Scope *FnBodyScope);
ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
SourceLocation IdLoc, Scope *S);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 41f509a..1fb2219 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -544,14 +544,16 @@
return hadError;
}
+/// ObjcActOnMethodDefinition - Build the AST node for a method definition
+/// header. Return this AST.
Sema::DeclTy *
-Sema::ObjcActOnDeclarator(Scope *S, DeclTy *D, DeclTy *lastDecl) {
+Sema::ObjcActOnMethodDefinition(Scope *S, DeclTy *D, DeclTy *lastDecl) {
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
ScopedDecl *LastDeclarator = dyn_cast_or_null<ScopedDecl>((Decl *)lastDecl);
const char *name = MDecl->getSelector().getName().c_str();
IdentifierInfo *II = &Context.Idents.get(name);
- assert (II && "ObjcActOnDeclarator - selector name is missing");
+ assert (II && "ObjcActOnMethodDefinition - selector name is missing");
// The scope passed in may not be a decl scope. Zip up the scope tree until
// we find one that is.
@@ -559,20 +561,17 @@
S = S->getParent();
ScopedDecl *New;
- QualType R = ObjcGetTypeForDeclarator(MDecl, S);
- assert(!R.isNull() && "ObjcGetTypeForDeclarator() returned null type");
+ QualType R = ObjcGetTypeForMethodDefinition(MDecl, S);
+ assert(!R.isNull() && "ObjcGetTypeForMethodDefinition() returned null type");
FunctionDecl *NewFD = new FunctionDecl(MDecl->getLocation(), II, R,
FunctionDecl::Static,
false, LastDeclarator);
New = NewFD;
- // If this has an identifier, add it to the scope stack.
- if (II) {
- New->setNext(II->getFETokenInfo<ScopedDecl>());
- II->setFETokenInfo(New);
- S->AddDecl(New);
- }
+ New->setNext(II->getFETokenInfo<ScopedDecl>());
+ II->setFETokenInfo(New);
+ S->AddDecl(New);
if (S->getParent() == 0)
AddTopLevelDecl(New, LastDeclarator);
@@ -890,18 +889,11 @@
return New;
}
-// Called from Sema::ObjcParseStartOfFunctionDef().
+// Called from Sema::ObjcParseStartOfMethodDef().
ParmVarDecl *
-Sema::ObjcParseParamDeclarator(ParmVarDecl *PI, Scope *FnScope) {
+Sema::ObjcBuildMethodParameter(ParmVarDecl *PI, Scope *FnScope) {
IdentifierInfo *II = PI->getIdentifier();
- // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
- // Can this happen for params? We already checked that they don't conflict
- // among each other. Here they can only shadow globals, which is ok.
- if (/*Decl *PrevDecl = */LookupScopedDecl(II, Decl::IDNS_Ordinary,
- PI->getLocation(), FnScope)) {
-
- }
// FIXME: Handle storage class (auto, register). No declarator?
// TODO: Chain to previous parameter with the prevdeclarator chain?
@@ -1031,7 +1023,9 @@
return FD;
}
-Sema::DeclTy *Sema::ObjcActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
+/// ObjcActOnStartOfMethodDef - This routine sets up parameters; invisible
+/// and user declared, in the method definition's AST.
+Sema::DeclTy *Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
assert(CurFunctionDecl == 0 && "Function parsing confused");
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
@@ -1040,7 +1034,7 @@
Scope *GlobalScope = FnBodyScope->getParent();
FunctionDecl *FD =
- static_cast<FunctionDecl*>(ObjcActOnDeclarator(GlobalScope, D, 0));
+ static_cast<FunctionDecl*>(ObjcActOnMethodDefinition(GlobalScope, D, 0));
CurFunctionDecl = FD;
// Create Decl objects for each parameter, adding them to the FunctionDecl.
@@ -1059,16 +1053,16 @@
PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/),
&Context.Idents.get("self"),
Context.getObjcIdType(), VarDecl::None, 0);
- Params.push_back(ObjcParseParamDeclarator(PDecl, FnBodyScope));
+ Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope));
PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/),
&Context.Idents.get("_cmd"),
Context.getObjcSelType(), VarDecl::None, 0);
- Params.push_back(ObjcParseParamDeclarator(PDecl, FnBodyScope));
+ Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope));
for (int i = 0; i < MDecl->getNumParams(); i++) {
PDecl = MDecl->getParamDecl(i);
- Params.push_back(ObjcParseParamDeclarator(PDecl, FnBodyScope));
+ Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope));
}
FD->setParams(&Params[0], Params.size());
diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp
index 71ec3f3..7eb546e 100644
--- a/Sema/SemaType.cpp
+++ b/Sema/SemaType.cpp
@@ -325,9 +325,9 @@
return T;
}
-/// ObjcGetTypeForDeclarator - Convert the type for the specified declarator to Type
-/// instances.
-QualType Sema::ObjcGetTypeForDeclarator(DeclTy *D, Scope *S) {
+/// ObjcGetTypeForMethodDefinition - Builds the type for a method definition
+/// declarator
+QualType Sema::ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S) {
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
QualType T = MDecl->getResultType();
llvm::SmallVector<QualType, 16> ArgTys;
@@ -346,20 +346,9 @@
ParmVarDecl *PDecl = MDecl->getParamDecl(i);
QualType ArgTy = PDecl->getType();
assert(!ArgTy.isNull() && "Couldn't parse type?");
- //
// Perform the default function/array conversion (C99 6.7.5.3p[7,8]).
// This matches the conversion that is done in
- // Sema::ParseParamDeclarator(). Without this conversion, the
- // argument type in the function prototype *will not* match the
- // type in ParmVarDecl (which makes the code generator unhappy).
- //
- // FIXME: We still apparently need the conversion in
- // Sema::ParseParamDeclarator(). This doesn't make any sense, since
- // it should be driving off the type being created here.
- //
- // FIXME: If a source translation tool needs to see the original type,
- // then we need to consider storing both types somewhere...
- //
+ // Sema::ObjcBuildMethodParameter().
if (const ArrayType *AT = ArgTy->getAsArrayType())
ArgTy = Context.getPointerType(AT->getElementType());
else if (ArgTy->isFunctionType())