diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-18 15:29:38 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-18 15:29:38 +0100 |
commit | 5c9433161e116704730693254fdaf161c69cbcb5 (patch) | |
tree | 6c9adc3d7e3b91ee07f7335aac0479df68d67af2 /src/dotty/tools/dotc/core/TypedTreeGen.scala | |
parent | 2b4a19e80a643dfdf8eea5fa40811f76edb27be3 (diff) | |
download | dotty-5c9433161e116704730693254fdaf161c69cbcb5.tar.gz dotty-5c9433161e116704730693254fdaf161c69cbcb5.tar.bz2 dotty-5c9433161e116704730693254fdaf161c69cbcb5.zip |
Improved position handling.
1. All positions are range position.
2. Improved position API
3. renamed Offset to Coord, and made sure indices cannot be confused with positions.
4. Trees now automatically get positions that enclose their subtree's positions.
5. typed DefTrees contain positions that also enclose their symbol's position.
To make this work well, a symbol's coord should point to the introducing keyword (e.g. def, val, class).
Diffstat (limited to 'src/dotty/tools/dotc/core/TypedTreeGen.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/TypedTreeGen.scala | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/TypedTreeGen.scala b/src/dotty/tools/dotc/core/TypedTreeGen.scala index b081a6ba7..7672f1f77 100644 --- a/src/dotty/tools/dotc/core/TypedTreeGen.scala +++ b/src/dotty/tools/dotc/core/TypedTreeGen.scala @@ -9,6 +9,8 @@ object TypedTrees { class TypeTreeGen { implicit def pos(implicit ctx: Context): Position = ctx.position + def defPos(sym: Symbol)(implicit ctx: Context) = ctx.position union sym.coord.toPosition + def Modifiers(sym: Symbol)(implicit ctx: Context): Modifiers[Type] = Trees.Modifiers[Type]( sym.flags & ModifierFlags, if (sym.privateWithin.exists) sym.privateWithin.asType.name else tpnme.EMPTY, @@ -118,7 +120,7 @@ object TypedTrees { Trees.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)) def Bind(sym: Symbol, body: TypedTree)(implicit ctx: Context): Bind[Type] = - Trees.Bind(sym.name, body).withType(sym.info) + Trees.Bind(sym.name, body)(defPos(sym)).withType(sym.info) def Alternative(trees: List[TypedTree])(implicit ctx: Context): Alternative[Type] = Trees.Alternative(trees).withType(ctx.lub(trees map (_.tpe))) @@ -131,7 +133,7 @@ object TypedTrees { def refType(sym: Symbol)(implicit ctx: Context) = NamedType(sym.owner.thisType, sym) def ValDef(sym: TermSymbol, rhs: TypedTree = EmptyTree)(implicit ctx: Context): ValDef[Type] = - Trees.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs) + Trees.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs)(defPos(sym)) .withType(refType(sym)) def DefDef(sym: TermSymbol, rhs: TypedTree = EmptyTree)(implicit ctx: Context): DefDef[Type] = { @@ -165,12 +167,12 @@ object TypedTrees { Trees.DefDef( Modifiers(sym), sym.name, tparams map TypeDef, - vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhs) + vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhs)(defPos(sym)) .withType(refType(sym)) } def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef[Type] = - Trees.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info)) + Trees.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info))(defPos(sym)) .withType(refType(sym)) def ClassDef(cls: ClassSymbol, typeParams: List[TypeSymbol], body: List[TypedTree])(implicit ctx: Context): ClassDef[Type] = { @@ -191,7 +193,7 @@ object TypedTrees { .orElse(ctx.newLocalDummy(cls)) val impl = Trees.Template(parents, selfType, rest) .withType(refType(localDummy)) - Trees.ClassDef(Modifiers(cls), cls.name, tparams, impl) + Trees.ClassDef(Modifiers(cls), cls.name, tparams, impl)(defPos(cls)) .withType(refType(cls)) } |