diff options
author | michelou <michelou@epfl.ch> | 2005-05-20 12:54:23 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2005-05-20 12:54:23 +0000 |
commit | 9907ade461e90f331b3a1edf41a5b00f225ba10e (patch) | |
tree | 5740c7f04dfc73f089cc94d64cfe33441b808f16 /sources | |
parent | 535c7e54fcdb3950ae490cd40ad5ef9da1882d98 (diff) | |
download | scala-9907ade461e90f331b3a1edf41a5b00f225ba10e.tar.gz scala-9907ade461e90f331b3a1edf41a5b00f225ba10e.tar.bz2 scala-9907ade461e90f331b3a1edf41a5b00f225ba10e.zip |
- cleaned up.
Diffstat (limited to 'sources')
15 files changed, 530 insertions, 466 deletions
diff --git a/sources/scala/tools/scalac/ast/parser/Scanner.scala b/sources/scala/tools/scalac/ast/parser/Scanner.scala index 45d6ec2a3b..f9240de01d 100644 --- a/sources/scala/tools/scalac/ast/parser/Scanner.scala +++ b/sources/scala/tools/scalac/ast/parser/Scanner.scala @@ -1,6 +1,6 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2004, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** ** ** ** $Id$ @@ -36,7 +36,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { /** add the given character to the documentation buffer */ protected def addCharToDoc(ch: Char): unit = - if (docBuffer != null) docBuffer.append(ch); + if (docBuffer != null) docBuffer.append(ch); /** layout & character constants */ @@ -64,7 +64,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { var bp: Int = -1; */ - class SourceIterator(charArray:Array[Char]) extends Iterator[Char] { + class SourceIterator(charArray: Array[Char]) extends Iterator[Char] { val buf:Array[Char] = charArray; var bp: Int = -1; /* inv: true if buf( bp ) is last of an odd number of ASCII '\' */ @@ -75,7 +75,9 @@ class Scanner(_unit: CompilationUnit) extends TokenData { def hasMore(j: Int) = bp + j < buf.length; def hasNext = hasMore( 1 ); - /** gets next char, handles unicode transform */ + /** + * Gets next char, handles unicode transform + */ def next: Char = { bp = bp + 1; val ch = buf( bp ); @@ -96,12 +98,13 @@ class Scanner(_unit: CompilationUnit) extends TokenData { */ def lookahead1 = { val ahead1 = buf( bp + 1 ); - if( ahead1 == '\\' && !odd && hasMore( 2 ) && 'u' == buf( bp + 1 )) { - val Pair( newch, offset ) = nextUnicode( bp + 1 ); + if (ahead1 == '\\' && !odd && hasMore(2) && 'u' == buf(bp + 1)) { + val Pair(newch, offset) = nextUnicode(bp + 1); unicode1 = offset; bp = bp + offset; newch; - } else { + } + else { unicode1 = 0; ahead1 } @@ -112,11 +115,12 @@ class Scanner(_unit: CompilationUnit) extends TokenData { val j = bp + unicode1 + 1 + 1; val ahead2 = buf( j ); val even1 = unicode1 > 0 || '\\' != buf( j - 1 ) || odd; - if( ahead2 == '\\' && even1 && hasMore( j, 1 ) && 'u' == buf( j + 1 )) { - val Pair( newch, offset ) = nextUnicode( j + 1 ); + if (ahead2 == '\\' && even1 && hasMore(j, 1) && 'u' == buf(j + 1)) { + val Pair(newch, offset) = nextUnicode(j + 1); unicode2 = offset; newch; - } else { + } + else { ahead2 } } @@ -127,8 +131,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { val ahead3 = buf( j ); var even2 = unicode2 > 0 || '\\' != buf( j - 1 ) || '\\' == buf( j - 2 ); - if( ahead3 == '\\' && even2 && hasMore( j, 1 ) && 'u' == buf( j + 1 )) { - val Pair( newch, offset ) = nextUnicode( j + 1 ); + if (ahead3 == '\\' && even2 && hasMore( j, 1 ) && 'u' == buf(j + 1)) { + val Pair(newch, offset) = nextUnicode(j + 1); newch; } else { ahead3 @@ -140,10 +144,10 @@ class Scanner(_unit: CompilationUnit) extends TokenData { /** returns unicode and offset of next character */ def nextUnicode(p: Int): Pair[Char,Int] = { var j = p; - while ( buf( j ) == 'u' ) { j = j + 1 }; - if ( j + 4 >= buf.length ) syntaxError("incomplete unicode escape"); + while ( buf(j) == 'u' ) { j = j + 1 }; + if (j + 4 >= buf.length) syntaxError("incomplete unicode escape"); def munch = { - val i = digit2int( buf( j ), 16 ); + val i = digit2int( buf(j), 16 ); if( i == -1 ) { syntaxError("error in unicode escape"); }; @@ -151,11 +155,11 @@ class Scanner(_unit: CompilationUnit) extends TokenData { i } var code:Int = munch; - //Console.println("nextUnicode2, code ="+code); + //Console.println("nextUnicode2, code =" + code); code = (code << 4) + munch; code = (code << 4) + munch; code = (code << 4) + munch; - Pair( code.asInstanceOf[Char], j - p ) + Pair(code.asInstanceOf[Char], j - p) } } /* class SourceIterator */ @@ -238,7 +242,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { next.copyFrom(this); this.copyFrom(prev); } - } else if (token == SEMI) { + } + else if (token == SEMI) { prev.copyFrom(this); fetchToken(); if (token != ELSE) { @@ -280,7 +285,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { //index = bp; ch match { case '\u21D2' => - nextch(); token = ARROW; + nextch(); + token = ARROW; return; case 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | @@ -294,12 +300,12 @@ class Scanner(_unit: CompilationUnit) extends TokenData { 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | // scala-mode: need to understand multi-line case patterns 'z' => - putChar( ch ); + putChar(ch); nextch(); getIdentRest; // scala-mode: wrong indent for multi-line case blocks return; case _ if (java.lang.Character.isUnicodeIdentifierStart(ch)) => - putChar( ch ); + putChar(ch); nextch(); getIdentRest; return; @@ -307,8 +313,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { case '<' => // is XMLSTART? var last = lastch; nextch(); - last.match { - case ' '|'\t'|'\n'|'{'|'('|'>' if xml.Parsing.isNameStart( ch ) => + last match { + case ' '|'\t'|'\n'|'{'|'('|'>' if xml.Parsing.isNameStart(ch) => token = XMLSTART; case _ => putChar('<'); @@ -332,7 +338,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { return; } case '0' => - putChar( ch ); + putChar(ch); nextch(); if (ch == 'x' || ch == 'X') { nextch(); @@ -370,8 +376,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' => - cbuf.setLength( 0 ); - putChar( ch ); + cbuf.setLength(0); + putChar(ch); nextch(); if (ch != '\'') { getIdentRest; @@ -380,7 +386,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { } case _ if(java.lang.Character.isUnicodeIdentifierStart(ch)) => cbuf.setLength( 0 ); - putChar( ch ); + putChar(ch); nextch(); if (ch != '\'') { getIdentRest; @@ -395,7 +401,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { nextch(); token = CHARLIT; name = Name.fromString( cbuf.toString() ); - cbuf.setLength( 0 ); + cbuf.setLength(0); } else { syntaxError("unclosed character literal"); } @@ -403,7 +409,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { case '.' => nextch(); if (('0' <= ch) && (ch <= '9')) { - putChar( '.' ); + putChar('.'); getFraction; } else token = DOT; return; @@ -443,7 +449,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { case java.lang.Character.MATH_SYMBOL => true; case java.lang.Character.OTHER_SYMBOL => true; case _ => false;}) { - putChar( ch ); + putChar(ch); getOperatorRest; } else { nextch(); @@ -455,13 +461,14 @@ class Scanner(_unit: CompilationUnit) extends TokenData { } } - private def skipComment(): boolean = { + private def skipComment(): Boolean = { if (ch == '/') { do { nextch(); } while ((ch != CR) && (ch != LF) && (ch != SU)); true - } else if (ch == '*') { + } + else if (ch == '*') { docBuffer = null; var openComments = 1; nextch(); @@ -511,7 +518,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { } } - def isIdentStart( c: Char ) = c.match { + def isIdentStart(ch: Char) = ch match { case 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | @@ -525,19 +532,21 @@ class Scanner(_unit: CompilationUnit) extends TokenData { 'u' | 'v' | 'w' | 'x' | 'y' | 'z' => true - case _ if(java.lang.Character.isUnicodeIdentifierStart(c)) => - true; - case _ => false; + case _ if (java.lang.Character.isUnicodeIdentifierStart(ch)) => + true + case _ => + false } - def isIdentPart( c: Char ) = isIdentStart( c ) || c.match { + def isIdentPart(ch: Char) = isIdentStart(ch) || (ch match { case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => - true - case _ if(java.lang.Character.isUnicodeIdentifierPart(c)) => - true; - case _ => false } ; - + true + case _ if (java.lang.Character.isUnicodeIdentifierPart(ch)) => + true + case _ => + false + }); private def getIdentRest: Unit = { while (true) { @@ -559,7 +568,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { putChar( ch ); nextch(); case '_' => - putChar( ch ); + putChar(ch); nextch(); getIdentOrOperatorRest; return; @@ -568,8 +577,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { treatIdent; return; - case _ if(java.lang.Character.isUnicodeIdentifierPart(ch)) => - putChar( ch ); + case _ if (java.lang.Character.isUnicodeIdentifierPart(ch)) => + putChar(ch); nextch(); case _ => treatIdent; @@ -585,7 +594,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { '^' | '*' | '+' | '-' | '<' | '>' | '?' | ':' | '=' | '&' | '|' | '\\' => - putChar( ch ); + putChar(ch); nextch(); case '/' => nextch(); @@ -596,12 +605,12 @@ class Scanner(_unit: CompilationUnit) extends TokenData { putChar( '/' ); } case _ => - if( java.lang.Character.getType( ch ).asInstanceOf[byte] match { + if (java.lang.Character.getType(ch).asInstanceOf[byte] match { case java.lang.Character.MATH_SYMBOL => true; case java.lang.Character.OTHER_SYMBOL => true; case _ => false; }) { - putChar( ch ); + putChar(ch); nextch(); } else { treatIdent; @@ -612,7 +621,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { } private def getIdentOrOperatorRest: unit = { - if( isIdentPart( ch ) ) + if (isIdentPart(ch)) getIdentRest else ch match { case '~' | '!' | '@' | '#' | '%' | @@ -635,15 +644,16 @@ class Scanner(_unit: CompilationUnit) extends TokenData { private def getStringLit(delimiter: Char): unit = { nextch(); - while (srcIterator.hasNext && ch != delimiter && ch != CR && ch != LF ) { + while (srcIterator.hasNext && ch != delimiter && ch != CR && ch != LF) { getlitch(); } if (ch == delimiter) { token = STRINGLIT; name = Name.fromString( cbuf.toString() ); - cbuf.setLength( 0 );; + cbuf.setLength(0); nextch(); - } else { + } + else { syntaxError("unclosed string literal"); name = Names.ERROR; } @@ -673,7 +683,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { /** append Unicode character to "lit" buffer */ - private def putChar(c: Char) = cbuf.append( c ); + private def putChar(ch: Char) = cbuf.append(ch); /* if (litlen == lit.length) { val newlit = new Array[char](lit.length * 2); @@ -696,11 +706,11 @@ class Scanner(_unit: CompilationUnit) extends TokenData { */ /** precondition: isUnicode() == true - protected def getUnicodeChar():char = { + protected def getUnicodeChar(): Char = { var i : Int = 0; var k = bp + 2; while( k < bp + 6 ) { - i = 16 * i + SourceRepresentation.digit2int(buf( k ), 16); + i = 16 * i + SourceRepresentation.digit2int(buf(k), 16); k = k + 1; }; i.asInstanceOf[char] @@ -754,7 +764,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { nextch(); } /* } */ - } else { + } + else { putChar(ch); nextch(); } @@ -763,7 +774,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { */ protected def getFraction = { while (SourceRepresentation.digit2int(ch, 10) >= 0) { - putChar( ch ); + putChar(ch); nextch(); } token = DOUBLELIT; @@ -773,12 +784,12 @@ class Scanner(_unit: CompilationUnit) extends TokenData { val c2 = srcIterator.lookahead2; if ((c1 == '+') || (c1 == '-') && ('0' >= c2) || (c2 <= '9')) { nextch(); - putChar( ch ); + putChar(ch); nextch(); } else nextch(); while (SourceRepresentation.digit2int(ch, 10) >= 0) { - putChar( ch ); + putChar(ch); nextch(); } } @@ -786,7 +797,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { putChar( ch ); nextch(); } else if ((ch == 'f') || (ch == 'F')) { - putChar( ch ); + putChar(ch); token = FLOATLIT; nextch(); } @@ -802,7 +813,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { if (token == CHARLIT && !negated) { if (name.length() > 0) - name.charAt( 0 ) + name.charAt(0) else 0 } else { @@ -844,7 +855,8 @@ class Scanner(_unit: CompilationUnit) extends TokenData { if (value > limit) syntaxError("floating point number too large"); if (negated) -value else value - } catch { + } + catch { case _: NumberFormatException => syntaxError("malformed floating point number"); 0.0 @@ -855,9 +867,9 @@ class Scanner(_unit: CompilationUnit) extends TokenData { /** see Java spec 3.10.2 */ - def exponentPart(c1: Char,c2: Char) = + def exponentPart(c1: Char, c2: Char) = (c1 == 'e' || c1 == 'E') && - ((c2 >= '0' && c2 <= '9') || (c2 == '+' || c2 == '-')) ; + ((c2 >= '0' && c2 <= '9') || (c2 == '+' || c2 == '-')) ; /** see Java spec 3.10.2 */ def floatTypeSuffix(c1: Char) = @@ -878,19 +890,21 @@ class Scanner(_unit: CompilationUnit) extends TokenData { putChar(ch); nextch(); getFraction; - } else { + } + else { val c2 = srcIterator.lookahead2; - if(exponentPart(c1,c2)) { + if (exponentPart(c1,c2)) { putChar(ch);// + getFraction; return; } - if(isIdentStart(c1)&&isIdentPart(c2)) { // is select + if (isIdentStart(c1)&&isIdentPart(c2)) { // is select name = Name.fromString( cbuf.toString() ); cbuf.setLength( 0 ); token = INTLIT; return; - } else { + } + else { putChar(ch); nextch(); getFraction; @@ -901,15 +915,16 @@ class Scanner(_unit: CompilationUnit) extends TokenData { ch == 'f' || ch == 'F' || ch == 'd' || ch == 'D')) { getFraction; - } else { + } + else { if (ch == 'l' || ch == 'L') { - name = Name.fromString( cbuf.toString()); - cbuf.setLength( 0 ); + name = Name.fromString(cbuf.toString()); + cbuf.setLength(0); nextch(); token = LONGLIT; } else { - name = Name.fromString( cbuf.toString() ); - cbuf.setLength( 0 ); + name = Name.fromString(cbuf.toString()); + cbuf.setLength(0); token = INTLIT; } } @@ -991,5 +1006,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { case _ => token2string(token) } + } -} + +} // package diff --git a/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala b/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala index 41b1d69871..76f8c8d871 100644 --- a/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala +++ b/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala @@ -1,6 +1,6 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2004, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** \* */ @@ -28,36 +28,36 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: var isPattern:Boolean = _; - val _ArrayBuffer = Name.fromString("ArrayBuffer"); - val _Attribute = Name.fromString("Attribute"); - val _MetaData = Name.fromString("MetaData"); - val _NamespaceBinding = Name.fromString("NamespaceBinding"); - val _NodeBuffer = Name.fromString("NodeBuffer"); - val _NoAttributes = Name.fromString("NoAttributes"); - - val _Null = Name.fromString("Null"); - - val _PrefixedAttribute = Name.fromString("PrefixedAttribute"); - val _UnprefixedAttribute = Name.fromString("UnprefixedAttribute"); - val _TreeMap = Name.fromString("TreeMap"); - val _Elem = Name.fromString("Elem"); - val _Seq = Name.fromString("Seq"); - val _String = Name.fromString("String"); - val _immutable = Name.fromString("immutable"); - val _mutable = Name.fromString("mutable"); - val _append = Name.fromString("append"); - val _plus = Name.fromString("$plus"); - val _collection = Name.fromString("collection"); - val _toList = Name.fromString("toList"); - val _xml = Name.fromString("xml"); - val _Comment = Name.fromString("Comment"); - val _CharData = Name.fromString("CharData"); - val _Node = Name.fromString("Node"); - val _None = Name.fromString("None"); - val _Some = Name.fromString("Some"); - val _ProcInstr = Name.fromString("ProcInstr"); - val _Text = Name.fromString("Text"); - val _EntityRef = Name.fromString("EntityRef"); + val _ArrayBuffer = Name.fromString("ArrayBuffer"); + val _Attribute = Name.fromString("Attribute"); + val _MetaData = Name.fromString("MetaData"); + val _NamespaceBinding = Name.fromString("NamespaceBinding"); + val _NodeBuffer = Name.fromString("NodeBuffer"); + val _NoAttributes = Name.fromString("NoAttributes"); + + val _Null = Name.fromString("Null"); + + val _PrefixedAttribute = Name.fromString("PrefixedAttribute"); + val _UnprefixedAttribute = Name.fromString("UnprefixedAttribute"); + val _TreeMap = Name.fromString("TreeMap"); + val _Elem = Name.fromString("Elem"); + val _Seq = Name.fromString("Seq"); + val _String = Name.fromString("String"); + val _immutable = Name.fromString("immutable"); + val _mutable = Name.fromString("mutable"); + val _append = Name.fromString("append"); + val _plus = Name.fromString("$plus"); + val _collection = Name.fromString("collection"); + val _toList = Name.fromString("toList"); + val _xml = Name.fromString("xml"); + val _Comment = Name.fromString("Comment"); + val _CharData = Name.fromString("CharData"); + val _Node = Name.fromString("Node"); + val _None = Name.fromString("None"); + val _Some = Name.fromString("Some"); + val _ProcInstr = Name.fromString("ProcInstr"); + val _Text = Name.fromString("Text"); + val _EntityRef = Name.fromString("EntityRef"); // convenience methods private def _scala( pos: int, name: Name ) = @@ -70,17 +70,17 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: private def _scala_None( pos: int ) = _scala( pos, _None ) ; - private def _scala_Some( pos: int ) = - p.convertToConstr( _scala( pos, _Some )); + private def _scala_Some(pos: int) = + p.convertToConstr(_scala(pos, _Some)); - private def _string( pos: int ) = - p.convertToTypeId( make.Ident( pos, _String ) ); + private def _string(pos: int) = + p.convertToTypeId(make.Ident(pos, _String)); - private def _scala_xml( pos: int, name: Name ) = - make.Select( pos, _scala( pos, _xml ), name ); + private def _scala_xml(pos: int, name: Name) = + make.Select( pos, _scala(pos, _xml), name ); - private def _scala_xml_MetaData( pos: int ) = + private def _scala_xml_MetaData(pos: int) = p.convertToTypeId(_scala_xml( pos, _MetaData )); private def _scala_xml_NamespaceBinding( pos: int ) = @@ -116,31 +116,31 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: private def _scala_xml_ProcInstr( pos: int ) = p.convertToConstr( _scala_xml( pos, _ProcInstr )); - private def _scala_xml_Text( pos: int ) = + private def _scala_xml_Text(pos: int) = _scala_xml( pos, _Text ); - private def _scala_collection( pos: int, name: Name ) = + private def _scala_collection(pos: int, name: Name) = make.Select( pos, _scala( pos, _collection ), name ); - private def _scala_collection_mutable( pos: int, name: Name ) = + private def _scala_collection_mutable(pos: int, name: Name) = make.Select(pos, _scala_collection(pos, _mutable ), name); - private def _scala_collection_immutable( pos: int, name: Name ) = - make.Select(pos, _scala_collection(pos, _immutable ), name); + private def _scala_collection_immutable(pos: int, name: Name) = + make.Select(pos, _scala_collection(pos, _immutable), name); - private def _scala_collection_mutable_ArrayBuffer( pos: int ) = + private def _scala_collection_mutable_ArrayBuffer(pos: int) = make.Apply( pos, make.AppliedType(pos, p.convertToConstr( _scala_collection_mutable(pos, _ArrayBuffer )), Predef.Array[Tree]( convertToTypeId( - _scala_xml_Node( pos ) )) + _scala_xml_Node(pos) )) ), Tree.EMPTY_ARRAY ); - private def _scala_collection_immutable_TreeMap( pos: int ) = + private def _scala_collection_immutable_TreeMap(pos: int) = make.Apply( pos, make.AppliedType(pos, p.convertToConstr( @@ -152,17 +152,17 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: ), Tree.EMPTY_ARRAY ); - private def _emptyMap( pos:int ) = { + private def _emptyMap(pos: Int) = { make.New( pos,_scala_collection_immutable_TreeMap( pos: int )); } - private def _scala_Tuple2( pos:int ) = + private def _scala_Tuple2(pos: Int) = _scala( pos, Names.Tuple2 ); - private def _scala_xml_Elem( pos:int ) = + private def _scala_xml_Elem(pos: Int) = _scala_xml( pos, _Elem ); - private def _scala_xml_Attribute( pos: int ) = + private def _scala_xml_Attribute(pos: Int) = _scala_xml( pos, _Attribute ); @@ -409,7 +409,7 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: /** splits */ protected def qualifiedAttr( pos:Int, namespace:String, name:String ):Pair[String,String] = { - getPrefix( name ).match { + getPrefix( name ) match { case Some( pref ) => val newLabel = name.substring( pref.length()+1, name.length() ); // if( newLabel.indexOf(':') != -1 ) syntaxError @@ -419,7 +419,7 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: } } protected def qualified( pos:Int, name:String ):Pair[String,String] = - getPrefix( name ).match { + getPrefix( name ) match { case Some( pref ) => val newLabel = name.substring( pref.length()+1, name.length() ); // if( newLabel.indexOf(':') != -1 ) syntaxError @@ -486,7 +486,7 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: val i = qname.indexOf(':'); var newlabel = qname; - val pre = getPrefix(qname).match { + val pre = getPrefix(qname) match { case Some(p) => newlabel = qname.substring(p.length()+1, qname.length()); p; @@ -547,10 +547,10 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: /* DEBUG */ // var k = 0; var it = attrMap.elements; - while( it.hasNext ) { + while (it.hasNext) { val ansk = it.next; - getPrefix( ansk._1 ).match { + getPrefix(ansk._1) match { case Some(pre) => val key = ansk._1.substring(pre.length()+1, ansk._1.length()); handlePrefixedAttribute(pre, key, ansk._2); @@ -570,7 +570,7 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: val ts = new mutable.ArrayBuffer[Tree](); - if(moreNamespaces) { + if (moreNamespaces) { ts + make.ValDef(pos, Modifiers.MUTABLE, _tmpscope, @@ -607,14 +607,14 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: ts2.elements.copyToArray( stms2, 0 ); val makeSymbolicPrefix = { - if(null == pre) + if (null == pre) gen.mkNullLit(pos) else gen.mkStringLit(pos,pre) } val makeSymbolicAttrs = { - if(moreAttributes) + if (moreAttributes) make.Ident(pos, _md) //attr:Array[Tree], else _scala_xml_Null(pos) @@ -638,11 +638,11 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: Console.println(t.toString()); */ - if(0 < stms2.length) { - t = make.Block( pos, stms2, t ); + if (0 < stms2.length) { + t = make.Block(pos, stms2, t); } ; - if(0 < stms.length) { + if (0 < stms.length) { t = make.Block(pos, stms, t); } ; @@ -651,10 +651,10 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: t /* DEBUG - if( !setNS.isEmpty ) { - val nsStms = new Array[Tree]( setNS.size ); + if (! setNS.isEmpty) { + val nsStms = new Array[Tree](setNS.size); var i = 0; - for( val Pair(ns:String, uri:Tree) <- setNS.toList ) { + for (val Pair(ns:String, uri:Tree) <- setNS.toList) { nsStms( i ) = setNamespacePrefix(pos, ns, uri ); i = i + 1; } @@ -668,6 +668,6 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: def setNamespacePrefix(pos:Int, pref:String, uri:Tree) = make.ValDef(pos, 0, Name.fromString("namespace$"+pref), Tree.Empty, uri); - -} } + +} // package diff --git a/sources/scala/tools/scalac/transformer/matching/AlgebraicMatcher.scala b/sources/scala/tools/scalac/transformer/matching/AlgebraicMatcher.scala index fc1c960019..4764e14fca 100644 --- a/sources/scala/tools/scalac/transformer/matching/AlgebraicMatcher.scala +++ b/sources/scala/tools/scalac/transformer/matching/AlgebraicMatcher.scala @@ -1,6 +1,6 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** \* */ @@ -8,6 +8,7 @@ import java.io._; import java.util._; + import scalac.{Global => scalac_Global}; import scalac._; import scalac.ast._; @@ -61,7 +62,7 @@ import java.util.Iterator ; this._m = m; super.initialize( _m.selector, _m.owner, _m.resultType, doBinding ); var i = 0; while (i < cases.length) { - enter( cases( i ) ); //(CaseDef) cases[i], i); + enter(cases(i)); //(CaseDef) cases[i], i); i = i + 1; } if (unit.global.log()) { @@ -89,7 +90,7 @@ import java.util.Iterator ; override def toTree(): Tree = { val ts = NewArray.Tree ( - gen.ValDef(root.symbol(), _m.selector ), + gen.ValDef(root.symbol(), _m.selector), gen.ValDef(resultVar, gen.mkDefaultValue(_m.pos, resultVar.info()) )); val res = gen.If( super.toTree(root.and), @@ -109,7 +110,7 @@ import java.util.Iterator ; //System.err.println("AM.toTree called"+node); if (node == null) gen.mkBooleanLit(_m.pos, false); - else node.match { + else node match { case SeqContainerPat( _, _ ) => callSequenceMatcher( node, selector ); @@ -120,7 +121,7 @@ import java.util.Iterator ; /** collects all sequence patterns and returns the default */ - def collectSeqPats(node1: PatternNode, seqPatNodes: Vector, bodies: Vector ): PatternNode = { + def collectSeqPats(node1: PatternNode, seqPatNodes: Vector, bodies: Vector): PatternNode = { var node = node1; var defaultNode: PatternNode = null; var exit = false; @@ -128,7 +129,7 @@ import java.util.Iterator ; if( node == null ) exit=true;//defaultNode = node; // break else - node.match { + node match { case SeqContainerPat( _, _ ) => seqPatNodes.add( node ); bodies.add( super.toTree( node.and ) ); @@ -155,30 +156,30 @@ import java.util.Iterator ; val seqPatNodes = new Vector(); val bodies = new Vector(); - var defaultNode = collectSeqPats( node, seqPatNodes, bodies ); + var defaultNode = collectSeqPats(node, seqPatNodes, bodies); - val defaultCase = toTree( defaultNode, selector ); + val defaultCase = toTree(defaultNode, selector); val wordRec = new SequenceMatcher(unit); - val m = new PartialMatcher( _m.owner, selector, defs.boolean_TYPE() ); + val m = new PartialMatcher(_m.owner, selector, defs.boolean_TYPE()); - val pats = new Array[Tree]( seqPatNodes.size() ); - val body = new Array[Tree]( seqPatNodes.size() ); + val pats = new Array[Tree](seqPatNodes.size()); + val body = new Array[Tree](seqPatNodes.size()); val tmp = bodies.toArray(); var j = 0; val it = seqPatNodes.iterator(); - while(it.hasNext()) { - pats( j ) = it.next().asInstanceOf[SeqContainerPat].seqpat; - body( j ) = tmp(j).asInstanceOf[Tree]; + while (it.hasNext()) { + pats(j) = it.next().asInstanceOf[SeqContainerPat].seqpat; + body(j) = tmp(j).asInstanceOf[Tree]; j = j + 1; } - //Tree defaultTree = toTree( node.or, selector ); // cdef.body ; + //Tree defaultTree = toTree(node.or, selector); // cdef.body ; - wordRec.construct( m, pats, body, defaultCase, doBinding ); + wordRec.construct(m, pats, body, defaultCase, doBinding); - //_m.defs.addAll( m.defs ); + //_m.defs.addAll(m.defs); m.tree; } diff --git a/sources/scala/tools/scalac/transformer/matching/BerrySethi.scala b/sources/scala/tools/scalac/transformer/matching/BerrySethi.scala index 2039e8c28b..d0515adab9 100644 --- a/sources/scala/tools/scalac/transformer/matching/BerrySethi.scala +++ b/sources/scala/tools/scalac/transformer/matching/BerrySethi.scala @@ -1,14 +1,21 @@ -/** $Id */ -import scalac.CompilationUnit ; -import scalac.ApplicationError ; -import scalac.ast.Tree ; -import scalac.ast.TreeInfo ; -import scalac.util.Name ; -import Tree._ ; +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +** ** +** $Id$ +\* */ -import java.util._ ; +import scalac.CompilationUnit; +import scalac.ApplicationError; +import scalac.ast.Tree; +import scalac.ast.TreeInfo; +import scalac.util.Name; +import Tree._; -//import scala.compiler.printer.XMLAutomPrinter ; +import java.util._; + +//import scala.compiler.printer.XMLAutomPrinter; /** a Berry-Sethi style construction for nfas. * this class plays is the "Builder" for the "Director" class WordRecognizer. @@ -18,7 +25,7 @@ package scala.tools.scalac.transformer.matching { class BerrySethi(val unit: CompilationUnit ) { def isStar(n: Name): boolean = { - TreeInfo.isNameOfStarPattern( n ); + TreeInfo.isNameOfStarPattern(n); } /* @@ -45,29 +52,29 @@ class BerrySethi(val unit: CompilationUnit ) { // Unit test ? - def nullable( pat: Tree ): boolean = { + def nullable(pat: Tree): Boolean = { //System.out.print("<nullable>"); //DEBUG.print( pat ); //System.out.println("</nullable>"); - pat.match { + pat match { case Apply(_, _) => return false; case Sequence( trees ) => - return (trees.length == 0) || nullable( trees ); - //case Subsequence( Tree[] trees ): + return (trees.length == 0) || nullable(trees); + //case Subsequence(Tree[] trees): //return case Bind(n, t) => /* - if( isStar( n ) ) // generated for star/plus(?) + if (isStar(n)) // generated for star/plus(?) return true; */ return nullable( t ); - case Alternative( choices) => + case Alternative(choices) => var result = false; var i = 0; while(i < choices.length && !result) { - result = result || nullable( choices( i ) ); + result = result || nullable(choices(i)); i = i + 1 } return result; @@ -80,10 +87,10 @@ class BerrySethi(val unit: CompilationUnit ) { /** returns true if a Sequence pattern matches the empty sequence * @param pat the sequence pattern. */ - def nullableSequence(pat: Tree): boolean = { - pat.match { - case Sequence( pats ) => - return nullable( pats ); + def nullableSequence(pat: Tree): Boolean = { + pat match { + case Sequence(pats) => + return nullable(pats); } return false; } @@ -92,7 +99,7 @@ class BerrySethi(val unit: CompilationUnit ) { * sequence or subsequence node) is nullable. * @param pats the sequence of patterns */ - def nullable( pats:Array[Tree] ): boolean = { + def nullable(pats: Array[Tree]): Boolean = { var result = true; var i = 0; while(i < pats.length && result){ @@ -109,7 +116,7 @@ class BerrySethi(val unit: CompilationUnit ) { //System.out.print("<compFirst>"); //DEBUG.print( pat ); //System.out.println("</compFirst>"); - pat.match { + pat match { case Sequence( trees ) => return compFirst( trees ); case Typed(_,_) | Select(_,_) | Apply(_, _) => @@ -132,11 +139,11 @@ class BerrySethi(val unit: CompilationUnit ) { } return tmp; - case Bind( _, tree ) => - return compFirst( tree ); + case Bind(_, tree) => + return compFirst(tree); case Ident( name ) => - //if( name != Name.fromString("_") ) + //if (name != Name.fromString("_")) // throw new ApplicationError("unexpected pattern"); val tmp = new TreeSet(); tmp.add( posMap.get( pat ).asInstanceOf[Integer]); // singleton set @@ -151,12 +158,12 @@ class BerrySethi(val unit: CompilationUnit ) { /** computes last( alpha ) where alpha is a word regexp */ - def compLast( pat:Tree ): TreeSet = { + def compLast(pat: Tree): TreeSet = { //System.out.print("<last>"); //DEBUG.print( pat ); //System.out.println("</compLast>"); - pat.match { - case Sequence( _ ) | Apply(_, _) => + pat match { + case Sequence( _ ) | Apply(_, _) => val tmp = new TreeSet(); tmp.add(posMap.get( pat ).asInstanceOf[Integer]); // singleton set return tmp; @@ -266,7 +273,7 @@ class BerrySethi(val unit: CompilationUnit ) { def compFollow1( fol1:TreeSet , pat:Tree ): TreeSet = { var fol = fol1; //System.out.println("compFollow1("+fol+","+pat+")"); - pat.match { + pat match { case Sequence( trees ) => var first: TreeSet = null; var i = trees.length; @@ -389,7 +396,7 @@ class BerrySethi(val unit: CompilationUnit ) { // todo: replace global variable pos with acc def traverse( pat:Tree ): Unit = { - pat.match { + pat match { // (is tree automaton stuff, more than Berry-Sethi) case Apply( _, _ ) | Typed( _, _ )| Select( _, _ ) => @@ -474,7 +481,7 @@ class BerrySethi(val unit: CompilationUnit ) { var dest = destI.intValue() ; var arrows: Vector = _; //, revArrows; //Label revLabel = new Pair( srcI, label ); - label.match { + label match { case DefaultLabel() => arrows = defaultq( src ); //revArrows = defaultqRev[ dest ]; @@ -569,7 +576,7 @@ class BerrySethi(val unit: CompilationUnit ) { //System.out.println( "enter automatonFrom("+pat+","+finalTag+")"); // UNIT TEST //System.out.println( pat ); //System.out.println( nullableSequence( pat )); // UNIT TEST - pat.match { + pat match { case Sequence( subexpr ) => initialize( subexpr ); @@ -595,15 +602,15 @@ class BerrySethi(val unit: CompilationUnit ) { initializeAutom(); - // defaultqRev = new Vector[ pos ]; // default transitions + // defaultqRev = new Vector[pos]; // default transitions collectTransitions(); - if( nullable( subexpr )) // initial state is final - finals.put( new Integer(0), finalTag ); + if (nullable(subexpr)) // initial state is final + finals.put(new Integer(0), finalTag); //TreeSet initials = new TreeSet(); - //initials.add( new Integer( 0 ) ); + //initials.add(new Integer(0)); val result = new NondetWordAutom(pos, // = nstates @@ -618,8 +625,8 @@ class BerrySethi(val unit: CompilationUnit ) { System.out.println("inBerrySethi"); XMLAutomPrinter pr = new XMLAutomPrinter( System.out ); pr.begin(); - pr.print( result ); - pr.print( revNfa ); + pr.print(result); + pr.print(revNfa); pr.end(); System.out.println("initialsRev = "+initialsRev); System.out.println("outBerrySethi"); @@ -640,7 +647,7 @@ class BerrySethi(val unit: CompilationUnit ) { var it = this.posMap.keySet().iterator(); while(it.hasNext()) { val t = it.next().asInstanceOf[Tree]; - t.match { + t match { case Literal( _ ) => Console.print( "(" + t.toString() + " -> "); val s2 = (posMap.get(t).asInstanceOf[Integer]).toString(); diff --git a/sources/scala/tools/scalac/transformer/matching/BindingBerrySethi.scala b/sources/scala/tools/scalac/transformer/matching/BindingBerrySethi.scala index dbdc7fcc89..b3e0cdb716 100644 --- a/sources/scala/tools/scalac/transformer/matching/BindingBerrySethi.scala +++ b/sources/scala/tools/scalac/transformer/matching/BindingBerrySethi.scala @@ -1,4 +1,10 @@ - +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +** ** +** $Id$ +\* */ import scalac.CompilationUnit; import scalac.Global ; @@ -19,44 +25,44 @@ package scala.tools.scalac.transformer.matching { * WordRecognizer. */ -class BindingBerrySethi(unit:CompilationUnit) extends BerrySethi(unit) { +class BindingBerrySethi(unit:CompilationUnit) extends BerrySethi(unit) { // variables - var deltaqRev: Array[HashMap ] = _; // delta of Rev - var defaultqRev:Array[Vector] = _; // default transitions of Rev - var qbinders:Array[Vector] = _; // transitions <-> variables - var revnfa: NondetWordAutom = _ ; - var varAt: HashMap = _; // chi: Positions -> Vars (Symbol) + var deltaqRev : Array[HashMap] = _; // delta of Rev + var defaultqRev: Array[Vector] = _; // default transitions of Rev + var qbinders : Array[Vector] = _; // transitions <-> variables + var revnfa : NondetWordAutom = _ ; + var varAt : HashMap = _; // chi: Positions -> Vars (Symbol) override def makeTransition(srcI: Integer, destI: Integer, label: Label): Unit = { val src = srcI.intValue() ; val dest = destI.intValue() ; var arrows: Vector = _; var revArrows: Vector = _; - val revLabel = new LPair( srcI, label ); - label.match { + val revLabel = new LPair(srcI, label); + label match { case DefaultLabel() => - arrows = defaultq( src ); - revArrows = defaultqRev( dest ); + arrows = defaultq(src); + revArrows = defaultqRev(dest); case _ => - arrows = deltaq( src ).get( label ).asInstanceOf[Vector]; - if( arrows == null ) - deltaq( src ).put( label, + arrows = deltaq(src).get(label).asInstanceOf[Vector]; + if (arrows == null) + deltaq(src).put(label, {arrows = new Vector(); arrows} ); - revArrows = deltaqRev( dest ).get( revLabel ).asInstanceOf[Vector]; - if( revArrows == null ) - deltaqRev( dest ).put(revLabel, {revArrows = new Vector(); revArrows} ); + revArrows = deltaqRev(dest).get(revLabel).asInstanceOf[Vector]; + if (revArrows == null) + deltaqRev(dest).put(revLabel, {revArrows = new Vector(); revArrows} ); } - arrows.add( destI ); - revArrows.add( srcI ); + arrows.add(destI); + revArrows.add(srcI); } - override def seenLabel( pat:Tree , label:Label ): Unit = { + override def seenLabel(pat: Tree, label: Label): Unit = { var i = new Integer({pos = pos + 1; pos} ); seenLabel( pat, i, label ); - pat.match { + pat match { case Apply(_, _) | Literal( _ ) | Select(_, _) | Typed(_,_) => this.varAt.put( i, activeBinders.clone() ); // below @ ? @@ -80,29 +86,28 @@ class BindingBerrySethi(unit:CompilationUnit) extends BerrySethi(unit) { override def initializeAutom(): Unit = { super.initializeAutom(); - deltaqRev = new Array[HashMap]( pos ); // deltaRev - defaultqRev = new Array[Vector]( pos ); // default transitions - qbinders = new Array[Vector]( pos ); // transitions <-> variables + deltaqRev = new Array[HashMap](pos); // deltaRev + defaultqRev = new Array[Vector](pos); // default transitions + qbinders = new Array[Vector](pos); // transitions <-> variables var j = 0; - while(j < pos) { - deltaqRev( j ) = new HashMap(); - defaultqRev( j ) = new Vector(); - qbinders( j ) = varAt.get( new Integer( j ) ).asInstanceOf[Vector]; + while (j < pos) { + deltaqRev(j) = new HashMap(); + defaultqRev(j) = new Vector(); + qbinders(j) = varAt.get(new Integer(j)).asInstanceOf[Vector]; j = j + 1; } varAt.clear(); // clean up } - override def automatonFrom( pat:Tree , finalTag:Integer ): NondetWordAutom = { - + override def automatonFrom(pat: Tree, finalTag: Integer): NondetWordAutom = { this.finalTag = finalTag ; - //System.out.println( "enter automatonFrom("+ pat +")"); - pat.match { - case Sequence( subexpr ) => + //System.out.println("enter automatonFrom("+ pat +")"); + pat match { + case Sequence(subexpr) => - initialize( subexpr ); + initialize(subexpr); // (1) compute first + follow; pos = pos + 1; @@ -126,20 +131,20 @@ class BindingBerrySethi(unit:CompilationUnit) extends BerrySethi(unit) { result.leftTrans = true; - val revInitials = new TreeSet( finals.keySet() ); + val revInitials = new TreeSet(finals.keySet()); /* pos++; // adding a state HashSet deltaqRev2[] = new HashSet[ deltaqRev.length + 1]; HashSet defaultqRev2[] = new HashSet[ deltaqRev.length + 1]; HashSet qbinders[] = new HashSet[ deltaqRev.length + 1]; - for(Iterator it = finals.keySet().iterator(); it.hasNext(); ) { + for (Iterator it = finals.keySet().iterator(); it.hasNext(); ) { } */ val revFinals = new TreeMap(); var it = initials.iterator(); while(it.hasNext()) { - revFinals.put( it.next(), finalTag); + revFinals.put(it.next(), finalTag); } revnfa = new NondetWordAutom(pos, labels, @@ -153,18 +158,20 @@ class BindingBerrySethi(unit:CompilationUnit) extends BerrySethi(unit) { /* System.out.println("inBerrySethi"); - XMLAutomPrinter pr = new XMLAutomPrinter( System.out ); + XMLAutomPrinter pr = new XMLAutomPrinter(System.out); pr.begin(); - pr.print( result ); - pr.print( revnfa ); + pr.print(result); + pr.print(revnfa); pr.end(); - System.out.println("initialsRev = "+initialsRev); + System.out.println("initialsRev = " + initialsRev); System.out.println("outBerrySethi"); */ //System.exit(0); return result; //print(); } } + } + } diff --git a/sources/scala/tools/scalac/transformer/matching/CodeFactory.scala b/sources/scala/tools/scalac/transformer/matching/CodeFactory.scala index f664ec69d8..70df601f3a 100644 --- a/sources/scala/tools/scalac/transformer/matching/CodeFactory.scala +++ b/sources/scala/tools/scalac/transformer/matching/CodeFactory.scala @@ -1,6 +1,6 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** ** ** ** $Id$ @@ -26,14 +26,14 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit /** a faked switch statement */ - def Switch(condition: Array[Tree], body: Array[Tree], defaultBody: Tree ): Tree = { + def Switch(condition: Array[Tree], body: Array[Tree], defaultBody: Tree): Tree = { //assert condition != null:"cond is null"; //assert body != null:"body is null"; //assert defaultBody != null:"defaultBody is null"; var result = defaultBody; var i = condition.length-1; - while(i >= 0) { + while (i >= 0) { result = gen.If(condition(i), body(i), result); i = i - 1 } @@ -144,7 +144,7 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit gen.mkApply__(gen.Select(arg, defs.LIST_HEAD())); } - def Negate(tree:Tree ): Tree = { + def Negate(tree: Tree): Tree = { tree match { case Literal(BOOLEAN(value))=> gen.mkBooleanLit(tree.pos, !value); @@ -153,7 +153,7 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit } } - /*protected*/ def And(left: Tree, right: Tree): Tree = { + /*protected*/ def And(left: Tree, right: Tree): Tree = { left match { case Literal(BOOLEAN(value)) => return if(value) right else left; @@ -167,13 +167,13 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit gen.mkApply_V(gen.Select(left, defs.BOOLEAN_AND()), Predef.Array[Tree](right)); } - /*protected*/ def Or(left:Tree , right:Tree ): Tree = { + /*protected*/ def Or(left: Tree, right: Tree): Tree = { left match { case Literal(BOOLEAN(value))=> return if(value) left else right; case _ => } - right.match { + right match { case Literal(BOOLEAN(value)) => if (!value) return left; case _ => @@ -200,7 +200,7 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit } // used by Equals - private def getEqEq(left:Type , right:Type ): Symbol = { + private def getEqEq(left: Type, right: Type): Symbol = { val sym = left.lookupNonPrivate(Names.EQEQ); //assert sym != Symbol.NONE // : Debug.show(left) + "::" + Debug.show(left.members()); @@ -260,7 +260,7 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit )); } - def Error(pos:int , tpe:Type ): Tree = { + def Error(pos: Int, tpe: Type): Tree = { gen.mkApplyTV( gen.mkGlobalRef(pos, defs.MATCHERROR_FAIL()), Predef.Array[Tree](gen.mkType(pos, tpe)), @@ -271,11 +271,11 @@ class CodeFactory(val unit: CompilationUnit, pos1: Int) extends PatternTool(unit } - def pairType( left:Type , right:Type ): Type = { + def pairType(left: Type, right: Type): Type = { defs.TUPLE_TYPE(Predef.Array[Type] ( left, right ) ); } - def newPair(left: Tree , right: Tree): Tree = { + def newPair(left: Tree, right: Tree): Tree = { gen.New( gen.mkApplyTV( gen.mkPrimaryConstructorGlobalRef( pos, defs.TUPLE_CLASS(2)), diff --git a/sources/scala/tools/scalac/transformer/matching/DetWordAutom.scala b/sources/scala/tools/scalac/transformer/matching/DetWordAutom.scala index 357b6fe652..ef2c61f7e6 100644 --- a/sources/scala/tools/scalac/transformer/matching/DetWordAutom.scala +++ b/sources/scala/tools/scalac/transformer/matching/DetWordAutom.scala @@ -1,3 +1,12 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +** ** +\* */ + +// $Id$ + import scalac.ast.Tree ; import Tree._ ; @@ -360,11 +369,11 @@ class DetWordAutom { - def isDead( state: int ): boolean = { + def isDead(state: Int): Boolean = { return state == _nstates - 1; // by construction } - def isDead( state: Integer ): boolean = { + def isDead(state: Integer): Boolean = { return state.intValue() == _nstates - 1; // by construction } @@ -372,26 +381,25 @@ class DetWordAutom { /** returns target of the transition from state i with label label. * null if no such transition exists. */ - def delta( i:int , label:Label ): Integer = { - var target:Integer =_; - label.match { - case DefaultLabel() => - if( !hasDefault( i ) ) - return null; - return _defaultq( i ).asInstanceOf[Integer] ; - case SimpleLabel( _ ) | TreeLabel( _ ) => - return _deltaq( i ).get( label ).asInstanceOf[Integer] ; - /*case LPair( Integer state, Label lab ): - return state; - */ - case _ => - throw new ApplicationError("whut's this: label="+label+", class "+label.getClass()); - } + def delta(i: Int, label: Label): Integer = { + var target:Integer =_; + label match { + case DefaultLabel() => + if (! hasDefault(i)) + return null; + return _defaultq( i ).asInstanceOf[Integer] ; + case SimpleLabel( _ ) | TreeLabel( _ ) => + return _deltaq( i ).get( label ).asInstanceOf[Integer] ; + /*case LPair( Integer state, Label lab ): + return state; + */ + case _ => + throw new ApplicationError("whut's this: label="+label+", class "+label.getClass()); + } } - def delta( i:Integer , label:Label ): Integer = { - return delta( i.intValue(), label ); - } + def delta(i: Integer, label: Label): Integer = + delta(i.intValue(), label); /** should maybe in nfa, not here */ @@ -400,12 +408,12 @@ class DetWordAutom { var min = Integer.MAX_VALUE ; val it = states.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { val state = it.next().asInstanceOf[Integer]; if( nfa.isFinal( state ) && (state.intValue() < min )) min = state.intValue(); } - if( min == Integer.MAX_VALUE ) + if (min == Integer.MAX_VALUE) throw new ApplicationError("I expected a final set of states"); return new Integer( min ); } @@ -858,13 +866,13 @@ class DetWordAutom { /** you may only call this before the set[set[...]] representation * gets flattened. */ - def printBefore( states:TreeSet , deftrans:HashMap ): Unit = { + def printBefore(states: TreeSet, deftrans: HashMap): Unit = { var trans: HashMap = _; - Console.println( states ); + Console.println(states); val it = states.iterator(); - while(it.hasNext()) { + while (it.hasNext()) { val state = it.next().asInstanceOf[TreeSet]; - Console.print("state:"+state.toString()+" transitions "); + Console.print("state:" + state.toString() + " transitions "); trans = delta.get( state ).asInstanceOf[HashMap]; val labs = _labels.iterator(); while(labs.hasNext()) { @@ -873,10 +881,10 @@ class DetWordAutom { Console.print( " (" + label.toString() + "," + target.toString()+")"); } - Console.print("default trans"+deftrans.get( state )); + Console.print("default trans"+deftrans.get(state)); Console.println; } - Console.println("final states:" + finals ); + Console.println("final states:" + finals); } } } diff --git a/sources/scala/tools/scalac/transformer/matching/Label.scala b/sources/scala/tools/scalac/transformer/matching/Label.scala index 3935ffc631..d260feded6 100644 --- a/sources/scala/tools/scalac/transformer/matching/Label.scala +++ b/sources/scala/tools/scalac/transformer/matching/Label.scala @@ -1,30 +1,40 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + import scalac.ApplicationError; -import scalac.ast.Tree ; -import scalac.ast.TreeInfo ; -import scalac.symtab.Symbol ; -import scalac.symtab.Type ; -import Tree.Literal ; - -/** this class represents the label that a transition in an automaton may carry. - * these get translated to specific (boolean) tests +import scalac.ast.Tree; +import scalac.ast.TreeInfo; +import scalac.symtab.Symbol; +import scalac.symtab.Type; + +import Tree.Literal; + +/** + * This class represents the label that a transition in an automaton + * may carry. These get translated to specific (boolean) tests */ package scala.tools.scalac.transformer.matching { class Label { - //case class RLabel( Object rstate, Label lab, Symbol vars[] ); + //case class RLabel(Object rstate, Label lab, Symbol vars[]); - override def hashCode(): Int = match { + override def hashCode(): Int = this match { case DefaultLabel() => return 0; - case SimpleLabel( lit )=> + case SimpleLabel(lit) => return lit.value.hashCode(); - case TreeLabel( pat ) => + case TreeLabel(pat) => // if pat is an Apply, than this case can only be correctly // handled there are no other similar Applys (nondeterminism) return pat.getType().hashCode(); - case TypeLabel( tpe ) => + case TypeLabel(tpe) => return tpe.hashCode(); case _ => return super.hashCode(); @@ -35,15 +45,15 @@ class Label { return false; val oL = o.asInstanceOf[Label]; //System.out.print(this + " equals " + oL); - this.match { + this match { case DefaultLabel()=> - oL.match { + oL match { case DefaultLabel() => return true; case _ => false; } // case SimpleLabel( lit ) => - oL.match { + oL match { case SimpleLabel( lit2 ) => return /*(lit.kind == lit2.kind) && */lit.value.equals( lit2.value ); @@ -51,11 +61,11 @@ class Label { } case TreeLabel( pat ) => - oL.match { + oL match { case TreeLabel( pat2 ) => - pat.match { + pat match { case Tree.Apply( _, _ ) => - pat2.match { + pat2 match { case Tree.Apply( _, _ ) => return TreeInfo.methSymbol( pat ) == TreeInfo.methSymbol( pat2 ); } @@ -64,16 +74,16 @@ class Label { case _ => false } - case TypeLabel( tpe ) => - oL.match { + case TypeLabel(tpe) => + oL match { case TypeLabel( tpe2) => - return tpe.equals( tpe2 ); + return tpe.equals(tpe2); case _ => false; } - case LPair( state, lab ) => - oL.match { - case LPair( state2, lab2 ) => - return state.equals( state2 ) && lab.equals( lab2 ) ; + case LPair(state, lab) => + oL match { + case LPair(state2, lab2) => + return state.equals(state2) && lab.equals(lab2); case _ => false; } case _ => return false; @@ -81,10 +91,10 @@ class Label { } - def toString2(): String = { + def toString2(): String = { val ext = System.getProperty("extendedMatching"); - if(( ext != null )&& ext.equals( "true" )) { - this.match { + if ((ext != null) && ext.equals("true")) { + this match { case DefaultLabel() => return "<>:p"+p; case SimpleLabel( lit ) => @@ -98,36 +108,29 @@ class Label { throw new ApplicationError("this never happens"); } - override def toString(): String = { - - this.match { - case DefaultLabel() => - return "<>"; - case SimpleLabel( lit) => - return lit.toString(); - case TreeLabel(pat) => - return pat.toString(); - case TypeLabel( tpe ) => - return tpe.toString(); - case LPair( state, lab ) => - return "("+state.toString()+","+lab.toString()+")"; - case _ => - throw new ApplicationError("this never happens"); - } + override def toString(): String = this match { + case DefaultLabel() => + "<>"; + case SimpleLabel( lit) => + lit.toString(); + case TreeLabel(pat) => + pat.toString(); + case TypeLabel(tpe) => + tpe.toString(); + case LPair(state, lab) => + "(" + state.toString() + "," + lab.toString() + ")"; + case _ => + throw new ApplicationError("this never happens"); } val p = -1; // tree state - only needed for extended matching - } +case class DefaultLabel() extends Label; +case class SimpleLabel(lit: Literal) extends Label; +case class TreeLabel(pat: Tree) extends Label; // Apply, Sequence +case class TypeLabel(tpe: Type) extends Label; // Apply, Sequence +case class LPair(state: Integer, lab: Label) extends Label; - case class DefaultLabel() extends Label; - case class SimpleLabel( lit: Literal ) extends Label; - case class TreeLabel( pat: Tree ) extends Label; // Apply, Sequence - - case class TypeLabel( tpe: Type ) extends Label; // Apply, Sequence - - case class LPair( state: Integer, lab: Label ) extends Label; -} - +} // package diff --git a/sources/scala/tools/scalac/transformer/matching/LeftTracerInScala.scala b/sources/scala/tools/scalac/transformer/matching/LeftTracerInScala.scala index 9813bd4fee..3629f94ed6 100644 --- a/sources/scala/tools/scalac/transformer/matching/LeftTracerInScala.scala +++ b/sources/scala/tools/scalac/transformer/matching/LeftTracerInScala.scala @@ -1,3 +1,11 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + import scalac._; import scalac.ast._; import scalac.symtab._; @@ -10,8 +18,8 @@ import scala.tools.util.Position; package scala.tools.scalac.transformer.matching { -class LeftTracerInScala(dfa: DetWordAutom, elementType: Type, owner: Symbol, cf: CodeFactory, val selector: Tree ) -extends TracerInScala( dfa, elementType, owner, cf ) { +class LeftTracerInScala(dfa: DetWordAutom, elementType: Type, owner: Symbol, cf: CodeFactory, val selector: Tree) +extends TracerInScala(dfa, elementType, owner, cf) { //final def defs = cf.defs; @@ -120,22 +128,22 @@ extends TracerInScala( dfa, elementType, owner, cf ) { // state [ nstates-1 ] is the dead state, so we skip it //`if( state == q ) <code_state> else {...}' - var i = dfa.nstates()-2; - while(i >= 0) { - body = code_state( i, body ); + var i = dfa.nstates() - 2; + while (i >= 0) { + body = code_state(i, body); i = i - 1; } - loadCurrentElem( body ); + loadCurrentElem(body); } /** return code for state i of the dfa SAME AS IN SUPER, ONLY SINK IS GONE */ - def code_state(i: Int, elseBody: Tree): Tree = { + def code_state(i: Int, elseBody: Tree): Tree = { var runFinished: Tree = _; // holds result of the run var finalSwRes: Int = 0; - runFinished = run_finished( i ); + runFinished = run_finished(i); var stateBody: Tree = _ ; // action(delta) for one particular label/test @@ -161,7 +169,7 @@ extends TracerInScala( dfa, elementType, owner, cf ) { stateBody); } } - stateBody = gen.If( cf.Negate( gen.Ident( cf.pos, hasnSym )), + stateBody = gen.If(cf.Negate(gen.Ident(cf.pos, hasnSym)), runFinished, stateBody ); gen.If( cf.Equals( _state(), gen.mkIntLit(cf.pos, i )), @@ -173,7 +181,7 @@ extends TracerInScala( dfa, elementType, owner, cf ) { initializeSyms(); - cf.gen.mkBlock( cf.pos, Predef.Array[Tree] ( + cf.gen.mkBlock(cf.pos, Predef.Array[Tree] ( gen.ValDef( iterSym, cf.newIterator( selector, selector.getType() )), gen.ValDef( stateSym, gen.mkIntLit( cf.pos, 0) ), gen.ValDef( accumSym, gen.mkNil( cf.pos )), @@ -191,14 +199,14 @@ extends TracerInScala( dfa, elementType, owner, cf ) { override def _cur_match(pat: Tree): Tree = { //return gen.mkBooleanLit(cf.pos, true); - //System.out.println("calling algebraic matcher on type:"+pat.type); + //System.out.println("calling algebraic matcher on type:" + pat.type); val m = new PartialMatcher( owner, currentElem(), defs.boolean_TYPE() ); - val res1 = if(containsBinding( pat )) { - pat.match { + val res1 = if(containsBinding(pat)) { + pat match { case Sequence(pats) => gen.mkBooleanLit(cf.pos, true); case _ => @@ -208,7 +216,7 @@ extends TracerInScala( dfa, elementType, owner, cf ) { if (res1 == null) { - am.construct( m, Predef.Array[Tree] ( + am.construct(m, Predef.Array[Tree] ( cf.gen.CaseDef( pat, gen.mkBooleanLit( cf.pos, true )), cf.gen.CaseDef( cf.gen.Ident( pat.pos, defs.PATTERN_WILDCARD ), @@ -223,12 +231,12 @@ extends TracerInScala( dfa, elementType, owner, cf ) { /** return the accumulator + last state */ - override def run_finished(state: Int): Tree = { - val hd = cf.newPair( gen.mkIntLit( cf.pos, state ), + override def run_finished(state: Int): Tree = { + val hd = cf.newPair( gen.mkIntLit(cf.pos, state), gen.mkDefaultValue(cf.pos, elementType)); //System.err.println(hd.type); - gen.mkNewCons( cf.pos, + gen.mkNewCons(cf.pos, accumTypeArg, hd, gen.Ident( cf.pos, accumSym )); diff --git a/sources/scala/tools/scalac/transformer/matching/Npair.scala b/sources/scala/tools/scalac/transformer/matching/Npair.scala index 41d09fa510..a33bd7d77f 100644 --- a/sources/scala/tools/scalac/transformer/matching/Npair.scala +++ b/sources/scala/tools/scalac/transformer/matching/Npair.scala @@ -1,3 +1,11 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +** ** +** $Id$ +\* */ + package scala.tools.scalac.transformer.matching ; import java.util.{ HashMap, TreeSet }; @@ -9,34 +17,32 @@ import java.util.{ HashMap, TreeSet }; case class Npair(nstate: Integer, nset: TreeSet) { override def equals(that: Any): Boolean = { - this.match { - case Npair( nstate, nset ) => - that.match { - case Npair( _nstate, _nset ) => + this match { + case Npair(nstate, nset) => + that match { + case Npair(_nstate, _nset) => return ((nstate == _nstate) - &&( nset == _nset )); + && (nset == _nset)); case _ => return false } case _ => return false } } - override def toString(): String = { - this.match { - case Npair( nstate, nset ) => - //Integer dstate = (Integer) indexMap.get( nset ); - return "<n"+nstate.toString()+" in "+nset /*+" = d"+dstate*/ +">"; - case _ => null - } + override def toString(): String = this match { + case Npair(nstate, nset) => + //Integer dstate = (Integer) indexMap.get(nset); + "<n" + nstate.toString() + " in " + nset /*+" = d"+dstate*/ + ">"; + case _ => null } def toString(indexMap: HashMap): String = { //assert indexMap != null; - this.match { - case Npair( nstate, nset ) => - //assert nstate!=null; + this match { + case Npair(nstate, nset) => + //assert nstate != null; val dstate = indexMap.get( nset ).asInstanceOf[Integer]; - return "<n"+nstate.toString()+" in "+nset +" = d"+dstate +">"; + return "<n" + nstate.toString() + " in " + nset + " = d" + dstate + ">"; case _ => return null; } @@ -46,15 +52,15 @@ case class Npair(nstate: Integer, nset: TreeSet) { } class NpairComparator extends StateSetComparator { - override def compare( o1: Any, o2: Any ): Int = { - o1.match { - case Npair( nstate, nset ) => o2.match { - case Npair( _nstate, _nset ) => - val res = nstate.compareTo( _nstate ); - if( res != 0 ) + override def compare(o1: Any, o2: Any): Int = { + o1 match { + case Npair(nstate, nset) => o2 match { + case Npair(_nstate, _nset) => + val res = nstate.compareTo(_nstate); + if (res != 0) return res; else - return super.compare( nset, _nset ); + return super.compare(nset, _nset); } } } diff --git a/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala b/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala index 7249cc4360..c0258cf883 100644 --- a/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala +++ b/sources/scala/tools/scalac/transformer/matching/PatternMatcher.scala @@ -1,6 +1,6 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** ** ** ** $Id$ @@ -55,7 +55,8 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { /** init method, also needed in subclass AlgebraicMatcher */ - def initialize(selector: Tree, owner: Symbol, resultType: Type , doBinding: Boolean ): Unit = { + def initialize(selector: Tree, owner: Symbol, + resultType: Type, doBinding: Boolean): Unit = { this.mk = new PatternNodeCreator(unit, owner); this.cf = new CodeFactory(unit, selector.pos); this.root = mk.ConstrPat(selector.pos, selector.getType().widen()); @@ -78,7 +79,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { print(root.and, ""); } - def print(patNode: PatternNode, indent: String ): Unit = { + def print(patNode: PatternNode, indent: String): Unit = { def newIndent(s: String) = { val removeBar: Boolean = (null == patNode.or); @@ -86,7 +87,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { sb.append(indent); if (removeBar) sb.setCharAt(indent.length() - 1, ' '); - var i = 0; while(i < s.length()) { + var i = 0; while (i < s.length()) { sb.append(' '); i = i + 1 } @@ -96,7 +97,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { if (patNode == null) System.out.println(indent + "NULL"); else - patNode.match { + patNode match { case _h: Header => val selector = _h.selector; @@ -213,7 +214,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { } protected def patternArgs(tree: Tree):Array[Tree] = { - tree.match { + tree match { case Bind(_, pat) => patternArgs(pat); case Apply(_, args) => @@ -254,13 +255,14 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { protected def patternNode(tree:Tree , header:Header , env: CaseEnv ): PatternNode = { //Console.println("patternNode("+tree+","+header+")"); //Console.println("tree.getType()"+tree.getType()); - tree.match { + tree match { case Bind(name, Typed(Ident(Names.PATTERN_WILDCARD), tpe)) => // x@_:Type - if(header.getTpe().isSubType(tpe.getType())) { + if (header.getTpe().isSubType(tpe.getType())) { val node = mk.DefaultPat(tree.pos, tpe.getType()); env.newBoundVar( tree.symbol(), tree.getType(), header.selector ); node; - } else { + } + else { val node = mk.ConstrPat(tree.pos, tpe.getType()); env.newBoundVar( tree.symbol(), tree.getType(), gen.Ident(tree.pos, node.casted)); node; @@ -279,9 +281,9 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { } node; case t @ Apply(fn, args) => // pattern with args - if(isSeqApply(t)) { + if (isSeqApply(t)) { if (!delegateSequenceMatching) { - args(0).match { + args(0) match { case Sequence(ts)=> mk.SequencePat(tree.pos, tree.getType(), ts.length); } @@ -314,7 +316,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { mk.ConstrPat(tree.pos, tpe.getType()); } if ((null != env) && (ident.symbol() != defs.PATTERN_WILDCARD)) - node.match { + node match { case ConstrPat(casted) => env.newBoundVar(t.expr.symbol(), tpe.getType(), @@ -371,7 +373,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { } protected def enter(pat: Tree, index: Int, target: PatternNode, casted: Symbol, env: CaseEnv ): PatternNode = { - target.match { + target match { case ConstrPat(newCasted) => enter1(pat, index, target, newCasted, env); case SequencePat(newCasted, len) => @@ -384,7 +386,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { private def newHeader(pos: Int, casted: Symbol, index: Int): Header = { //Console.println("newHeader(pos,"+casted+","+index+")"); //Console.println(" casted.getType()"+casted.getType()); - val ident = gen.Ident( pos, casted ); + val ident = gen.Ident(pos, casted); if (casted.pos == Position.FIRSTPOS) { //Console.println("FIRSTPOS"); val t = gen.mkApply_V( @@ -399,7 +401,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { //Console.println("ts="+ts); val accType = casted.getType().memberType(ts); val accTree = gen.Select( ident, ts); - accType.match { + accType match { // scala case accessor case Type.MethodType(_, _) => mk.Header(pos, accType.resultType(), gen.mkApply__(accTree)); @@ -420,11 +422,12 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { var curHeader = target.and.asInstanceOf[Header]; // advance one step in intermediate representation if (curHeader == null) { // check if we have to add a new header //assert index >= 0 : casted; - if( index < 0 ) throw new ApplicationError("error entering:"+casted); + if (index < 0) throw new ApplicationError("error entering:" + casted); target.and = {curHeader = newHeader(pat.pos, casted, index); curHeader}; curHeader.or = patternNode(pat, curHeader, env); enter(patArgs, curHeader.or, casted, env); - } else { + } + else { // find most recent header while (curHeader.next != null) curHeader = curHeader.next; @@ -435,7 +438,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { while (true) { if (next.isSameAs(patNode)) { // test for patNode already present --> reuse // substitute... !!! - patNode.match { + patNode match { case ConstrPat(ocasted) => env.substitute(ocasted, gen.Ident(patNode.pos, next.asInstanceOf[ConstrPat].casted)); @@ -471,7 +474,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { protected def enter(pats:Array[Tree], target1: PatternNode , casted1: Symbol , env: CaseEnv): PatternNode = { var target = target1; var casted = casted1; - target.match { + target match { case ConstrPat(newCasted) => casted = newCasted; case SequencePat(newCasted, len) => @@ -486,11 +489,11 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { } protected def nCaseComponents(tree: Tree): int = { - tree.match { + tree match { case Apply(fn, _) => val tpe = tree.getType().symbol().primaryConstructor().getType(); //Console.println("~~~ " + tree.type() + ", " + tree.type().symbol().primaryConstructor()); - tpe.match { + tpe match { // I'm not sure if this is a good idea, but obviously, currently all case classes // without constructor arguments have type NoType case Type.NoType => @@ -513,7 +516,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { //////////// generator methods - def toTree(): Tree = { + def toTree(): Tree = { if (optimize && isSimpleIntSwitch()) intSwitchToTree(); else if (false && optimize && isSimpleSwitch()) @@ -533,7 +536,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { while (patNode != null) { var node = patNode; while (({node = node.or; node}) != null) { - node.match { + node match { case VariablePat(tree) => Console.println(((tree.symbol().flags & Modifiers.CASE) != 0)); case ConstrPat(_) => @@ -541,7 +544,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { var inner = node.and; def funct(inner: PatternNode): Boolean = { //outer: while (true) { - inner.match { + inner match { case _h:Header => if (_h.next != null) throw Break(false); @@ -581,18 +584,18 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { return true; } - protected def isSimpleIntSwitch(): Boolean = { + protected def isSimpleIntSwitch(): Boolean = { if (selector.getType().widen().isSameAs(defs.int_TYPE())) { var patNode = root.and; while (patNode != null) { var node = patNode; while (({node = node.or; node}) != null) { - node.match { + node match { case ConstantPat(_) => ; case _ => return false; } - node.and.match { + node.and match { case _b:Body => if ((_b.guard.length > 1) || (_b.guard(0) != Tree.Empty) || @@ -615,13 +618,13 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { var body: Tree = body1; var next: TagBodyPair = next1; - def length(): Int = { + def length(): Int = { if (null == next) 1 else (next.length() + 1); } } /* static */ - def insert( tag:int, body:Tree, current:TagBodyPair ): TagBodyPair = { + def insert(tag: Int, body: Tree, current: TagBodyPair): TagBodyPair = { if (current == null) return new TagBodyPair(tag, body, null); else if (tag > current.tag) @@ -634,7 +637,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { var patNode = patNode1; var n = 0; while (({patNode = patNode.or; patNode}) != null) - patNode.match { + patNode match { case DefaultPat() => ; case _ => n = n + 1; @@ -647,7 +650,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { while (patNode != null) { var node = patNode; while (({node = node.or; node}) != null) - node.match { + node match { case DefaultPat() => return bodyToTree(node.and); case _ => @@ -660,7 +663,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { /** This method translates pattern matching expressions that match * on integers on the top level. */ - def intSwitchToTree(): Tree = { + def intSwitchToTree(): Tree = { //print(); val ncases = numCases(root.and); val matchError = cf.ThrowMatchError(selector.pos, resultVar.getType()); @@ -669,7 +672,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { return defaultBody(root.and, matchError); // for one case we use a normal if-then-else instruction else if (ncases == 1) { - root.and.or.match { + root.and.or match { case ConstantPat(value) => return gen.If(cf.Equals(selector, gen.Literal(root.and.or.pos, value)), @@ -681,7 +684,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { } // // if we have more than 2 cases than use a switch statement - root.and.match { + root.and match { case _h:Header => val next = _h.next; var mappings: TagBodyPair = null; @@ -690,7 +693,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { while (patNode != null) { var node = patNode.or; while (node != null) { - node.match { + node match { case DefaultPat() => if (defaultBody != null) throw new ApplicationError(); @@ -731,7 +734,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { } protected def bodyToTree(node: PatternNode): Tree = { - node.match { + node match { case _b:Body => return _b.body(0); case _ => @@ -759,7 +762,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { var node = node1; var res = gen.mkBooleanLit(node.pos, false); while (node != null) - node.match { + node match { case _h:Header => val selector = _h.selector; val next = _h.next; @@ -856,7 +859,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { var cases: TagNodePair = null; var defaultCase: PatternNode = null; while (node != null) - node.match { + node match { case ConstrPat(casted) => cases = insertNode(node.getTpe().symbol().tag(), node, cases); node = node.or; @@ -890,7 +893,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { if (node == null) return gen.mkBooleanLit(selector.pos, false); else - node.match { + node match { case DefaultPat() => return toTree(node.and); @@ -980,7 +983,7 @@ class PatternMatcher(unit: CompilationUnit) extends PatternTool(unit) { if (node == null) return gen.mkBooleanLit(pos(), false); else - node.match { + node match { case DefaultPat() => return toTree(node.and); diff --git a/sources/scala/tools/scalac/transformer/matching/PatternTool.scala b/sources/scala/tools/scalac/transformer/matching/PatternTool.scala index b6b81bc52b..8bff11742b 100644 --- a/sources/scala/tools/scalac/transformer/matching/PatternTool.scala +++ b/sources/scala/tools/scalac/transformer/matching/PatternTool.scala @@ -1,23 +1,21 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** ** ** -** $Id$ \* */ +// $Id$ - +import scalac.ApplicationError; import scalac.CompilationUnit; //import scalac.ast.TreeGen; //import scalac.util.*; //import scalac.symtab.*; - import scalac.util.Name ; - import scalac.ast.Tree ; - import scalac.symtab.Symbol ; - +import scalac.ast.Tree; +import scalac.symtab.Symbol; +import scalac.util.Name; -import scalac.ApplicationError ; package scala.tools.scalac.transformer.matching { /** this class takes care of tedious stuff which has nothing to do with * matching @@ -28,8 +26,8 @@ package scala.tools.scalac.transformer.matching { var generatedVars = false; def handleVariableSymbol(sym: Symbol): Unit = - if( sym.name.toString().indexOf("$") == -1 ) { - generatedVars = true; // .add( sym ); + if (sym.name.toString().indexOf("$") == -1) { + generatedVars = true; // .add(sym); } def isVariableName(name: Name): Boolean = @@ -48,17 +46,17 @@ package scala.tools.scalac.transformer.matching { import Tree._ ; - tree.match { - case x @ Ident(name)=> + tree match { + case x @ Ident(name) => if(x.symbol() != unit.global.definitions.PATTERN_WILDCARD) throw new ApplicationError("shouldn't happen?!"); case Bind(name, subtree) => var sym: Symbol = _; - if( isVariableName( name ) + if (isVariableName(name) && isVariableSymbol( {sym = tree.symbol(); tree.symbol()} )) - handleVariableSymbol( sym ); + handleVariableSymbol(sym); traverse( subtree ); @@ -74,10 +72,11 @@ package scala.tools.scalac.transformer.matching { case _ : Alternative | _ : Select | _ : Literal => ; // no variables case _ => - throw new ApplicationError("unknown pattern node:"+tree+" = "+tree.getClass()); + throw new ApplicationError( + "unknown pattern node:" + tree + " = " + tree.getClass()); } } - traverse( pat ); + traverse(pat); generatedVars; } diff --git a/sources/scala/tools/scalac/transformer/matching/RightTracerInScala.scala b/sources/scala/tools/scalac/transformer/matching/RightTracerInScala.scala index c098b0f36a..6c8c239f6e 100644 --- a/sources/scala/tools/scalac/transformer/matching/RightTracerInScala.scala +++ b/sources/scala/tools/scalac/transformer/matching/RightTracerInScala.scala @@ -1,6 +1,10 @@ -/** - * $Id$ - */ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ import scalac._; import scalac.ast._; @@ -25,11 +29,11 @@ package scala.tools.scalac.transformer.matching { * @param elementType ... */ class RightTracerInScala(dfa: DetWordAutom, seqVars: Set, owner: Symbol, cf: CodeFactory, pat:Tree, elementType: Type) -extends TracerInScala( dfa, elementType, owner, cf ) { +extends TracerInScala(dfa, elementType, owner, cf) { - final def collectVars( pat:Tree ): HashSet = { - var vars = new HashSet(); + final def collectVars(pat: Tree): HashSet = { + var vars = new HashSet(); def handleVariableSymbol(sym: Symbol): Unit = { vars.add( sym ); @@ -49,7 +53,7 @@ extends TracerInScala( dfa, elementType, owner, cf ) { } def traverse(tree: Tree): Unit = { import Tree._ ; - tree.match { + tree match { case x @ Ident(name)=> if(x.symbol() != cf.unit.global.definitions.PATTERN_WILDCARD) throw new ApplicationError("shouldn't happen?!"); @@ -256,7 +260,7 @@ extends TracerInScala( dfa, elementType, owner, cf ) { } override def currentMatches(label: Label): Tree = { - label.match { + label match { case LPair( target, theLab ) => cf.Equals( gen.mkIntLit( cf.pos, target.intValue() ), current() ); @@ -419,11 +423,11 @@ extends TracerInScala( dfa, elementType, owner, cf ) { //System.out.println("delta("+i+","+label+")" ); var theLab: Label = null; - label.match { + label match { case LPair ( state, lab2 )=> //assert ntarget == state; theLab = lab2; - lab2.match { + lab2 match { case TreeLabel( pat ) => algMatchTree = _cur_match( pat ); case _ => @@ -433,11 +437,11 @@ extends TracerInScala( dfa, elementType, owner, cf ) { } //assert dfa.qbinders != null : "qbinders ?"; - var vars = dfa.qbinders( i ); + var vars = dfa.qbinders(i); //System.out.println("dfa.qbinders[ i ]"+vars); - if( null == vars ) vars = new Vector(); // TODO: make this more consistent + if (null == vars) vars = new Vector(); // TODO: make this more consistent //assert vars != null; val stms = new Array[Tree]( vars.size() @@ -463,10 +467,10 @@ extends TracerInScala( dfa, elementType, owner, cf ) { } override def stateWrap(i: Int): Tree = { - if( i == 0 ) + if (i == 0) code_state0_NEW(); else - code_state_NEW( i ); + code_state_NEW(i); } /* returns statements that do the work of the right-transducer @@ -523,12 +527,12 @@ extends TracerInScala( dfa, elementType, owner, cf ) { } def assignToHelpVar(realVar: Symbol, rhs: Tree): Tree = { - val hv = refHelpVar( realVar ); - gen.Assign( hv, rhs ); + val hv = refHelpVar(realVar); + gen.Assign(hv, rhs); } def bindVar(realVar: Symbol): Tree = { - val hv = refHelpVar( realVar ); + val hv = refHelpVar(realVar); /* System.out.println("binding realVar.name "+realVar.name+" type:"+realVar.type()+" to hv type:"+hv.type()); realVar.setOwner( owner ); diff --git a/sources/scala/tools/scalac/transformer/matching/WordAutomInScala.scala b/sources/scala/tools/scalac/transformer/matching/WordAutomInScala.scala index 3bc4323182..3d30cf6f91 100644 --- a/sources/scala/tools/scalac/transformer/matching/WordAutomInScala.scala +++ b/sources/scala/tools/scalac/transformer/matching/WordAutomInScala.scala @@ -1,13 +1,11 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** \* */ // $Id$ - - import scala.tools.util.Position; import scalac._; @@ -98,17 +96,17 @@ package scala.tools.scalac.transformer.matching { /** code for the return value of the automaton translation */ - override def run_finished( state: Int): Tree = { // T E S T - if( dfa.isFinal( state )) - gen.mkIntLit(Position.FIRSTPOS, dfa.finals.get( new Integer( state ) ).asInstanceOf[Integer].intValue() ); + override def run_finished(state: Int): Tree = { // T E S T + if( dfa.isFinal(state)) + gen.mkIntLit(Position.FIRSTPOS, dfa.finals.get(new Integer(state)).asInstanceOf[Integer].intValue()); else - gen.mkIntLit( Position.FIRSTPOS, FAIL ); + gen.mkIntLit(Position.FIRSTPOS, FAIL); } // calling the /*AlgebraicMatcher*/PatternMatcher here override def _cur_match(pat: Tree): Tree = { // TE ST - val m = new PartialMatcher( this.owner, /* owner*/ + val m = new PartialMatcher(this.owner, /* owner*/ currentElem(), /* root */ defs.boolean_TYPE() /* restype */); @@ -139,7 +137,7 @@ package scala.tools.scalac.transformer.matching { val target = dfa.delta(i, label); if (target == null) - label.match { + label match { case DefaultLabel() => code_error(); // this may not happen ! case _ => diff --git a/sources/scala/tools/scalac/typechecker/DeSugarize.scala b/sources/scala/tools/scalac/typechecker/DeSugarize.scala index 6b22743e00..c860ae84db 100644 --- a/sources/scala/tools/scalac/typechecker/DeSugarize.scala +++ b/sources/scala/tools/scalac/typechecker/DeSugarize.scala @@ -1,20 +1,22 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** ** ** -** $Id$ \* */ + +// $Id$ + import java.io._; -import java.util.ArrayList; import java.lang.Object; +import java.util.ArrayList; import scalac._; -import scalac.util._; -import scalac.symtab._; +import scalac.{Global => scalac_Global, CompilationUnit => scalac_CompilationUnit} import scalac.ast._; +import scalac.symtab._; import scalac.typechecker.Infer; -import scalac.{Global => scalac_Global, CompilationUnit => scalac_CompilationUnit} +import scalac.util._; import scala.tools.scalac.util.NewArray; @@ -385,18 +387,19 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala // e.match (case p => Tuple_N(x_1, ..., x_N)) val cases = NewArray.CaseDef(make.CaseDef(pos, pat, Tree.Empty, tuple)); - val match: Tree = make.Apply( + val matchTree: Tree = make.Apply( pos, make.Select(pos, rhs, Names._match), NewArray.Tree(make.Visitor(pos, cases))); if (vars.length == 0) { // e.match (case p => ()) - print(pat, "patdef", match); - NewArray.Tree(match); - } else if (vars.length == 1) { + print(pat, "patdef", matchTree); + NewArray.Tree(matchTree); + } + else if (vars.length == 1) { // val x_1 = e.match (case p => x_1) - val valdef: Tree = make.ValDef(pos, mods, vars(0), Tree.Empty, match); + val valdef: Tree = make.ValDef(pos, mods, vars(0), Tree.Empty, matchTree); print(pat, "patdef", valdef); NewArray.Tree(valdef) } else { @@ -405,7 +408,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala // private synthetic val t$ = e.match (case p => (x_1, ..., x_N)) val res = new Array[Tree](vars.length + 1); - res(0) = make.ValDef(pos, PRIVATE | SYNTHETIC, vble, Tree.Empty, match); + res(0) = make.ValDef(pos, PRIVATE | SYNTHETIC, vble, Tree.Empty, matchTree); for (val i <- Iterator.range(0, vars.length)) { // val x_i = t$._i res(i + 1) = make.ValDef( |