diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/MinimalAction.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseObjc.cpp | 41 | ||||
| -rw-r--r-- | clang/lib/Sema/Sema.h | 18 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 83 | 
6 files changed, 85 insertions, 71 deletions
diff --git a/clang/lib/Parse/MinimalAction.cpp b/clang/lib/Parse/MinimalAction.cpp index f48e8461666..91f3c6e4a4d 100644 --- a/clang/lib/Parse/MinimalAction.cpp +++ b/clang/lib/Parse/MinimalAction.cpp @@ -91,7 +91,8 @@ Action::DeclTy *  MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc,                      IdentifierInfo *ClassName, SourceLocation ClassLoc,                      IdentifierInfo *SuperName, SourceLocation SuperLoc, -                    IdentifierInfo **ProtocolNames, unsigned NumProtocols, +                    const IdentifierLocPair *ProtocolNames, +                    unsigned NumProtocols,                      SourceLocation EndProtoLoc, AttributeList *AttrList) {    TypeNameInfo *TI =      new TypeNameInfo(1, ClassName->getFETokenInfo<TypeNameInfo>()); diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 95344c438ef..1ac26a309fa 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -413,8 +413,11 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {            ConsumeToken(); // The identifier            if (Tok.is(tok::less)) {              SourceLocation endProtoLoc; -            llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; +            llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;              ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc); +             +            // FIXME: New'ing this here seems wrong, why not have the action do +            // it?              llvm::SmallVector<DeclTy *, 8> *ProtocolDecl =                       new llvm::SmallVector<DeclTy *, 8>;              DS.setProtocolQualifiers(ProtocolDecl); @@ -553,7 +556,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {      case tok::less:        if (!DS.hasTypeSpecifier()) {          SourceLocation endProtoLoc; -        llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; +        llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;          ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);          llvm::SmallVector<DeclTy *, 8> *ProtocolDecl =                   new llvm::SmallVector<DeclTy *, 8>; diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index baf2667a54f..7d7ba10a38b 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -131,7 +131,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(      SourceLocation lparenLoc = ConsumeParen();      SourceLocation categoryLoc, rparenLoc;      IdentifierInfo *categoryId = 0; -    llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; +    llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;      // For ObjC2, the category name is optional (not an error).      if (Tok.is(tok::identifier)) { @@ -185,7 +185,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(      superClassLoc = ConsumeToken();    }    // Next, we need to check for any protocol references. -  llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; +  llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs;    SourceLocation endProtoLoc;    if (Tok.is(tok::less)) {      if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) @@ -337,7 +337,7 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,  ///     copy  ///     nonatomic  /// -void Parser::ParseObjCPropertyAttribute (ObjCDeclSpec &DS) { +void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) {    SourceLocation loc = ConsumeParen(); // consume '('    while (isObjCPropertyAttribute()) {      const IdentifierInfo *II = Tok.getIdentifierInfo(); @@ -715,8 +715,9 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,  ///   objc-protocol-refs:  ///     '<' identifier-list '>'  /// -bool Parser::ParseObjCProtocolReferences( -  llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc){ +bool Parser:: +ParseObjCProtocolReferences(llvm::SmallVectorImpl<IdentifierLocPair> &Protocols, +                            SourceLocation &endLoc) {    assert(Tok.is(tok::less) && "expected <");    ConsumeToken(); // the "<" @@ -727,7 +728,8 @@ bool Parser::ParseObjCProtocolReferences(        SkipUntil(tok::greater);        return true;      } -    ProtocolRefs.push_back(Tok.getIdentifierInfo()); +    Protocols.push_back(std::make_pair(Tok.getIdentifierInfo(), +                                          Tok.getLocation()));      ConsumeToken();      if (Tok.isNot(tok::comma)) @@ -865,15 +867,17 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {    IdentifierInfo *protocolName = Tok.getIdentifierInfo();    SourceLocation nameLoc = ConsumeToken(); -  llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;    if (Tok.is(tok::semi)) { // forward declaration of one protocol. +    IdentifierLocPair ProtoInfo(protocolName, nameLoc);      ConsumeToken(); -    ProtocolRefs.push_back(protocolName); +    return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1);    } +      if (Tok.is(tok::comma)) { // list of forward declarations. +    llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; +    ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); +      // Parse the list of forward declarations. -    ProtocolRefs.push_back(protocolName); -          while (1) {        ConsumeToken(); // the ','        if (Tok.isNot(tok::identifier)) { @@ -881,7 +885,8 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {          SkipUntil(tok::semi);          return 0;        } -      ProtocolRefs.push_back(Tok.getIdentifierInfo()); +      ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), +                                               Tok.getLocation()));        ConsumeToken(); // the identifier        if (Tok.isNot(tok::comma)) @@ -890,17 +895,19 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {      // Consume the ';'.      if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))        return 0; -  } -  if (!ProtocolRefs.empty()) +          return Actions.ActOnForwardProtocolDeclaration(AtLoc,                                                     &ProtocolRefs[0],                                                      ProtocolRefs.size()); +  } +      // Last, and definitely not least, parse a protocol declaration.    SourceLocation endProtoLoc; -  if (Tok.is(tok::less)) { -    if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) -      return 0; -  } +  llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; + +  if (Tok.is(tok::less) && +      ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) +    return 0;    DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc,                                   protocolName, nameLoc, diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 4e563a934ea..714256a4cf7 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -241,7 +241,7 @@ private:                             SourceLocation KWLoc, IdentifierInfo *Name,                             SourceLocation NameLoc, AttributeList *Attr);    virtual void ActOnDefs(Scope *S, SourceLocation DeclStart, IdentifierInfo -      *ClassName, llvm::SmallVector<DeclTy*, 16> &Decls); +      *ClassName, llvm::SmallVectorImpl<DeclTy*> &Decls);    virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart,                               Declarator &D, ExprTy *BitfieldWidth); @@ -615,7 +615,8 @@ public:                      SourceLocation AtInterafceLoc,                      IdentifierInfo *ClassName, SourceLocation ClassLoc,                      IdentifierInfo *SuperName, SourceLocation SuperLoc, -                    IdentifierInfo **ProtocolNames, unsigned NumProtocols, +                    const IdentifierLocPair *ProtocolNames, +                    unsigned NumProtocols,                      SourceLocation EndProtoLoc, AttributeList *AttrList);    virtual DeclTy *ActOnCompatiblityAlias( @@ -626,14 +627,16 @@ public:    virtual DeclTy *ActOnStartProtocolInterface(                      SourceLocation AtProtoInterfaceLoc,                      IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, -                    IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, +                    const IdentifierLocPair *ProtoRefNames, +                    unsigned NumProtoRefs,                      SourceLocation EndProtoLoc);    virtual DeclTy *ActOnStartCategoryInterface(                      SourceLocation AtInterfaceLoc,                      IdentifierInfo *ClassName, SourceLocation ClassLoc,                      IdentifierInfo *CategoryName, SourceLocation CategoryLoc, -                    IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, +                    const IdentifierLocPair *ProtoRefNames, +                    unsigned NumProtoRefs,                      SourceLocation EndProtoLoc);    virtual DeclTy *ActOnStartClassImplementation( @@ -654,14 +657,13 @@ public:                                                 unsigned NumElts);    virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, -                                                  IdentifierInfo **IdentList, +                                            const IdentifierLocPair *IdentList,                                                    unsigned NumElts);    virtual void FindProtocolDeclaration(SourceLocation TypeLoc, -                                       IdentifierInfo **ProtocolId, +                                       const IdentifierLocPair *ProtocolId,                                         unsigned NumProtocols, -                                       llvm::SmallVector<DeclTy *, 8> &  -                                       Protocols); +                                   llvm::SmallVectorImpl<DeclTy *> &Protocols);    void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,                                   ObjCPropertyDecl *SuperProperty, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e2ac7c5ea51..7753a757961 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1789,7 +1789,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,  /// Collect the instance variables declared in an Objective-C object.  Used in  /// the creation of structures from objects using the @defs directive.  static void CollectIvars(ObjCInterfaceDecl *Class, -                         llvm::SmallVector<Sema::DeclTy*, 16> &ivars) { +                         llvm::SmallVectorImpl<Sema::DeclTy*> &ivars) {    if (Class->getSuperClass())      CollectIvars(Class->getSuperClass(), ivars);    ivars.append(Class->ivar_begin(), Class->ivar_end()); @@ -1799,7 +1799,7 @@ static void CollectIvars(ObjCInterfaceDecl *Class,  /// instance variables of ClassName into Decls.  void Sema::ActOnDefs(Scope *S, SourceLocation DeclStart,                        IdentifierInfo *ClassName, -                     llvm::SmallVector<DeclTy*, 16> &Decls) { +                     llvm::SmallVectorImpl<DeclTy*> &Decls) {    // Check that ClassName is a valid class    ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName);    if (!Class) { diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 9de9efab4cd..f71f4f4b786 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -68,12 +68,13 @@ void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {    }  } -Sema::DeclTy *Sema::ActOnStartClassInterface( -                    SourceLocation AtInterfaceLoc, -                    IdentifierInfo *ClassName, SourceLocation ClassLoc, -                    IdentifierInfo *SuperName, SourceLocation SuperLoc, -                    IdentifierInfo **ProtocolNames, unsigned NumProtocols, -                    SourceLocation EndProtoLoc, AttributeList *AttrList) { +Sema::DeclTy *Sema:: +ActOnStartClassInterface(SourceLocation AtInterfaceLoc, +                         IdentifierInfo *ClassName, SourceLocation ClassLoc, +                         IdentifierInfo *SuperName, SourceLocation SuperLoc, +                         const IdentifierLocPair *ProtocolNames, +                         unsigned NumProtocols, +                         SourceLocation EndProtoLoc, AttributeList *AttrList) {    assert(ClassName && "Missing class identifier");    // Check for another declaration kind with the same name. @@ -133,14 +134,14 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(    if (NumProtocols) {      llvm::SmallVector<ObjCProtocolDecl*, 8> RefProtos;      for (unsigned int i = 0; i != NumProtocols; i++) { -      ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtocolNames[i]]; +      ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtocolNames[i].first];        if (!RefPDecl) -        Diag(EndProtoLoc, diag::err_undef_protocolref, -             ProtocolNames[i]->getName(), ClassName->getName()); +        Diag(ProtocolNames[i].second, diag::err_undef_protocolref, +             ProtocolNames[i].first->getName(), ClassName->getName());        else {          if (RefPDecl->isForwardDecl()) -          Diag(EndProtoLoc, diag::warn_undef_protocolref, -               ProtocolNames[i]->getName(), ClassName->getName()); +          Diag(ProtocolNames[i].second, diag::warn_undef_protocolref, +               ProtocolNames[i].first->getName(), ClassName->getName());          RefProtos.push_back(RefPDecl);        }      } @@ -194,7 +195,7 @@ Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,  Sema::DeclTy *Sema::ActOnStartProtocolInterface(                  SourceLocation AtProtoInterfaceLoc,                  IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, -                IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, +                const IdentifierLocPair *ProtoRefNames, unsigned NumProtoRefs,                  SourceLocation EndProtoLoc) {    assert(ProtocolName && "Missing protocol identifier");    ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName]; @@ -219,14 +220,14 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(      /// Check then save referenced protocols.      llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;      for (unsigned int i = 0; i != NumProtoRefs; i++) { -      ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i]]; +      ObjCProtocolDecl *RefPDecl = ObjCProtocols[ProtoRefNames[i].first];        if (!RefPDecl) -        Diag(ProtocolLoc, diag::err_undef_protocolref, -             ProtoRefNames[i]->getName(), ProtocolName->getName()); +        Diag(ProtoRefNames[i].second, diag::err_undef_protocolref, +             ProtoRefNames[i].first->getName(), ProtocolName->getName());        else {          if (RefPDecl->isForwardDecl()) -          Diag(ProtocolLoc, diag::warn_undef_protocolref, -               ProtoRefNames[i]->getName(), ProtocolName->getName()); +          Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref, +               ProtoRefNames[i].first->getName(), ProtocolName->getName());          Protocols.push_back(RefPDecl);        }      } @@ -242,16 +243,15 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(  /// declarations in its 'Protocols' argument.  void  Sema::FindProtocolDeclaration(SourceLocation TypeLoc, -                              IdentifierInfo **ProtocolId, +                              const IdentifierLocPair *ProtocolId,                                unsigned NumProtocols, -                              llvm::SmallVector<DeclTy *,8> &Protocols) { +                              llvm::SmallVectorImpl<DeclTy*> &Protocols) {    for (unsigned i = 0; i != NumProtocols; ++i) { -    ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i]]; -    if (!PDecl) -      Diag(TypeLoc, diag::err_undeclared_protocol,  -           ProtocolId[i]->getName()); -    else +    if (ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first])        Protocols.push_back(PDecl);  +    else +      Diag(ProtocolId[i].second, diag::err_undeclared_protocol,  +           ProtocolId[i].first->getName());    }  } @@ -382,16 +382,15 @@ Sema::MergeProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,  /// ActOnForwardProtocolDeclaration -   Action::DeclTy *  Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, -        IdentifierInfo **IdentList, unsigned NumElts) { +                                      const IdentifierLocPair *IdentList, +                                      unsigned NumElts) {    llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols;    for (unsigned i = 0; i != NumElts; ++i) { -    IdentifierInfo *Ident = IdentList[i]; +    IdentifierInfo *Ident = IdentList[i].first;      ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident]; -    if (PDecl == 0)  { // Not already seen? -      // FIXME: Pass in the location of the identifier! -      PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, Ident); -    } +    if (PDecl == 0) // Not already seen? +      PDecl = ObjCProtocolDecl::Create(Context, IdentList[i].second, Ident);      Protocols.push_back(PDecl);    } @@ -399,12 +398,14 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,                                           &Protocols[0], Protocols.size());  } -Sema::DeclTy *Sema::ActOnStartCategoryInterface( -                      SourceLocation AtInterfaceLoc, -                      IdentifierInfo *ClassName, SourceLocation ClassLoc, -                      IdentifierInfo *CategoryName, SourceLocation CategoryLoc, -                      IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, -                      SourceLocation EndProtoLoc) { +Sema::DeclTy *Sema:: +ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, +                            IdentifierInfo *ClassName, SourceLocation ClassLoc, +                            IdentifierInfo *CategoryName, +                            SourceLocation CategoryLoc, +                            const IdentifierLocPair *ProtoRefNames, +                            unsigned NumProtoRefs, +                            SourceLocation EndProtoLoc) {    ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);    ObjCCategoryDecl *CDecl =  @@ -433,14 +434,14 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(      llvm::SmallVector<ObjCProtocolDecl*, 32> RefProtocols;      /// Check and then save the referenced protocols.      for (unsigned int i = 0; i != NumProtoRefs; i++) { -      ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]]; +      ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i].first];        if (!RefPDecl) -        Diag(CategoryLoc, diag::err_undef_protocolref, -             ProtoRefNames[i]->getName(), CategoryName->getName()); +        Diag(ProtoRefNames[i].second, diag::err_undef_protocolref, +             ProtoRefNames[i].first->getName(), CategoryName->getName());        else {          if (RefPDecl->isForwardDecl()) -          Diag(CategoryLoc, diag::warn_undef_protocolref, -               ProtoRefNames[i]->getName(), CategoryName->getName()); +          Diag(ProtoRefNames[i].second, diag::warn_undef_protocolref, +               ProtoRefNames[i].first->getName(), CategoryName->getName());          RefProtocols.push_back(RefPDecl);        }      }  | 

