|
6 | 6 |
|
7 | 7 | package viper.silicon |
8 | 8 |
|
9 | | -import scala.annotation.implicitNotFound |
10 | | -import scala.collection.immutable.ArraySeq |
| 9 | +import viper.silicon.state.terms._ |
| 10 | +import viper.silicon.verifier.Verifier |
11 | 11 | import viper.silver |
| 12 | +import viper.silver.ast.utility.Triggers.TriggerGenerationWithAddAndSubtract |
| 13 | +import viper.silver.ast.utility.rewriter.Traverse |
| 14 | +import viper.silver.ast.SourcePNodeInfo |
12 | 15 | import viper.silver.components.StatefulComponent |
13 | | -import viper.silver.verifier.{VerificationError, errors} |
| 16 | +import viper.silver.parser.{PExp, PType, PUnknown, PUnnamedTypedDeclaration} |
14 | 17 | import viper.silver.verifier.errors.Internal |
15 | 18 | import viper.silver.verifier.reasons.{FeatureUnsupported, UnexpectedNode} |
16 | | -import viper.silver.ast.utility.rewriter.Traverse |
17 | | -import viper.silicon.state.terms.{Sort, Term, Var} |
18 | | -import viper.silicon.verifier.Verifier |
19 | | -import viper.silver.ast.utility.Triggers.TriggerGenerationWithAddAndSubtract |
| 19 | +import viper.silver.verifier.{VerificationError, errors} |
| 20 | + |
| 21 | +import scala.annotation.implicitNotFound |
| 22 | +import scala.collection.immutable.ArraySeq |
20 | 23 |
|
21 | 24 | package object utils { |
22 | | - def freshSnap: (Sort, Verifier) => Var = (sort, v) => v.decider.fresh(sort) |
| 25 | + def freshSnap: (Sort, Verifier) => Var = (sort, v) => v.decider.fresh(sort, Option.when(Verifier.config.enableDebugging())(PUnknown())) |
23 | 26 | def toSf(t: Term): (Sort, Verifier) => Term = (sort, _) => t.convert(sort) |
24 | 27 |
|
25 | 28 | def mapReduceLeft[E](it: Iterable[E], f: E => E, op: (E, E) => E, unit: E): E = |
@@ -131,6 +134,59 @@ package object utils { |
131 | 134 | (e0: silver.ast.Exp, e1: silver.ast.Exp) => silver.ast.Or(e0, e1)(e0.pos, e0.info), |
132 | 135 | silver.ast.FalseLit()(emptyPos)) |
133 | 136 |
|
| 137 | + def removeKnownToBeTrueExp(exps: List[silver.ast.Exp], terms: List[Term]): List[silver.ast.Exp] = { |
| 138 | + exps.zip(terms).filter(t => t._2 != True).map(e => e._1) |
| 139 | + } |
| 140 | + |
| 141 | + def simplifyVariableName(str: String) : String = { |
| 142 | + str.substring(0, str.lastIndexOf("@")) |
| 143 | + } |
| 144 | + |
| 145 | + def replaceVarsInExp(e: silver.ast.Exp, varNames: Seq[String], replacements: Seq[silver.ast.Exp]): silver.ast.Exp = { |
| 146 | + silver.utility.Sanitizer.replaceFreeVariablesInExpression(e, varNames.zip(replacements).toMap, Set()) |
| 147 | + } |
| 148 | + |
| 149 | + def extractPTypeFromStmt(stmt: silver.ast.Stmt): PType = { |
| 150 | + stmt.info.getUniqueInfo[SourcePNodeInfo] match { |
| 151 | + case Some(info) => |
| 152 | + val sourceNode = info.sourcePNode |
| 153 | + sourceNode match { |
| 154 | + case decl: PUnnamedTypedDeclaration => decl.typ |
| 155 | + case _ => PUnknown() |
| 156 | + } |
| 157 | + case _ => PUnknown() |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + def extractPTypeFromExp(exp: silver.ast.Exp): PType = { |
| 162 | + exp.info.getUniqueInfo[SourcePNodeInfo] match { |
| 163 | + case Some(info) => |
| 164 | + val sourceNode = info.sourcePNode |
| 165 | + sourceNode match { |
| 166 | + case e: PExp => e.typ |
| 167 | + case d: PUnnamedTypedDeclaration => d.typ |
| 168 | + case _ => PUnknown() |
| 169 | + } |
| 170 | + case _ => PUnknown() |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + def buildMinExp(exps: Seq[silver.ast.Exp], typ: silver.ast.Type): silver.ast.Exp = { |
| 175 | + exps match { |
| 176 | + case Seq(e) => e |
| 177 | + case Seq(e0, e1) => silver.ast.DebugPermMin(e0, e1)(e0.pos, e0.info) |
| 178 | + case exps if exps.length > 2 => silver.ast.DebugPermMin(exps.head, buildMinExp(exps.tail, typ))(exps.head.pos, exps.head.info) |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + def buildQuantExp(quantifier: Quantifier, vars: Seq[silver.ast.LocalVarDecl], eBody: silver.ast.Exp, eTrigger: Seq[silver.ast.Trigger]): silver.ast.Exp = { |
| 183 | + quantifier match { |
| 184 | + case Forall => silver.ast.Forall(vars, eTrigger, eBody)(eBody.pos, eBody.info, eBody.errT) |
| 185 | + case Exists => silver.ast.Exists(vars, eTrigger, eBody)(eBody.pos, eBody.info, eBody.errT) |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + |
134 | 190 | /** Note: be aware of Silver issue #95!*/ |
135 | 191 | def rewriteRangeContains(program: silver.ast.Program): silver.ast.Program = |
136 | 192 | program.transform({ |
@@ -211,7 +267,7 @@ package object utils { |
211 | 267 | def toUnambiguousShortString(resource: silver.ast.Resource): String = { |
212 | 268 | resource match { |
213 | 269 | case l: silver.ast.Location => l.name |
214 | | - case m: silver.ast.MagicWand => m.toString() |
| 270 | + case m: silver.ast.MagicWand => m.toString |
215 | 271 | case m@silver.ast.MagicWandOp => s"${silver.ast.MagicWandOp.op}@${sourceLineColumn(m)}" |
216 | 272 | } |
217 | 273 | } |
|
0 commit comments