]> granicus.if.org Git - clang/commitdiff
Replace CurFunctionDecl and CurMethodDecl with methods getCurFunctionDecl() and getCu...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 28 Jun 2008 06:07:14 +0000 (06:07 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 28 Jun 2008 06:07:14 +0000 (06:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52852 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
lib/Sema/Sema.h
lib/Sema/SemaChecking.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprObjC.cpp
lib/Sema/SemaStmt.cpp

index 93210ab70f491b39f7157503bdb248f65af57b4a..c87e615f90fc0a1886c53c56d1ed237d3e942fb8 100644 (file)
@@ -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.  
index 0dda082d7e3021af10e8099df9fa6699b4efda83..73468dc579c953e403beaed1466c2106039f055b 100644 (file)
@@ -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);
index 7c0ff47a60542ca2f9a5bad9b4bb6c340aa535f3..9008884909f1bb303ef7046c4dc51438f5c8af5a 100644 (file)
@@ -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;
     }
   }
index 0b048b0a0afedd5076874a03e606aa8658d8c468..df75109e562c9082e4aeacf2099bb76d830ad42e 100644 (file)
@@ -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.
index 5ac493140b6450f986580ac20bd25acd622da2cd..09f1179112483440cb61d122de5ed6e9bf7637fe 100644 (file)
@@ -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;
 }
-
index 70899190839bf393aac404a1cf7a890529b7d83d..97513925fdaa76831789ebdfc15bd1fb2e1aff01 100644 (file)
@@ -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;
 }
-
-
-
index c33efbd743f64cfd3a3f299501926328ae3c96a2..abbc7666e90f7ee4034898ae725be8f780e7fe41 100644 (file)
@@ -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 = 
index d8f213a973c222f3111588d2970de286959296b6..a1ec7d993076e55b3d17233d1822e8bbc5851734 100644 (file)
@@ -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;
 }
-
-