diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Parse/Parser.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Parse/Parser.cpp | 133 |
1 files changed, 76 insertions, 57 deletions
diff --git a/contrib/llvm/tools/clang/lib/Parse/Parser.cpp b/contrib/llvm/tools/clang/lib/Parse/Parser.cpp index ccefb3d..f968f99 100644 --- a/contrib/llvm/tools/clang/lib/Parse/Parser.cpp +++ b/contrib/llvm/tools/clang/lib/Parse/Parser.cpp @@ -491,6 +491,8 @@ void Parser::Initialize() { Ident_deprecated = nullptr; Ident_obsoleted = nullptr; Ident_unavailable = nullptr; + Ident_strict = nullptr; + Ident_replacement = nullptr; Ident__except = nullptr; @@ -545,7 +547,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) { if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof)) ConsumeToken(); - Result = DeclGroupPtrTy(); + Result = nullptr; switch (Tok.getKind()) { case tok::annot_pragma_unused: HandlePragmaUnused(); @@ -625,52 +627,54 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, if (PP.isCodeCompletionReached()) { cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } Decl *SingleDecl = nullptr; switch (Tok.getKind()) { case tok::annot_pragma_vis: HandlePragmaVisibility(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_pack: HandlePragmaPack(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_msstruct: HandlePragmaMSStruct(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_align: HandlePragmaAlign(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_weak: HandlePragmaWeak(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_weakalias: HandlePragmaWeakAlias(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_redefine_extname: HandlePragmaRedefineExtname(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_fp_contract: HandlePragmaFPContract(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_opencl_extension: HandlePragmaOpenCLExtension(); - return DeclGroupPtrTy(); - case tok::annot_pragma_openmp: - return ParseOpenMPDeclarativeDirective(); + return nullptr; + case tok::annot_pragma_openmp: { + AccessSpecifier AS = AS_none; + return ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, attrs); + } case tok::annot_pragma_ms_pointers_to_members: HandlePragmaMSPointersToMembers(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_ms_vtordisp: HandlePragmaMSVtorDisp(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_ms_pragma: HandlePragmaMSPragma(); - return DeclGroupPtrTy(); + return nullptr; case tok::annot_pragma_dump: HandlePragmaDump(); - return DeclGroupPtrTy(); + return nullptr; case tok::semi: // Either a C++11 empty-declaration or attribute-declaration. SingleDecl = Actions.ActOnEmptyDeclaration(getCurScope(), @@ -681,10 +685,10 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, case tok::r_brace: Diag(Tok, diag::err_extraneous_closing_brace); ConsumeBrace(); - return DeclGroupPtrTy(); + return nullptr; case tok::eof: Diag(Tok, diag::err_expected_external_declaration); - return DeclGroupPtrTy(); + return nullptr; case tok::kw___extension__: { // __extension__ silences extension warnings in the subexpression. ExtensionRAIIObject O(Diags); // Use RAII to do this. @@ -712,7 +716,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, "top-level asm block"); if (Result.isInvalid()) - return DeclGroupPtrTy(); + return nullptr; SingleDecl = Actions.ActOnFileScopeAsmDecl(Result.get(), StartLoc, EndLoc); break; } @@ -723,7 +727,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, if (!getLangOpts().ObjC1) { Diag(Tok, diag::err_expected_external_declaration); ConsumeToken(); - return DeclGroupPtrTy(); + return nullptr; } SingleDecl = ParseObjCMethodDefinition(); break; @@ -732,7 +736,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, CurParsedObjCImpl? Sema::PCC_ObjCImplementation : Sema::PCC_Namespace); cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; case tok::kw_using: case tok::kw_namespace: case tok::kw_typedef: @@ -796,8 +800,8 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, case tok::kw___if_exists: case tok::kw___if_not_exists: ParseMicrosoftIfExistsExternalDeclaration(); - return DeclGroupPtrTy(); - + return nullptr; + default: dont_know: // We can't tell whether this is a function-definition or declaration yet. @@ -876,15 +880,21 @@ Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, // may get this far before the problem becomes obvious. if (DS.hasTagDefinition() && DiagnoseMissingSemiAfterTagDefinition(DS, AS, DSC_top_level)) - return DeclGroupPtrTy(); + return nullptr; // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };" // declaration-specifiers init-declarator-list[opt] ';' if (Tok.is(tok::semi)) { ProhibitAttributes(attrs); ConsumeToken(); - Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS); + RecordDecl *AnonRecord = nullptr; + Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, + DS, AnonRecord); DS.complete(TheDecl); + if (AnonRecord) { + Decl* decls[] = {AnonRecord, TheDecl}; + return Actions.BuildDeclaratorGroup(decls, /*TypeMayContainAuto=*/false); + } return Actions.ConvertDeclToDeclGroup(TheDecl); } @@ -899,7 +909,7 @@ Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs, !Tok.isObjCAtKeyword(tok::objc_protocol)) { Diag(Tok, diag::err_objc_unexpected_attr); SkipUntil(tok::semi); // FIXME: better skip? - return DeclGroupPtrTy(); + return nullptr; } DS.abort(); @@ -1034,6 +1044,12 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, D.complete(DP); D.getMutableDeclSpec().abort(); + if (SkipFunctionBodies && (!DP || Actions.canSkipFunctionBody(DP)) && + trySkippingFunctionBody()) { + BodyScope.Exit(); + return Actions.ActOnSkippedFunctionBody(DP); + } + CachedTokens Toks; LexTemplateFunctionForLateParsing(Toks); @@ -1126,6 +1142,13 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, return Res; } + if (SkipFunctionBodies && (!Res || Actions.canSkipFunctionBody(Res)) && + trySkippingFunctionBody()) { + BodyScope.Exit(); + Actions.ActOnSkippedFunctionBody(Res); + return Actions.ActOnFinishFunctionBody(Res, nullptr, false); + } + if (Tok.is(tok::kw_try)) return ParseFunctionTryBlock(Res, BodyScope); @@ -1400,7 +1423,7 @@ Parser::TryAnnotateName(bool IsAddressOfOperand, CXXScopeSpec SS; if (getLangOpts().CPlusPlus && - ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext)) + ParseOptionalCXXScopeSpecifier(SS, nullptr, EnteringContext)) return ANK_Error; if (Tok.isNot(tok::identifier) || SS.isInvalid()) { @@ -1588,9 +1611,9 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) { // simple-template-id SourceLocation TypenameLoc = ConsumeToken(); CXXScopeSpec SS; - if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/ParsedType(), - /*EnteringContext=*/false, - nullptr, /*IsTypename*/ true)) + if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr, + /*EnteringContext=*/false, nullptr, + /*IsTypename*/ true)) return true; if (!SS.isSet()) { if (Tok.is(tok::identifier) || Tok.is(tok::annot_template_id) || @@ -1646,7 +1669,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) { SourceLocation EndLoc = Tok.getLastLoc(); Tok.setKind(tok::annot_typename); - setTypeAnnotation(Tok, Ty.isInvalid() ? ParsedType() : Ty.get()); + setTypeAnnotation(Tok, Ty.isInvalid() ? nullptr : Ty.get()); Tok.setAnnotationEndLoc(EndLoc); Tok.setLocation(TypenameLoc); PP.AnnotateCachedTokens(Tok); @@ -1658,7 +1681,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) { CXXScopeSpec SS; if (getLangOpts().CPlusPlus) - if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext)) + if (ParseOptionalCXXScopeSpecifier(SS, nullptr, EnteringContext)) return true; return TryAnnotateTypeOrScopeTokenAfterScopeSpec(EnteringContext, NeedType, @@ -1675,15 +1698,12 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, if (Tok.is(tok::identifier)) { IdentifierInfo *CorrectedII = nullptr; // Determine whether the identifier is a type name. - if (ParsedType Ty = Actions.getTypeName(*Tok.getIdentifierInfo(), - Tok.getLocation(), getCurScope(), - &SS, false, - NextToken().is(tok::period), - ParsedType(), - /*IsCtorOrDtorName=*/false, - /*NonTrivialTypeSourceInfo*/ true, - NeedType ? &CorrectedII - : nullptr)) { + if (ParsedType Ty = Actions.getTypeName( + *Tok.getIdentifierInfo(), Tok.getLocation(), getCurScope(), &SS, + false, NextToken().is(tok::period), nullptr, + /*IsCtorOrDtorName=*/false, + /*NonTrivialTypeSourceInfo*/ true, + NeedType ? &CorrectedII : nullptr)) { // A FixIt was applied as a result of typo correction if (CorrectedII) Tok.setIdentifierInfo(CorrectedII); @@ -1734,12 +1754,11 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool EnteringContext, UnqualifiedId TemplateName; TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); bool MemberOfUnknownSpecialization; - if (TemplateNameKind TNK - = Actions.isTemplateName(getCurScope(), SS, - /*hasTemplateKeyword=*/false, TemplateName, - /*ObjectType=*/ ParsedType(), - EnteringContext, - Template, MemberOfUnknownSpecialization)) { + if (TemplateNameKind TNK = + Actions.isTemplateName(getCurScope(), SS, + /*hasTemplateKeyword=*/false, TemplateName, + /*ObjectType=*/nullptr, EnteringContext, + Template, MemberOfUnknownSpecialization)) { // Consume the identifier. ConsumeToken(); if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), @@ -1793,7 +1812,7 @@ bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) { "Cannot be a type or scope token!"); CXXScopeSpec SS; - if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext)) + if (ParseOptionalCXXScopeSpecifier(SS, nullptr, EnteringContext)) return true; if (SS.isEmpty()) return false; @@ -1897,7 +1916,7 @@ bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) { // Parse nested-name-specifier. if (getLangOpts().CPlusPlus) - ParseOptionalCXXScopeSpecifier(Result.SS, ParsedType(), + ParseOptionalCXXScopeSpecifier(Result.SS, nullptr, /*EnteringContext=*/false); // Check nested-name specifier. @@ -1908,8 +1927,8 @@ bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) { // Parse the unqualified-id. SourceLocation TemplateKWLoc; // FIXME: parsed, but unused. - if (ParseUnqualifiedId(Result.SS, false, true, true, ParsedType(), - TemplateKWLoc, Result.Name)) { + if (ParseUnqualifiedId(Result.SS, false, true, true, nullptr, TemplateKWLoc, + Result.Name)) { T.skipToEnd(); return true; } @@ -1990,12 +2009,12 @@ Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) { if (Tok.is(tok::code_completion)) { Actions.CodeCompleteModuleImport(ImportLoc, Path); cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } Diag(Tok, diag::err_module_expected_ident); SkipUntil(tok::semi); - return DeclGroupPtrTy(); + return nullptr; } // Record this part of the module path. @@ -2013,14 +2032,14 @@ Parser::DeclGroupPtrTy Parser::ParseModuleImport(SourceLocation AtLoc) { if (PP.hadModuleLoaderFatalFailure()) { // With a fatal failure in the module loader, we abort parsing. cutOffParsing(); - return DeclGroupPtrTy(); + return nullptr; } DeclResult Import = Actions.ActOnModuleImport(AtLoc, ImportLoc, Path); ExpectAndConsumeSemi(diag::err_module_expected_semi); if (Import.isInvalid()) - return DeclGroupPtrTy(); - + return nullptr; + return Actions.ConvertDeclToDeclGroup(Import.get()); } |