diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-26 22:09:03 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-26 22:09:03 +0000 | 
| commit | c3b054d250cdca485c71845089c316e10610ebad (patch) | |
| tree | abae0246ec9156cc1a7cbb947b2b0dfe95fa3189 /lib/Parse | |
| parent | bca07a4524feb4edec581062d631a13116320a24 (diff) | |
Diffstat (limited to 'lib/Parse')
| -rw-r--r-- | lib/Parse/ParseDecl.cpp | 49 | ||||
| -rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 55 | ||||
| -rw-r--r-- | lib/Parse/ParseTemplate.cpp | 2 | ||||
| -rw-r--r-- | lib/Parse/Parser.cpp | 8 | 
4 files changed, 74 insertions, 40 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 5a7fc7e72d06..077edd700ad6 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -667,6 +667,8 @@ Decl *Parser::ParseDeclarationAfterDeclarator(Declarator &D,      Actions.ActOnUninitializedDecl(ThisDecl, TypeContainsAuto);    } +  Actions.FinalizeDeclaration(ThisDecl); +    return ThisDecl;  } @@ -954,8 +956,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,          goto DoneWithDeclSpec;        CXXScopeSpec SS; -      SS.setScopeRep((NestedNameSpecifier*) Tok.getAnnotationValue()); -      SS.setRange(Tok.getAnnotationRange()); +      Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), +                                                   Tok.getAnnotationRange(), +                                                   SS);        // We are looking for a qualified typename.        Token Next = NextToken(); @@ -1244,9 +1247,18 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,                                           DiagID, getLang());        break;      case tok::kw_auto: -      if (getLang().CPlusPlus0x) -        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, -                                       DiagID); +      if (getLang().CPlusPlus0x || getLang().ObjC2) { +        if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { +          isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec, +                                           DiagID, getLang()); +          if (!isInvalid) +            Diag(Tok, diag::auto_storage_class) +              << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc()); +        } +        else +          isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, +                                         DiagID); +      }        else          isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec,                                             DiagID, getLang()); @@ -1459,6 +1471,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,        else          Diag(Tok, DiagID) << PrevSpec;      } +      DS.SetRangeEnd(Tok.getLocation());      ConsumeToken();    } @@ -1973,6 +1986,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,      }    } +  bool AllowFixedUnderlyingType = getLang().CPlusPlus0x || getLang().Microsoft;    bool IsScopedEnum = false;    bool IsScopedUsingClassTag = false; @@ -1984,7 +1998,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,    }    // Must have either 'enum name' or 'enum {...}'. -  if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) { +  if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) && +      (AllowFixedUnderlyingType && Tok.isNot(tok::colon))) {      Diag(Tok, diag::err_expected_ident_lbrace);      // Skip the rest of this declarator, up until the comma or semicolon. @@ -2011,7 +2026,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,    TypeResult BaseType;    // Parse the fixed underlying type. -  if (getLang().CPlusPlus0x && Tok.is(tok::colon)) { +  if (AllowFixedUnderlyingType && Tok.is(tok::colon)) {      bool PossibleBitfield = false;      if (getCurScope()->getFlags() & Scope::ClassScope) {        // If we're in class scope, this can either be an enum declaration with @@ -2043,7 +2058,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,          // Consume the ':'.          ConsumeToken(); -        if (isCXXDeclarationSpecifier() != TPResult::True()) { +        if ((getLang().CPlusPlus &&  +             isCXXDeclarationSpecifier() != TPResult::True()) || +            (!getLang().CPlusPlus && !isDeclarationSpecifier(true))) {            // We'll parse this as a bitfield later.            PossibleBitfield = true;            TPA.Revert(); @@ -2060,6 +2077,10 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,      if (!PossibleBitfield) {        SourceRange Range;        BaseType = ParseTypeName(&Range); +       +      if (!getLang().CPlusPlus0x) +        Diag(StartLoc, diag::ext_ms_enum_fixed_underlying_type) +          << Range;      }    } @@ -2090,6 +2111,14 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,      return;          } +  if (!Name && TUK != Sema::TUK_Definition) { +    Diag(Tok, diag::err_enumerator_unnamed_no_def); +     +    // Skip the rest of this declarator, up until the comma or semicolon. +    SkipUntil(tok::comma, true); +    return; +  } +          bool Owned = false;    bool IsDependent = false;    SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc; @@ -2734,6 +2763,9 @@ void Parser::ParseDeclaratorInternal(Declarator &D,      if (Kind == tok::star)        // Remember that we parsed a pointer type, and remember the type-quals.        D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc, +                                                DS.getConstSpecLoc(), +                                                DS.getVolatileSpecLoc(), +                                                DS.getRestrictSpecLoc(),                                                  DS.takeAttributes()),                      SourceLocation());      else @@ -3730,4 +3762,3 @@ bool Parser::TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc,    }    return false;  } -   diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index e73578f23e36..d8db711809ed 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -65,8 +65,9 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,           "Call sites of this function should be guarded by checking for C++");    if (Tok.is(tok::annot_cxxscope)) { -    SS.setScopeRep(static_cast<NestedNameSpecifier*>(Tok.getAnnotationValue())); -    SS.setRange(Tok.getAnnotationRange()); +    Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), +                                                 Tok.getAnnotationRange(), +                                                 SS);      ConsumeToken();      return false;    } @@ -80,10 +81,9 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,        return false;      // '::' - Global scope qualifier. -    SourceLocation CCLoc = ConsumeToken(); -    SS.setBeginLoc(CCLoc); -    SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(getCurScope(), CCLoc)); -    SS.setEndLoc(CCLoc); +    if (Actions.ActOnCXXGlobalScopeSpecifier(getCurScope(), ConsumeToken(), SS)) +      return true; +          HasScopeSpecifier = true;    } @@ -208,20 +208,20 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,          assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");          SourceLocation CCLoc = ConsumeToken(); -        if (!HasScopeSpecifier) { -          SS.setBeginLoc(TypeToken.getLocation()); +        if (!HasScopeSpecifier)            HasScopeSpecifier = true; -        }          if (ParsedType T = getTypeAnnotation(TypeToken)) { -          CXXScopeTy *Scope = -            Actions.ActOnCXXNestedNameSpecifier(getCurScope(), SS, T, -                                                TypeToken.getAnnotationRange(), -                                                CCLoc); -          SS.setScopeRep(Scope); -        } else -          SS.setScopeRep(0); -        SS.setEndLoc(CCLoc); +          if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), T, CCLoc, SS)) +            SS.SetInvalid(SourceRange(SS.getBeginLoc(), CCLoc)); +           +          continue; +        } else { +          SourceLocation Start = SS.getBeginLoc().isValid()? SS.getBeginLoc()  +                                                           : CCLoc; +          SS.SetInvalid(SourceRange(Start, CCLoc)); +        } +                  continue;        } @@ -245,7 +245,9 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,      // If we get foo:bar, this is almost certainly a typo for foo::bar.  Recover      // and emit a fixit hint for it.      if (Next.is(tok::colon) && !ColonIsSacred) { -      if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, II, ObjectType,  +      if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, II,  +                                            Tok.getLocation(),  +                                            Next.getLocation(), ObjectType,                                              EnteringContext) &&            // If the token after the colon isn't an identifier, it's still an            // error, but they probably meant something else strange so don't @@ -274,16 +276,11 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,               "NextToken() not working properly!");        SourceLocation CCLoc = ConsumeToken(); -      if (!HasScopeSpecifier) { -        SS.setBeginLoc(IdLoc); -        HasScopeSpecifier = true; -      } - -      if (!SS.isInvalid()) -        SS.setScopeRep( -            Actions.ActOnCXXNestedNameSpecifier(getCurScope(), SS, IdLoc, CCLoc, II, -                                                ObjectType, EnteringContext)); -      SS.setEndLoc(CCLoc); +      HasScopeSpecifier = true; +      if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), II, IdLoc, CCLoc, +                                              ObjectType, EnteringContext, SS)) +        SS.SetInvalid(SourceRange(IdLoc, CCLoc)); +              continue;      } @@ -836,6 +833,8 @@ bool Parser::ParseCXXCondition(ExprResult &ExprOut,    // FIXME: Build a reference to this declaration? Convert it to bool?    // (This is currently handled by Sema). + +  Actions.FinalizeDeclaration(DeclOut);    return false;  } diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 8387c8819525..59ced8b07fc5 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -829,7 +829,7 @@ bool Parser::AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,      TemplateId->RAngleLoc = RAngleLoc;      ParsedTemplateArgument *Args = TemplateId->getTemplateArgs();      for (unsigned Arg = 0, ArgEnd = TemplateArgs.size(); Arg != ArgEnd; ++Arg) -      Args[Arg] = TemplateArgs[Arg]; +      Args[Arg] = ParsedTemplateArgument(TemplateArgs[Arg]);      Tok.setAnnotationValue(TemplateId);      if (TemplateKWLoc.isValid())        Tok.setLocation(TemplateKWLoc); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index a50763a0e38e..07e592cdb05b 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -296,6 +296,10 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,      case tok::wide_string_literal:        ConsumeStringToken();        break; +         +    case tok::at: +      return false; +            case tok::semi:        if (StopAtSemi)          return false; @@ -1159,7 +1163,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) {    else      PP.EnterToken(Tok);    Tok.setKind(tok::annot_cxxscope); -  Tok.setAnnotationValue(SS.getScopeRep()); +  Tok.setAnnotationValue(Actions.SaveNestedNameSpecifierAnnotation(SS));    Tok.setAnnotationRange(SS.getRange());    // In case the tokens were cached, have Preprocessor replace them @@ -1196,7 +1200,7 @@ bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) {    else      PP.EnterToken(Tok);    Tok.setKind(tok::annot_cxxscope); -  Tok.setAnnotationValue(SS.getScopeRep()); +  Tok.setAnnotationValue(Actions.SaveNestedNameSpecifierAnnotation(SS));    Tok.setAnnotationRange(SS.getRange());    // In case the tokens were cached, have Preprocessor replace them with the  | 
