-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
166 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 39 additions & 5 deletions
44
tlair/src/main/scala/at/forsyte/apalache/tla/lir/storage/SourceLocator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
package at.forsyte.apalache.tla.lir.storage | ||
|
||
import at.forsyte.apalache.tla.lir.{TlaEx, UID} | ||
import at.forsyte.apalache.tla.lir._ | ||
import at.forsyte.apalache.tla.lir.src.SourceLocation | ||
import com.typesafe.scalalogging.LazyLogging | ||
|
||
/** | ||
* SourceLocator is used to identify locations in the original .tla specification, | ||
* from which a given expression, possibly derived from a transformation, originates. | ||
*/ | ||
sealed case class SourceLocator( | ||
sourceMap : SourceMap, | ||
changeListener : ChangeListener | ||
) { | ||
sealed case class SourceLocator(sourceMap : SourceMap, | ||
changeListener : ChangeListener) extends LazyLogging { | ||
def sourceOf( id : UID ) : Option[SourceLocation] = | ||
sourceMap.get( changeListener.traceBack( id ) ) | ||
|
||
def sourceOf( ex : TlaEx ) : Option[SourceLocation] = | ||
sourceOf( ex.ID ) | ||
|
||
|
||
/** | ||
* A debugging method that recursively checks whether all subexpressions of the operator body have source information. | ||
* When this is not the case, the function prints ids of the topmost problematic expressions. | ||
* This method may be quite slow, so it should be used in the debugging mode only. | ||
*/ | ||
def checkConsistency(decl: TlaOperDecl): Unit = { | ||
checkConsistency(decl.body) | ||
} | ||
|
||
/** | ||
* A debugging method that recursively checks whether all subexpressions of an expression have source information. | ||
* When this is not the case, the function prints ids of the topmost problematic expressions. | ||
* This method may be quite slow, so it should be used in the debugging mode only. | ||
*/ | ||
def checkConsistency(ex: TlaEx): Unit = { | ||
if (sourceOf(ex).isEmpty) { | ||
var str = ex.toString | ||
str = if (str.length > 70) str.substring(0, 69) + "..." else str | ||
logger.error("No source for expr@%s: %s".format(ex.ID, str)) | ||
} else { | ||
ex match { | ||
case OperEx(_, args @ _*) => | ||
args foreach checkConsistency | ||
|
||
case LetInEx(body, decls @ _*) => | ||
checkConsistency(body) | ||
decls.foreach(d => checkConsistency(d.body)) | ||
|
||
case _ => // do nothing | ||
} | ||
} | ||
} | ||
|
||
} |
24 changes: 23 additions & 1 deletion
24
tlair/src/main/scala/at/forsyte/apalache/tla/lir/transformations/TransformationTracker.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
package at.forsyte.apalache.tla.lir.transformations | ||
|
||
import at.forsyte.apalache.tla.lir.TlaEx | ||
|
||
/** | ||
* An implementation of this trait wraps an expression transformer with the code that somehow tracks the transformation. | ||
* For instance, it can wrap a transformation with calls to transformation listeners. | ||
* | ||
* @author Igor Konnov | ||
*/ | ||
trait TransformationTracker { | ||
def track(t: TlaExTransformation): TlaExTransformation | ||
/** | ||
* Decorate a transformation with a tracker. | ||
* @param tr an expression transformation | ||
* @return a new transformation that applies tr and tracks the changes | ||
*/ | ||
def track(tr: TlaExTransformation): TlaExTransformation | ||
|
||
/** | ||
* Sometimes, one has to track a change in a temporary expression that will get transformed into something else | ||
* before it gets a chance to get tracked with `track`, which only works with end-to-end transformations. | ||
* In this case, we have to record the change as a side effect and return the new expression. | ||
* Avoid using this method by default. This is a second-chance method. | ||
* | ||
* @param from the original expression | ||
* @param to the new expression | ||
* @return the new expression | ||
*/ | ||
def hold(from: TlaEx, to: TlaEx): TlaEx = { | ||
def tr(f : TlaEx): TlaEx = to | ||
track(tr)(from) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters