diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-03-18 22:33:24 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-03-18 22:33:24 +0000 |
commit | 38e24c782c17b6058bf61d635747bbde19fb1bc7 (patch) | |
tree | beb09e8aa66b92cfbc7ecb904fb34f8fb578dd61 | |
parent | e530ad407af4a8904377592bfdb236acd320c6c2 (diff) |
objc: Implemented variables declared in class interface
whose sema decl is at the translation unit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67249 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/DeclObjC.h | 15 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 4 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 18 | ||||
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 13 | ||||
-rw-r--r-- | test/CodeGenObjC/interface-tu-variable.m | 24 |
7 files changed, 75 insertions, 11 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index e1737f37f5..cab61fc869 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -246,6 +246,11 @@ public: /// 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; public: ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L, @@ -298,7 +303,15 @@ public: 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. diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 355eed1f91..19616d5c9f 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -1366,7 +1366,9 @@ public: 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 diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 0cb9228536..aed067617e 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1234,16 +1234,24 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { // 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 diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index bb85536cd4..ca722fa68d 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -215,6 +215,7 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, 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 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, // 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 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, 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. diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 38541ef96e..d84829a0c7 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1986,7 +1986,8 @@ public: 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, diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index fb74519b57..9314134161 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1233,7 +1233,9 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, // 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 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, } } } + 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); + } } diff --git a/test/CodeGenObjC/interface-tu-variable.m b/test/CodeGenObjC/interface-tu-variable.m new file mode 100644 index 0000000000..423a05f6db --- /dev/null +++ b/test/CodeGenObjC/interface-tu-variable.m @@ -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 + +@interface XX +int x; +int one=1; +int two = 2; +@end + +@protocol PPP +int ddd; +@end + +@interface XX(CAT) + char * III; +@end + + +int main( int argc, const char *argv[] ) { + return x+one+two; +} + |