Skip to content

Commit b20c1be

Browse files
committed
Don't pass docstring as a parameter.
It's completely redundant, docstring is just the comment found at the `start` offset, which is passed anyway.
1 parent 5b91815 commit b20c1be

File tree

1 file changed

+33
-39
lines changed

1 file changed

+33
-39
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,17 +1891,17 @@ object Parsers {
18911891
case VAL =>
18921892
val mod = atPos(in.skipToken()) { Mod.Val() }
18931893
val mods1 = mods.withAddedMod(mod)
1894-
patDefOrDcl(start, mods1, in.getDocComment(start))
1894+
patDefOrDcl(start, mods1)
18951895
case VAR =>
18961896
val mod = atPos(in.skipToken()) { Mod.Var() }
18971897
val mod1 = addMod(mods, mod)
1898-
patDefOrDcl(start, mod1, in.getDocComment(start))
1898+
patDefOrDcl(start, mod1)
18991899
case DEF =>
1900-
defDefOrDcl(start, posMods(start, mods), in.getDocComment(start))
1900+
defDefOrDcl(start, posMods(start, mods))
19011901
case TYPE =>
1902-
typeDefOrDcl(start, posMods(start, mods), in.getDocComment(start))
1902+
typeDefOrDcl(start, posMods(start, mods))
19031903
case CASE =>
1904-
enumCase(start, mods, in.getDocComment(start))
1904+
enumCase(start, mods)
19051905
case _ =>
19061906
tmplDef(start, mods)
19071907
}
@@ -1911,7 +1911,7 @@ object Parsers {
19111911
* ValDcl ::= id {`,' id} `:' Type
19121912
* VarDcl ::= id {`,' id} `:' Type
19131913
*/
1914-
def patDefOrDcl(start: Offset, mods: Modifiers, docstring: Option[Comment] = None): Tree = atPos(start, nameStart) {
1914+
def patDefOrDcl(start: Offset, mods: Modifiers): Tree = atPos(start, nameStart) {
19151915
val lhs = commaSeparated(pattern2)
19161916
val tpt = typedOpt()
19171917
val rhs =
@@ -1926,7 +1926,7 @@ object Parsers {
19261926
} else EmptyTree
19271927
lhs match {
19281928
case (id @ Ident(name: TermName)) :: Nil => {
1929-
ValDef(name, tpt, rhs).withMods(mods).setComment(docstring)
1929+
ValDef(name, tpt, rhs).withMods(mods).setComment(in.getDocComment(start))
19301930
} case _ =>
19311931
PatDef(mods, lhs, tpt, rhs)
19321932
}
@@ -1937,7 +1937,7 @@ object Parsers {
19371937
* DefDcl ::= DefSig `:' Type
19381938
* DefSig ::= id [DefTypeParamClause] ParamClauses
19391939
*/
1940-
def defDefOrDcl(start: Offset, mods: Modifiers, docstring: Option[Comment] = None): Tree = atPos(start, nameStart) {
1940+
def defDefOrDcl(start: Offset, mods: Modifiers): Tree = atPos(start, nameStart) {
19411941
def scala2ProcedureSyntax(resultTypeStr: String) = {
19421942
val toInsert =
19431943
if (in.token == LBRACE) s"$resultTypeStr ="
@@ -1980,7 +1980,7 @@ object Parsers {
19801980
accept(EQUALS)
19811981
expr()
19821982
}
1983-
DefDef(name, tparams, vparamss, tpt, rhs).withMods(mods1).setComment(docstring)
1983+
DefDef(name, tparams, vparamss, tpt, rhs).withMods(mods1).setComment(in.getDocComment(start))
19841984
}
19851985
}
19861986

@@ -2014,17 +2014,17 @@ object Parsers {
20142014
/** TypeDef ::= type id [TypeParamClause] `=' Type
20152015
* TypeDcl ::= type id [TypeParamClause] TypeBounds
20162016
*/
2017-
def typeDefOrDcl(start: Offset, mods: Modifiers, docstring: Option[Comment] = None): Tree = {
2017+
def typeDefOrDcl(start: Offset, mods: Modifiers): Tree = {
20182018
newLinesOpt()
20192019
atPos(start, nameStart) {
20202020
val name = ident().toTypeName
20212021
val tparams = typeParamClauseOpt(ParamOwner.Type)
20222022
in.token match {
20232023
case EQUALS =>
20242024
in.nextToken()
2025-
TypeDef(name, lambdaAbstract(tparams, typ())).withMods(mods).setComment(docstring)
2025+
TypeDef(name, lambdaAbstract(tparams, typ())).withMods(mods).setComment(in.getDocComment(start))
20262026
case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | EOF =>
2027-
TypeDef(name, lambdaAbstract(tparams, typeBounds())).withMods(mods).setComment(docstring)
2027+
TypeDef(name, lambdaAbstract(tparams, typeBounds())).withMods(mods).setComment(in.getDocComment(start))
20282028
case _ =>
20292029
syntaxErrorOrIncomplete("`=', `>:', or `<:' expected")
20302030
EmptyTree
@@ -2037,23 +2037,22 @@ object Parsers {
20372037
* | `enum' EnumDef
20382038
*/
20392039
def tmplDef(start: Int, mods: Modifiers): Tree = {
2040-
val docstring = in.getDocComment(start)
20412040
in.token match {
20422041
case TRAIT =>
2043-
classDef(start, posMods(start, addFlag(mods, Trait)), docstring)
2042+
classDef(start, posMods(start, addFlag(mods, Trait)))
20442043
case CLASS =>
2045-
classDef(start, posMods(start, mods), docstring)
2044+
classDef(start, posMods(start, mods))
20462045
case CASECLASS =>
2047-
classDef(start, posMods(start, mods | Case), docstring)
2046+
classDef(start, posMods(start, mods | Case))
20482047
case OBJECT =>
2049-
objectDef(start, posMods(start, mods | Module), docstring)
2048+
objectDef(start, posMods(start, mods | Module))
20502049
case CASEOBJECT =>
2051-
objectDef(start, posMods(start, mods | Case | Module), docstring)
2050+
objectDef(start, posMods(start, mods | Case | Module))
20522051
case ENUM =>
20532052
val mods1 = addMod(mods, atPos(in.skipToken()) { Mod.Enum() })
20542053
in.token match {
20552054
case CLASS | TRAIT | OBJECT => tmplDef(start, mods1)
2056-
case _ => enumDef(start, mods, docstring)
2055+
case _ => enumDef(start, mods)
20572056
}
20582057
case _ =>
20592058
syntaxErrorOrIncomplete("expected start of definition")
@@ -2063,14 +2062,14 @@ object Parsers {
20632062

20642063
/** ClassDef ::= id ClassConstr TemplateOpt
20652064
*/
2066-
def classDef(start: Offset, mods: Modifiers, docstring: Option[Comment]): TypeDef = atPos(start, nameStart) {
2067-
classDefRest(start, mods, docstring, ident().toTypeName)
2065+
def classDef(start: Offset, mods: Modifiers): TypeDef = atPos(start, nameStart) {
2066+
classDefRest(start, mods, ident().toTypeName)
20682067
}
20692068

2070-
def classDefRest(start: Offset, mods: Modifiers, docstring: Option[Comment], name: TypeName): TypeDef = {
2069+
def classDefRest(start: Offset, mods: Modifiers, name: TypeName): TypeDef = {
20712070
val constr = classConstr(name, isCaseClass = mods is Case)
20722071
val templ = templateOpt(constr)
2073-
TypeDef(name, templ).withMods(mods).setComment(docstring)
2072+
TypeDef(name, templ).withMods(mods).setComment(in.getDocComment(start))
20742073
}
20752074

20762075
/** ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
@@ -2095,19 +2094,19 @@ object Parsers {
20952094

20962095
/** ObjectDef ::= id TemplateOpt
20972096
*/
2098-
def objectDef(start: Offset, mods: Modifiers, docstring: Option[Comment] = None): ModuleDef = atPos(start, nameStart) {
2099-
objectDefRest(start, mods, docstring, ident())
2097+
def objectDef(start: Offset, mods: Modifiers): ModuleDef = atPos(start, nameStart) {
2098+
objectDefRest(start, mods, ident())
21002099
}
21012100

2102-
def objectDefRest(start: Offset, mods: Modifiers, docstring: Option[Comment] = None, name: TermName): ModuleDef = {
2101+
def objectDefRest(start: Offset, mods: Modifiers, name: TermName): ModuleDef = {
21032102
val template = templateOpt(emptyConstructor)
2104-
ModuleDef(name, template).withMods(mods).setComment(docstring)
2103+
ModuleDef(name, template).withMods(mods).setComment(in.getDocComment(start))
21052104
}
21062105

21072106
/** id ClassConstr [`extends' [ConstrApps]]
21082107
* [nl] ‘{’ EnumCaseStats ‘}’
21092108
*/
2110-
def enumDef(start: Offset, mods: Modifiers, docstring: Option[Comment] = None): EnumDef = atPos(start, nameStart) {
2109+
def enumDef(start: Offset, mods: Modifiers): EnumDef = atPos(start, nameStart) {
21112110
val name = ident().toTypeName
21122111
val constr = classConstr(name)
21132112
val parents =
@@ -2134,23 +2133,19 @@ object Parsers {
21342133
}
21352134

21362135
/** EnumCaseStat = {Annotation [nl]} {Modifier} EnumCase */
2137-
def enumCaseStat(): MemberDef = {
2138-
val start = in.offset
2139-
val docstring = in.getDocComment(start)
2140-
val mods = defAnnotsMods(modifierTokens)
2141-
enumCase(start, mods, docstring)
2142-
}
2136+
def enumCaseStat(): MemberDef =
2137+
enumCase(in.offset, defAnnotsMods(modifierTokens))
21432138

21442139
/** EnumCase = `case' (EnumClassDef | ObjectDef) */
2145-
def enumCase(start: Offset, mods: Modifiers, docstring: Option[Comment]): MemberDef = {
2140+
def enumCase(start: Offset, mods: Modifiers): MemberDef = {
21462141
val mods1 = mods.withAddedMod(atPos(in.offset)(Mod.EnumCase())) | Case
21472142
accept(CASE)
21482143
atPos(start, nameStart) {
21492144
val name = ident()
21502145
if (in.token == LBRACKET || in.token == LPAREN)
2151-
classDefRest(start, mods1, docstring, name.toTypeName)
2146+
classDefRest(start, mods1, name.toTypeName)
21522147
else
2153-
objectDefRest(start, mods1, docstring, name)
2148+
objectDefRest(start, mods1, name)
21542149
}
21552150
}
21562151

@@ -2377,8 +2372,7 @@ object Parsers {
23772372
if (in.token == PACKAGE) {
23782373
in.nextToken()
23792374
if (in.token == OBJECT) {
2380-
val docstring = in.getDocComment(start)
2381-
ts += objectDef(start, atPos(start, in.skipToken()) { Modifiers(Package) }, docstring)
2375+
ts += objectDef(start, atPos(start, in.skipToken()) { Modifiers(Package) })
23822376
if (in.token != EOF) {
23832377
acceptStatSep()
23842378
ts ++= topStatSeq()

0 commit comments

Comments
 (0)