[cfe-commits] r52852 - in /cfe/trunk/lib/Sema: Sema.cpp Sema.h SemaChecking.cpp SemaDecl.cpp SemaDeclObjC.cpp SemaExpr.cpp SemaExprObjC.cpp SemaStmt.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Fri Jun 27 23:07:14 PDT 2008


Author: akirtzidis
Date: Sat Jun 28 01:07:14 2008
New Revision: 52852

URL: http://llvm.org/viewvc/llvm-project?rev=52852&view=rev
Log:
Replace CurFunctionDecl and CurMethodDecl with methods getCurFunctionDecl() and getCurMethodDecl() that return the appropriate Decl through CurContext.

Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Jun 28 01:07:14 2008
@@ -97,8 +97,7 @@
 }
 
 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.  

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Jun 28 01:07:14 2008
@@ -68,15 +68,8 @@
   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 @@
   /// 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);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Jun 28 01:07:14 2008
@@ -151,11 +151,11 @@
   
   // 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 @@
       // 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;
     }
   }

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jun 28 01:07:14 2008
@@ -1463,7 +1463,7 @@
 }
 
 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 @@
   }
   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 @@
   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.

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Jun 28 01:07:14 2008
@@ -21,7 +21,7 @@
 /// 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 @@
     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 @@
     }
   } 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 @@
     
   return PIDecl;
 }
-

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Jun 28 01:07:14 2008
@@ -81,7 +81,7 @@
   
   // 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 @@
     // 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 @@
     }
     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 @@
   }
 
   // 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 @@
   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 @@
        SrcExpr->getSourceRange());
   return isInvalid;
 }
-
-
-

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sat Jun 28 01:07:14 2008
@@ -147,12 +147,12 @@
 
   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 @@
           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 = 

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=52852&r1=52851&r2=52852&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Jun 28 01:07:14 2008
@@ -626,21 +626,24 @@
 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 @@
     static_cast<Stmt*>(SynchExpr), static_cast<Stmt*>(SynchBody));
   return SS;
 }
-
-





More information about the cfe-commits mailing list