diff options
author | buraq <buraq@epfl.ch> | 2003-06-20 16:02:39 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2003-06-20 16:02:39 +0000 |
commit | 9ee72242892a8d94a918dfd89dd89bffa7b49d30 (patch) | |
tree | 607b42670037f904dd20049d7695a672e38e6439 /sources/scalac | |
parent | ec5989695e1301a021746263eb927171b686c55b (diff) | |
download | scala-9ee72242892a8d94a918dfd89dd89bffa7b49d30.tar.gz scala-9ee72242892a8d94a918dfd89dd89bffa7b49d30.tar.bz2 scala-9ee72242892a8d94a918dfd89dd89bffa7b49d30.zip |
changes for WordAutomInScala
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/transformer/matching/CodeFactory.java | 81 |
1 files changed, 76 insertions, 5 deletions
diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java index 92a8d4ec8f..2507670351 100644 --- a/sources/scalac/transformer/matching/CodeFactory.java +++ b/sources/scalac/transformer/matching/CodeFactory.java @@ -20,15 +20,21 @@ import Tree.*; class CodeFactory extends PatternTool { - static final Name SEQ_ITER_N = Name.fromString("scala.SequenceIterator"); - static final Name HAS_CUR_N = Name.fromString("hasCur"); - static final Name CUR_N = Name.fromString("cur"); - static final Name NEXT_N = Name.fromString("next"); + static final Name SEQ_N = Name.fromString("scala.Sequence"); + static final Name SEQ_ITER_N = Name.fromString("scala.SequenceIterator"); + static final Name NEW_ITERATOR_N = Name.fromString("newIterator"); + static final Name HAS_CUR_N = Name.fromString("hasCur"); + static final Name CUR_N = Name.fromString("cur"); + static final Name NEXT_N = Name.fromString("next"); /** symbol of `scala.SequenceIterator' */ Symbol seqIterSym; + /** symbol of `scala.Sequence.newIterator' + */ + Symbol newIterSym; + Symbol curSym; Symbol hasCurSym; Symbol nextSym; @@ -36,8 +42,17 @@ class CodeFactory extends PatternTool { public CodeFactory( Unit unit, Infer infer ) { super( unit, infer ); + // get `Sequence:newIterator' + Symbol sequenceSym = defs.getClass( SEQ_N ); + + Scope scp = sequenceSym.members(); + + this.newIterSym = scp.lookup/*Term */( NEW_ITERATOR_N ); + assert !( newIterSym == Symbol.NONE ) : " did not find newIterator "; + this.seqIterSym = defs.getType( SEQ_ITER_N ).symbol(); - Scope scp = seqIterSym.members(); + + scp = seqIterSym.members(); curSym = scp.lookup/*Term*/ ( CUR_N ); assert !( curSym == Symbol.NONE ) : "did not find cur"; } @@ -61,6 +76,25 @@ class CodeFactory extends PatternTool { elseBody ).setType( elseBody.type() ); } + Tree Switch( Tree selector, + Tree condition[], + Tree body[], + Tree defaultBody ) { + assert selector != null:"selector is null"; + assert condition != null:"cond is null"; + assert body != null:"body is null"; + assert defaultBody != null:"defaultBody is null"; + Tree result = defaultBody; + + for( int i = condition.length-1; i >= 0; i-- ) + result = If( condition[ i ], + body[ i ], + result + ).setType( result.type ); + + return result ; + } + /** `SequenceIterator[ elemType ]' // TODO: Move to TypeFactory */ Type _seqIterType( Type elemType ) { @@ -69,6 +103,34 @@ class CodeFactory extends PatternTool { new Type[] { elemType }); } + /** returns code `<seqObj>.newIterator' + * the parameter needs to have type attribute `Sequence[<elemType>]' + * it is not checked whether seqObj really has type `Sequence' + */ + Tree newIterator( Tree seqObj ) { + Type args[] = seqObj.type().typeArgs(); + assert ( args.length== 1 ) : "seqObj does not have right type"; + Type elemType = args[ 0 ]; + //System.out.println( "elemType:"+elemType ); + + //Tree t1 = gen.Select(seqObj, newIterSym); + Tree t1 = make.Select( Position.NOPOS, seqObj, newIterSym.name ) + .setSymbol( newIterSym ) + .setType( Type.MethodType(new Symbol[] {},_seqIterType( elemType ))); + + //System.out.println( "t1.type:"+t1.type() ); + + Tree theIterator = gen.Apply(seqObj.pos, + t1, + Tree.EMPTY_ARRAY) + .setType( _seqIterType( elemType ) ); + + //System.out.println( "theit.type:"+theIterator.type() ); + + return theIterator; + + } + // the caller needs to set the type ! Tree _applyNone( Tree arg ) { return make.Apply(Position.NOPOS, arg, Tree.EMPTY_ARRAY ); @@ -90,6 +152,15 @@ class CodeFactory extends PatternTool { .setType( elemType ); } + /** `it.next()' + */ + public Tree _next( Tree iter ) { + Type elemType = getElemType( iter.type() ); + + return _applyNone( gen.Select( iter, nextSym )) + .setType( iter.type() ); + } + /** `it.hasCur()' */ public Tree _hascur( Tree iter ) { |