From: peter klausler Date: Mon, 18 Mar 2019 19:24:44 +0000 (-0700) Subject: [flang] Simplify X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f8c80f90ee6fe91e2dec6a499bb8b1097614630c;p=platform%2Fupstream%2Fllvm.git [flang] Simplify Original-commit: flang-compiler/f18@42bee00a457e46e77f4ee912a3a5fcd7fb4ae44f Reviewed-on: https://github.com/flang-compiler/f18/pull/339 Tree-same-pre-rewrite: false --- diff --git a/flang/documentation/ParserCombinators.md b/flang/documentation/ParserCombinators.md index 05f3aa2..4f60ceb 100644 --- a/flang/documentation/ParserCombinators.md +++ b/flang/documentation/ParserCombinators.md @@ -143,8 +143,6 @@ is built. All of the following parsers consume characters acquired from the combinator `/`. * `"..."_sptok` is a string match in which the spaces are required in free form source. -* `"..."_wsptok` is a string match in which the spaces are not allowed in - free form source, but safe to ignore with a warning when they do appear. * `parenthesized(p)` is shorthand for `"(" >> p / ")"`. * `bracketed(p)` is shorthand for `"[" >> p / "]"`. * `nonEmptyList(p)` matches a comma-separated list of one or more diff --git a/flang/lib/parser/grammar.h b/flang/lib/parser/grammar.h index cf9e82c..8c1a7ea 100644 --- a/flang/lib/parser/grammar.h +++ b/flang/lib/parser/grammar.h @@ -497,8 +497,7 @@ TYPE_PARSER(construct(scalarIntExpr) || // to disambiguate the cases where a derived type name begins with the name // of an intrinsic type, e.g., REALITY. TYPE_CONTEXT_PARSER("type spec"_en_US, - construct( - intrinsicTypeSpec / lookAhead("::"_wsptok || ")"_tok)) || + construct(intrinsicTypeSpec / lookAhead("::"_tok || ")"_tok)) || construct(derivedTypeSpec)) // R703 declaration-type-spec -> @@ -742,9 +741,8 @@ TYPE_PARSER(construct("SEQUENCE"_tok)) constexpr auto kindOrLen{"KIND" >> pure(common::TypeParamAttr::Kind) || "LEN" >> pure(common::TypeParamAttr::Len)}; TYPE_PARSER(construct(integerTypeSpec / ",", kindOrLen, - "::"_wsptok >> - nonemptyList("expected type parameter declarations"_err_en_US, - Parser{}))) + "::" >> nonemptyList("expected type parameter declarations"_err_en_US, + Parser{}))) // R733 type-param-decl -> type-param-name [= scalar-int-constant-expr] TYPE_PARSER(construct(name, maybe("=" >> scalarIntConstantExpr))) @@ -810,7 +808,7 @@ TYPE_CONTEXT_PARSER("PROCEDURE component definition statement"_en_US, localRecovery("expected PROCEDURE component attributes"_err_en_US, "," >> nonemptyList(Parser{}), ok), localRecovery("expected PROCEDURE declarations"_err_en_US, - "::"_wsptok >> nonemptyList(procDecl), SkipTo<'\n'>{}))) + "::" >> nonemptyList(procDecl), SkipTo<'\n'>{}))) // R742 proc-component-attr-spec -> // access-spec | NOPASS | PASS [(arg-name)] | POINTER @@ -829,8 +827,8 @@ constexpr auto initialDataTarget{indirect(designator)}; // R805 initialization -> // = constant-expr | => null-init | => initial-data-target // Universal extension: initialization -> / data-stmt-value-list / -TYPE_PARSER(construct("=>"_wsptok >> nullInit) || - construct("=>"_wsptok >> initialDataTarget) || +TYPE_PARSER(construct("=>" >> nullInit) || + construct("=>" >> initialDataTarget) || construct("=" >> constantExpr) || extension(construct( "/" >> nonemptyList("expected values"_err_en_US, @@ -870,7 +868,7 @@ TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US, localRecovery("expected list of binding attributes"_err_en_US, "," >> nonemptyList(Parser{}), ok), localRecovery("expected list of binding names"_err_en_US, - "::"_wsptok >> listOfNames, SkipTo<'\n'>{}))) || + "::" >> listOfNames, SkipTo<'\n'>{}))) || construct( construct( optionalListBeforeColons(Parser{}), @@ -879,13 +877,13 @@ TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US, Parser{}))))) // R750 type-bound-proc-decl -> binding-name [=> procedure-name] -TYPE_PARSER(construct(name, maybe("=>"_wsptok >> name))) +TYPE_PARSER(construct(name, maybe("=>" >> name))) // R751 type-bound-generic-stmt -> // GENERIC [, access-spec] :: generic-spec => binding-name-list TYPE_CONTEXT_PARSER("type bound GENERIC statement"_en_US, construct("GENERIC" >> maybe("," >> accessSpec), - "::"_wsptok >> indirect(genericSpec), "=>"_wsptok >> listOfNames)) + "::" >> indirect(genericSpec), "=>" >> listOfNames)) // R752 bind-attr -> // access-spec | DEFERRED | NON_OVERRIDABLE | NOPASS | PASS [(arg-name)] @@ -897,7 +895,7 @@ TYPE_PARSER(construct(accessSpec) || // R753 final-procedure-stmt -> FINAL [::] final-subroutine-name-list TYPE_CONTEXT_PARSER("FINAL statement"_en_US, - construct("FINAL" >> maybe("::"_wsptok) >> listOfNames)) + construct("FINAL" >> maybe("::"_tok) >> listOfNames)) // R754 derived-type-spec -> type-name [(type-param-spec-list)] TYPE_PARSER(construct(name, @@ -939,7 +937,7 @@ TYPE_PARSER(construct("ENUM , BIND ( C )"_tok)) // R761 enumerator-def-stmt -> ENUMERATOR [::] enumerator-list TYPE_CONTEXT_PARSER("ENUMERATOR statement"_en_US, - construct("ENUMERATOR" >> maybe("::"_wsptok) >> + construct("ENUMERATOR" >> maybe("::"_tok) >> nonemptyList("expected enumerators"_err_en_US, Parser{}))) // R762 enumerator -> named-constant [= scalar-int-constant-expr] @@ -968,18 +966,15 @@ template inline constexpr auto loopBounds(const PA &p) { } // R769 array-constructor -> (/ ac-spec /) | lbracket ac-spec rbracket -// Note: _wsptok is used here only for consistency; no warnings will -// issue on "( /" or "/ )" because the prescanner removes free-form -// spaces after '(' and before ')'. TYPE_CONTEXT_PARSER("array constructor"_en_US, - construct("(/"_wsptok >> Parser{} / "/)"_wsptok || - bracketed(Parser{}))) + construct( + "(/" >> Parser{} / "/)" || bracketed(Parser{}))) // R770 ac-spec -> type-spec :: | [type-spec ::] ac-value-list -TYPE_PARSER(construct(maybe(typeSpec / "::"_wsptok), +TYPE_PARSER(construct(maybe(typeSpec / "::"), nonemptyList("expected array constructor values"_err_en_US, Parser{})) || - construct(typeSpec / "::"_wsptok)) + construct(typeSpec / "::")) // R773 ac-value -> expr | ac-implied-do TYPE_PARSER( @@ -1000,7 +995,7 @@ TYPE_PARSER(parenthesized( // scalar-int-expr [, scalar-int-expr] // R776 ac-do-variable -> do-variable TYPE_PARSER(construct( - maybe(integerTypeSpec / "::"_wsptok), loopBounds(scalarIntExpr))) + maybe(integerTypeSpec / "::"), loopBounds(scalarIntExpr))) // R801 type-declaration-stmt -> // declaration-type-spec [[, attr-spec]... ::] entity-decl-list @@ -1139,7 +1134,7 @@ TYPE_PARSER(construct("IN OUT" >> pure(IntentSpec::Intent::InOut) || // R827 access-stmt -> access-spec [[::] access-id-list] TYPE_PARSER(construct(accessSpec, - defaulted(maybe("::"_wsptok) >> + defaulted(maybe("::"_tok) >> nonemptyList("expected names and generic specifications"_err_en_US, Parser{})))) @@ -1148,7 +1143,7 @@ TYPE_PARSER(construct(indirect(genericSpec)) || construct(name)) // initially ambiguous with genericSpec // R829 allocatable-stmt -> ALLOCATABLE [::] allocatable-decl-list -TYPE_PARSER(construct("ALLOCATABLE" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("ALLOCATABLE" >> maybe("::"_tok) >> nonemptyList( "expected object declarations"_err_en_US, Parser{}))) @@ -1160,11 +1155,11 @@ TYPE_PARSER( construct(objectName, maybe(arraySpec), maybe(coarraySpec))) // R831 asynchronous-stmt -> ASYNCHRONOUS [::] object-name-list -TYPE_PARSER(construct("ASYNCHRONOUS" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("ASYNCHRONOUS" >> maybe("::"_tok) >> nonemptyList("expected object names"_err_en_US, objectName))) // R832 bind-stmt -> language-binding-spec [::] bind-entity-list -TYPE_PARSER(construct(languageBindingSpec / maybe("::"_wsptok), +TYPE_PARSER(construct(languageBindingSpec / maybe("::"_tok), nonemptyList("expected bind entities"_err_en_US, Parser{}))) // R833 bind-entity -> entity-name | / common-block-name / @@ -1172,7 +1167,7 @@ TYPE_PARSER(construct(pure(BindEntity::Kind::Object), name) || construct("/" >> pure(BindEntity::Kind::Common), name / "/")) // R834 codimension-stmt -> CODIMENSION [::] codimension-decl-list -TYPE_PARSER(construct("CODIMENSION" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("CODIMENSION" >> maybe("::"_tok) >> nonemptyList("expected codimension declarations"_err_en_US, Parser{}))) @@ -1180,7 +1175,7 @@ TYPE_PARSER(construct("CODIMENSION" >> maybe("::"_wsptok) >> TYPE_PARSER(construct(name, coarraySpec)) // R836 contiguous-stmt -> CONTIGUOUS [::] object-name-list -TYPE_PARSER(construct("CONTIGUOUS" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("CONTIGUOUS" >> maybe("::"_tok) >> nonemptyList("expected object names"_err_en_US, objectName))) // R837 data-stmt -> DATA data-stmt-set [[,] data-stmt-set]... @@ -1208,7 +1203,7 @@ TYPE_PARSER(construct(indirect(variable)) || // R842 data-i-do-variable -> do-variable TYPE_PARSER(parenthesized(construct( nonemptyList(Parser{} / lookAhead(","_tok)) / ",", - maybe(integerTypeSpec / "::"_wsptok), loopBounds(scalarIntConstantExpr)))) + maybe(integerTypeSpec / "::"), loopBounds(scalarIntConstantExpr)))) // R841 data-i-do-object -> // array-element | scalar-structure-component | data-implied-do @@ -1252,19 +1247,18 @@ TYPE_PARSER(first(construct(scalar(Parser{})), // DIMENSION [::] array-name ( array-spec ) // [, array-name ( array-spec )]... TYPE_CONTEXT_PARSER("DIMENSION statement"_en_US, - construct("DIMENSION" >> maybe("::"_wsptok) >> + construct("DIMENSION" >> maybe("::"_tok) >> nonemptyList("expected array specifications"_err_en_US, construct(name, arraySpec)))) // R849 intent-stmt -> INTENT ( intent-spec ) [::] dummy-arg-name-list TYPE_CONTEXT_PARSER("INTENT statement"_en_US, construct( - "INTENT" >> parenthesized(intentSpec) / maybe("::"_wsptok), - listOfNames)) + "INTENT" >> parenthesized(intentSpec) / maybe("::"_tok), listOfNames)) // R850 optional-stmt -> OPTIONAL [::] dummy-arg-name-list TYPE_PARSER( - construct("OPTIONAL" >> maybe("::"_wsptok) >> listOfNames)) + construct("OPTIONAL" >> maybe("::"_tok) >> listOfNames)) // R851 parameter-stmt -> PARAMETER ( named-constant-def-list ) // Legacy extension: omitted parentheses, no implicit typing from names @@ -1279,7 +1273,7 @@ TYPE_CONTEXT_PARSER("old style PARAMETER statement"_en_US, TYPE_PARSER(construct(namedConstant, "=" >> constantExpr)) // R853 pointer-stmt -> POINTER [::] pointer-decl-list -TYPE_PARSER(construct("POINTER" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("POINTER" >> maybe("::"_tok) >> nonemptyList( "expected pointer declarations"_err_en_US, Parser{}))) @@ -1290,11 +1284,11 @@ TYPE_PARSER( // R855 protected-stmt -> PROTECTED [::] entity-name-list TYPE_PARSER( - construct("PROTECTED" >> maybe("::"_wsptok) >> listOfNames)) + construct("PROTECTED" >> maybe("::"_tok) >> listOfNames)) // R856 save-stmt -> SAVE [[::] saved-entity-list] TYPE_PARSER(construct( - "SAVE" >> defaulted(maybe("::"_wsptok) >> + "SAVE" >> defaulted(maybe("::"_tok) >> nonemptyList("expected SAVE entities"_err_en_US, Parser{})))) @@ -1304,14 +1298,14 @@ TYPE_PARSER(construct(pure(SavedEntity::Kind::Entity), name) || construct("/" >> pure(SavedEntity::Kind::Common), name / "/")) // R859 target-stmt -> TARGET [::] target-decl-list -TYPE_PARSER(construct("TARGET" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("TARGET" >> maybe("::"_tok) >> nonemptyList("expected objects"_err_en_US, Parser{}))) // R861 value-stmt -> VALUE [::] dummy-arg-name-list -TYPE_PARSER(construct("VALUE" >> maybe("::"_wsptok) >> listOfNames)) +TYPE_PARSER(construct("VALUE" >> maybe("::"_tok) >> listOfNames)) // R862 volatile-stmt -> VOLATILE [::] object-name-list -TYPE_PARSER(construct("VOLATILE" >> maybe("::"_wsptok) >> +TYPE_PARSER(construct("VOLATILE" >> maybe("::"_tok) >> nonemptyList("expected object names"_err_en_US, objectName))) // R866 implicit-name-spec -> EXTERNAL | TYPE @@ -1371,7 +1365,7 @@ TYPE_CONTEXT_PARSER("IMPORT statement"_en_US, construct( "IMPORT , ALL" >> pure(common::ImportKind::All)) || construct( - "IMPORT" >> maybe("::"_wsptok) >> optionalList(name))) + "IMPORT" >> maybe("::"_tok) >> optionalList(name))) // R868 namelist-stmt -> // NAMELIST / namelist-group-name / namelist-group-object-list @@ -1483,7 +1477,7 @@ TYPE_PARSER( // R912 part-ref -> part-name [( section-subscript-list )] [image-selector] TYPE_PARSER(construct(name, defaulted( - parenthesized(nonemptyList(Parser{})) / !"=>"_wsptok), + parenthesized(nonemptyList(Parser{})) / !"=>"_tok), maybe(Parser{}))) // R913 structure-component -> data-ref @@ -1928,11 +1922,10 @@ TYPE_CONTEXT_PARSER("assignment statement"_en_US, // and proc-target. TYPE_CONTEXT_PARSER("pointer assignment statement"_en_US, construct(dataRef, - parenthesized(nonemptyList(Parser{})), - "=>"_wsptok >> expr) || + parenthesized(nonemptyList(Parser{})), "=>" >> expr) || construct(dataRef, defaulted(parenthesized(nonemptyList(Parser{}))), - "=>"_wsptok >> expr)) + "=>" >> expr)) // R1035 bounds-spec -> lower-bound-expr : TYPE_PARSER(construct(boundExpr / ":")) @@ -2041,7 +2034,7 @@ TYPE_CONTEXT_PARSER("ASSOCIATE statement"_en_US, "ASSOCIATE" >> parenthesized(nonemptyList(Parser{})))) // R1104 association -> associate-name => selector -TYPE_PARSER(construct(name, "=>"_wsptok >> selector)) +TYPE_PARSER(construct(name, "=>" >> selector)) // R1105 selector -> expr | variable TYPE_PARSER(construct(variable) / lookAhead(","_tok || ")"_tok) || @@ -2093,8 +2086,8 @@ TYPE_CONTEXT_PARSER("CHANGE TEAM statement"_en_US, ")") // R1113 coarray-association -> codimension-decl => selector -TYPE_PARSER(construct( - Parser{}, "=>"_wsptok >> selector)) +TYPE_PARSER( + construct(Parser{}, "=>" >> selector)) // R1114 end-change-team-stmt -> // END TEAM [( [sync-stat-list] )] [team-construct-name] @@ -2268,8 +2261,7 @@ TYPE_CONTEXT_PARSER("SELECT RANK construct"_en_US, // ( [associate-name =>] selector ) TYPE_CONTEXT_PARSER("SELECT RANK statement"_en_US, construct(maybe(name / ":"), - "SELECT RANK"_sptok >> "("_tok >> maybe(name / "=>"_wsptok), - selector / ")")) + "SELECT RANK"_sptok >> "("_tok >> maybe(name / "=>"), selector / ")")) // R1150 select-rank-case-stmt -> // RANK ( scalar-int-constant-expr ) [select-construct-name] | @@ -2296,7 +2288,7 @@ TYPE_CONTEXT_PARSER("SELECT TYPE construct"_en_US, // ( [associate-name =>] selector ) TYPE_CONTEXT_PARSER("SELECT TYPE statement"_en_US, construct(maybe(name / ":"), - "SELECT TYPE (" >> maybe(name / "=>"_wsptok), selector / ")")) + "SELECT TYPE (" >> maybe(name / "=>"), selector / ")")) // R1154 type-guard-stmt -> // TYPE IS ( type-spec ) [select-construct-name] | @@ -3103,7 +3095,7 @@ TYPE_PARSER(construct("USE" >> optionalBeforeColons(moduleNature), TYPE_PARSER(construct("OPERATOR (" >> construct( definedOpName / ") => OPERATOR (", definedOpName / ")")) || - construct(construct(name, "=>"_wsptok >> name))) + construct(construct(name, "=>" >> name))) // R1412 only -> generic-spec | only-use-name | rename // R1413 only-use-name -> use-name @@ -3184,10 +3176,10 @@ constexpr auto specificProcedures{ // R1506 procedure-stmt -> [MODULE] PROCEDURE [::] specific-procedure-list TYPE_PARSER(construct("MODULE PROCEDURE"_sptok >> pure(ProcedureStmt::Kind::ModuleProcedure), - maybe("::"_wsptok) >> specificProcedures) || + maybe("::"_tok) >> specificProcedures) || construct( "PROCEDURE" >> pure(ProcedureStmt::Kind::Procedure), - maybe("::"_wsptok) >> specificProcedures)) + maybe("::"_tok) >> specificProcedures)) // R1508 generic-spec -> // generic-name | OPERATOR ( defined-operator ) | @@ -3212,11 +3204,11 @@ TYPE_PARSER(first(construct( // R1510 generic-stmt -> // GENERIC [, access-spec] :: generic-spec => specific-procedure-list TYPE_PARSER(construct("GENERIC" >> maybe("," >> accessSpec), - "::"_wsptok >> genericSpec, "=>"_wsptok >> specificProcedures)) + "::" >> genericSpec, "=>" >> specificProcedures)) // R1511 external-stmt -> EXTERNAL [::] external-name-list TYPE_PARSER( - "EXTERNAL" >> maybe("::"_wsptok) >> construct(listOfNames)) + "EXTERNAL" >> maybe("::"_tok) >> construct(listOfNames)) // R1512 procedure-declaration-stmt -> // PROCEDURE ( [proc-interface] ) [[, proc-attr-spec]... ::] @@ -3242,8 +3234,7 @@ TYPE_PARSER(construct(accessSpec) || construct(protectedAttr) || construct(save)) // R1515 proc-decl -> procedure-entity-name [=> proc-pointer-init] -TYPE_PARSER( - construct(name, maybe("=>"_wsptok >> Parser{}))) +TYPE_PARSER(construct(name, maybe("=>" >> Parser{}))) // R1517 proc-pointer-init -> null-init | initial-proc-target // R1518 initial-proc-target -> procedure-name @@ -3252,7 +3243,7 @@ TYPE_PARSER( // R1519 intrinsic-stmt -> INTRINSIC [::] intrinsic-procedure-name-list TYPE_PARSER( - "INTRINSIC" >> maybe("::"_wsptok) >> construct(listOfNames)) + "INTRINSIC" >> maybe("::"_tok) >> construct(listOfNames)) // R1520 function-reference -> procedure-designator ( [actual-arg-spec-list] ) TYPE_CONTEXT_PARSER("function reference"_en_US, diff --git a/flang/lib/parser/token-parsers.h b/flang/lib/parser/token-parsers.h index 449e8f2..bd92159 100644 --- a/flang/lib/parser/token-parsers.h +++ b/flang/lib/parser/token-parsers.h @@ -91,15 +91,6 @@ inline void MissingSpace(ParseState &state) { } } -// Skips a space that is in invalid in free form but unambiguously safe to -// ignore (e.g., in a multi-character operator or delimiter.) Always succeeds. -inline void UnexpectedSpace(ParseState &state) { - if (!state.inFixedForm()) { - state.Nonstandard( - LanguageFeature::OptionalFreeFormSpace, "unexpected space"_en_US); - } -} - constexpr struct SpaceCheck { using resultType = Success; constexpr SpaceCheck() {} @@ -132,13 +123,10 @@ class TokenStringMatch { public: using resultType = Success; constexpr TokenStringMatch(const TokenStringMatch &) = default; - constexpr TokenStringMatch( - const char *str, std::size_t n, bool mandatory = false, bool warn = false) - : str_{str}, bytes_{n}, mandatoryFreeFormSpace_{mandatory}, warnOnSpaces_{ - warn} {} - constexpr explicit TokenStringMatch( - const char *str, bool mandatory = false, bool warn = false) - : str_{str}, mandatoryFreeFormSpace_{mandatory}, warnOnSpaces_{warn} {} + constexpr TokenStringMatch(const char *str, std::size_t n, bool mandatory) + : str_{str}, bytes_{n}, mandatoryFreeFormSpace_{mandatory} {} + constexpr TokenStringMatch(const char *str, bool mandatory) + : str_{str}, mandatoryFreeFormSpace_{mandatory} {} std::optional Parse(ParseState &state) const { space.Parse(state); const char *start{state.GetLocation()}; @@ -169,12 +157,6 @@ public: // 'at' remains full for next iteration } else if (**at == ToLowerCaseLetter(*p)) { at.reset(); - } else if (**at == ' ' && warnOnSpaces_) { - at = nextCh.Parse(state); - if (!at.has_value()) { - return std::nullopt; - } - UnexpectedSpace(state); } else { state.Say(start, MessageExpectedText{str_, bytes_}); return std::nullopt; @@ -192,31 +174,27 @@ private: const char *const str_; const std::size_t bytes_{std::string::npos}; const bool mandatoryFreeFormSpace_; - const bool warnOnSpaces_; }; constexpr TokenStringMatch operator""_tok(const char str[], std::size_t n) { - return TokenStringMatch{str, n}; + return TokenStringMatch{str, n, false}; } constexpr TokenStringMatch operator""_sptok(const char str[], std::size_t n) { return TokenStringMatch{str, n, true}; } -constexpr TokenStringMatch operator""_wsptok(const char str[], std::size_t n) { - return TokenStringMatch{str, n, false, true}; -} - template::value, int> = 0> inline constexpr SequenceParser operator>>( const char *str, const PA &p) { - return SequenceParser{TokenStringMatch{str}, p}; + return SequenceParser{TokenStringMatch{str, false}, p}; } template::value, int> = 0> inline constexpr InvertedSequenceParser operator/( const PA &p, const char *str) { - return InvertedSequenceParser{p, TokenStringMatch{str}}; + return InvertedSequenceParser{ + p, TokenStringMatch{str, false}}; } template