diff options
author | Steve Naroff <snaroff@apple.com> | 2007-11-12 03:44:46 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-11-12 03:44:46 +0000 |
commit | 6649992b19c83645ea02f4287eb977027548855d (patch) | |
tree | 076dd469c4e378c0420fd189cc73a84702b8468b | |
parent | d6d054da8e0cfd320f2bba2f97ecdb1511b1cbc4 (diff) |
Remove Sema::ObjcBuildMethodParameter().
Modify Sema::ParseParamDeclarator() to work for both ActOnStartOfFunctionDef() and ObjcActOnStartOfMethodDef().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44006 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Sema/Sema.h | 8 | ||||
-rw-r--r-- | Sema/SemaDecl.cpp | 101 | ||||
-rw-r--r-- | Sema/SemaType.cpp | 2 |
3 files changed, 30 insertions, 81 deletions
diff --git a/Sema/Sema.h b/Sema/Sema.h index 0aea99e2d5..34f82e125d 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -16,6 +16,7 @@ #define LLVM_CLANG_AST_SEMA_H #include "clang/Parse/Action.h" +#include "clang/Parse/DeclSpec.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallPtrSet.h" @@ -39,7 +40,6 @@ namespace clang { class FunctionDecl; class QualType; struct LangOptions; - struct DeclaratorChunk; class Token; class IntegerLiteral; class ArrayType; @@ -231,10 +231,8 @@ private: void AddTopLevelDecl(Decl *current, Decl *last); /// More parsing and symbol table subroutines... - ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo, - Scope *FnBodyScope); - ParmVarDecl *ObjcBuildMethodParameter(ParmVarDecl *param, Scope *FnBodyScope); - + ParmVarDecl *ParseParamDeclarator(struct DeclaratorChunk::ParamInfo &PI, + Scope *FnBodyScope); ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc, Scope *S); ScopedDecl *LookupInterfaceDecl(IdentifierInfo *II); diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index c0fb92c420..ec88087f89 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -840,10 +840,8 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) { // Called from Sema::ParseStartOfFunctionDef(). ParmVarDecl * -Sema::ParseParamDeclarator(DeclaratorChunk &FTI, unsigned ArgNo, - Scope *FnScope) { - const DeclaratorChunk::ParamInfo &PI = FTI.Fun.ArgInfo[ArgNo]; - +Sema::ParseParamDeclarator(struct DeclaratorChunk::ParamInfo &PI, Scope *FnScope) +{ IdentifierInfo *II = PI.Ident; // 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 @@ -894,57 +892,6 @@ Sema::ParseParamDeclarator(DeclaratorChunk &FTI, unsigned ArgNo, return New; } -// Called from Sema::ObjcParseStartOfMethodDef(). -ParmVarDecl * -Sema::ObjcBuildMethodParameter(ParmVarDecl *PI, Scope *FnScope) { - - IdentifierInfo *II = PI->getIdentifier(); - - // FIXME: Handle storage class (auto, register). No declarator? - // TODO: Chain to previous parameter with the prevdeclarator chain? - - // Perform the default function/array conversion (C99 6.7.5.3p[7,8]). - // Doing the promotion here has a win and a loss. The win is the type for - // both Decl's and DeclRefExpr's will match (a convenient invariant for the - // code generator). The loss is the orginal type isn't preserved. For example: - // - // void func(int parmvardecl[5]) { // convert "int [5]" to "int *" - // int blockvardecl[5]; - // sizeof(parmvardecl); // size == 4 - // sizeof(blockvardecl); // size == 20 - // } - // - // For expressions, all implicit conversions are captured using the - // ImplicitCastExpr AST node (we have no such mechanism for Decl's). - // - // FIXME: If a source translation tool needs to see the original type, then - // we need to consider storing both types (in ParmVarDecl)... - // - QualType parmDeclType = PI->getType(); - if (const ArrayType *AT = parmDeclType->getAsArrayType()) - parmDeclType = Context.getPointerType(AT->getElementType()); - else if (parmDeclType->isFunctionType()) - parmDeclType = Context.getPointerType(parmDeclType); - - ParmVarDecl *New = new ParmVarDecl(PI->getLocation(), II, parmDeclType, - VarDecl::None, 0); - // FIXME: need to check for invalid type. - /** - if (PI.InvalidType) - New->setInvalidDecl(); - */ - - // If this has an identifier, add it to the scope stack. - if (II) { - New->setNext(II->getFETokenInfo<ScopedDecl>()); - II->setFETokenInfo(New); - FnScope->AddDecl(New); - } - - return New; -} - - Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { assert(CurFunctionDecl == 0 && "Function parsing confused"); assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function && @@ -987,8 +934,10 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { FTI.ArgInfo[0].TypeInfo == Context.VoidTy.getAsOpaquePtr()) { // empty arg list, don't push any params. } else { - for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) - Params.push_back(ParseParamDeclarator(D.getTypeObject(0), i,FnBodyScope)); + for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) { + Params.push_back(ParseParamDeclarator(D.getTypeObject(0).Fun.ArgInfo[i], + FnBodyScope)); + } } FD->setParams(&Params[0], Params.size()); @@ -1047,30 +996,32 @@ void Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { // Create Decl objects for each parameter, adding them to the FunctionDecl. llvm::SmallVector<ParmVarDecl*, 16> Params; - ParmVarDecl *PDecl; + struct DeclaratorChunk::ParamInfo PI; + + PI.Ident = &Context.Idents.get("self"); + PI.IdentLoc = SourceLocation(/*FIXME*/); + // Insert the invisible arguments! if (MDecl->isInstance()) { QualType selfTy = Context.getObjcInterfaceType(MDecl->getClassInterface()); selfTy = Context.getPointerType(selfTy); - PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), - &Context.Idents.get("self"), - selfTy, - VarDecl::None, 0); - } - else - PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), - &Context.Idents.get("self"), - Context.getObjcIdType(), VarDecl::None, 0); - Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope)); - PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), - &Context.Idents.get("_cmd"), - Context.getObjcSelType(), VarDecl::None, 0); - Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope)); - + PI.TypeInfo = selfTy.getAsOpaquePtr(); + } else + PI.TypeInfo = Context.getObjcIdType().getAsOpaquePtr(); + Params.push_back(ParseParamDeclarator(PI, FnBodyScope)); + + PI.Ident = &Context.Idents.get("_cmd"); + PI.IdentLoc = SourceLocation(/*FIXME*/); + PI.TypeInfo = Context.getObjcSelType().getAsOpaquePtr(); + Params.push_back(ParseParamDeclarator(PI, FnBodyScope)); + for (int i = 0; i < MDecl->getNumParams(); i++) { - PDecl = MDecl->getParamDecl(i); - Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope)); + ParmVarDecl *PDecl = MDecl->getParamDecl(i); + PI.Ident = PDecl->getIdentifier(); + PI.IdentLoc = PDecl->getLocation(); + PI.TypeInfo = PDecl->getType().getAsOpaquePtr(); + Params.push_back(ParseParamDeclarator(PI, FnBodyScope)); } FD->setParams(&Params[0], Params.size()); diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index 7eb546efbf..2da843d977 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -348,7 +348,7 @@ QualType Sema::ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S) { 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::ObjcBuildMethodParameter(). + // Sema::ParseParamDeclarator(). if (const ArrayType *AT = ArgTy->getAsArrayType()) ArgTy = Context.getPointerType(AT->getElementType()); else if (ArgTy->isFunctionType()) |