diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 125 | ||||
-rw-r--r-- | src/library/scala/util/automata/WordBerrySethi.scala | 58 |
2 files changed, 117 insertions, 66 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 670ce28ca2..9850f71ae4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -55,41 +55,61 @@ trait Typers requires Analyzer { def newDecls(tree : Template, clazz : Symbol) = newScope def newTemplateScope(impl : Template, clazz : Symbol) = newScope - /** Mode constants + // Mode constants + + /** The three mode <code>NOmode</code>, <code>EXPRmode</code> + * and <code>PATTERNmode</code> are mutually exclusive. */ val NOmode = 0x000 - val EXPRmode = 0x001 // these 3 modes are mutually exclusive. + val EXPRmode = 0x001 val PATTERNmode = 0x002 val TYPEmode = 0x004 - val SCCmode = 0x008 // orthogonal to above. When set we are - // in the this or super constructor call of a constructor. + /** The mode <code>SCCmode</code> is orthogonal to above. When set we are + * in the this or super constructor call of a constructor. + */ + val SCCmode = 0x008 - val FUNmode = 0x10 // orthogonal to above. When set - // we are looking for a method or constructor + /** The mode <code>FUNmode</code> is orthogonal to above. + * When set we are looking for a method or constructor. + */ + val FUNmode = 0x010 - val POLYmode = 0x020 // orthogonal to above. When set - // expression types can be polymorphic. + /** The mode <code>POLYmode</code> is orthogonal to above. + * When set expression types can be polymorphic. + */ + val POLYmode = 0x020 - val QUALmode = 0x040 // orthogonal to above. When set - // expressions may be packages and - // Java statics modules. + /** The mode <code>QUALmode</code> is orthogonal to above. When set + * expressions may be packages and Java statics modules. + */ + val QUALmode = 0x040 - val TAPPmode = 0x080 // Set for the function/type constructor part - // of a type application. When set we do not - // decompose PolyTypes. + /** The mode <code>TAPPmode</code> is set for the function/type constructor + * part of a type application. When set we do not decompose PolyTypes. + */ + val TAPPmode = 0x080 - val SUPERCONSTRmode = 0x100 // Set for the `super' in a superclass constructor call - // super.<init> + /** The mode <code>SUPERCONSTRmode</code> is set for the <code>super</code> + * in a superclass constructor call <code>super.<init></code>. + */ + val SUPERCONSTRmode = 0x100 - val SNDTRYmode = 0x200 // indicates that an application is typed for the 2nd - // time. In that case functions may no longer be - // be coerced with implicit views. + /** The mode <code>SNDTRYmode</code> indicates that an application is typed + * for the 2nd time. In that case functions may no longer be coerced with + * implicit views. + */ + val SNDTRYmode = 0x200 - val LHSmode = 0x400 // Set for the left-hand side of an assignment + /** The mode <code>LHSmode</code> is set for the left-hand side of an + * assignment. + */ + val LHSmode = 0x400 - val CONSTmode = 0x800 // expressions should evaluate to constants - // used for attribute arguments + /** The mode <code>CONSTmode</code> is set when expressions should evaluate + * to constant sused for attribute arguments. + */ + val CONSTmode = 0x800 class Typer(context0: Context) { import context0.unit @@ -740,7 +760,7 @@ trait Typers requires Analyzer { * @return ... */ def typedModuleDef(mdef: ModuleDef): Tree = { - System.out.println("sourcefile of " + mdef.symbol + "=" + mdef.symbol.sourceFile) + //System.out.println("sourcefile of " + mdef.symbol + "=" + mdef.symbol.sourceFile) attributes(mdef) val clazz = mdef.symbol.moduleClass val impl1 = newTyper(context.make(mdef.impl, clazz, newTemplateScope(mdef.impl, clazz))) @@ -810,6 +830,10 @@ trait Typers requires Analyzer { copy.Template(templ, parents1, body1) setType clazz.tpe } + /** + * @param vdef ... + * @return ... + */ def typedValDef(vdef: ValDef): ValDef = { attributes(vdef) val sym = vdef.symbol @@ -1975,7 +1999,6 @@ trait Typers requires Analyzer { case SelectFromTypeTree(qual, selector) => tree setType typedSelect(typedType(qual), selector).tpe - case tree @ CompoundTypeTree(templ: Template) => tree setType { val parents1 = List.mapConserve(templ.parents)(typedType) @@ -2062,17 +2085,31 @@ trait Typers requires Analyzer { def atOwner(tree: Tree, owner: Symbol): Typer = newTyper(context.make(tree, owner)) - /** Types expression or definition `tree' */ + /** Types expression or definition <code>tree</code>. + * + * @param tree ... + * @return ... + */ def typed(tree: Tree): Tree = { val ret = typed(tree, EXPRmode, WildcardType) ret } - /** Types expression `tree' with given prototype `pt' */ + /** Types expression <code>tree</code> with given prototype <code>pt</code>. + * + * @param tree ... + * @param pt ... + * @return ... + */ def typed(tree: Tree, pt: Type): Tree = typed(tree, EXPRmode, pt) - /** Types qualifier `tree' of a select node. E.g. is tree occurs in acontext like `tree.m'. */ + /** Types qualifier <code>tree</code> of a select node. + * E.g. is tree occurs in a context like <code>tree.m</code>. + * + * @param tree ... + * @return ... + */ def typedQualifier(tree: Tree): Tree = typed(tree, EXPRmode | QUALmode | POLYmode, WildcardType) @@ -2136,9 +2173,9 @@ trait Typers requires Analyzer { * @param info The given implicit info describing the implicit definition * @param pt The expected type * @param isLocal Is implicit definition visible without prefix? - * @return A typed tree if the implicit info can be made to conform - * to `pt', EmptyTree otherwise. - * @pre info.tpe does not contain an error + * @return A typed tree if the implicit info can be made to conform + * to <code>pt</code>, EmptyTree otherwise. + * @pre <code>info.tpe</code> does not contain an error */ private def typedImplicit(pos: PositionType, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree = { def isStable(tp: Type): boolean = tp match { @@ -2172,11 +2209,14 @@ trait Typers requires Analyzer { /** Infer implicit argument or view. * - * @param pos position for error reporting - * @param pt the expected type of the implicit - * @param isView are we searching for a view? (this affects the error message) - * @param reportAmbiguous should ambiguous errors be reported? False iff we search for a view - * to find out whether one type is coercible to another (@see isCoercible) + * @param pos position for error reporting + * @param pt the expected type of the implicit + * @param isView are we searching for a view? (this affects the error message) + * @param reportAmbiguous should ambiguous errors be reported? + * False iff we search for a view to find out + * whether one type is coercible to another + * @return ... + * @see <code>isCoercible</code> */ private def inferImplicit(pos: PositionType, pt: Type, isView: boolean, reportAmbiguous: boolean): Tree = { @@ -2194,13 +2234,16 @@ trait Typers requires Analyzer { (if (isView) "\n are possible conversion functions from "+ pt.typeArgs(0)+" to "+pt.typeArgs(1) else "\n match expected type "+pt)) - /** Search list of implicit info lists for one matching prototype `pt' - * If found return a tree from found implicit info which is typed with expected type `pt'. + /** Search list of implicit info lists for one matching prototype + * <code>pt</code>. If found return a tree from found implicit info + * which is typed with expected type <code>pt</code>. * Otherwise return EmptyTree - * @param implicitInfoss The given list of lists of implicit infos - * @isLocal Is implicit definition visible without prefix? - * If this is the case then symbols in preceding lists shadow - * symbols of the same name in succeeding lists. + * + * @param implicitInfoss The given list of lists of implicit infos + * @param isLocal Is implicit definition visible without prefix? + * If this is the case then symbols in preceding lists shadow + * symbols of the same name in succeeding lists. + * @return ... */ def searchImplicit(implicitInfoss: List[List[ImplicitInfo]], isLocal: boolean): Tree = { def isSubClassOrObject(sym1: Symbol, sym2: Symbol) = { diff --git a/src/library/scala/util/automata/WordBerrySethi.scala b/src/library/scala/util/automata/WordBerrySethi.scala index c1dae7566a..e553fde90d 100644 --- a/src/library/scala/util/automata/WordBerrySethi.scala +++ b/src/library/scala/util/automata/WordBerrySethi.scala @@ -46,31 +46,39 @@ abstract class WordBerrySethi extends BaseBerrySethi { // is not *really* needed (preorder determines position!) //protected var posMap: mutable.HashMap[RegExp, Int] = _; - /** computes first( r ) where the word regexp r */ + /** Computes <code>first(r)</code> where the word regexp <code>r</code>. + * + * @param r the regular expression + * @return the computed set <code>first(r)</code> + */ protected override def compFirst(r: RegExp): immutable.Set[Int] = r match { case x:Letter => emptySet + x.pos //posMap(x); // singleton set case Eps => emptySet /*ignore*/ case _ => super.compFirst(r) } - /** computes last( r ) where the word regexp r */ + /** Computes <code>last(r)</code> where the word regexp <code>r</code>. + * + * @param r the regular expression + * @return the computed set <code>last(r)</code> + */ protected override def compLast(r: RegExp): immutable.Set[Int] = r match { case x:Letter => emptySet + x.pos //posMap(x) // singleton set case Eps => emptySet /*ignore*/ case _ => super.compLast(r) } - /** returns the first set of an expression, setting the follow set along + /** Returns the first set of an expression, setting the follow set along * the way. * * @param fol1 ... - * @param r ... - * @return ... + * @param r the regular expression + * @return the computed set */ protected override def compFollow1(fol1: immutable.Set[Int], r: RegExp): immutable.Set[Int] = r match { case x:Letter => - //val i = posMap( x ); + //val i = posMap(x) val i = x.pos this.follow.update(i, fol1) emptySet + i @@ -88,8 +96,8 @@ abstract class WordBerrySethi extends BaseBerrySethi { /** called at the leaves of the regexp */ protected def seenLabel(r: RegExp, i: Int, label: _labelT): Unit = { //Console.println("seenLabel (1)"); - //this.posMap.update( r, i ); - this.labelAt = this.labelAt.update( i, label ); + //this.posMap.update(r, i) + this.labelAt = this.labelAt.update(i, label) //@ifdef if( label != Wildcard ) { this.labels += label //@ifdef } @@ -103,7 +111,6 @@ abstract class WordBerrySethi extends BaseBerrySethi { pos } - // todo: replace global variable pos with acc override def traverse(r: RegExp): Unit = r match { case a @ Letter(label) => a.pos = seenLabel(r, label) @@ -125,8 +132,8 @@ abstract class WordBerrySethi extends BaseBerrySethi { protected def initialize(subexpr: Seq[RegExp]): Unit = { //this.posMap = new mutable.HashMap[RegExp,Int]() - this.labelAt = new immutable.TreeMap[Int,_labelT]() - this.follow = new mutable.HashMap[Int,immutable.Set[Int]]() + this.labelAt = new immutable.TreeMap[Int, _labelT]() + this.follow = new mutable.HashMap[Int, immutable.Set[Int]]() this.labels = new mutable.HashSet[_labelT]() this.pos = 0 @@ -159,16 +166,16 @@ abstract class WordBerrySethi extends BaseBerrySethi { //Console.println("WBS.collectTrans, pos = "+this.follow.keys) var j = 0; while (j < pos) { //Console.println("WBS.collectTrans, j = "+j) - val fol = this.follow( j ); - val it = fol.elements; - while( it.hasNext ) { - val k = it.next; - if( pos == k ) - finals = finals.update( j, finalTag ) + val fol = this.follow(j) + val it = fol.elements + while (it.hasNext) { + val k = it.next + if (pos == k) + finals = finals.update(j, finalTag) else - makeTransition( j, k, labelAt( k )); + makeTransition( j, k, labelAt(k)) } - j = j + 1; + j = j + 1 } } @@ -188,7 +195,7 @@ abstract class WordBerrySethi extends BaseBerrySethi { collectTransitions() if (x.isNullable) // initial state is final - finals = finals.update(0, finalTag) + finals = finals.update(0, finalTag) var delta1: immutable.TreeMap[Int, Map[_labelT, List[Int]]] = new immutable.TreeMap[Int, Map[_labelT, List[Int]]] @@ -218,12 +225,12 @@ abstract class WordBerrySethi extends BaseBerrySethi { } } - val deltaArr = new Array[Map[_labelT,immutable.BitSet]](pos) + val deltaArr = new Array[Map[_labelT, immutable.BitSet]](pos) { var k = 0; while(k < pos) { val labels = delta1(k).keys val hmap = - new mutable.HashMap[_labelT,immutable.BitSet] + new mutable.HashMap[_labelT, immutable.BitSet] for (val lab <- labels) { val trans = delta1(k) val x = new mutable.BitSet(pos) @@ -247,7 +254,7 @@ abstract class WordBerrySethi extends BaseBerrySethi { } new NondetWordAutom[_labelT] { - type _labelT = WordBerrySethi.this._labelT + type _labelT = WordBerrySethi.this._labelT val nstates = pos val labels = WordBerrySethi.this.labels.toList val initials = initialsArr @@ -255,8 +262,9 @@ abstract class WordBerrySethi extends BaseBerrySethi { val delta = deltaArr val default = defaultArr } - case z:this.lang._regexpT => - automatonFrom(Sequ(z), finalTag) + case z => + val z1 = z.asInstanceOf[this.lang._regexpT] + automatonFrom(Sequ(z1), finalTag) } } |