@@ -1097,8 +1097,9 @@ object Parsers {
1097
1097
/** Expr ::= implicit Id `=>' Expr
1098
1098
* BlockResult ::= implicit Id [`:' InfixType] `=>' Block
1099
1099
*/
1100
- def implicitClosure (start : Int , location : Location .Value ): Tree = {
1101
- val mods = atPos(start) { Modifiers (Implicit ) }
1100
+ def implicitClosure (start : Int , location : Location .Value , implicitMod : Option [Mod ] = None ): Tree = {
1101
+ var mods = atPos(start) { Modifiers (Implicit ) }
1102
+ if (implicitMod.nonEmpty) mods = mods.withAddedMod(implicitMod.get)
1102
1103
val id = termIdent()
1103
1104
val paramExpr =
1104
1105
if (location == Location .InBlock && in.token == COLON )
@@ -1464,19 +1465,19 @@ object Parsers {
1464
1465
1465
1466
/* -------- MODIFIERS and ANNOTATIONS ------------------------------------------- */
1466
1467
1467
- private def flagOfToken (tok : Int ): FlagSet = tok match {
1468
- case ABSTRACT => Abstract
1469
- case FINAL => Final
1470
- case IMPLICIT => ImplicitCommon
1471
- case INLINE => Inline
1472
- case LAZY => Lazy
1473
- case OVERRIDE => Override
1474
- case PRIVATE => Private
1475
- case PROTECTED => Protected
1476
- case SEALED => Sealed
1468
+ private def modOfToken (tok : Int ): Mod = tok match {
1469
+ case ABSTRACT => Mod . Abstract ()
1470
+ case FINAL => Mod . Final ()
1471
+ case IMPLICIT => Mod . Implicit ( ImplicitCommon )
1472
+ case INLINE => Mod . Inline ()
1473
+ case LAZY => Mod . Lazy ()
1474
+ case OVERRIDE => Mod . Override ()
1475
+ case PRIVATE => Mod . Private ()
1476
+ case PROTECTED => Mod . Protected ()
1477
+ case SEALED => Mod . Sealed ()
1477
1478
}
1478
1479
1479
- /** Drop `private' modifier when followed by a qualifier.
1480
+ /** Drop `private' modifier when followed by a qualifier.
1480
1481
* Contract `abstract' and `override' to ABSOVERRIDE
1481
1482
*/
1482
1483
private def normalize (mods : Modifiers ): Modifiers =
@@ -1488,11 +1489,11 @@ object Parsers {
1488
1489
mods
1489
1490
1490
1491
private def addModifier (mods : Modifiers ): Modifiers = {
1491
- val flag = flagOfToken( in.token)
1492
- if (mods is flag) syntaxError( RepeatedModifier (flag.toString))
1493
- val res = addFlag(mods, flag)
1494
- in.nextToken( )
1495
- res
1492
+ val tok = in.token
1493
+ val mod = atPos(in.skipToken()) { modOfToken(tok) }
1494
+
1495
+ if (mods is mod.flags) syntaxError( RepeatedModifier (mod.flags.toString) )
1496
+ addMod(mods, mod)
1496
1497
}
1497
1498
1498
1499
private def compatible (flags1 : FlagSet , flags2 : FlagSet ): Boolean = (
@@ -1518,6 +1519,11 @@ object Parsers {
1518
1519
}
1519
1520
}
1520
1521
1522
+ /** Always add the syntactic `mod`, but check and conditionally add semantic `mod.flags`
1523
+ */
1524
+ def addMod (mods : Modifiers , mod : Mod ): Modifiers =
1525
+ addFlag(mods, mod.flags).withAddedMod(mod)
1526
+
1521
1527
/** AccessQualifier ::= "[" (Id | this) "]"
1522
1528
*/
1523
1529
def accessQualifierOpt (mods : Modifiers ): Modifiers =
@@ -1614,8 +1620,8 @@ object Parsers {
1614
1620
mods =
1615
1621
atPos(start, in.offset) {
1616
1622
if (in.token == TYPE ) {
1617
- in.nextToken()
1618
- mods | Param | ParamAccessor
1623
+ val mod = atPos( in.skipToken()) { Mod . Type () }
1624
+ ( mods | Param | ParamAccessor ).withAddedMod(mod)
1619
1625
} else {
1620
1626
if (mods.hasFlags) syntaxError(" `type' expected" )
1621
1627
mods | Param | PrivateLocal
@@ -1659,7 +1665,7 @@ object Parsers {
1659
1665
* Param ::= id `:' ParamType [`=' Expr]
1660
1666
*/
1661
1667
def paramClauses (owner : Name , ofCaseClass : Boolean = false ): List [List [ValDef ]] = {
1662
- var implicitFlag = EmptyFlags
1668
+ var implicitMod : Mod = null
1663
1669
var firstClauseOfCaseClass = ofCaseClass
1664
1670
var implicitOffset = - 1 // use once
1665
1671
def param (): ValDef = {
@@ -1670,11 +1676,11 @@ object Parsers {
1670
1676
mods =
1671
1677
atPos(start, in.offset) {
1672
1678
if (in.token == VAL ) {
1673
- in.nextToken()
1674
- mods
1679
+ val mod = atPos( in.skipToken()) { Mod . Val () }
1680
+ mods.withAddedMod(mod)
1675
1681
} else if (in.token == VAR ) {
1676
- in.nextToken()
1677
- addFlag (mods, Mutable )
1682
+ val mod = atPos( in.skipToken()) { Mod . Var () }
1683
+ addMod (mods, mod )
1678
1684
} else {
1679
1685
if (! (mods.flags &~ (ParamAccessor | Inline )).isEmpty)
1680
1686
syntaxError(" `val' or `var' expected" )
@@ -1696,7 +1702,7 @@ object Parsers {
1696
1702
if (in.token == ARROW ) {
1697
1703
if (owner.isTypeName && ! (mods is Local ))
1698
1704
syntaxError(s " ${if (mods is Mutable ) " `var'" else " `val'" } parameters may not be call-by-name " )
1699
- else if (! implicitFlag.isEmpty )
1705
+ else if (implicitMod != null )
1700
1706
syntaxError(" implicit parameters may not be call-by-name" )
1701
1707
}
1702
1708
paramType()
@@ -1708,15 +1714,16 @@ object Parsers {
1708
1714
mods = mods.withPos(mods.pos.union(Position (implicitOffset, implicitOffset)))
1709
1715
implicitOffset = - 1
1710
1716
}
1711
- ValDef (name, tpt, default).withMods(addFlag(mods, implicitFlag))
1717
+ if (implicitMod != null ) mods = addMod(mods, implicitMod)
1718
+ ValDef (name, tpt, default).withMods(mods)
1712
1719
}
1713
1720
}
1714
1721
def paramClause (): List [ValDef ] = inParens {
1715
1722
if (in.token == RPAREN ) Nil
1716
1723
else {
1717
1724
if (in.token == IMPLICIT ) {
1718
- implicitOffset = in.skipToken()
1719
- implicitFlag = Implicit
1725
+ implicitOffset = in.offset
1726
+ implicitMod = atPos(in.skipToken()) { Mod . Implicit ( Implicit ) }
1720
1727
}
1721
1728
commaSeparated(param)
1722
1729
}
@@ -1726,7 +1733,7 @@ object Parsers {
1726
1733
if (in.token == LPAREN )
1727
1734
paramClause() :: {
1728
1735
firstClauseOfCaseClass = false
1729
- if (implicitFlag.isEmpty ) clauses() else Nil
1736
+ if (implicitMod == null ) clauses() else Nil
1730
1737
}
1731
1738
else Nil
1732
1739
}
@@ -1819,9 +1826,13 @@ object Parsers {
1819
1826
*/
1820
1827
def defOrDcl (start : Int , mods : Modifiers ): Tree = in.token match {
1821
1828
case VAL =>
1822
- patDefOrDcl(start, posMods(start, mods), in.getDocComment(start))
1829
+ val mod = atPos(in.skipToken()) { Mod .Val () }
1830
+ val mods1 = mods.withAddedMod(mod)
1831
+ patDefOrDcl(start, mods1, in.getDocComment(start))
1823
1832
case VAR =>
1824
- patDefOrDcl(start, posMods(start, addFlag(mods, Mutable )), in.getDocComment(start))
1833
+ val mod = atPos(in.skipToken()) { Mod .Var () }
1834
+ val mod1 = addMod(mods, mod)
1835
+ patDefOrDcl(start, mod1, in.getDocComment(start))
1825
1836
case DEF =>
1826
1837
defDefOrDcl(start, posMods(start, mods), in.getDocComment(start))
1827
1838
case TYPE =>
@@ -2184,8 +2195,11 @@ object Parsers {
2184
2195
stats.toList
2185
2196
}
2186
2197
2187
- def localDef (start : Int , implicitFlag : FlagSet ): Tree =
2188
- defOrDcl(start, addFlag(defAnnotsMods(localModifierTokens), implicitFlag))
2198
+ def localDef (start : Int , implicitFlag : FlagSet , implicitMod : Option [Mod ] = None ): Tree = {
2199
+ var mods = addFlag(defAnnotsMods(localModifierTokens), implicitFlag)
2200
+ if (implicitMod.nonEmpty) mods = mods.withAddedMod(implicitMod.get)
2201
+ defOrDcl(start, mods)
2202
+ }
2189
2203
2190
2204
/** BlockStatSeq ::= { BlockStat semi } [ResultExpr]
2191
2205
* BlockStat ::= Import
@@ -2205,9 +2219,10 @@ object Parsers {
2205
2219
stats += expr(Location .InBlock )
2206
2220
else if (isDefIntro(localModifierTokens))
2207
2221
if (in.token == IMPLICIT ) {
2208
- val start = in.skipToken()
2209
- if (isIdent) stats += implicitClosure(start, Location .InBlock )
2210
- else stats += localDef(start, ImplicitCommon )
2222
+ val start = in.offset
2223
+ val mod = atPos(in.skipToken()) { Mod .Implicit (ImplicitCommon ) }
2224
+ if (isIdent) stats += implicitClosure(start, Location .InBlock , Some (mod))
2225
+ else stats += localDef(start, ImplicitCommon , Some (mod))
2211
2226
} else {
2212
2227
stats += localDef(in.offset, EmptyFlags )
2213
2228
}
0 commit comments