This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsymbol.go
58 lines (49 loc) · 1.42 KB
/
symbol.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
package z3
import (
"strconv"
"unsafe"
)
// #include <stdlib.h>
// #include "go-z3.h"
import "C"
// Symbol represents a named
type Symbol struct {
rawCtx C.Z3_context
rawSymbol C.Z3_symbol
}
// Create a symbol named by a string within the context.
//
// The memory associated with this symbol is freed when the context is freed.
func (c *Context) Symbol(name string) *Symbol {
ns := C.CString(name)
defer C.free(unsafe.Pointer(ns))
return &Symbol{
rawCtx: c.raw,
rawSymbol: C.Z3_mk_string_symbol(c.raw, ns),
}
}
// Create a symbol named by an int within the context.
//
// The memory associated with this symbol is freed when the context is freed.
func (c *Context) SymbolInt(name int) *Symbol {
return &Symbol{
rawCtx: c.raw,
rawSymbol: C.Z3_mk_int_symbol(c.raw, C.int(name)),
}
}
// String returns a string value for this symbol no matter what kind
// of symbol it is. If it is an int, it will be converted to a string
// result.
func (s *Symbol) String() string {
switch C.Z3_get_symbol_kind(s.rawCtx, s.rawSymbol) {
case C.Z3_INT_SYMBOL:
return strconv.FormatInt(
int64(C.Z3_get_symbol_int(s.rawCtx, s.rawSymbol)), 10)
case C.Z3_STRING_SYMBOL:
// We don't need to free this value since it uses statically allocated
// space that is reused by Z3. The GoString call will copy the memory.
return C.GoString(C.Z3_get_symbol_string(s.rawCtx, s.rawSymbol))
default:
return "unknown symbol kind"
}
}