From acf8e1ba68f708ce68c08e950e4567ed6b4d215a Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Fri, 20 Jan 2012 17:31:36 +0400 Subject: [PATCH 1/4] Add SourcePosition to setting. --- util/collection/Settings.scala | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/util/collection/Settings.scala b/util/collection/Settings.scala index 4111c9082..fe97313f2 100644 --- a/util/collection/Settings.scala +++ b/util/collection/Settings.scala @@ -58,10 +58,10 @@ trait Init[Scope] type ScopeLocal = ScopedKey[_] => Seq[Setting[_]] type MapConstant = ScopedKey ~> Option - def setting[T](key: ScopedKey[T], init: Initialize[T]): Setting[T] = new Setting[T](key, init) + def setting[T](key: ScopedKey[T], init: Initialize[T], pos: SourcePosition = NoPosition): Setting[T] = new Setting[T](key, init, pos) def value[T](value: => T): Initialize[T] = new Value(value _) def optional[T,U](i: Initialize[T])(f: Option[T] => U): Initialize[U] = new Optional(Some(i), f) - def update[T](key: ScopedKey[T])(f: T => T): Setting[T] = new Setting[T](key, app(key :^: KNil)(hl => f(hl.head))) + def update[T](key: ScopedKey[T])(f: T => T): Setting[T] = new Setting[T](key, app(key :^: KNil)(hl => f(hl.head)), NoPosition) def bind[S,T](in: Initialize[S])(f: S => Initialize[T]): Initialize[T] = new Bind(f, in) def app[HL <: HList, T](inputs: KList[Initialize, HL])(f: HL => T): Initialize[T] = new Apply(f, inputs) def uniform[S,T](inputs: Seq[Initialize[S]])(f: Seq[S] => T): Initialize[T] = new Uniform(f, inputs) @@ -245,19 +245,32 @@ trait Init[Scope] def settings: Seq[Setting[_]] } final class SettingList(val settings: Seq[Setting[_]]) extends SettingsDefinition - final class Setting[T](val key: ScopedKey[T], val init: Initialize[T]) extends SettingsDefinition + final class Setting[T](val key: ScopedKey[T], val init: Initialize[T], val pos: SourcePosition) extends SettingsDefinition { def settings = this :: Nil def definitive: Boolean = !init.dependencies.contains(key) def dependencies: Seq[ScopedKey[_]] = remove(init.dependencies, key) - def mapReferenced(g: MapScoped): Setting[T] = new Setting(key, init mapReferenced g) - def validateReferenced(g: ValidateRef): Either[Seq[Undefined], Setting[T]] = (init validateReferenced g).right.map(newI => new Setting(key, newI)) - def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init) - def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t))) - def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g) - override def toString = "setting(" + key + ")" + def mapReferenced(g: MapScoped): Setting[T] = new Setting(key, init mapReferenced g, pos) + def validateReferenced(g: ValidateRef): Either[Seq[Undefined], Setting[T]] = (init validateReferenced g).right.map(newI => new Setting(key, newI, pos)) + def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init, pos) + def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t)), pos) + def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g, pos) + def setPos(pos: SourceCoord) = new Setting(key, init, pos) + override def toString = "setting(" + key + ") at " + pos } + trait SourcePosition { + def fileName: String + def line: Int + } + + case object NoPosition extends SourcePosition { + override def fileName = throw new UnsupportedOperationException("NoPosition") + override def line = throw new UnsupportedOperationException("NoPosition") + } + + case class SourceCoord(fileName: String, line: Int) extends SourcePosition + // mainly for reducing generated class count private[this] def validateReferencedT(g: ValidateRef) = new (Initialize ~> ValidatedInit) { def apply[T](i: Initialize[T]) = i validateReferenced g } From e1182031a0adc6b2023d74dfe93ba8100968306d Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Fri, 20 Jan 2012 17:31:36 +0400 Subject: [PATCH 2/4] Add SourcePosition to setting. --- util/collection/Settings.scala | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/util/collection/Settings.scala b/util/collection/Settings.scala index 4111c9082..fe97313f2 100644 --- a/util/collection/Settings.scala +++ b/util/collection/Settings.scala @@ -58,10 +58,10 @@ trait Init[Scope] type ScopeLocal = ScopedKey[_] => Seq[Setting[_]] type MapConstant = ScopedKey ~> Option - def setting[T](key: ScopedKey[T], init: Initialize[T]): Setting[T] = new Setting[T](key, init) + def setting[T](key: ScopedKey[T], init: Initialize[T], pos: SourcePosition = NoPosition): Setting[T] = new Setting[T](key, init, pos) def value[T](value: => T): Initialize[T] = new Value(value _) def optional[T,U](i: Initialize[T])(f: Option[T] => U): Initialize[U] = new Optional(Some(i), f) - def update[T](key: ScopedKey[T])(f: T => T): Setting[T] = new Setting[T](key, app(key :^: KNil)(hl => f(hl.head))) + def update[T](key: ScopedKey[T])(f: T => T): Setting[T] = new Setting[T](key, app(key :^: KNil)(hl => f(hl.head)), NoPosition) def bind[S,T](in: Initialize[S])(f: S => Initialize[T]): Initialize[T] = new Bind(f, in) def app[HL <: HList, T](inputs: KList[Initialize, HL])(f: HL => T): Initialize[T] = new Apply(f, inputs) def uniform[S,T](inputs: Seq[Initialize[S]])(f: Seq[S] => T): Initialize[T] = new Uniform(f, inputs) @@ -245,19 +245,32 @@ trait Init[Scope] def settings: Seq[Setting[_]] } final class SettingList(val settings: Seq[Setting[_]]) extends SettingsDefinition - final class Setting[T](val key: ScopedKey[T], val init: Initialize[T]) extends SettingsDefinition + final class Setting[T](val key: ScopedKey[T], val init: Initialize[T], val pos: SourcePosition) extends SettingsDefinition { def settings = this :: Nil def definitive: Boolean = !init.dependencies.contains(key) def dependencies: Seq[ScopedKey[_]] = remove(init.dependencies, key) - def mapReferenced(g: MapScoped): Setting[T] = new Setting(key, init mapReferenced g) - def validateReferenced(g: ValidateRef): Either[Seq[Undefined], Setting[T]] = (init validateReferenced g).right.map(newI => new Setting(key, newI)) - def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init) - def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t))) - def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g) - override def toString = "setting(" + key + ")" + def mapReferenced(g: MapScoped): Setting[T] = new Setting(key, init mapReferenced g, pos) + def validateReferenced(g: ValidateRef): Either[Seq[Undefined], Setting[T]] = (init validateReferenced g).right.map(newI => new Setting(key, newI, pos)) + def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init, pos) + def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t)), pos) + def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g, pos) + def setPos(pos: SourceCoord) = new Setting(key, init, pos) + override def toString = "setting(" + key + ") at " + pos } + trait SourcePosition { + def fileName: String + def line: Int + } + + case object NoPosition extends SourcePosition { + override def fileName = throw new UnsupportedOperationException("NoPosition") + override def line = throw new UnsupportedOperationException("NoPosition") + } + + case class SourceCoord(fileName: String, line: Int) extends SourcePosition + // mainly for reducing generated class count private[this] def validateReferencedT(g: ValidateRef) = new (Initialize ~> ValidatedInit) { def apply[T](i: Initialize[T]) = i validateReferenced g } From a3fa54be2ce509abbdcaae1e5b6768bf40c6e631 Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Tue, 24 Jan 2012 13:32:21 +0400 Subject: [PATCH 3/4] Change SourcePosition definition + minor cleanup. --- util/collection/Settings.scala | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/util/collection/Settings.scala b/util/collection/Settings.scala index fe97313f2..1c5634c1c 100644 --- a/util/collection/Settings.scala +++ b/util/collection/Settings.scala @@ -259,16 +259,8 @@ trait Init[Scope] override def toString = "setting(" + key + ") at " + pos } - trait SourcePosition { - def fileName: String - def line: Int - } - - case object NoPosition extends SourcePosition { - override def fileName = throw new UnsupportedOperationException("NoPosition") - override def line = throw new UnsupportedOperationException("NoPosition") - } - + sealed trait SourcePosition + case object NoPosition extends SourcePosition case class SourceCoord(fileName: String, line: Int) extends SourcePosition // mainly for reducing generated class count From 79ee34fa9706826859a2456479426ad0895ad6eb Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Fri, 27 Jan 2012 17:51:13 +0400 Subject: [PATCH 4/4] More cleanup. --- util/collection/Settings.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/collection/Settings.scala b/util/collection/Settings.scala index 1c5634c1c..01c3d5e2f 100644 --- a/util/collection/Settings.scala +++ b/util/collection/Settings.scala @@ -255,13 +255,13 @@ trait Init[Scope] def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init, pos) def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t)), pos) def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g, pos) - def setPos(pos: SourceCoord) = new Setting(key, init, pos) + def withPos(pos: SourceCoord) = new Setting(key, init, pos) override def toString = "setting(" + key + ") at " + pos } sealed trait SourcePosition case object NoPosition extends SourcePosition - case class SourceCoord(fileName: String, line: Int) extends SourcePosition + final case class SourceCoord(fileName: String, line: Int) extends SourcePosition // mainly for reducing generated class count private[this] def validateReferencedT(g: ValidateRef) =