diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-05 14:26:01 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-05 15:25:58 -0800 |
commit | 020053c3215579e8aeb871a4ad0078516994270d (patch) | |
tree | 447f518a7361a9a49993a22012b37a5c653e6284 /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | |
parent | 749b476beca481b48cad8ea3810865634a010686 (diff) | |
download | scala-020053c3215579e8aeb871a4ad0078516994270d.tar.gz scala-020053c3215579e8aeb871a4ad0078516994270d.tar.bz2 scala-020053c3215579e8aeb871a4ad0078516994270d.zip |
More consistent use of Names.
Several large helpings of tedium later, fewer strings are being
discarded like so much refuse. Some names now cache a String, but only
"named Names", so it's not very many and they pay for themselves pretty
quickly. Many fewer name-related implicit conversions now taking place.
A number of efficiency related measures.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index db97dd3475..5881821ab3 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -314,7 +314,7 @@ self => val stmts = templateStatSeq(false)._2 accept(EOF) - def mainModuleName = settings.script.value + def mainModuleName = newTermName(settings.script.value) /** If there is only a single object template in the file and it has a * suitable main method, we will use it rather than building another object * around it. Since objects are loaded lazily the whole script would have @@ -343,7 +343,7 @@ self => * whole additional parse. So instead, if the actual object's name differs from * what the script is expecting, we transform it to match. */ - if (name.toString == mainModuleName) md + if (name == mainModuleName) md else treeCopy.ModuleDef(md, mods, mainModuleName, template) case _ => /** If we see anything but the above, fail. */ @@ -352,7 +352,7 @@ self => Some(makePackaging(0, emptyPkg, newStmts)) } - if (mainModuleName == ScriptRunner.defaultScriptMain) + if (mainModuleName == newTermName(ScriptRunner.defaultScriptMain)) searchForMain() foreach { return _ } /** Here we are building an AST representing the following source fiction, @@ -384,13 +384,13 @@ self => // def main def mainParamType = AppliedTypeTree(Ident(tpnme.Array), List(Ident(tpnme.String))) - def mainParameter = List(ValDef(Modifiers(Flags.PARAM), "argv", mainParamType, EmptyTree)) - def mainSetArgv = List(ValDef(NoMods, "args", TypeTree(), Ident("argv"))) + def mainParameter = List(ValDef(Modifiers(Flags.PARAM), nme.argv, mainParamType, EmptyTree)) + def mainSetArgv = List(ValDef(NoMods, nme.args, TypeTree(), Ident(nme.argv))) def mainNew = makeNew(Nil, emptyValDef, stmts, List(Nil), NoPosition, NoPosition) def mainDef = DefDef(NoMods, nme.main, Nil, List(mainParameter), scalaDot(tpnme.Unit), Block(mainSetArgv, mainNew)) // object Main - def moduleName = ScriptRunner scriptMain settings + def moduleName = newTermName(ScriptRunner scriptMain settings) def moduleBody = Template(List(scalaScalaObjectConstr), emptyValDef, List(emptyInit, mainDef)) def moduleDef = ModuleDef(NoMods, moduleName, moduleBody) @@ -980,6 +980,7 @@ self => nme.ERROR } def ident(): Name = ident(true) + def rawIdent(): Name = try in.name finally in.nextToken() /** For when it's known already to be a type name. */ def identForType(): TypeName = ident().toTypeName @@ -1117,7 +1118,7 @@ self => case LONGLIT => in.intVal(isNegated) case FLOATLIT => in.floatVal(isNegated).toFloat case DOUBLELIT => in.floatVal(isNegated) - case STRINGLIT => in.strVal + case STRINGLIT => in.strVal.intern() case TRUE => true case FALSE => false case NULL => null @@ -1465,8 +1466,9 @@ self => def prefixExpr(): Tree = { if (isUnaryOp) { atPos(in.offset) { - val name: Name = "unary_" + ident() - if (in.name == raw.MINUS && isNumericLit) simpleExprRest(atPos(in.offset)(literal(true)), true) + val name = nme.toUnaryName(rawIdent()) + // val name = nme.toUnaryName(ident()) // val name: Name = "unary_" + ident() + if (name == nme.UNARY_- && isNumericLit) simpleExprRest(atPos(in.offset)(literal(true)), true) else Select(stripParens(simpleExpr()), name) } } |