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
8145b1c2
Commit
8145b1c2
authored
8 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
SMTLIBCVC4Target
parent
b7493d67
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/inox/solvers/smtlib/SMTLIBCVC4Target.scala
+41
-58
41 additions, 58 deletions
src/main/scala/inox/solvers/smtlib/SMTLIBCVC4Target.scala
with
41 additions
and
58 deletions
src/main/scala/inox/solvers/smtlib/SMTLIBCVC4Target.scala
+
41
−
58
View file @
8145b1c2
/* Copyright 2009-2016 EPFL, Lausanne */
package
leon
package
inox
package
solvers
package
smtlib
import
purescala.Common._
import
purescala.Expressions._
import
purescala.Constructors._
import
purescala.Extractors._
import
purescala.Types._
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.apache.commons.lang3.StringEscapeUtils
import
_root_.smtlib.parser.Terms.
{
Identifier
=>
SMTIdentifier
,
Forall
=>
SMTForall
,
_
}
import
_root_.smtlib.parser.Commands._
...
...
@@ -19,15 +13,18 @@ import _root_.smtlib.theories.experimental.Sets
import
_root_.smtlib.theories.experimental.Strings
trait
SMTLIBCVC4Target
extends
SMTLIBTarget
{
import
program._
import
trees._
import
symbols._
override
def
getNewInterpreter
(
ctx
:
Leon
Context
)
=
{
override
def
getNewInterpreter
(
ctx
:
Inox
Context
)
=
{
val
opts
=
interpreterOps
(
ctx
)
c
ontex
t
.
reporter
.
debug
(
"Invoking solver with "
+
opts
.
mkString
(
" "
))
ct
x
.
reporter
.
debug
(
"Invoking solver with "
+
opts
.
mkString
(
" "
))
new
CVC4Interpreter
(
"cvc4"
,
opts
.
toArray
)
}
override
protected
def
declareSort
(
t
:
Type
Tree
)
:
Sort
=
{
override
protected
def
declareSort
(
t
:
Type
)
:
Sort
=
{
val
tpe
=
normalizeType
(
t
)
sorts
.
cachedB
(
tpe
)
{
tpe
match
{
...
...
@@ -40,63 +37,62 @@ trait SMTLIBCVC4Target extends SMTLIBTarget {
}
}
override
protected
def
fromSMT
(
t
:
Term
,
otpe
:
Option
[
Type
Tree
]
=
None
)
override
protected
def
fromSMT
(
t
:
Term
,
otpe
:
Option
[
Type
]
=
None
)
(
implicit
lets
:
Map
[
SSymbol
,
Term
],
letDefs
:
Map
[
SSymbol
,
DefineFun
])
:
Expr
=
{
(
t
,
otpe
)
match
{
// EK: This hack is necessary for sygus which does not strictly follow smt-lib for negative literals
case
(
SimpleSymbol
(
SSymbol
(
v
)),
Some
(
IntegerType
))
if
v
.
startsWith
(
"-"
)
=>
try
{
Infinite
IntegerLiteral
(
v
.
toInt
)
IntegerLiteral
(
v
.
toInt
)
}
catch
{
case
_:
Throwable
=>
super
.
fromSMT
(
t
,
otpe
)
}
case
(
QualifiedIdentifier
(
SMTIdentifier
(
SSymbol
(
"emptyset"
),
Seq
()),
_
),
Some
(
SetType
(
base
)))
=>
FiniteSet
(
Se
t
(),
base
)
FiniteSet
(
Se
q
(),
base
)
case
(
FunctionApplication
(
QualifiedIdentifier
(
SMTIdentifier
(
SSymbol
(
"const"
),
_
),
_
),
Seq
(
elem
)),
Some
(
tpe
))
=>
tpe
match
{
case
RawArrayType
(
k
,
v
)
=>
RawArrayValue
(
k
,
Map
(),
fromSMT
(
elem
,
v
))
case
ft
@
FunctionType
(
from
,
to
)
=>
F
initeLambda
(
Seq
.
empty
,
fromSMT
(
elem
,
to
),
ft
)
f
initeLambda
(
Seq
.
empty
,
fromSMT
(
elem
,
to
),
ft
)
case
MapType
(
k
,
v
)
=>
FiniteMap
(
Map
(),
k
,
v
)
FiniteMap
(
Seq
(),
fromSMT
(
elem
,
v
),
k
)
}
case
(
FunctionApplication
(
SimpleSymbol
(
SSymbol
(
"__array_store_all__"
)),
Seq
(
_
,
elem
)),
Some
(
tpe
))
=>
tpe
match
{
case
RawArrayType
(
k
,
v
)
=>
RawArrayValue
(
k
,
Map
(),
fromSMT
(
elem
,
v
))
case
ft
@
FunctionType
(
from
,
to
)
=>
F
initeLambda
(
Seq
.
empty
,
fromSMT
(
elem
,
to
),
ft
)
f
initeLambda
(
Seq
.
empty
,
fromSMT
(
elem
,
to
),
ft
)
case
MapType
(
k
,
v
)
=>
FiniteMap
(
Map
(),
k
,
v
)
FiniteMap
(
Seq
(),
fromSMT
(
elem
,
v
),
k
)
}
case
(
FunctionApplication
(
SimpleSymbol
(
SSymbol
(
"store"
)),
Seq
(
arr
,
key
,
elem
)),
Some
(
tpe
))
=>
tpe
match
{
case
RawArrayType
(
_
,
v
)
=>
val
RawArrayValue
(
k
,
elems
,
base
)
=
fromSMT
(
arr
,
otpe
)
RawArrayValue
(
k
,
elems
+
(
fromSMT
(
key
,
k
)
->
fromSMT
(
elem
,
v
)),
base
)
case
FunctionType
(
from
,
v
)
=>
val
FiniteLambda
(
mapping
,
dflt
,
ft
)
=
fromSMT
(
arr
,
otpe
)
val
args
=
unwrapTuple
(
fromSMT
(
key
,
tupleTypeWrap
(
from
)),
from
.
size
)
FiniteLambda
(
mapping
:+
(
args
->
fromSMT
(
elem
,
v
)),
dflt
,
ft
)
case
MapType
(
k
,
v
)
=>
val
FiniteMap
(
elems
,
k
,
v
)
=
fromSMT
(
arr
,
otpe
)
FiniteMap
(
elems
+
(
fromSMT
(
key
,
k
)
->
fromSMT
(
elem
,
v
)),
k
,
v
)
val
Lambda
(
args
,
bd
)
=
fromSMT
(
arr
,
otpe
)
Lambda
(
args
,
IfExpr
(
Equals
(
tupleWrap
(
args
.
map
(
_
.
toVariable
)),
fromSMT
(
key
,
tupleTypeWrap
(
from
))
),
fromSMT
(
elem
,
v
),
bd
))
case
MapType
(
kT
,
vT
)
=>
val
FiniteMap
(
elems
,
default
,
_
)
=
fromSMT
(
arr
,
otpe
)
val
newKey
=
fromSMT
(
key
,
kT
)
val
newV
=
fromSMT
(
elem
,
vT
)
val
newElems
=
elems
.
filterNot
(
_
.
_1
==
newKey
)
:+
(
newKey
->
newV
)
FiniteMap
(
newElems
,
default
,
kT
)
}
case
(
FunctionApplication
(
SimpleSymbol
(
SSymbol
(
"singleton"
)),
elems
),
Some
(
SetType
(
base
)))
=>
FiniteSet
(
elems
.
map
(
fromSMT
(
_
,
base
))
.
toSet
,
base
)
FiniteSet
(
elems
.
map
(
fromSMT
(
_
,
base
)),
base
)
case
(
FunctionApplication
(
SimpleSymbol
(
SSymbol
(
"insert"
)),
elems
),
Some
(
SetType
(
base
)))
=>
val
selems
=
elems
.
init
.
map
(
fromSMT
(
_
,
base
))
...
...
@@ -106,18 +102,14 @@ trait SMTLIBCVC4Target extends SMTLIBTarget {
case
(
FunctionApplication
(
SimpleSymbol
(
SSymbol
(
"union"
)),
elems
),
Some
(
SetType
(
base
)))
=>
FiniteSet
(
elems
.
flatMap
(
fromSMT
(
_
,
otpe
)
match
{
case
FiniteSet
(
elems
,
_
)
=>
elems
})
.
toSet
,
base
)
}),
base
)
case
(
SString
(
v
),
Some
(
StringType
))
=>
StringLiteral
(
StringEscapeUtils
.
unescapeJava
(
v
))
case
(
Strings
.
Length
(
a
),
Some
(
Int32Type
))
=>
val
aa
=
fromSMT
(
a
)
StringLength
(
aa
)
case
(
Strings
.
Length
(
a
),
Some
(
IntegerType
))
=>
val
aa
=
fromSMT
(
a
)
String
Big
Length
(
aa
)
StringLength
(
aa
)
case
(
Strings
.
Concat
(
a
,
b
,
c
@
_
*),
_
)
=>
val
aa
=
fromSMT
(
a
)
...
...
@@ -131,14 +123,9 @@ trait SMTLIBCVC4Target extends SMTLIBTarget {
val
tt
=
fromSMT
(
start
)
val
oo
=
fromSMT
(
offset
)
oo
match
{
case
BVMinus
(
otherEnd
,
`tt`
)
=>
SubString
(
ss
,
tt
,
otherEnd
)
case
Minus
(
otherEnd
,
`tt`
)
=>
BigSubString
(
ss
,
tt
,
otherEnd
)
case
_
=>
if
(
tt
.
getType
==
IntegerType
)
{
BigSubString
(
ss
,
tt
,
Plus
(
tt
,
oo
))
}
else
{
SubString
(
ss
,
tt
,
BVPlus
(
tt
,
oo
))
}
case
Minus
(
otherEnd
,
`tt`
)
=>
SubString
(
ss
,
tt
,
otherEnd
)
case
_
=>
SubString
(
ss
,
tt
,
Plus
(
tt
,
oo
))
}
case
(
Strings
.
At
(
a
,
b
),
_
)
=>
fromSMT
(
Strings
.
Substring
(
a
,
b
,
SNumeral
(
1
)))
...
...
@@ -156,7 +143,7 @@ trait SMTLIBCVC4Target extends SMTLIBTarget {
if
(
elems
.
isEmpty
)
{
Sets
.
EmptySet
(
declareSort
(
fs
.
getType
))
}
else
{
val
selems
=
elems
.
toSeq
.
map
(
toSMT
)
val
selems
=
elems
.
map
(
toSMT
)
val
sgt
=
Sets
.
Singleton
(
selems
.
head
)
...
...
@@ -176,14 +163,10 @@ trait SMTLIBCVC4Target extends SMTLIBTarget {
declareSort
(
StringType
)
Strings
.
StringLit
(
StringEscapeUtils
.
escapeJava
(
v
))
case
StringLength
(
a
)
=>
Strings
.
Length
(
toSMT
(
a
))
case
StringBigLength
(
a
)
=>
Strings
.
Length
(
toSMT
(
a
))
case
StringConcat
(
a
,
b
)
=>
Strings
.
Concat
(
toSMT
(
a
),
toSMT
(
b
))
case
SubString
(
a
,
start
,
BVPlus
(
start2
,
length
))
if
start
==
start2
=>
Strings
.
Substring
(
toSMT
(
a
),
toSMT
(
start
),
toSMT
(
length
))
case
SubString
(
a
,
start
,
end
)
=>
Strings
.
Substring
(
toSMT
(
a
),
toSMT
(
start
),
toSMT
(
BVMinus
(
end
,
start
)))
case
BigSubString
(
a
,
start
,
Plus
(
start2
,
length
))
if
start
==
start2
=>
case
SubString
(
a
,
start
,
Plus
(
start2
,
length
))
if
start
==
start2
=>
Strings
.
Substring
(
toSMT
(
a
),
toSMT
(
start
),
toSMT
(
length
))
case
Big
SubString
(
a
,
start
,
end
)
=>
Strings
.
Substring
(
toSMT
(
a
),
toSMT
(
start
),
toSMT
(
Minus
(
end
,
start
)))
case
SubString
(
a
,
start
,
end
)
=>
Strings
.
Substring
(
toSMT
(
a
),
toSMT
(
start
),
toSMT
(
Minus
(
end
,
start
)))
case
_
=>
super
.
toSMT
(
e
)
}
...
...
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