[cfe-commits] r94122 - in /cfe/trunk/lib: AST/DeclBase.cpp Sema/SemaDecl.cpp Sema/SemaExpr.cpp Sema/SemaTemplate.cpp Sema/SemaTemplateInstantiateDecl.cpp

John McCall rjmccall at apple.com
Thu Jan 21 16:28:28 PST 2010


Author: rjmccall
Date: Thu Jan 21 18:28:27 2010
New Revision: 94122

URL: http://llvm.org/viewvc/llvm-project?rev=94122&view=rev
Log:
Create function, block, and template parameters in the context of the
translation unit.  This is temporary for function and block parameters;
template parameters can just stay this way, since Templates aren't
DeclContexts.  This gives us the nice property that everything created
in a record DC should have access in C++.


Modified:
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=94122&r1=94121&r2=94122&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Thu Jan 21 18:28:27 2010
@@ -418,8 +418,6 @@
   //    FunctionDecl)
   // 4. the context is not a record
   if (isa<TranslationUnitDecl>(this) ||
-      isTemplateParameter() ||
-      isa<ParmVarDecl>(this) ||
       !isa<CXXRecordDecl>(getDeclContext()))
     return;
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 21 18:28:27 2010
@@ -2864,7 +2864,7 @@
     // Synthesize a parameter for each argument type.
     for (FunctionProtoType::arg_type_iterator AI = FT->arg_type_begin(),
          AE = FT->arg_type_end(); AI != AE; ++AI) {
-      ParmVarDecl *Param = ParmVarDecl::Create(Context, DC,
+      ParmVarDecl *Param = ParmVarDecl::Create(Context, NewFD,
                                                SourceLocation(), 0,
                                                *AI, /*TInfo=*/0,
                                                VarDecl::None, 0);
@@ -3862,8 +3862,13 @@
 
   QualType T = adjustParameterType(parmDeclType);
 
+  // Temporarily put parameter variables in the translation unit, not
+  // the enclosing context.  This prevents them from accidentally
+  // looking like class members in C++.
+  DeclContext *DC = Context.getTranslationUnitDecl();
+
   ParmVarDecl *New
-    = ParmVarDecl::Create(Context, CurContext, D.getIdentifierLoc(), II,
+    = ParmVarDecl::Create(Context, DC, D.getIdentifierLoc(), II,
                           T, TInfo, StorageClass, 0);
 
   if (D.isInvalidType())

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jan 21 18:28:27 2010
@@ -6801,10 +6801,13 @@
   CurBlock->TheDecl->setIsVariadic(CurBlock->isVariadic);
   ProcessDeclAttributes(CurScope, CurBlock->TheDecl, ParamInfo);
   for (BlockDecl::param_iterator AI = CurBlock->TheDecl->param_begin(),
-       E = CurBlock->TheDecl->param_end(); AI != E; ++AI)
+         E = CurBlock->TheDecl->param_end(); AI != E; ++AI) {
+    (*AI)->setOwningFunction(CurBlock->TheDecl);
+
     // If this has an identifier, add it to the scope stack.
     if ((*AI)->getIdentifier())
       PushOnScopeChains(*AI, CurBlock->TheScope);
+  }
 
   // Check for a valid sentinel attribute on this block.
   if (!CurBlock->isVariadic &&

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Jan 21 18:28:27 2010
@@ -449,8 +449,8 @@
     Loc = KeyLoc;
 
   TemplateTypeParmDecl *Param
-    = TemplateTypeParmDecl::Create(Context, CurContext, Loc,
-                                   Depth, Position, ParamName, Typename,
+    = TemplateTypeParmDecl::Create(Context, Context.getTranslationUnitDecl(),
+                                   Loc, Depth, Position, ParamName, Typename,
                                    Ellipsis);
   if (Invalid)
     Param->setInvalidDecl();
@@ -572,7 +572,8 @@
   }
 
   NonTypeTemplateParmDecl *Param
-    = NonTypeTemplateParmDecl::Create(Context, CurContext, D.getIdentifierLoc(),
+    = NonTypeTemplateParmDecl::Create(Context, Context.getTranslationUnitDecl(),
+                                      D.getIdentifierLoc(),
                                       Depth, Position, ParamName, T, TInfo);
   if (Invalid)
     Param->setInvalidDecl();
@@ -625,8 +626,8 @@
 
   // Construct the parameter object.
   TemplateTemplateParmDecl *Param =
-    TemplateTemplateParmDecl::Create(Context, CurContext, TmpLoc, Depth,
-                                     Position, Name,
+    TemplateTemplateParmDecl::Create(Context, Context.getTranslationUnitDecl(),
+                                     TmpLoc, Depth, Position, Name,
                                      (TemplateParameterList*)Params);
 
   // Make sure the parameter is valid.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Jan 21 18:28:27 2010
@@ -1012,7 +1012,9 @@
 
   // Allocate the parameter
   ParmVarDecl *Param
-    = ParmVarDecl::Create(SemaRef.Context, Owner, D->getLocation(),
+    = ParmVarDecl::Create(SemaRef.Context,
+                          SemaRef.Context.getTranslationUnitDecl(),
+                          D->getLocation(),
                           D->getIdentifier(), T, DI, D->getStorageClass(), 0);
 
   // Mark the default argument as being uninstantiated.





More information about the cfe-commits mailing list