Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcp19 committed Nov 28, 2023
1 parent 3ee6911 commit a356557
Show file tree
Hide file tree
Showing 12 changed files with 3,746 additions and 3,588 deletions.
3 changes: 3 additions & 0 deletions src/main/antlr4/GobraLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ PROOF : 'proof';
GHOST_EQUALS : '===';
GHOST_NOT_EQUALS : '!==';
WITH : 'with';
EXHALEMODE : 'exhaleMode' -> mode(NLSEMI);
MCE : 'mce';
STRICT : 'strict';
7 changes: 6 additions & 1 deletion src/main/antlr4/GobraParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ sqType: (kind=(SEQ | SET | MSET | OPT) L_BRACKET type_ R_BRACKET)
// Specifications

specification returns[boolean trusted = false, boolean pure = false;]:
((specStatement | PURE {$pure = true;} | TRUSTED {$trusted = true;}) eos)*? (PURE {$pure = true;})? // Non-greedily match PURE to avoid missing eos errors.
((specStatement | PURE {$pure = true;} | (EXHALEMODE L_PAREN exhaleMode R_PAREN) | TRUSTED {$trusted = true;}) eos)*? (PURE {$pure = true;})? // Non-greedily match PURE to avoid missing eos errors.
;

exhaleMode
: MCE
| STRICT
;

specStatement
Expand Down
2,164 changes: 1,092 additions & 1,072 deletions src/main/java/viper/gobra/frontend/GobraLexer.java

Large diffs are not rendered by default.

5,091 changes: 2,591 additions & 2,500 deletions src/main/java/viper/gobra/frontend/GobraParser.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from src/main/antlr4/GobraParser.g4 by ANTLR 4.13.0
// Generated from /Users/joao/code/gobra/src/main/antlr4/GobraParser.g4 by ANTLR 4.13.1
package viper.gobra.frontend;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;

