diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2006-08-02 13:42:21 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2006-08-02 13:42:21 +0000 |
commit | e40c9ebc9696448e04769bf9603e0011bd7fe8fc (patch) | |
tree | 3129cc1792fad0f3a7a2916c180728caa5a6951f | |
parent | 65c14d6dc774359d9c6c034ee66d868dc4d89d08 (diff) | |
download | scala-e40c9ebc9696448e04769bf9603e0011bd7fe8fc.tar.gz scala-e40c9ebc9696448e04769bf9603e0011bd7fe8fc.tar.bz2 scala-e40c9ebc9696448e04769bf9603e0011bd7fe8fc.zip |
Generate SYNTHETIC flags.
Dont emit debugging info for synthetic variables.
Added the SYNTHETIC flag to some local vars created by the compiler.
3 files changed, 34 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 931a041d3f..9885f06034 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -463,6 +463,7 @@ abstract class GenICode extends SubComponent { handlers = Pair(NoSymbol, { ctx: Context => val exception = new Local(ctx.method.symbol.newVariable(finalizer.pos, unit.fresh.newName("exc")) + .setFlag(Flags.SYNTHETIC) .setInfo(definitions.ThrowableClass.tpe), REFERENCE(definitions.ThrowableClass), false); ctx.method.addLocal(exception); @@ -479,7 +480,7 @@ abstract class GenICode extends SubComponent { generatedType = kind; //toTypeKind(block.tpe); val ctx1 = genLoad(block, bodyCtx, generatedType); if (kind != UNIT && mayCleanStack(finalizer)) { - val tmp = new Local(ctx.method.symbol.newVariable(tree.pos, unit.fresh.newName("tmp")).setInfo(tree.tpe), + val tmp = new Local(ctx.method.symbol.newVariable(tree.pos, unit.fresh.newName("tmp")).setInfo(tree.tpe).setFlag(Flags.SYNTHETIC), kind, false); ctx1.method.addLocal(tmp); ctx1.bb.emit(STORE_LOCAL(tmp)); @@ -651,7 +652,8 @@ abstract class GenICode extends SubComponent { generatedType = BOOL; ctx1 = afterCtx; } else if (code == scalaPrimitives.SYNCHRONIZED) { - val monitor = new Local(ctx.method.symbol.newVariable(tree.pos, unit.fresh.newName("monitor")).setInfo(definitions.ObjectClass.tpe), + val monitor = new Local(ctx.method.symbol.newVariable(tree.pos, unit.fresh.newName("monitor")) + .setInfo(definitions.ObjectClass.tpe).setFlag(Flags.SYNTHETIC), ANY_REF_CLASS, false); ctx.method.addLocal(monitor); @@ -1246,7 +1248,7 @@ abstract class GenICode extends SubComponent { ctx.method.lookupLocal(eqEqTemp) match { case Some(local) => eqEqTempVar = local.sym; eqEqTempLocal = local; case None => - eqEqTempVar = ctx.method.symbol.newVariable(l.pos, eqEqTemp); + eqEqTempVar = ctx.method.symbol.newVariable(l.pos, eqEqTemp).setFlag(Flags.SYNTHETIC); eqEqTempVar.setInfo(definitions.AnyRefClass.typeConstructor); eqEqTempLocal = new Local(eqEqTempVar, REFERENCE(definitions.AnyRefClass), false); ctx.method.addLocal(eqEqTempLocal); diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index eedf108b36..8f45d4f777 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -391,7 +391,7 @@ abstract class GenJVM extends SubComponent { jcode = jmethod.getCode().asInstanceOf[JExtendedCode]; genCode(m); if (emitVars) - genLocalVariableTable; + genLocalVariableTable(m); } addExceptionsAttribute(m.symbol) @@ -1178,6 +1178,7 @@ abstract class GenJVM extends SubComponent { var jf: Int = 0; val f = sym.flags; + jf = jf | (if (sym hasFlag Flags.SYNTHETIC) ACC_SYNTHETIC else 0); jf = jf | (if (sym hasFlag Flags.PRIVATE) ACC_PRIVATE else ACC_PUBLIC); jf = jf | (if ((sym hasFlag Flags.ABSTRACT) || (sym hasFlag Flags.DEFERRED)) ACC_ABSTRACT else 0); @@ -1226,29 +1227,41 @@ abstract class GenJVM extends SubComponent { settings.outdir.value + File.separatorChar + path + suffix } - private def genLocalVariableTable: Unit = { - val vars: Array[JLocalVariable] = jmethod.getLocalVariables(); + /** Emit a Local variable table for debugging purposes. + * Synthetic locals are skipped. All variables are method-scoped. + */ + private def genLocalVariableTable(m: IMethod): Unit = { + var vars = m.locals.filter(l => !l.sym.hasFlag(Flags.SYNTHETIC)); - if (vars.length == 0) - return; + if (vars.length == 0) return; val pool = jclass.getConstantPool(); val pc = jcode.getPC(); var anonCounter = 0; + val locals = if (jmethod.isStatic()) vars.length else 1 + vars.length; + + val lvTab = ByteBuffer.allocate(2 + 10 * locals); + def emitEntry(name: String, signature: String, idx: Short): Unit = { + lvTab.putShort(0.asInstanceOf[Short]); + lvTab.putShort(pc.asInstanceOf[Short]); + lvTab.putShort(pool.addUtf8(name).asInstanceOf[Short]); + lvTab.putShort(pool.addUtf8(signature).asInstanceOf[Short]); + lvTab.putShort(idx); + } + + lvTab.putShort(locals.asInstanceOf[Short]); + + if (!jmethod.isStatic()) { + emitEntry("this", jclass.getType().getSignature(), 0); + } - val lvTab = ByteBuffer.allocate(2 + 10 * vars.length); - lvTab.putShort(vars.length.asInstanceOf[Short]); for (val lv <- vars) { - val name = if (lv.getName() == null) { + val name = if (javaName(lv.sym) eq null) { anonCounter = anonCounter + 1; "<anon" + anonCounter + ">" - } else lv.getName(); + } else javaName(lv.sym) - lvTab.putShort(0.asInstanceOf[Short]); - lvTab.putShort(pc.asInstanceOf[Short]); - lvTab.putShort(pool.addUtf8(name).asInstanceOf[Short]); - lvTab.putShort(pool.addUtf8(lv.getType().getSignature()).asInstanceOf[Short]); - lvTab.putShort(lv.getIndex().asInstanceOf[Short]); + emitEntry(name, javaType(lv.kind).getSignature(), indexOf(lv).asInstanceOf[Short]); } val attr = fjbgContext.JOtherAttribute(jclass, diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala b/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala index 23f1f7fa45..092be313c6 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternNodeCreator.scala @@ -1,6 +1,7 @@ package scala.tools.nsc.matching; import scala.tools.nsc.util.Position; +import scala.tools.nsc.symtab.Flags; /** PatternNode factory. * we inherit the globals from PatternTool. @@ -112,7 +113,7 @@ trait PatternNodeCreator requires (TransMatcher with PatternNodes) { } def newVar(pos: int, tpe: Type): Symbol = { - newVar(pos, cunit.fresh.newName("temp"), tpe); + newVar(pos, cunit.fresh.newName("temp"), tpe).setFlag(Flags.SYNTHETIC); } } |