diff options
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 19 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Modes.scala | 18 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 2 |
3 files changed, 27 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 2315cb58a..faa015793 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -9,6 +9,7 @@ import TreeInfo._ import Decorators._ import language.higherKinds import collection.mutable.ListBuffer +import typer.Mode object desugar { @@ -16,10 +17,6 @@ object desugar { private type VarInfo = (NameTree, Tree) - object Mode extends Enumeration { - val Type, Expr, Pattern = Value - } - def valDef(vdef: ValDef)(implicit ctx: Context): Tree = { val ValDef(mods, name, tpt, rhs) = vdef if (!ctx.owner.isClass || (mods is Private)) vdef @@ -191,7 +188,7 @@ object desugar { case tree: ModuleDef => moduleDef(tree) } - def apply(tree: Tree, mode: Mode.Value)(implicit ctx: Context): Tree = { + def apply(tree: Tree, mode: Mode)(implicit ctx: Context): Tree = { def labelDefAndCall(lname: TermName, rhs: Tree, call: Tree) = { val ldef = DefDef(Modifiers(Label), lname, Nil, ListOfNil, TypeTree(), rhs) @@ -415,7 +412,7 @@ object desugar { } def isPatternVar(id: Ident) = - mode == Mode.Pattern && isVarPattern(id) && id.name != nme.WILDCARD + (mode is Mode.Pattern) && isVarPattern(id) && id.name != nme.WILDCARD // begin desugar val tree1 = tree match { // todo: move general tree desugaring to typer, and keep only untyped trees here? @@ -440,7 +437,7 @@ object desugar { case InterpolatedString(id, strs, elems) => Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems) case Function(args, body) => - if (mode == Mode.Type) // FunctionN[args: _*, body] + if (mode is Mode.Type) // FunctionN[args: _*, body] AppliedTypeTree( ref(defn.FunctionClass(args.length).typeConstructor), args :+ body) @@ -456,15 +453,15 @@ object desugar { AppliedTypeTree(Ident(op), l :: r :: Nil) } case PostfixOp(t, op) => - if (mode == Mode.Type && op == nme.raw.STAR) + if ((mode is Mode.Type) && op == nme.raw.STAR) AppliedTypeTree(ref(defn.RepeatedParamType), t) else { - assert(mode == Mode.Expr) + assert(mode is Mode.Expr) if (op == nme.WILDCARD) tree // desugar later by eta expansion else Select(t, op) } case PrefixOp(op, t) => - if (mode == Mode.Type && op == nme.ARROWkw) + if ((mode is Mode.Type) && op == nme.ARROWkw) AppliedTypeTree(ref(defn.ByNameParamClass.typeConstructor), t) else Select(t, nme.UNARY_PREFIX ++ op) @@ -473,7 +470,7 @@ object desugar { case Tuple(ts) => def PairTypeTree(l: Tree, r: Tree) = AppliedTypeTree(ref(defn.PairClass.typeConstructor), l :: r :: Nil) - if (mode == Mode.Type) ts.reduceRight(PairTypeTree) + if (mode is Mode.Type) ts.reduceRight(PairTypeTree) else if (ts.isEmpty) unitLiteral else ts.reduceRight(Pair(_, _)) case WhileDo(cond, body) => diff --git a/src/dotty/tools/dotc/typer/Modes.scala b/src/dotty/tools/dotc/typer/Modes.scala new file mode 100644 index 000000000..edcbc79b4 --- /dev/null +++ b/src/dotty/tools/dotc/typer/Modes.scala @@ -0,0 +1,18 @@ +package dotty.tools.dotc.typer + +case class Mode(val bits: Int) extends AnyVal { + def | (that: Mode) = Mode(bits | that.bits) + def & (that: Mode) = Mode(bits & that.bits) + def &~ (that: Mode) = Mode(bits & ~that.bits) + def is (that: Mode) = (bits & that.bits) == that.bits +} + +object Mode { + val None = Mode(1 << 0) + + val Expr = Mode(1 << 1) + val Pattern = Mode(1 << 2) + val Type = Mode(1 << 3) + + +}
\ No newline at end of file diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 0b8c1ada2..6ed45e4df 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -215,7 +215,7 @@ class Namer { typer: Typer => } /** Typecheck tree during completion, and remember result in yypedtree map */ - def typedAhead(tree: Tree, mode: Mode.Value = Mode.Expr, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree = + def typedAhead(tree: Tree, mode: Mode = Mode.Expr, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree = typedTree.getOrElseUpdate(tree, typer.typedExpanded(tree, mode, pt)) /** Enter and typecheck parameter list */ |