[cfe-commits] r67249 - in /cfe/trunk: include/clang/AST/DeclObjC.h include/clang/Parse/Action.h lib/CodeGen/CodeGenModule.cpp lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp test/CodeGenObjC/interface-tu-variable.m

steve naroff snaroff at apple.com
Wed Mar 18 15:58:50 PDT 2009


On Mar 18, 2009, at 6:33 PM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Wed Mar 18 17:33:24 2009
> New Revision: 67249
>
> URL: http://llvm.org/viewvc/llvm-project?rev=67249&view=rev
> Log:
> objc: Implemented variables declared in class interface
> whose sema decl is at the translation unit.
>
> Added:
>    cfe/trunk/test/CodeGenObjC/interface-tu-variable.m
> Modified:
>    cfe/trunk/include/clang/AST/DeclObjC.h
>    cfe/trunk/include/clang/Parse/Action.h
>    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>    cfe/trunk/lib/Parse/ParseObjc.cpp
>    cfe/trunk/lib/Sema/Sema.h
>    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>
> Modified: cfe/trunk/include/clang/AST/DeclObjC.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=67249&r1=67248&r2=67249&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> +++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Mar 18 17:33:24 2009
> @@ -246,6 +246,11 @@
> ///
> class ObjCContainerDecl : public NamedDecl, public DeclContext {
>   SourceLocation AtEndLoc; // marks the end of the method container.
> +  // FIXME. In the long term, all TU variables declared in class  
> scope belong
> +  // to class's decl context. This waits till we can establish  
> class's
> +  // context before processing all decls in the class.
> +  /// Instance variables in the interface.
> +  ObjCList<VarDecl> TUVars;

Fariborz,

Since this idiom is extremely uncommon, I'd prefer we don't add a list  
to every ObjCContainerDecl.

What's the problem with inserting these in the "right" context from  
the beginning?

Please advise,

snaroff

>
> public:
>
>   ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
> @@ -298,7 +303,15 @@
>   ObjCMethodDecl *getMethod(Selector Sel, bool isInstance) const {
>     return isInstance ? getInstanceMethod(Sel) : getClassMethod(Sel);
>   }
> -
> +
> +  typedef ObjCList<VarDecl>::iterator tuvar_iterator;
> +  tuvar_iterator tuvar_begin() const { return TUVars.begin(); }
> +  tuvar_iterator tuvar_end() const { return TUVars.end(); }
> +  unsigned tuvar_size() const { return TUVars.size(); }
> +  void setTUVarList(VarDecl * const *List, unsigned Num, ASTContext  
> &C) {
> +    TUVars.set(List, Num, C);
> +  }
> +
>   ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo  
> *PropertyId) const;
>
>   // Marks the end of the container.
>
> Modified: cfe/trunk/include/clang/Parse/Action.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=67249&r1=67248&r2=67249&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/Parse/Action.h (original)
> +++ cfe/trunk/include/clang/Parse/Action.h Wed Mar 18 17:33:24 2009
> @@ -1366,7 +1366,9 @@
>     DeclTy **allMethods = 0,
>     unsigned allNum = 0,
>     DeclTy **allProperties = 0,
> -    unsigned pNum = 0) {
> +    unsigned pNum = 0,
> +    DeclTy **allTUVars = 0,
> +    unsigned tuvNum = 0) {
>     return;
>   }
>   // ActOnProperty - called to build one property AST
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=67249&r1=67248&r2=67249&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Mar 18 17:33:24 2009
> @@ -1234,16 +1234,24 @@
>
>     // Objective-C Decls
>
> -    // Forward declarations, no (immediate) code generation.
> +  // Forward declarations, no (immediate) code generation.
>   case Decl::ObjCClass:
> -  case Decl::ObjCCategory:
>   case Decl::ObjCForwardProtocol:
> -  case Decl::ObjCInterface:
>     break;
> -
> +
>   case Decl::ObjCProtocol:
> -    Runtime->GenerateProtocol(cast<ObjCProtocolDecl>(D));
> +  case Decl::ObjCCategory:
> +  case Decl::ObjCInterface: {
> +    ObjCContainerDecl *OCD = cast<ObjCContainerDecl>(D);
> +    for (ObjCContainerDecl::tuvar_iterator i = OCD->tuvar_begin(),
> +         e = OCD->tuvar_end(); i != e; ++i) {
> +        VarDecl *VD = *i;
> +        EmitGlobal(VD);
> +    }
> +    if (D->getKind() == Decl::ObjCProtocol)
> +      Runtime->GenerateProtocol(cast<ObjCProtocolDecl>(D));
>     break;
> +  }
>
>   case Decl::ObjCCategoryImpl:
>     // Categories have properties but don't support synthesize so we
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=67249&r1=67248&r2=67249&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Mar 18 17:33:24 2009
> @@ -215,6 +215,7 @@
>                                         tok::ObjCKeywordKind  
> contextKey) {
>   llvm::SmallVector<DeclTy*, 32> allMethods;
>   llvm::SmallVector<DeclTy*, 16> allProperties;
> +  llvm::SmallVector<DeclTy*, 8> allTUVariables;
>   tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
>
>   SourceLocation AtEndLoc;
> @@ -252,7 +253,8 @@
>
>       // FIXME: as the name implies, this rule allows function  
> definitions.
>       // We could pass a flag or check for functions during semantic  
> analysis.
> -      ParseDeclarationOrFunctionDefinition();
> +      DeclTy *VFDecl = ParseDeclarationOrFunctionDefinition();
> +      allTUVariables.push_back(VFDecl);
>       continue;
>     }
>
> @@ -360,7 +362,10 @@
>                      allMethods.empty() ? 0 : &allMethods[0],
>                      allMethods.size(),
>                      allProperties.empty() ? 0 : &allProperties[0],
> -                     allProperties.size());
> +                     allProperties.size(),
> +                     allTUVariables.empty() ? 0 :
> +                     &allTUVariables[0],
> +                     allTUVariables.size());
> }
>
> ///   Parse property attribute declarations.
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=67249&r1=67248&r2=67249&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Wed Mar 18 17:33:24 2009
> @@ -1986,7 +1986,8 @@
>
>   virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
>                       DeclTy **allMethods = 0, unsigned allNum = 0,
> -                      DeclTy **allProperties = 0, unsigned pNum = 0);
> +                      DeclTy **allProperties = 0, unsigned pNum = 0,
> +                      DeclTy **allTUVars = 0, unsigned tuvNum = 0);
>
>   virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
>                                 FieldDeclarator &FD, ObjCDeclSpec  
> &ODS,
>
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=67249&r1=67248&r2=67249&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Mar 18 17:33:24 2009
> @@ -1233,7 +1233,9 @@
> // always null.
> void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
>                       DeclTy **allMethods, unsigned allNum,
> -                      DeclTy **allProperties, unsigned pNum) {
> +                      DeclTy **allProperties, unsigned pNum,
> +                      DeclTy **allTUVars,
> +                      unsigned tuvNum) {
>   Decl *ClassDecl = static_cast<Decl *>(classDecl);
>
>   // FIXME: If we don't have a ClassDecl, we have an error. We  
> should consider
> @@ -1337,6 +1339,15 @@
>       }
>     }
>   }
> +  llvm::SmallVector<VarDecl*, 8> allTUVariables;
> +  for (unsigned i = 0; i < tuvNum; i++) {
> +    if (VarDecl *VD = dyn_cast<VarDecl>((Decl*)allTUVars[i]))
> +      allTUVariables.push_back(VD);
> +  }
> +  if (!allTUVariables.empty() && isInterfaceDeclKind) {
> +    ObjCContainerDecl *OCD = dyn_cast<ObjCContainerDecl>(ClassDecl);
> +    OCD->setTUVarList(&allTUVariables[0], allTUVariables.size(),  
> Context);
> +  }
> }
>
>
>
> Added: cfe/trunk/test/CodeGenObjC/interface-tu-variable.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/interface-tu-variable.m?rev=67249&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/test/CodeGenObjC/interface-tu-variable.m (added)
> +++ cfe/trunk/test/CodeGenObjC/interface-tu-variable.m Wed Mar 18  
> 17:33:24 2009
> @@ -0,0 +1,24 @@
> +// RUN: clang -fnext-runtime -emit-llvm -o %t %s
> +// RUN: grep 'two = global' %t &&
> +// RUN: grep 'ddd = common' %t &&
> +// RUN: grep 'III = common' %t
> +
> + at interface XX
> +int x;
> +int one=1;
> +int two = 2;
> + at end
> +
> + at protocol PPP
> +int ddd;
> + at end
> +
> + at interface XX(CAT)
> +  char * III;
> + at end
> +
> +
> +int main( int argc, const char *argv[] ) {
> +    return x+one+two;
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list