diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-16 14:23:05 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-16 14:23:05 +0100 |
commit | 6bd453e8f3b50e7c48b6969bd4aaf6638b0455f8 (patch) | |
tree | 024c591cf5f22c65218e0f33d053f7806b781f53 /src/dotty/tools/dotc/core/TypedTreeGen.scala | |
parent | cf425f04b9342d15f25380e2227c6b142bd26f16 (diff) | |
download | dotty-6bd453e8f3b50e7c48b6969bd4aaf6638b0455f8.tar.gz dotty-6bd453e8f3b50e7c48b6969bd4aaf6638b0455f8.tar.bz2 dotty-6bd453e8f3b50e7c48b6969bd4aaf6638b0455f8.zip |
Fleshed out tree handling
Diffstat (limited to 'src/dotty/tools/dotc/core/TypedTreeGen.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/TypedTreeGen.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/TypedTreeGen.scala b/src/dotty/tools/dotc/core/TypedTreeGen.scala new file mode 100644 index 000000000..0b47c4489 --- /dev/null +++ b/src/dotty/tools/dotc/core/TypedTreeGen.scala @@ -0,0 +1,43 @@ +package dotty.tools.dotc +package core + +import Trees._, Positions._, Types._, Contexts._, Constants._, Names._ +import SymDenotations._, Symbols._ + +object TypedTrees { + + class TypeTreeGen { + implicit def pos(implicit ctx: Context): Position = ctx.position + def Ident(tp: NamedType)(implicit ctx: Context): Ident[Type] = + Trees.Ident(tp.name).withType(tp) + def Select(pre: TypedTree, tp: NamedType)(implicit ctx: Context): Select[Type] = + Trees.Select(pre, tp.name).withType(tp) + def Apply(fn: TypedTree, args: List[TypedTree])(implicit ctx: Context): Apply[Type] = { + val fntpe @ MethodType(pnames, ptypes) = fn.tpe + assert(sameLength(ptypes, args)) + Trees.Apply(fn, args).withType(fntpe.instantiate(args map (_.tpe))) + } + def TypeTree(tp: Type)(implicit ctx: Context):TypeTree[Type] = + Trees.TypeTree().withType(tp) + def New(tp: Type)(implicit ctx: Context): New[Type] = + Trees.New(TypeTree(tp)) + def Literal(const: Constant)(implicit ctx: Context): Literal[Type] = + Trees.Literal(const).withType(const.tpe) + def ArrayValue(elemtpt: TypedTree, elems: List[TypedTree])(implicit ctx: Context) = + Trees.ArrayValue(elemtpt, elems).withType(defn.ArrayType.appliedTo(elemtpt.tpe)) + def NamedArg[T](name: Name, arg: TypedTree)(implicit ctx: Context) = + Trees.NamedArg(name, arg).withType(arg.tpe) + + // ---------------------------------------------------------- + + def New(tp: Type, args: List[TypedTree])(implicit ctx: Context): Apply[Type] = + Apply( + Select( + New(tp), + TermRef(tp.normalizedPrefix, tp.typeSymbol.primaryConstructor.asTerm)), + args) + } + + object tpd extends TypeTreeGen +} + |