-
Notifications
You must be signed in to change notification settings - Fork 35
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
5 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
Submodule silver
updated
3 files
+1 −25 | src/main/scala/viper/silver/parser/FastParser.scala | |
+1 −18 | src/main/scala/viper/silver/parser/Resolver.scala | |
+7 −8 | src/main/scala/viper/silver/parser/Translator.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package debugger | ||
|
||
import fastparse._ | ||
import viper.silver.ast | ||
import viper.silver.ast.{AnnotationInfo, ConsInfo, DebugLabelledOld, Exp, Info, LocalVarWithVersion, Node, SourcePNodeInfo} | ||
import viper.silver.parser.{FastParser, PDebugLabelledOld, PExp, PProgram, PVersionedIdnUse, Translator} | ||
|
||
import scala.collection.mutable | ||
class DebugParser extends FastParser { | ||
|
||
def versionedIdentifier[$: P]: P[Unit] = CharIn("A-Z", "a-z", "$_") ~~ CharIn("0-9", "A-Z", "a-z", "$_").repX ~~ CharIn("@") ~~ CharIn("0-9") ~~ CharIn("0-9").repX | ||
|
||
def versionedIdent[$: P]: P[String] = versionedIdentifier.!.opaque("versionedIdentifier") | ||
|
||
def versionedidnuse[$: P]: P[PVersionedIdnUse] = FP(versionedIdent).map { case (pos, id) => | ||
val parts = id.split("@") | ||
PVersionedIdnUse(name = parts(0), version = parts(1))(pos) | ||
} | ||
|
||
def debugOldLabel[$: P]: P[String] = (StringIn("line") ~~ CharIn("@") ~~ CharIn("0-9", "A-Z", "a-z", "$_.").repX).!.opaque("debugOldLabel") | ||
|
||
def debugOldLabelUse[$: P]: P[PVersionedIdnUse] = FP(debugOldLabel).map { case (pos, id) => | ||
val parts = id.split("@") | ||
PVersionedIdnUse(name = parts(0), version = parts(1))(pos) | ||
} | ||
|
||
def debugOld[$: P]: P[PExp] = P(StringIn("old") ~ FP("[" ~ debugOldLabelUse ~ "](" ~ exp ~ ")").map { | ||
case (pos, (a, b)) => PDebugLabelledOld(a, b)(pos) | ||
}) | ||
|
||
override def atom(implicit ctx: P[_]): P[PExp] = // TODO ake: | ||
P(ParserExtension.newExpAtStart(ctx) | versionedidnuse | ||
| debugOld | ||
| annotatedAtom | ||
| integer | booltrue | boolfalse | nul | old | ||
| result | unExp | typedFuncApp | ||
| "(" ~ exp ~ ")" | accessPred | inhaleExhale | perm | let | quant | forperm | unfolding | applying | ||
| setTypedEmpty | explicitSetNonEmpty | multiSetTypedEmpty | explicitMultisetNonEmpty | seqTypedEmpty | ||
| size | explicitSeqNonEmpty | seqRange | ||
| mapTypedEmpty | explicitMapNonEmpty | mapDomain | mapRange | ||
| newExp | funcApp | idnuse | ParserExtension.newExpAtEnd(ctx)) | ||
} | ||
|
||
|
||
class DebugTranslator(p: PProgram, override val members: mutable.Map[String, Node]) extends Translator(p) { | ||
|
||
override protected def expInternal(pexp: PExp, pos: PExp, info: Info): Exp = { | ||
pexp match { | ||
case pviu@PVersionedIdnUse(_, _, _) => | ||
pexp.typ match { | ||
case null => sys.error("should not occur in type-checked program") | ||
case _ => LocalVarWithVersion(pviu.versionedName, ttyp(pexp.typ))(pos, info) | ||
} | ||
case PDebugLabelledOld(lbl, e) => | ||
DebugLabelledOld(exp(e), lbl.versionedName)(pos, info) | ||
case _ => super.expInternal(pexp, pos, info) | ||
} | ||
} | ||
|
||
} |
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,14 +1,37 @@ | ||
package debugger | ||
|
||
import viper.silver.parser.{NameAnalyser, PProgram, Resolver, TypeChecker} | ||
import viper.silver.FastMessaging | ||
import viper.silver.parser.{NameAnalyser, PAnyVarDecl, PExp, PProgram, PType, PVersionedIdnUse, Resolver, TypeChecker} | ||
|
||
import scala.reflect.ClassTag | ||
|
||
class DebugResolver(override val p: PProgram) extends Resolver(p){ | ||
override val typechecker: TypeChecker = new DebugTypeChecker(names) | ||
|
||
class DebugResolver(override val p: PProgram, names: NameAnalyser) extends Resolver(p){ | ||
override val typechecker: DebugTypeChecker = new DebugTypeChecker(names) | ||
} | ||
|
||
class DebugTypeChecker(override val names: NameAnalyser) extends TypeChecker(names) { | ||
var debugVariableTypes: Map[String, PType] = Map.empty | ||
|
||
override def checkInternal(exp: PExp): Unit = { | ||
exp match { | ||
case pviu: PVersionedIdnUse => | ||
acceptAndCheckTypedEntityWithVersion[PAnyVarDecl, Nothing](Seq(pviu), "expected variable identifier with version") | ||
case _ => super.checkInternal(exp) | ||
} | ||
} | ||
|
||
def acceptAndCheckTypedEntityWithVersion[T1: ClassTag, T2: ClassTag] | ||
(idnUses: Seq[PVersionedIdnUse], errorMessage: => String): Unit = { | ||
|
||
idnUses.foreach { use => | ||
val decl1 = debugVariableTypes.get(use.versionedName) | ||
|
||
decl1 match { | ||
case Some(value) => use.typ = value | ||
case None => messages ++= FastMessaging.message(use, errorMessage) | ||
} | ||
} | ||
} | ||
|
||
} |
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