Skip to content
Snippets Groups Projects
Commit a9c9719f authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Block positions, explicit errors from xlang features.

parent 1171a9a0
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,33 @@ abstract class Position extends Ordered[Position] { ...@@ -34,6 +34,33 @@ abstract class Position extends Ordered[Position] {
def isDefined: Boolean def isDefined: Boolean
} }
object Position {
def between(a: Position, b: Position): Position = {
if (a.file == b.file) {
if (a.line == b.line && a.col == b.col) {
a
} else {
val (from, to) = if (a < b) (a, b) else (b, a)
(from, to) match {
case (p1: OffsetPosition, p2: OffsetPosition) =>
RangePosition(p1.line, p1.col, p1.point, p2.line, p2.col, p2.point, p1.file)
case (p1: RangePosition, p2: RangePosition) =>
RangePosition(p1.lineFrom, p1.colFrom, p1.pointFrom, p2.lineTo, p2.colTo, p2.pointTo, p1.file)
case (p1: OffsetPosition, p2: RangePosition) =>
RangePosition(p1.line, p1.col, p1.point, p2.lineTo, p2.colTo, p2.pointTo, p1.file)
case (p1: RangePosition, p2: OffsetPosition) =>
RangePosition(p1.lineFrom, p1.colFrom, p1.pointFrom, p2.line, p2.col, p2.point, p1.file)
case (a,b) =>
a
}
}
} else {
a
}
}
}
abstract class DefinedPosition extends Position { abstract class DefinedPosition extends Position {
override def toString = line+":"+col override def toString = line+":"+col
override def fullString = file.getPath+":"+line+":"+col override def fullString = file.getPath+":"+line+":"+col
......
...@@ -6,11 +6,13 @@ package xlang ...@@ -6,11 +6,13 @@ package xlang
import purescala.Common._ import purescala.Common._
import purescala.TypeTrees._ import purescala.TypeTrees._
import purescala.Trees._ import purescala.Trees._
import purescala.TreeOps.collect
import purescala.Definitions._ import purescala.Definitions._
import purescala.Constructors._ import purescala.Constructors._
import utils.Position
import xlang.Trees._ import xlang.Trees._
import xlang.TreeOps.isXLang
object NoXLangFeaturesChecking extends UnitPhase[Program] { object NoXLangFeaturesChecking extends UnitPhase[Program] {
...@@ -18,11 +20,30 @@ object NoXLangFeaturesChecking extends UnitPhase[Program] { ...@@ -18,11 +20,30 @@ object NoXLangFeaturesChecking extends UnitPhase[Program] {
val description = "Ensure and enforce that no xlang features are used" val description = "Ensure and enforce that no xlang features are used"
override def apply(ctx: LeonContext, pgm: Program): Unit = { override def apply(ctx: LeonContext, pgm: Program): Unit = {
pgm.definedFunctions.foreach(fd => { val errors = pgm.definedFunctions.flatMap(fd => collect[(Position, String)]{
if(isXLang(fd.fullBody)) { case (e: Block) =>
ctx.reporter.fatalError(fd.fullBody.getPos, "Expr is using xlang features") Set((e.getPos, "Block expressions require xlang desugaring"))
} case (e: Assignment) =>
}) Set((e.getPos, "Mutating variables requires xlang desugaring"))
case (e: While) =>
Set((e.getPos, "While expressions require xlang desugaring"))
case (e: Epsilon) =>
Set((e.getPos, "Usage of epsilons requires xlang desugaring"))
case (e: EpsilonVariable) =>
Set((e.getPos, "Usage of epsilons requires xlang desugaring"))
case (e: LetVar) =>
Set((e.getPos, "Mutable variables (e.g. 'var x' instead of 'val x') require xlang desugaring"))
case (e: Waypoint) =>
Set((e.getPos, "Usage of waypoints requires xlang desugaring"))
case (e: ArrayUpdate) =>
Set((e.getPos, "In-place updates of arrays require xlang desugaring"))
case _ =>
Set()
}(fd.fullBody))
for ((p, msg) <- errors) {
ctx.reporter.error(p, msg)
}
} }
} }
......
...@@ -24,6 +24,10 @@ object Trees { ...@@ -24,6 +24,10 @@ object Trees {
Some((exprs :+ last, exprs => Block(exprs.init, exprs.last))) Some((exprs :+ last, exprs => Block(exprs.init, exprs.last)))
} }
override def getPos = {
Position.between(exprs.head.getPos, last.getPos)
}
def printWith(implicit pctx: PrinterContext) { def printWith(implicit pctx: PrinterContext) {
p"""|{ p"""|{
| ${nary(exprs :+ last, "\n")} | ${nary(exprs :+ last, "\n")}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment