This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
forked from mitchellh/go-z3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast_arith.go
105 lines (93 loc) · 1.99 KB
/
ast_arith.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package z3
import (
"unsafe"
)
// #include "go-z3.h"
import "C"
// Add creates an AST node representing adding.
//
// All AST values must be part of the same context.
func (a *AST) Add(args ...*AST) *AST {
raws := make([]C.Z3_ast, len(args)+1)
raws[0] = a.rawAST
for i, arg := range args {
raws[i+1] = arg.rawAST
}
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_add(
a.rawCtx,
C.uint(len(raws)),
(*C.Z3_ast)(unsafe.Pointer(&raws[0]))),
}
}
// Mul creates an AST node representing multiplication.
//
// All AST values must be part of the same context.
func (a *AST) Mul(args ...*AST) *AST {
raws := make([]C.Z3_ast, len(args)+1)
raws[0] = a.rawAST
for i, arg := range args {
raws[i+1] = arg.rawAST
}
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_mul(
a.rawCtx,
C.uint(len(raws)),
(*C.Z3_ast)(unsafe.Pointer(&raws[0]))),
}
}
// Sub creates an AST node representing subtraction.
//
// All AST values must be part of the same context.
func (a *AST) Sub(args ...*AST) *AST {
raws := make([]C.Z3_ast, len(args)+1)
raws[0] = a.rawAST
for i, arg := range args {
raws[i+1] = arg.rawAST
}
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_sub(
a.rawCtx,
C.uint(len(raws)),
(*C.Z3_ast)(unsafe.Pointer(&raws[0]))),
}
}
// Lt creates a "less than" comparison.
//
// Maps to: Z3_mk_lt
func (a *AST) Lt(a2 *AST) *AST {
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_lt(a.rawCtx, a.rawAST, a2.rawAST),
}
}
// Le creates a "less than" comparison.
//
// Maps to: Z3_mk_le
func (a *AST) Le(a2 *AST) *AST {
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_le(a.rawCtx, a.rawAST, a2.rawAST),
}
}
// Gt creates a "greater than" comparison.
//
// Maps to: Z3_mk_gt
func (a *AST) Gt(a2 *AST) *AST {
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_gt(a.rawCtx, a.rawAST, a2.rawAST),
}
}
// Ge creates a "less than" comparison.
//
// Maps to: Z3_mk_ge
func (a *AST) Ge(a2 *AST) *AST {
return &AST{
rawCtx: a.rawCtx,
rawAST: C.Z3_mk_ge(a.rawCtx, a.rawAST, a2.rawAST),
}
}