Skip to content

Commit

Permalink
proc: Implements expression interpreter
Browse files Browse the repository at this point in the history
Supported operators:

- All (binary and unary) operators between basic types except <-,
++ and -- (includes & to take the address of an expression)
- Comparison operators between supported compound types
- Typecast of integer constants into pointer types
- struct members
- indexing of arrays, slices and strings
- slicing of arrays, slices and strings
- pointer dereferencing
- true, false and nil constants

Implements #116, #117 and #251
  • Loading branch information
aarzilli committed Nov 4, 2015
1 parent 6f44016 commit 43b64ec
Show file tree
Hide file tree
Showing 10 changed files with 1,297 additions and 324 deletions.
41 changes: 40 additions & 1 deletion _fixtures/testvariables3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,49 @@ import (
"runtime"
)

type astruct struct {
A int
B int
}

type bstruct struct {
a astruct
}

type cstruct struct {
pb *bstruct
sa []*astruct
}

func afunc(x int) int {
return x + 2
}

type functype func(int) int

func main() {
i1 := 1
i2 := 2
f1 := 3.0
i3 := 3
p1 := &i1
s1 := []string{"one", "two", "three", "four", "five"}
a1 := [5]string{"one", "two", "three", "four", "five"}
c1 := cstruct{&bstruct{astruct{1, 2}}, []*astruct{&astruct{1, 2}, &astruct{2, 3}, &astruct{4, 5}}}
s2 := []astruct{{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {13, 14}, {15, 16}}
p2 := &(c1.sa[2].B)
as1 := astruct{1, 1}
var p3 *int
str1 := "01234567890"
var fn1 functype = afunc
var fn2 functype = nil
var nilslice []int = nil
var nilptr *int = nil

var amb1 = 1
runtime.Breakpoint()
fmt.Println(i1, i2, p1)
for amb1 := 0; amb1 < 10; amb1++ {
fmt.Println(amb1)
}
fmt.Println(i1, i2, i3, p1, amb1, s1, a1, p2, p3, s2, as1, str1, f1, fn1, fn2, nilslice, nilptr)
}
3 changes: 2 additions & 1 deletion _fixtures/testvariables4.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ type B struct {

func main() {
b := B{A: A{-314}, C: &C{"hello"}, a: A{42}, ptr: &A{1337}}
b2 := B{A: A{42}, a: A{47}}
runtime.Breakpoint()
fmt.Println(b)
fmt.Println(b, b2)
fmt.Println(b.val)
fmt.Println(b.A.val)
fmt.Println(b.a.val)
Expand Down
7 changes: 7 additions & 0 deletions dwarf/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ func (reader *Reader) SeekToTypeNamed(name string) (*dwarf.Entry, error) {
return nil, err
}

switch entry.Tag {
case dwarf.TagArrayType, dwarf.TagBaseType, dwarf.TagClassType, dwarf.TagStructType, dwarf.TagUnionType, dwarf.TagConstType, dwarf.TagVolatileType, dwarf.TagRestrictType, dwarf.TagEnumerationType, dwarf.TagPointerType, dwarf.TagSubroutineType, dwarf.TagTypedef, dwarf.TagUnspecifiedType:
//ok
default:
continue
}

n, ok := entry.Val(dwarf.AttrName).(string)
if !ok {
continue
Expand Down
Loading

0 comments on commit 43b64ec

Please sign in to comment.