diff options
author | buraq <buraq@epfl.ch> | 2004-09-30 08:58:44 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-09-30 08:58:44 +0000 |
commit | b9f91af85b7136996167b3af10c042858ede722a (patch) | |
tree | 37c001aff82d7302de4cfc2442d442aa595e0b97 /sources/scala/tools/scalac/transformer/TransMatch.scala | |
parent | 8673513033230f1d61bce577a83a8d89eb631746 (diff) | |
download | scala-b9f91af85b7136996167b3af10c042858ede722a.tar.gz scala-b9f91af85b7136996167b3af10c042858ede722a.tar.bz2 scala-b9f91af85b7136996167b3af10c042858ede722a.zip |
moved code for readability
Diffstat (limited to 'sources/scala/tools/scalac/transformer/TransMatch.scala')
-rw-r--r-- | sources/scala/tools/scalac/transformer/TransMatch.scala | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/sources/scala/tools/scalac/transformer/TransMatch.scala b/sources/scala/tools/scalac/transformer/TransMatch.scala index 1ebdcba40a..6a5e984722 100644 --- a/sources/scala/tools/scalac/transformer/TransMatch.scala +++ b/sources/scala/tools/scalac/transformer/TransMatch.scala @@ -73,11 +73,11 @@ class TransMatch( global:scalac_Global ) val z:Seq[Tree] = ps; z.elements.foreach( x => getNilVars( x )); } def getNilVars( p:Tree ):scala.Unit = p match { - case Tree$Alternative( _ ) => /* no bind allowed! */ - case Tree$Bind( _, pat ) => + case Tree$Alternative( _ ) => /* no bind allowed! */ + case Tree$Bind( _, pat ) => + getNilVars(pat); if( TreeInfo.isEmptySequence( pat ) ) res = p.symbol() :: res; - getNilVars(pat); case Tree$Ident(_) => case Tree$Sequence( trees ) => getNilVars1( trees ) case Tree$Apply( _, args ) => getNilVars1( args ) @@ -90,6 +90,20 @@ class TransMatch( global:scalac_Global ) res } + // 2do: remove binds from pattern + def handleNilVariables( cse: Tree$CaseDef ): Unit = { + val nilvars = nilVariables(cse.pat); + if( !nilvars.isEmpty ) { + val newBody = new Array[Tree]( nilvars.length ); + var j=0; + for( val v <- nilvars.elements ) { + val n = gen.mkNil( cse.pos ); + newBody( j ) = gen.ValDef( v, n ); + j = j + 1; + } + cse.body = gen.mkBlock( newBody, cse.body ); + } + } //val bsf = new scala.util.automaton.BerrySethi[ matching.PatternTest ]( pe ); @@ -111,18 +125,9 @@ class TransMatch( global:scalac_Global ) var containsReg = false; var i = 0; while (i < cases.length) { - containsReg = isRegular(cases( i ).pat) || containsReg; - - var nilvars = nilVariables(cases( i ).pat); - if( !nilvars.isEmpty ) { - val newBody = new Array[Tree]( nilvars.length ); - var j=0; - for( val v <- nilvars.elements ) { - val n = gen.mkNil( cases( i ).pos ); - newBody( j ) = gen.ValDef( v, n ); - j = j + 1; - } - cases(i).body = gen.mkBlock( newBody, cases(i).body ); + if(isRegular(cases( i ).pat)) { + containsReg = true; + handleNilVariables(cases( i )); } i = i+1; } |