Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
63f7d6fb
Commit
63f7d6fb
authored
9 years ago
by
Mikaël Mayer
Browse files
Options
Downloads
Patches
Plain Diff
Added comments for the whole Expressions.scala + some ExprOps.scala
parent
b1416b57
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/leon/purescala/ExprOps.scala
+40
-0
40 additions, 0 deletions
src/main/scala/leon/purescala/ExprOps.scala
src/main/scala/leon/purescala/Expressions.scala
+215
-39
215 additions, 39 deletions
src/main/scala/leon/purescala/Expressions.scala
with
255 additions
and
39 deletions
src/main/scala/leon/purescala/ExprOps.scala
+
40
−
0
View file @
63f7d6fb
...
...
@@ -1647,6 +1647,16 @@ object ExprOps {
* =================
*/
/** Replaces the precondition of an existing [[Expressions.Expr]] with a new one.
*
* If no precondition is provided, removes any existing precondition.
* Else, wraps the expression with a [[Expressions.Require]] clause referring to the new precondition.
*
* @param expr The current expression
* @param pred An optional precondition. Setting it to None removes any precondition.
* @see [[Expressions.Ensuring]]
* @see [[Expressions.Require]]
*/
def
withPrecondition
(
expr
:
Expr
,
pred
:
Option
[
Expr
])
:
Expr
=
(
pred
,
expr
)
match
{
case
(
Some
(
newPre
),
Require
(
pre
,
b
))
=>
Require
(
newPre
,
b
)
case
(
Some
(
newPre
),
Ensuring
(
Require
(
pre
,
b
),
p
))
=>
Ensuring
(
Require
(
newPre
,
b
),
p
)
...
...
@@ -1657,6 +1667,16 @@ object ExprOps {
case
(
None
,
b
)
=>
b
}
/** Replaces the postcondition of an existing [[Expressions.Expr]] with a new one.
*
* If no postcondition is provided, removes any existing postcondition.
* Else, wraps the expression with a [[Expressions.Ensuring]] clause referring to the new postcondition.
*
* @param expr The current expression
* @param pred An optional postcondition. Setting it to None removes any postcondition.
* @see [[Expressions.Ensuring]]
* @see [[Expressions.Require]]
*/
def
withPostcondition
(
expr
:
Expr
,
oie
:
Option
[
Expr
])
=
(
oie
,
expr
)
match
{
case
(
Some
(
npost
),
Ensuring
(
b
,
post
))
=>
Ensuring
(
b
,
npost
)
case
(
Some
(
npost
),
b
)
=>
Ensuring
(
b
,
npost
)
...
...
@@ -1664,6 +1684,14 @@ object ExprOps {
case
(
None
,
b
)
=>
b
}
/** Adds a body to a specification
*
* @param expr The specification expression [[Expressions.Ensuring]] or [[Expressions.Require]]. If none of these, the argument is discarded.
* @param body An option of [[Expressions.Expr]] possibly containing an expression body.
* @return The post/pre condition with the body. If no body is provided, returns [[Expressions.NoTree]]
* @see [[Expressions.Ensuring]]
* @see [[Expressions.Require]]
*/
def
withBody
(
expr
:
Expr
,
body
:
Option
[
Expr
])
=
expr
match
{
case
Require
(
pre
,
_
)
=>
Require
(
pre
,
body
.
getOrElse
(
NoTree
(
expr
.
getType
)))
case
Ensuring
(
Require
(
pre
,
_
),
post
)
=>
Ensuring
(
Require
(
pre
,
body
.
getOrElse
(
NoTree
(
expr
.
getType
))),
post
)
...
...
@@ -1671,6 +1699,15 @@ object ExprOps {
case
_
=>
body
.
getOrElse
(
NoTree
(
expr
.
getType
))
}
/** Extracts the body without its specification
*
* [[Expressions.Expr]] trees contain its specifications as part of certain nodes.
* This function helps extracting only the body part of an expression
*
* @return An option type with the resulting expression if not [[Expressions.NoTree]]
* @see [[Expressions.Ensuring]]
* @see [[Expressions.Require]]
*/
def
withoutSpec
(
expr
:
Expr
)
=
expr
match
{
case
Require
(
pre
,
b
)
=>
Option
(
b
).
filterNot
(
_
.
isInstanceOf
[
NoTree
])
case
Ensuring
(
Require
(
pre
,
b
),
post
)
=>
Option
(
b
).
filterNot
(
_
.
isInstanceOf
[
NoTree
])
...
...
@@ -1678,17 +1715,20 @@ object ExprOps {
case
b
=>
Option
(
b
).
filterNot
(
_
.
isInstanceOf
[
NoTree
])
}
/** Returns the precondition of an expression wrapped in Option */
def
preconditionOf
(
expr
:
Expr
)
=
expr
match
{
case
Require
(
pre
,
_
)
=>
Some
(
pre
)
case
Ensuring
(
Require
(
pre
,
_
),
_
)
=>
Some
(
pre
)
case
b
=>
None
}
/** Returns the postcondition of an expression wrapped in Option */
def
postconditionOf
(
expr
:
Expr
)
=
expr
match
{
case
Ensuring
(
_
,
post
)
=>
Some
(
post
)
case
_
=>
None
}
/** Returns a tuple of precondition, the raw body and the postcondition of an expression */
def
breakDownSpecs
(
e
:
Expr
)
=
(
preconditionOf
(
e
),
withoutSpec
(
e
),
postconditionOf
(
e
))
def
preTraversalWithParent
(
f
:
(
Expr
,
Option
[
Tree
])
=>
Unit
,
initParent
:
Option
[
Tree
]
=
None
)(
e
:
Expr
)
:
Unit
=
{
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/purescala/Expressions.scala
+
215
−
39
View file @
63f7d6fb
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment