diff options
author | Lex Spoon <lex@lexspoon.org> | 2007-04-11 19:34:08 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2007-04-11 19:34:08 +0000 |
commit | 9c90fcb0a5e7836e6254430f98c9eb016d42cb0d (patch) | |
tree | 05d68daa0c6c78b29b2dc215ddf31788e039839d /src | |
parent | ba3e6db5b8a0a7a35f895e6549b2b764fdf61039 (diff) | |
download | scala-9c90fcb0a5e7836e6254430f98c9eb016d42cb0d.tar.gz scala-9c90fcb0a5e7836e6254430f98c9eb016d42cb0d.tar.bz2 scala-9c90fcb0a5e7836e6254430f98c9eb016d42cb0d.zip |
- fixed printout for assignment statements
- force evaluation of objectName.accessPath, not just the outermost
objectName wrapper - print an extra newline after import statements
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 447da447a6..7079f32c21 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -493,8 +493,8 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) val boundNames = defNames ::: valAndVarNames ::: moduleNames ::: classNames ::: typeNames - /** names to print out to the user after evaluation */ - def namesToPrintForUser = valAndVarNames + /** the line of code to compute */ + def toCompute = line /** generate the source code for the object that computes this request */ def objectSourceCode: String = @@ -510,8 +510,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) if (needsVarName) code.print(" val " + varName + " = ") - // the line of code to compute - code.println(line) + code.println(toCompute) code.println(importsTrailer) @@ -529,7 +528,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) stringFrom(code => { code.println("object " + resultObjectName) code.println("{ val result: String = {") - code.println(objectName + ";") // evaluate the object, to make sure its constructor is run + code.println(objectName + accessPath + ";") // evaluate the object, to make sure its constructor is run code.print("\"\"") // print an initial empty string, so later code can // uniformly be: + morestuff resultExtractionCode(code) @@ -538,7 +537,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) }) def resultExtractionCode(code: PrintWriter): Unit = - for (val vname <- namesToPrintForUser) { + for (val vname <- valAndVarNames) { code.print(" + \"" + vname + ": " + typeOf(vname) + " = \" + " + objectName + accessPath + "." + vname + " + \"\\n\"") @@ -645,11 +644,17 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) /** Assignment of a single variable: lhs = exp */ private class AssignReq(val lhs: Name, line: String, lineName: String) extends Request(line, lineName) { - override def resultExtractionCode(code: PrintWriter): Unit = { - super.resultExtractionCode(code) - code.println(" + \"" + lhs + " = \" + " + lhs) + override val needsVarName = true + + /** Perform the assignment, and then return the new value */ + override def toCompute = "{" + line + ";" + lhs + "}" + + /** Print out lhs instead of the generated varName */ + override def resultExtractionCode(code: PrintWriter) { + code.print(" + \"" + lhs + ": " + typeOf(compiler.encode(varName)) + + " = \" + " + objectName + accessPath + + "." + varName + " + \"\\n\"") } - override def namesToPrintForUser = Nil } /** A single expression */ @@ -708,7 +713,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) extends Request(line, lineName) { override val boundNames = Nil override def resultExtractionCode(code: PrintWriter): Unit = { - code.println("+ \"" + trees.head.toString + "\"") + code.println("+ \"" + trees.head.toString + "\\n\"") } } } |