scala - Splitting scalac plugin into multiple files -
i'd split scalac plugin multiple files. sounds easy haven't managed pull off due path-dependent type issues stemming import global._ line.
here's lex spoon's sample plugin:
package localhost import scala.tools.nsc import nsc.global import nsc.phase import nsc.plugins.plugin import nsc.plugins.plugincomponent class divbyzero(val global: global) extends plugin { import global._ val name = "divbyzero" val description = "checks division zero" val components = list[plugincomponent](component) private object component extends plugincomponent { val global: divbyzero.this.global.type = divbyzero.this.global val runsafter = "refchecks" // using scala compiler 2.8.x runsafter should written below // val runsafter = list[string]("refchecks"); val phasename = divbyzero.this.name def newphase(_prev: phase) = new divbyzerophase(_prev) class divbyzerophase(prev: phase) extends stdphase(prev) { override def name = divbyzero.this.name def apply(unit: compilationunit) { ( tree @ apply(select(rcvr, nme.div), list(literal(constant(0)))) <- unit.body; if rcvr.tpe <:< definitions.intclass.tpe) { unit.error(tree.pos, "definitely division zero") } } } } } how can put component , divbyzerophase in own files without having import global._ in scope?
here's old project i've done same thing:
if don't need pass path-dependent types global, don't worry trying keep "this.global" portions of relevant.
Comments
Post a Comment