Expand Down Expand Up @@ -376,6 +376,13 @@ public class GobraParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitSpecification(GobraParser.SpecificationContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExhaleMode(GobraParser.ExhaleModeContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/viper/gobra/frontend/GobraParserVisitor.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from src/main/antlr4/GobraParser.g4 by ANTLR 4.13.0
// Generated from /Users/joao/code/gobra/src/main/antlr4/GobraParser.g4 by ANTLR 4.13.1
package viper.gobra.frontend;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;

Expand Down Expand Up @@ -326,6 +326,12 @@ public interface GobraParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitSpecification(GobraParser.SpecificationContext ctx);
/**
* Visit a parse tree produced by {@link GobraParser#exhaleMode}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExhaleMode(GobraParser.ExhaleModeContext ctx);
/**
* Visit a parse tree produced by {@link GobraParser#specStatement}.
* @param ctx the parse tree
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/viper/gobra/ast/frontend/Ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -876,13 +876,18 @@ case class PTupleTerminationMeasure(tuple: Vector[PExpression], cond: Option[PEx

sealed trait PSpecification extends PGhostNode

sealed trait PExhaleMode extends PNode
case object PStrict extends PExhaleMode
case object PMce extends PExhaleMode

case class PFunctionSpec(
pres: Vector[PExpression],
preserves: Vector[PExpression],
posts: Vector[PExpression],
terminationMeasures: Vector[PTerminationMeasure],
exhaleMode: Vector[PExhaleMode],
isPure: Boolean = false,
isTrusted: Boolean = false
isTrusted: Boolean = false,
) extends PSpecification

case class PBodyParameterInfo(
Expand Down
14 changes: 10 additions & 4 deletions src/main/scala/viper/gobra/ast/frontend/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,20 @@ class DefaultPrettyPrinter extends PrettyPrinter with kiama.output.PrettyPrinter
"decreases" <+> measureDoc(measure)
}

def showExhaleMode(mode: PExhaleMode): Doc = mode match {
case PStrict => "strict"
case PMce => "mce"
}

def showSpec(spec: PSpecification): Doc = spec match {
case PFunctionSpec(pres, preserves, posts, measures, isPure, isTrusted) =>
case PFunctionSpec(pres, preserves, posts, measures, exhaleMode, isPure, isTrusted) =>
(if (isPure) showPure else emptyDoc) <>
(if (isTrusted) showTrusted else emptyDoc) <>
hcat(pres map (showPre(_) <> line)) <>
hcat(preserves map (showPreserves(_) <> line)) <>
hcat(posts map (showPost(_) <> line)) <>
hcat(measures map (showTerminationMeasure(_) <> line))
hcat(preserves map (showPreserves(_) <> line)) <>
hcat(posts map (showPost(_) <> line)) <>
hcat(measures map (showTerminationMeasure(_) <> line)) <>
hcat(exhaleMode map (showExhaleMode(_) <> line))

case PLoopSpec(inv, measure) =>
hcat(inv map (showInv(_) <> line)) <> opt(measure)(showTerminationMeasure) <> line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ class ParseTreeTranslator(pom: PositionManager, source: Source, specOnly : Boole
*/
override def visitMethodSpec(ctx: GobraParser.MethodSpecContext): PMethodSig = {
val ghost = has(ctx.GHOST())
val spec = if (ctx.specification() != null) visitSpecification(ctx.specification()) else PFunctionSpec(Vector.empty,Vector.empty,Vector.empty, Vector.empty).at(ctx)
val spec =
if (ctx.specification() != null)
visitSpecification(ctx.specification())
else
PFunctionSpec(Vector.empty,Vector.empty,Vector.empty, Vector.empty, Vector.empty).at(ctx)
// The name of each explicitly specified method must be unique and not blank.
val id = idnDef.get(ctx.IDENTIFIER())
val args = visitNode[Vector[Vector[PParameter]]](ctx.parameters())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GhostLessPrinter(classifier: GhostClassifier) extends DefaultPrettyPrinter
rec,
filterParamList(args),
filterResult(res),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty, Vector.empty),
body.map( b => (PBodyParameterInfo(Vector.empty), b._2) )
)
)
Expand All @@ -32,7 +32,7 @@ class GhostLessPrinter(classifier: GhostClassifier) extends DefaultPrettyPrinter
id,
filterParamList(args),
filterResult(res),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty, Vector.empty),
body.map( b => (PBodyParameterInfo(Vector.empty), b._2) )
)
)
Expand Down Expand Up @@ -170,7 +170,7 @@ class GhostLessPrinter(classifier: GhostClassifier) extends DefaultPrettyPrinter
case PFunctionLit(_, PClosureDecl(args, result, _, body)) => super.showMisc(PClosureDecl(
filterParamList(args),
filterResult(result),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty, Vector.empty),
body.map( b => (PBodyParameterInfo(Vector.empty), b._2) )
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ class GoifyingPrinter(info: TypeInfoImpl) extends DefaultPrettyPrinter {
* Shows the Goified version of the function / method specification
*/
override def showSpec(spec: PSpecification): Doc = spec match {
case PFunctionSpec(pres, preserves, posts, measures, isPure, isTrusted) =>
case PFunctionSpec(pres, preserves, posts, measures, exhaleMode, isPure, isTrusted) =>
(if (isPure) specComment <+> showPure else emptyDoc) <>
(if (isTrusted) specComment <+> showTrusted else emptyDoc) <>
hcat(pres map (p => specComment <+> showPre(p) <> line)) <>
hcat(preserves map (p => specComment <+> showPreserves(p) <> line)) <>
hcat(posts map (p => specComment <+> showPost(p) <> line)) <>
hcat(measures map (p => specComment <+> showTerminationMeasure(p) <> line))
hcat(measures map (p => specComment <+> showTerminationMeasure(p) <> line)) <>
hcat(exhaleMode map (p => specComment <+> showExhaleMode(p) <> line))

case PLoopSpec(inv, measure) =>
hcat(inv map (p => specComment <+> showInv(p) <> line)) <>
Expand Down Expand Up @@ -124,7 +125,7 @@ class GoifyingPrinter(info: TypeInfoImpl) extends DefaultPrettyPrinter {
rec,
getActualParams(args),
getActualResult(res),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty, Vector.empty),
body
)
)
Expand All @@ -136,7 +137,7 @@ class GoifyingPrinter(info: TypeInfoImpl) extends DefaultPrettyPrinter {
id,
getActualParams(args),
getActualResult(res),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty),
PFunctionSpec(Vector.empty, Vector.empty, Vector.empty, Vector.empty, Vector.empty),
body
)
)
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/regressions/features/mce/mce-success1.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package pkg

requires true
exhaleMode(strict)
func f(x, y *int) {

}

0 comments on commit a356557

Please sign in to comment.