diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-07-21 22:17:28 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-07-21 22:17:28 +0000 | 
| commit | d7352d6801f3bae265c75e9d2d9d2eba3d1c802d (patch) | |
| tree | 37aa3d0164d3e6eb9dca920a3c84f4c38442ecd8 /clang/lib/Parse | |
| parent | 5224e6a81d110faeba866ab2fef8458b6bcac111 (diff) | |
| download | bcm5719-llvm-d7352d6801f3bae265c75e9d2d9d2eba3d1c802d.tar.gz bcm5719-llvm-d7352d6801f3bae265c75e9d2d9d2eba3d1c802d.zip  | |
minor cleanup to the actions interface to pass around SmallVectorImpl instead
of a specific smallvector size.
Fix protocol lists to pass down proper location info, so we get diagnostics
like this:
t.m:3:35: error: cannot find protocol definition for 'NSCopying', referenced by 'NSWhatever'
@interface NSWhatever : NSObject <NSCopying>
                                  ^
instead of this:
t.m:3:44: error: cannot find protocol definition for 'NSCopying', referenced by 'NSWhatever'
@interface NSWhatever : NSObject <NSCopying>
                                           ^
Add a new IdentifierLocPair typedef which is just a pair<IdentifierInfo*, SourceLocation>
llvm-svn: 53883
Diffstat (limited to 'clang/lib/Parse')
| -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 | 
3 files changed, 31 insertions, 20 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,  | 

