diff options
4 files changed, 87 insertions, 93 deletions
diff --git a/sources/scalac/transformer/matching/Autom2Scala.java b/sources/scalac/transformer/matching/Autom2Scala.java index 0b6d7509e6..51a378f960 100644 --- a/sources/scalac/transformer/matching/Autom2Scala.java +++ b/sources/scalac/transformer/matching/Autom2Scala.java @@ -224,7 +224,8 @@ public class Autom2Scala { return loadCurrentElem( cf.Switch( _state(), tags, bodies, - cf.Int( -1 )).setType( funRetType() ) ); + gen.mkIntLit(cf.pos, -1 )) + .setType( funRetType() ) ); Tree res = code_fail(); for( int i = dfa.nstates-2; i>= 0; i-- ) diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java index d6df1fba31..98b014861d 100644 --- a/sources/scalac/transformer/matching/CodeFactory.java +++ b/sources/scalac/transformer/matching/CodeFactory.java @@ -22,21 +22,13 @@ class CodeFactory extends PatternTool { public int pos = Position.FIRSTPOS ; - static final Name TUPLE2_N = Name.fromString("scala.Tuple2"); + static final Name TUPLE2_N = Name.fromString("scala.Tuple2"); static final Name LEFT_N = Name.fromString("_1"); static final Name RIGHT_N = Name.fromString("_2"); - static final Name HEAD_N = Name.fromString("head"); - - static final Name TAIL_N = Name.fromString("tail"); - - static final Name SEQ_TRACE_N = Name.fromString("scala.SeqTrace"); - - static final Name HEADSTATE_N = Name.fromString("headState"); - - static final Name HEADELEM_N = Name.fromString("headElem"); - - static final Name ISEMPTY_N = Name.fromString("isEmpty"); + static final Name HEAD_N = Name.fromString("head"); + static final Name TAIL_N = Name.fromString("tail"); + static final Name ISEMPTY_N = Name.fromString("isEmpty"); Symbol refSym() { // delete Names.Ref return defs.getType( Names.scala_Ref ).symbol() ; @@ -62,6 +54,7 @@ class CodeFactory extends PatternTool { return defs.getType( Names.scala_List ).symbol() ; } + /* Symbol seqConsSym() { return defs.getType( Names.scala_COLONCOLON ).symbol() ; } @@ -69,7 +62,7 @@ class CodeFactory extends PatternTool { Symbol seqNilSym() { return defs.getType( Names.scala_Nil ).symbol().module(); // no need for TypeApply anymore!x } - + */ Symbol seqIterSym() { return defs.getType( Names.scala_Iterator ).symbol(); } @@ -81,11 +74,11 @@ class CodeFactory extends PatternTool { Symbol seqIterSym_hasNext() { Scope scp = seqIterSym().members(); return scp.lookup( Names.hasNext ); } + /* Symbol seqTraceSym() { return defs.getType( Name.fromString( "scala.SeqTrace" ) ).symbol(); } - Symbol seqTraceConsSym() { return defs.getType( Name.fromString( "scala.SeqTraceCons" ) ).symbol(); } @@ -93,7 +86,7 @@ class CodeFactory extends PatternTool { Symbol seqTraceNilSym() { return defs.getType( Name.fromString( "scala.SeqTraceNil" ) ).symbol(); } - + */ Symbol iterableSym() { return defs.getType( Names.scala_Iterable ).symbol(); } @@ -212,7 +205,7 @@ class CodeFactory extends PatternTool { return make.Literal(pos, new Integer/*Short?*/( 0 )) .setType( defs.SHORT_TYPE ); else if( asType.isSameAs(defs.INT_TYPE )) - return Int( 0 ); + return gen.mkIntLit( pos, 0 ); else if( asType.isSameAs(defs.LONG_TYPE )) return make.Literal(pos, new Long( 0 )) .setType( defs.LONG_TYPE ); @@ -247,15 +240,13 @@ class CodeFactory extends PatternTool { } /** code `Nil' - */ - - Tree _seqTraceNil( Type elemType ) { + Tree _seqTraceNil( Type elemType ) { return newSeqNil( null ); } + */ /** creates an scala.Int constant - */ Tree Int( int val ) { return Int( new Integer( val )); } @@ -265,14 +256,10 @@ class CodeFactory extends PatternTool { .setType( defs.INT_TYPE ); } - - /** code `new SeqTraceCons[ elemType ]( state, head, tail )' */ - Tree newSeqTraceCons( Integer state, Tree head, Tree tail ) { - return newSeqCons( newPair( Int(state),head ),tail ); - } // `SeqCons[ elemType ]' + /* Type _seqConsType( Type elemType ) { return Type.TypeRef( defs.SCALA_TYPE, @@ -283,6 +270,7 @@ class CodeFactory extends PatternTool { Tree newSeqNil( Type tpe ) { return gen.Select(gen.Ident(pos, defs.SCALA), seqNilSym()); } + */ // EXPERIMENTAL Tree newRef( Tree init ) { @@ -292,12 +280,6 @@ class CodeFactory extends PatternTool { new Tree[] { init } )); } - Tree newSeqCons( Tree head, Tree tail ) { - return gen.New(gen.mkPrimaryConstr(pos, seqConsSym(), - new Type[] { head.type() }, - new Tree[] { head, tail })); - } - /** returns A for T <: Sequence[ A ] */ Type getElemType_Sequence( Type tpe ) { @@ -359,52 +341,52 @@ class CodeFactory extends PatternTool { .setType( defs.BOOLEAN_TYPE ); } - Tree SeqTrace_headElem( Tree arg ) { // REMOVE SeqTrace - Scope scp = seqListSym().members(); - Symbol headSym = scp.lookup ( HEAD_N ); - assert headSym != Symbol.NONE; - scp = tuple2Sym().members(); - Symbol leftSym = scp.lookup ( RIGHT_N ); - assert leftSym != Symbol.NONE; - Tree t = gen.Apply( gen.Select( pos, arg, headSym ), - Tree.EMPTY_ARRAY ); - return gen.Apply( gen.Select( pos, t, leftSym ), - Tree.EMPTY_ARRAY ); - } - - Tree SeqTrace_headState( Tree arg ) { // REMOVE SeqTrace - Scope scp = seqListSym().members(); - Symbol headSym = scp.lookup ( HEAD_N ); - assert headSym != Symbol.NONE; - scp = tuple2Sym().members(); - Symbol leftSym = scp.lookup ( LEFT_N ); - assert leftSym != Symbol.NONE; - Tree t = gen.Apply( gen.Select( pos, arg, headSym ), - Tree.EMPTY_ARRAY ); - t = gen.Apply( gen.Select( pos, t, leftSym ), - Tree.EMPTY_ARRAY ); - return t; - - } - - Tree SeqTrace_tail( Tree arg ) { - Scope scp = seqListSym()/*seqTraceSym()*/.members(); // REMOVE SeqTrace - Symbol tailSym = scp.lookup ( TAIL_N ); - assert tailSym != Symbol.NONE; - //System.err.println( "CodeFactory::SeqTrace_tail " + tailSym +" "+ tailSym.type() ); - return gen.Apply( gen.Select( pos, arg, tailSym ), - Tree.EMPTY_ARRAY ); - } - - /** `<seqlist>.head()' - */ - Tree SeqList_head( Tree arg ) { - Scope scp = seqListSym().members(); - Symbol headSym = scp.lookup ( HEAD_N ); - assert headSym != Symbol.NONE; - return gen.Apply( gen.Select( pos, arg, headSym ), - Tree.EMPTY_ARRAY ); - } + Tree SeqTrace_headElem( Tree arg ) { // REMOVE SeqTrace + Scope scp = seqListSym().members(); + Symbol headSym = scp.lookup ( HEAD_N ); + assert headSym != Symbol.NONE; + scp = tuple2Sym().members(); + Symbol leftSym = scp.lookup ( RIGHT_N ); + assert leftSym != Symbol.NONE; + Tree t = gen.Apply( gen.Select( pos, arg, headSym ), + Tree.EMPTY_ARRAY ); + return gen.Apply( gen.Select( pos, t, leftSym ), + Tree.EMPTY_ARRAY ); + } + + Tree SeqTrace_headState( Tree arg ) { // REMOVE SeqTrace + Scope scp = seqListSym().members(); + Symbol headSym = scp.lookup ( HEAD_N ); + assert headSym != Symbol.NONE; + scp = tuple2Sym().members(); + Symbol leftSym = scp.lookup ( LEFT_N ); + assert leftSym != Symbol.NONE; + Tree t = gen.Apply( gen.Select( pos, arg, headSym ), + Tree.EMPTY_ARRAY ); + t = gen.Apply( gen.Select( pos, t, leftSym ), + Tree.EMPTY_ARRAY ); + return t; + + } + + Tree SeqTrace_tail( Tree arg ) { + Scope scp = seqListSym()/*seqTraceSym()*/.members(); // REMOVE SeqTrace + Symbol tailSym = scp.lookup ( TAIL_N ); + assert tailSym != Symbol.NONE; + //System.err.println( "CodeFactory::SeqTrace_tail " + tailSym +" "+ tailSym.type() ); + return gen.Apply( gen.Select( pos, arg, tailSym ), + Tree.EMPTY_ARRAY ); + } + + /** `<seqlist>.head()' + */ + Tree SeqList_head( Tree arg ) { + Scope scp = seqListSym().members(); + Symbol headSym = scp.lookup ( HEAD_N ); + assert headSym != Symbol.NONE; + return gen.Apply( gen.Select( pos, arg, headSym ), + Tree.EMPTY_ARRAY ); + } /** return the analyzed type */ diff --git a/sources/scalac/transformer/matching/LeftTracerInScala.java b/sources/scalac/transformer/matching/LeftTracerInScala.java index cb58f4b196..a953551759 100644 --- a/sources/scalac/transformer/matching/LeftTracerInScala.java +++ b/sources/scalac/transformer/matching/LeftTracerInScala.java @@ -52,7 +52,7 @@ public class LeftTracerInScala extends TracerInScala { helpMap.put( realVar, helpVar ); - Tree varDef = gen.ValDef(helpVar, cf.newSeqNil( elementType )); + Tree varDef = gen.ValDef(helpVar, gen.Nil(cf.pos /*cf.newSeqNil elementType*/ )); // set mutable flag of symbol helpVar ?? helpVarDefs.add( varDef ); return helpVar; @@ -121,11 +121,20 @@ public class LeftTracerInScala extends TracerInScala { if( target == dfa.nstates - 1 ) return code_fail(); */ + + /* Tree newAcc = cf.newSeqTraceCons(new Integer(i), currentElem(), _ref( accumSym )); + */ + Tree hd = cf.newPair( gen.mkIntLit(cf.pos, i), currentElem() ); + + Tree newAcc = gen.Cons(cf.pos, + hd.type, + hd, + _ref( accumSym )); - return callFun( new Tree[] { newAcc , _iter(), cf.Int( target )} ); + return callFun( new Tree[] { newAcc , _iter(), gen.mkIntLit( cf.pos, target )} ); } @@ -201,7 +210,7 @@ public class LeftTracerInScala extends TracerInScala { // `def leftTracer(...) = ...' the function definition v.add( theDefDef ); - Tree emptyAcc = cf._seqTraceNil( elementType ); + Tree emptyAcc = gen.Nil( cf.pos ); //cf._seqTraceNil( elementType ); // the valdef is needed, because passing emptyAcc as a parameter // results in a ClassCastException at runtime (?!) @@ -218,7 +227,7 @@ public class LeftTracerInScala extends TracerInScala { Tree run = callFun( new Tree[] { gen.Ident( pos, emptyAccSym ), cf.newIterator( selector, selector.type() ), - cf.Int( 0 ) }); + gen.mkIntLit( cf.pos, 0 ) }); run = gen.ValDef( resultSym, run ); @@ -298,9 +307,11 @@ public class LeftTracerInScala extends TracerInScala { /** return the accumulator + last state */ Tree run_finished( int state ) { - return cf.newSeqTraceCons(new Integer( state ), - cf.ignoreValue( elementType ), - _ref( accumSym )); + Tree hd = cf.newPair( gen.mkIntLit( cf.pos, state ), cf.ignoreValue( elementType )); + return gen.Cons( cf.pos, + hd.type(), + hd, + _ref( accumSym )); } } diff --git a/sources/scalac/transformer/matching/RightTracerInScala.java b/sources/scalac/transformer/matching/RightTracerInScala.java index 2101eb382c..12eca9080f 100644 --- a/sources/scalac/transformer/matching/RightTracerInScala.java +++ b/sources/scalac/transformer/matching/RightTracerInScala.java @@ -113,7 +113,7 @@ public class RightTracerInScala extends TracerInScala { if( keepType ) rhs = cf.ignoreValue( realVar.type() ); else - rhs = /* cf.newRef( */ cf.newSeqNil( elementType ) + rhs = /* cf.newRef( cf.newSeqNil( */ gen.Nil( cf.pos ) .setType( cf.SeqListType( elementType )); /* ) */; helpVar.flags |= Modifiers.MUTABLE; @@ -125,7 +125,7 @@ public class RightTracerInScala extends TracerInScala { Tree prependToHelpVar( Symbol realVar, Tree elem ) { Tree hv = refHelpVar( realVar ); - return gen.Assign( hv, cf.newSeqCons( elem, hv )); + return gen.Assign( hv, gen.Cons(cf.pos, elem.type(), elem, hv));//cf.newSeqCons( elem, hv )); /* return cf.Block(pos, new Tree [] { @@ -228,14 +228,14 @@ public class RightTracerInScala extends TracerInScala { Integer targetR = (Integer) hmap.get( targetL ); stateBody = cf.If( cf.Equals( gen.Ident( pos, targetSym ), - cf.Int( targetL )), + gen.mkIntLit( cf.pos, targetL )), callFun( new Tree[] { cf.SeqTrace_tail( _iter() ), - cf.Int( targetR ) }), + gen.mkIntLit( cf.pos, targetR ) }), stateBody ); } - return cf.If( cf.Equals( _state(), cf.Int( 0 )), + return cf.If( cf.Equals( _state(), gen.mkIntLit( cf.pos, 0 )), stateBody , elseBody ); @@ -415,7 +415,7 @@ public class RightTracerInScala extends TracerInScala { stms[ j++ ] = algMatchTree ; stms[ j ] = callFun( new Tree[] { cf.SeqTrace_tail( _iter() ), - cf.Int( ntarget ) } ); + gen.mkIntLit( cf.pos, ntarget ) } ); return cf.Block( pos, stms, funRetType() ); } @@ -432,7 +432,7 @@ public class RightTracerInScala extends TracerInScala { v.add( (Tree) it.next() ); v.add( gen.DefDef( this.funSym, code_body() ) ); - v.add( callFun( new Tree[] { trace, cf.Int( 0 ) } ) ); + v.add( callFun( new Tree[] { trace, gen.mkIntLit( cf.pos, 0 ) } ) ); /* for(Iterator it = helpMap.keySet().iterator(); it.hasNext(); ) { @@ -478,7 +478,7 @@ public class RightTracerInScala extends TracerInScala { //System.out.println("_cur_eq, thelab: "+label); switch( label ) { case Pair( Integer target, Label theLab ): - return cf.Equals( cf.Int( target ), + return cf.Equals( gen.mkIntLit( cf.pos, target ), current() ); } throw new ApplicationError("expected Pair label"); |