[cfe-commits] r44576 - in /cfe/trunk: Sema/Sema.h Sema/SemaChecking.cpp Sema/SemaDecl.cpp Sema/SemaStmt.cpp Sema/SemaType.cpp include/clang/AST/Expr.h
Fariborz Jahanian
fjahanian at apple.com
Tue Dec 4 11:20:12 PST 2007
Author: fjahanian
Date: Tue Dec 4 13:20:11 2007
New Revision: 44576
URL: http://llvm.org/viewvc/llvm-project?rev=44576&view=rev
Log:
Simplified setting up Method's scope before generating AST for its nody.
Modified:
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaChecking.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/Sema/SemaStmt.cpp
cfe/trunk/Sema/SemaType.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44576&r1=44575&r2=44576&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Dec 4 13:20:11 2007
@@ -170,7 +170,7 @@
//
QualType GetTypeForDeclarator(Declarator &D, Scope *S);
- QualType ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S);
+ QualType ObjcGetTypeForMethodDefinition(DeclTy *D);
virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Modified: cfe/trunk/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaChecking.cpp?rev=44576&r1=44575&r2=44576&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/Sema/SemaChecking.cpp Tue Dec 4 13:20:11 2007
@@ -54,8 +54,9 @@
return true;
}
- FunctionTypeProto* proto =
- cast<FunctionTypeProto>(CurFunctionDecl->getType());
+ FunctionTypeProto* proto = CurFunctionDecl ?
+ cast<FunctionTypeProto>(CurFunctionDecl->getType()) :
+ cast<FunctionTypeProto>(ObjcGetTypeForMethodDefinition(CurMethodDecl));
if (!proto->isVariadic()) {
Diag(Fn->getLocStart(),
diag::err_va_start_used_in_non_variadic_function);
@@ -65,9 +66,10 @@
bool SecondArgIsLastNamedArgument = false;
if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Args[1])) {
if (ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) {
- ParmVarDecl *LastNamedArg =
- CurFunctionDecl->getParamDecl(CurFunctionDecl->getNumParams() - 1);
-
+ ParmVarDecl *LastNamedArg = CurFunctionDecl ?
+ CurFunctionDecl->getParamDecl(CurFunctionDecl->getNumParams() - 1) :
+ CurMethodDecl->getParamDecl(CurMethodDecl->getNumParams() - 1);
+
if (PV == LastNamedArg)
SecondArgIsLastNamedArgument = true;
}
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=44576&r1=44575&r2=44576&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Dec 4 13:20:11 2007
@@ -963,32 +963,11 @@
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
assert(MDecl != 0 && "Not a method declarator!");
- Scope *GlobalScope = FnBodyScope->getParent();
-
- // build [classname selector-name] for the name of method.
- std::string Name = "[";
- Name += MDecl->getClassInterface()->getName();
- Name += " ";
- Name += MDecl->getSelector().getName();
- Name += "]";
- IdentifierInfo *II = &Context.Idents.get(Name);
- assert (II && "ObjcActOnStartOfMethodDef - selector name is missing");
-
- QualType R = ObjcGetTypeForMethodDefinition(MDecl, GlobalScope);
- assert(!R.isNull() && "ObjcActOnStartOfMethodDef() returned null type");
-
- FunctionDecl *NewFD = new FunctionDecl(MDecl->getLocation(), II, R,
- FunctionDecl::Static, false, 0);
- NewFD->setNext(II->getFETokenInfo<ScopedDecl>());
- II->setFETokenInfo(NewFD);
- GlobalScope->AddDecl(NewFD);
-
// Allow all of Sema to see that we are entering a method definition.
CurMethodDecl = MDecl;
- CurFunctionDecl = NewFD;
- // Create Decl objects for each parameter, adding them to the FunctionDecl.
- llvm::SmallVector<ParmVarDecl*, 16> Params;
+ // 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!
@@ -1001,20 +980,19 @@
PI.TypeInfo = selfTy.getAsOpaquePtr();
} else
PI.TypeInfo = Context.getObjcIdType().getAsOpaquePtr();
- Params.push_back(ActOnParamDeclarator(PI, FnBodyScope));
+ ActOnParamDeclarator(PI, FnBodyScope);
PI.Ident = &Context.Idents.get("_cmd");
PI.TypeInfo = Context.getObjcSelType().getAsOpaquePtr();
- Params.push_back(ActOnParamDeclarator(PI, FnBodyScope));
+ ActOnParamDeclarator(PI, FnBodyScope);
for (int i = 0; i < MDecl->getNumParams(); i++) {
ParmVarDecl *PDecl = MDecl->getParamDecl(i);
PI.Ident = PDecl->getIdentifier();
PI.IdentLoc = PDecl->getLocation(); // user vars have a real location.
PI.TypeInfo = PDecl->getType().getAsOpaquePtr();
- Params.push_back(ActOnParamDeclarator(PI, FnBodyScope));
+ ActOnParamDeclarator(PI, FnBodyScope);
}
- NewFD->setParams(&Params[0], Params.size());
}
/// ImplicitlyDefineFunction - An undeclared identifier was used in a function
Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=44576&r1=44575&r2=44576&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Tue Dec 4 13:20:11 2007
@@ -580,17 +580,21 @@
Action::StmtResult
Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
Expr *RetValExp = static_cast<Expr *>(rex);
- QualType lhsType = CurFunctionDecl->getResultType();
+ QualType lhsType = CurFunctionDecl ? CurFunctionDecl->getResultType() :
+ CurMethodDecl->getResultType();
if (lhsType->isVoidType()) {
if (RetValExp) // C99 6.8.6.4p1 (ext_ since GCC warns)
- Diag(ReturnLoc, diag::ext_return_has_expr,
- CurFunctionDecl->getIdentifier()->getName(),
+ Diag(ReturnLoc, diag::ext_return_has_expr,
+ (CurFunctionDecl ? CurFunctionDecl->getIdentifier()->getName() :
+ CurMethodDecl->getSelector().getName()),
RetValExp->getSourceRange());
return new ReturnStmt(ReturnLoc, RetValExp);
} else {
if (!RetValExp) {
- const char *funcName = CurFunctionDecl->getIdentifier()->getName();
+ const char *funcName = CurFunctionDecl ?
+ CurFunctionDecl->getIdentifier()->getName() :
+ CurMethodDecl->getSelector().getName().c_str();
if (getLangOptions().C99) // C99 6.8.6.4p1 (ext_ since GCC warns)
Diag(ReturnLoc, diag::ext_return_missing_expr, funcName);
else // C90 6.6.6.4p4
Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=44576&r1=44575&r2=44576&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Tue Dec 4 13:20:11 2007
@@ -327,7 +327,7 @@
/// ObjcGetTypeForMethodDefinition - Builds the type for a method definition
/// declarator
-QualType Sema::ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S) {
+QualType Sema::ObjcGetTypeForMethodDefinition(DeclTy *D) {
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
QualType T = MDecl->getResultType();
llvm::SmallVector<QualType, 16> ArgTys;
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=44576&r1=44575&r2=44576&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Dec 4 13:20:11 2007
@@ -17,6 +17,7 @@
#include "clang/AST/Stmt.h"
#include "clang/AST/Type.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/APFloat.h"
More information about the cfe-commits
mailing list