11package scala .js .language
22
3+ import scala .language .higherKinds
4+
35import scala .language .experimental .macros
46import scala .virtualization .lms .common .Functions
57
@@ -40,7 +42,7 @@ trait Adts extends Functions {
4042 *
4143 *@return a staged smart constructor for the data type T
4244*/
43- def adt [T <: Adt ]= macroAdtsImpl .adt[T ]
45+ def adt [T <: Adt ]: AnyRef = macroAdtsImpl .adt[T ]
4446
4547/**
4648 * {{{
@@ -57,22 +59,22 @@ trait Adts extends Functions {
5759 *
5860 *@return an object with staged members for the type T
5961*/
60- def adtOps [T <: Adt ](o :Rep [T ])= macroAdtsImpl .ops[T ,Rep ]
62+ def adtOps [T <: Adt ](o :Rep [T ]): AnyRef = macroAdtsImpl .ops[T ,Rep ]
6163
6264}
6365
6466object AdtsImpl {
6567
66- import scala .reflect .macros .Context
68+ import scala .reflect .macros .whitebox . Context
6769
6870trait Adt
6971
7072def adt [U <: Adt : c.WeakTypeTag ](c :Context )=
71- c.Expr [Any ](new Generator [c.type ](c).construct[U ])
73+ c.Expr [AnyRef ](new Generator [c.type ](c).construct[U ])
7274
7375
7476def ops [U <: Adt : c.WeakTypeTag ,R [_]](c :Context )(o : c.Expr [R [U ]])=
75- c.Expr [Any ](new Generator [c.type ](c).ops(o))
77+ c.Expr [AnyRef ](new Generator [c.type ](c).ops(o))
7678
7779
7880class Generator [C <: Context ](val c : C ) {
@@ -99,13 +101,13 @@ object AdtsImpl {
99101 base.knownDirectSubclasses.foldLeft(List (base)) { (result, symbol)=>
100102val clazz = symbol.asClass
101103if (clazz.isCaseClass) clazz:: result
102- else if (clazz.isSealed&& (clazz.isTrait|| clazz.isAbstractClass )) subHierarchy(clazz)++ result
104+ else if (clazz.isSealed&& (clazz.isTrait|| clazz.isAbstract )) subHierarchy(clazz)++ result
103105else c.abort(c.enclosingPosition," A class hierarchy may only contain case classes, sealed traits and sealed abstract classes" )
104106 }
105107 }
106108
107109 subHierarchy(rootClass)
108- .sortBy(_.name.decoded )
110+ .sortBy(_.name.decodedName.toString )
109111 .ensuring(_.nonEmpty,s " Oops: whole hierarchy of $rootClass is empty " )
110112 }
111113
@@ -122,14 +124,14 @@ object AdtsImpl {
122124object Member {
123125def apply (symbol :Symbol )= {
124126// Trim because case classes members introduce a trailing space
125- val nameStr = symbol.name.decoded .trim
126- new Member (nameStr,newTermName (nameStr), symbol.typeSignature)
127+ val nameStr = symbol.name.decodedName.toString .trim
128+ new Member (nameStr,TermName (nameStr), symbol.typeSignature)
127129 }
128130 }
129131
130132/** @return The members of the type `tpe`*/
131133def listMembers (tpe :Type ): List [Member ]=
132- tpe.typeSymbol.typeSignature.declarations .toList.collect {case x :TermSymbol if x.isVal&& x.isCaseAccessor=> Member (x) }
134+ tpe.typeSymbol.typeSignature.decls .toList.collect {case x :TermSymbol if x.isVal&& x.isCaseAccessor=> Member (x) }
133135
134136/**
135137 * Expands to a value providing staged operations on algebraic data types.
@@ -159,17 +161,17 @@ object AdtsImpl {
159161*/
160162// TODO Simplify the expansion
161163def ops [U <: Adt : c.WeakTypeTag ,R [_]](obj : c.Expr [R [U ]])= {
162- val anon = newTypeName (c.fresh )
163- val wrapper = newTypeName (c.fresh )
164- val ctor = newTermName (c.fresh )
164+ val anon = TypeName (c.freshName )
165+ val wrapper = TypeName (c.freshName )
166+ val ctor = TermName (c.freshName )
165167
166168val U = weakTypeOf[U ]
167169val members = listMembers(U )
168170if (! U .typeSymbol.isClass) {
169171 c.abort(c.enclosingPosition,s " $U must be a sealed trait, an abstract class or a case class " )
170172 }
171173val typeSymbol = U .typeSymbol.asClass
172- if (! (typeSymbol.isCaseClass|| (typeSymbol.isSealed&& (typeSymbol.isTrait|| typeSymbol.isAbstractClass )))) {
174+ if (! (typeSymbol.isCaseClass|| (typeSymbol.isSealed&& (typeSymbol.isTrait|| typeSymbol.isAbstract )))) {
173175 c.abort(c.enclosingPosition,s " $U must be a sealed trait, an abstract class or a case class " )
174176 }
175177
@@ -216,7 +218,7 @@ object AdtsImpl {
216218 }
217219"""
218220
219- val variants2 = wholeHierarchy[U ].filter(_.isCaseClass).map(s=> s-> newTermName (c.fresh() ))
221+ val variants2 = wholeHierarchy[U ].filter(_.isCaseClass).map(s=> s-> TermName (c.freshName ))
220222
221223val paramsFold = for ((param, symbol)<- variants2)yield q " val $symbol: (Rep[ $param] => Rep[A]) "
222224
@@ -266,7 +268,7 @@ object AdtsImpl {
266268val U = weakTypeOf[U ]
267269if (U .typeSymbol.asClass.isCaseClass) {
268270val members = listMembers(U )
269- val objName = U .typeSymbol.name
271+ val objName : c. TypeName = U .typeSymbol.name. asInstanceOf [c. TypeName ]
270272val paramsDef = for (member<- members)yield q " val ${member.term}: Rep[ ${member.tpe}] "
271273val paramsConstruct = for (member<- members)yield q " ${member.name} -> ${member.term}"
272274val paramsType = for (member<- members)yield tq " Rep[ ${member.tpe}] "
@@ -278,7 +280,7 @@ object AdtsImpl {
278280 }
279281 }
280282q """
281- new ${newTypeName (" Function" + paramsType.length)}[.. $paramsType, Rep[ $objName]] {
283+ new ${TypeName (" Function" + paramsType.length)}[.. $paramsType, Rep[ $objName]] {
282284 def apply(.. $paramsDef) = adt_construct[ $objName](.. $allParams)
283285 }
284286"""