forked from OSchip/llvm-project
Replace CurFunctionDecl and CurMethodDecl with methods getCurFunctionDecl() and getCurMethodDecl() that return the appropriate Decl through CurContext.
llvm-svn: 52852
This commit is contained in:
parent
1701328675
commit
853fbea313
|
@ -97,8 +97,7 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
|
|||
}
|
||||
|
||||
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
|
||||
: PP(pp), Context(ctxt), Consumer(consumer),
|
||||
CurFunctionDecl(0), CurMethodDecl(0), CurContext(0) {
|
||||
: PP(pp), Context(ctxt), Consumer(consumer), CurContext(0) {
|
||||
|
||||
// Get IdentifierInfo objects for known functions for which we
|
||||
// do extra checking.
|
||||
|
|
|
@ -68,15 +68,8 @@ class Sema : public Action {
|
|||
Preprocessor &PP;
|
||||
ASTContext &Context;
|
||||
ASTConsumer &Consumer;
|
||||
|
||||
/// CurFunctionDecl - If inside of a function body, this contains a pointer to
|
||||
/// the function decl for the function being parsed.
|
||||
FunctionDecl *CurFunctionDecl;
|
||||
|
||||
/// CurMethodDecl - If inside of a method body, this contains a pointer to
|
||||
/// the method decl for the method being parsed.
|
||||
ObjCMethodDecl *CurMethodDecl;
|
||||
|
||||
/// CurContext - This is the current declaration context of parsing.
|
||||
DeclContext *CurContext;
|
||||
|
||||
/// LabelMap - This is a mapping from label identifiers to the LabelStmt for
|
||||
|
@ -267,6 +260,18 @@ private:
|
|||
/// Set the current declaration context until it gets popped.
|
||||
void PushDeclContext(DeclContext *DC);
|
||||
void PopDeclContext();
|
||||
|
||||
/// CurFunctionDecl - If inside of a function body, this returns a pointer to
|
||||
/// the function decl for the function being parsed.
|
||||
FunctionDecl *getCurFunctionDecl() {
|
||||
return dyn_cast<FunctionDecl>(CurContext);
|
||||
}
|
||||
|
||||
/// CurMethodDecl - If inside of a method body, this returns a pointer to
|
||||
/// the method decl for the method being parsed.
|
||||
ObjCMethodDecl *getCurMethodDecl() {
|
||||
return dyn_cast<ObjCMethodDecl>(CurContext);
|
||||
}
|
||||
|
||||
/// Add this decl to the scope shadowed decl chains.
|
||||
void PushOnScopeChains(NamedDecl *D, Scope *S);
|
||||
|
|
|
@ -151,11 +151,11 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) {
|
|||
|
||||
// Determine whether the current function is variadic or not.
|
||||
bool isVariadic;
|
||||
if (CurFunctionDecl)
|
||||
if (getCurFunctionDecl())
|
||||
isVariadic =
|
||||
cast<FunctionTypeProto>(CurFunctionDecl->getType())->isVariadic();
|
||||
cast<FunctionTypeProto>(getCurFunctionDecl()->getType())->isVariadic();
|
||||
else
|
||||
isVariadic = CurMethodDecl->isVariadic();
|
||||
isVariadic = getCurMethodDecl()->isVariadic();
|
||||
|
||||
if (!isVariadic) {
|
||||
Diag(Fn->getLocStart(), diag::err_va_start_used_in_non_variadic_function);
|
||||
|
@ -172,10 +172,10 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) {
|
|||
// FIXME: This isn't correct for methods (results in bogus warning).
|
||||
// Get the last formal in the current function.
|
||||
const ParmVarDecl *LastArg;
|
||||
if (CurFunctionDecl)
|
||||
LastArg = *(CurFunctionDecl->param_end()-1);
|
||||
if (getCurFunctionDecl())
|
||||
LastArg = *(getCurFunctionDecl()->param_end()-1);
|
||||
else
|
||||
LastArg = *(CurMethodDecl->param_end()-1);
|
||||
LastArg = *(getCurMethodDecl()->param_end()-1);
|
||||
SecondArgIsLastNamedArgument = PV == LastArg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1463,7 +1463,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
|
|||
}
|
||||
|
||||
Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
|
||||
assert(CurFunctionDecl == 0 && "Function parsing confused");
|
||||
assert(getCurFunctionDecl() == 0 && "Function parsing confused");
|
||||
assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
|
||||
"Not a function declarator!");
|
||||
DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun;
|
||||
|
@ -1512,7 +1512,6 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
|
|||
}
|
||||
Decl *decl = static_cast<Decl*>(ActOnDeclarator(GlobalScope, D, 0));
|
||||
FunctionDecl *FD = cast<FunctionDecl>(decl);
|
||||
CurFunctionDecl = FD;
|
||||
PushDeclContext(FD);
|
||||
|
||||
// Check the validity of our function parameters
|
||||
|
@ -1533,11 +1532,9 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
|
|||
Decl *dcl = static_cast<Decl *>(D);
|
||||
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(dcl)) {
|
||||
FD->setBody((Stmt*)Body);
|
||||
assert(FD == CurFunctionDecl && "Function parsing confused");
|
||||
CurFunctionDecl = 0;
|
||||
assert(FD == getCurFunctionDecl() && "Function parsing confused");
|
||||
} else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(dcl)) {
|
||||
MD->setBody((Stmt*)Body);
|
||||
CurMethodDecl = 0;
|
||||
}
|
||||
PopDeclContext();
|
||||
// Verify and clean out per-function state.
|
||||
|
|
|
@ -21,7 +21,7 @@ using namespace clang;
|
|||
/// ObjCActOnStartOfMethodDef - This routine sets up parameters; invisible
|
||||
/// and user declared, in the method definition's AST.
|
||||
void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
|
||||
assert(CurMethodDecl == 0 && "Method parsing confused");
|
||||
assert(getCurMethodDecl() == 0 && "Method parsing confused");
|
||||
ObjCMethodDecl *MDecl = dyn_cast<ObjCMethodDecl>(static_cast<Decl *>(D));
|
||||
assert(MDecl != 0 && "Not a method declarator!");
|
||||
|
||||
|
@ -32,7 +32,6 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
|
|||
AddFactoryMethodToGlobalPool(MDecl);
|
||||
|
||||
// Allow all of Sema to see that we are entering a method definition.
|
||||
CurMethodDecl = MDecl;
|
||||
PushDeclContext(MDecl);
|
||||
|
||||
// Create Decl objects for each parameter, entrring them in the scope for
|
||||
|
@ -53,11 +52,11 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
|
|||
}
|
||||
} else // we have a factory method.
|
||||
selfTy = Context.getObjCClassType();
|
||||
CurMethodDecl->setSelfDecl(CreateImplicitParameter(FnBodyScope,
|
||||
getCurMethodDecl()->setSelfDecl(CreateImplicitParameter(FnBodyScope,
|
||||
PI.Ident, PI.IdentLoc, selfTy));
|
||||
|
||||
PI.Ident = &Context.Idents.get("_cmd");
|
||||
CurMethodDecl->setCmdDecl(CreateImplicitParameter(FnBodyScope,
|
||||
getCurMethodDecl()->setCmdDecl(CreateImplicitParameter(FnBodyScope,
|
||||
PI.Ident, PI.IdentLoc, Context.getObjCSelType()));
|
||||
|
||||
// Introduce all of the other parameters into this scope.
|
||||
|
@ -1191,4 +1190,3 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
|||
|
||||
return PIDecl;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
|
|||
|
||||
// If this reference is in an Objective-C method, then ivar lookup happens as
|
||||
// well.
|
||||
if (CurMethodDecl) {
|
||||
if (getCurMethodDecl()) {
|
||||
ScopedDecl *SD = dyn_cast_or_null<ScopedDecl>(D);
|
||||
// There are two cases to handle here. 1) scoped lookup could have failed,
|
||||
// in which case we should look for an ivar. 2) scoped lookup could have
|
||||
|
@ -89,7 +89,8 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
|
|||
// variable). In these two cases, we do a lookup for an ivar with this
|
||||
// name, if the lookup suceeds, we replace it our current decl.
|
||||
if (SD == 0 || SD->isDefinedOutsideFunctionOrMethod()) {
|
||||
ObjCInterfaceDecl *IFace = CurMethodDecl->getClassInterface(), *DeclClass;
|
||||
ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
|
||||
ObjCInterfaceDecl *DeclClass;
|
||||
if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(&II, DeclClass)) {
|
||||
// FIXME: This should use a new expr for a direct reference, don't turn
|
||||
// this into Self->ivar, just return a BareIVarExpr or something.
|
||||
|
@ -101,7 +102,7 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
|
|||
}
|
||||
if (SD == 0 && !strcmp(II.getName(), "super")) {
|
||||
QualType T = Context.getPointerType(Context.getObjCInterfaceType(
|
||||
CurMethodDecl->getClassInterface()));
|
||||
getCurMethodDecl()->getClassInterface()));
|
||||
return new ObjCSuperRefExpr(T, Loc);
|
||||
}
|
||||
}
|
||||
|
@ -153,16 +154,16 @@ Sema::ExprResult Sema::ActOnPreDefinedExpr(SourceLocation Loc,
|
|||
}
|
||||
|
||||
// Verify that this is in a function context.
|
||||
if (CurFunctionDecl == 0 && CurMethodDecl == 0)
|
||||
if (getCurFunctionDecl() == 0 && getCurMethodDecl() == 0)
|
||||
return Diag(Loc, diag::err_predef_outside_function);
|
||||
|
||||
// Pre-defined identifiers are of type char[x], where x is the length of the
|
||||
// string.
|
||||
unsigned Length;
|
||||
if (CurFunctionDecl)
|
||||
Length = CurFunctionDecl->getIdentifier()->getLength();
|
||||
if (getCurFunctionDecl())
|
||||
Length = getCurFunctionDecl()->getIdentifier()->getLength();
|
||||
else
|
||||
Length = CurMethodDecl->getSynthesizedMethodSize();
|
||||
Length = getCurMethodDecl()->getSynthesizedMethodSize();
|
||||
|
||||
llvm::APInt LengthI(32, Length + 1);
|
||||
QualType ResTy = Context.CharTy.getQualifiedType(QualType::Const);
|
||||
|
@ -805,7 +806,7 @@ ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
|
|||
if (CheckInitializerTypes(literalExpr, literalType))
|
||||
return true;
|
||||
|
||||
bool isFileScope = !CurFunctionDecl && !CurMethodDecl;
|
||||
bool isFileScope = !getCurFunctionDecl() && !getCurMethodDecl();
|
||||
if (isFileScope) { // 6.5.2.5p3
|
||||
if (CheckForConstantInitializer(literalExpr, literalType))
|
||||
return true;
|
||||
|
@ -2459,6 +2460,3 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
|
|||
SrcExpr->getSourceRange());
|
||||
return isInvalid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -147,12 +147,12 @@ Sema::ExprResult Sema::ActOnClassMessage(
|
|||
|
||||
Expr **ArgExprs = reinterpret_cast<Expr **>(Args);
|
||||
ObjCInterfaceDecl* ClassDecl = 0;
|
||||
if (!strcmp(receiverName->getName(), "super") && CurMethodDecl) {
|
||||
ClassDecl = CurMethodDecl->getClassInterface()->getSuperClass();
|
||||
if (!strcmp(receiverName->getName(), "super") && getCurMethodDecl()) {
|
||||
ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
|
||||
if (!ClassDecl)
|
||||
return Diag(lbrac, diag::error_no_super_class,
|
||||
CurMethodDecl->getClassInterface()->getName());
|
||||
if (CurMethodDecl->isInstance()) {
|
||||
getCurMethodDecl()->getClassInterface()->getName());
|
||||
if (getCurMethodDecl()->isInstance()) {
|
||||
QualType superTy = Context.getObjCInterfaceType(ClassDecl);
|
||||
superTy = Context.getPointerType(superTy);
|
||||
ExprResult ReceiverExpr = new PreDefinedExpr(SourceLocation(), superTy,
|
||||
|
@ -246,8 +246,8 @@ Sema::ExprResult Sema::ActOnInstanceMessage(
|
|||
return true;
|
||||
}
|
||||
} else if (receiverType == Context.getObjCClassType().getCanonicalType()) {
|
||||
if (CurMethodDecl) {
|
||||
ObjCInterfaceDecl* ClassDecl = CurMethodDecl->getClassInterface();
|
||||
if (getCurMethodDecl()) {
|
||||
ObjCInterfaceDecl* ClassDecl = getCurMethodDecl()->getClassInterface();
|
||||
// If we have an implementation in scope, check "private" methods.
|
||||
if (ClassDecl)
|
||||
if (ObjCImplementationDecl *ImpDecl =
|
||||
|
|
|
@ -626,21 +626,24 @@ Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
|
|||
Action::StmtResult
|
||||
Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
|
||||
Expr *RetValExp = static_cast<Expr *>(rex);
|
||||
QualType FnRetType = CurFunctionDecl ? CurFunctionDecl->getResultType() :
|
||||
CurMethodDecl->getResultType();
|
||||
QualType FnRetType =
|
||||
getCurFunctionDecl() ? getCurFunctionDecl()->getResultType() :
|
||||
getCurMethodDecl()->getResultType();
|
||||
|
||||
if (FnRetType->isVoidType()) {
|
||||
if (RetValExp) // C99 6.8.6.4p1 (ext_ since GCC warns)
|
||||
Diag(ReturnLoc, diag::ext_return_has_expr,
|
||||
(CurFunctionDecl ? CurFunctionDecl->getIdentifier()->getName() :
|
||||
CurMethodDecl->getSelector().getName()),
|
||||
( getCurFunctionDecl() ?
|
||||
getCurFunctionDecl()->getIdentifier()->getName() :
|
||||
getCurMethodDecl()->getSelector().getName() ),
|
||||
RetValExp->getSourceRange());
|
||||
return new ReturnStmt(ReturnLoc, RetValExp);
|
||||
} else {
|
||||
if (!RetValExp) {
|
||||
const char *funcName = CurFunctionDecl ?
|
||||
CurFunctionDecl->getIdentifier()->getName() :
|
||||
CurMethodDecl->getSelector().getName().c_str();
|
||||
const char *funcName =
|
||||
getCurFunctionDecl() ?
|
||||
getCurFunctionDecl()->getIdentifier()->getName() :
|
||||
getCurMethodDecl()->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
|
||||
|
@ -816,5 +819,3 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprTy *SynchExpr,
|
|||
static_cast<Stmt*>(SynchExpr), static_cast<Stmt*>(SynchBody));
|
||||
return SS;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue