Diag (Tok, diag::err_expected_lbrace);
return 0;
}
- return ObjcParseFunctionDefinition(MDecl);
+ return ObjcParseMethodDefinition(MDecl);
}
/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
Diag (Tok, diag::err_expected_lbrace);
return 0;
}
- return ObjcParseFunctionDefinition(MDecl);
+ return ObjcParseMethodDefinition(MDecl);
}
Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc);
}
-Parser::DeclTy *Parser::ObjcParseFunctionDefinition(DeclTy *D) {
+/// ObjcParseMethodDefinition - This routine parses a method definition and
+/// returns its AST.
+Parser::DeclTy *Parser::ObjcParseMethodDefinition(DeclTy *D) {
// We should have an opening brace now.
if (Tok.isNot(tok::l_brace)) {
Diag(Tok, diag::err_expected_fn_body);
SourceLocation BraceLoc = Tok.getLocation();
- // Enter a scope for the function body.
+ // Enter a scope for the method body.
EnterScope(Scope::FnScope|Scope::DeclScope);
- // Tell the actions module that we have entered a function definition with the
- // specified Declarator for the function.
- DeclTy *Res = Actions.ObjcActOnStartOfFunctionDef(CurScope, D);
+ // Tell the actions module that we have entered a method definition with the
+ // specified Declarator for the method.
+ DeclTy *Res = Actions.ObjcActOnStartOfMethodDef(CurScope, D);
return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc);
}
//
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);
//
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.
/// 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);
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.
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);
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?
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));
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.
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());
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;
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())
return 0;
}
- virtual DeclTy *ObjcActOnDeclarator(Scope *S, DeclTy *D,DeclTy *LastInGroup) {
+ virtual DeclTy *ObjcActOnMethodDefinition(Scope *S, DeclTy *D,
+ DeclTy *LastInGroup) {
return 0;
}
/// AddInitializerToDecl - This action is called immediately after
return ActOnDeclarator(FnBodyScope, D, 0);
}
- virtual DeclTy *ObjcActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) {
+ virtual DeclTy *ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
// Default to ActOnDeclarator.
- return ObjcActOnDeclarator(FnBodyScope, D, 0);
+ return ObjcActOnMethodDefinition(FnBodyScope, D, 0);
}
/// ActOnFunctionDefBody - This is called when a function body has completed
DeclTy *ParseExternalDeclaration();
DeclTy *ParseDeclarationOrFunctionDefinition();
DeclTy *ParseFunctionDefinition(Declarator &D);
- DeclTy *ObjcParseFunctionDefinition(DeclTy *D);
+ DeclTy *ObjcParseMethodDefinition(DeclTy *D);
void ParseKNRParamDeclarations(Declarator &D);
void ParseSimpleAsm();
void ParseAsmStringLiteral();