Commit 211baa6d authored by Etienne Renault's avatar Etienne Renault

alive: support for global variables

* tests/expected, tests/run.sh,
transform/alive.go,
transform/localvariableassignments.go: Here.
parent 3e8a49d7
#alive.go,8017,8017
#array.go,47,47
#call.go,16,16
#concurrent_fibonacci.go,1136,2228
......
......@@ -31,6 +31,7 @@ for i in $(ls *.go); do
../go2pins -f -o output $i > /dev/null 2>&1
cd output > /dev/null 2>&1
make > /dev/null 2>&1
./go2pins-mc -kripke-size
TMP=$(./go2pins-mc -kripke-size | grep '#' | sed "s/kripke/$i/g")
EXPECTED=$(cat ../expected | grep "#$i,")
RES=$(diff <(echo "$TMP") <(echo "$EXPECTED"))
......
......@@ -41,6 +41,8 @@ isalive_v1 := 1
type Alive struct {
}
const alive_prefix = "G2P_is_alive_"
// Pre traversal applies the transformation.
func (t *Alive) Pre(meta *Meta, v *Visitor) bool {
c := v.Cursor()
......@@ -57,10 +59,10 @@ func (t *Alive) Pre(meta *Meta, v *Visitor) bool {
aliveList[j] = &ast.AssignStmt{
Lhs: []ast.Expr{
&ast.Ident{
Name: "isalive_" + lhsj.Name,
Name: alive_prefix + lhsj.Name,
Obj: &ast.Object{
Kind: ast.Var,
Name: "isalive_" + lhsj.Name,
Name: alive_prefix + lhsj.Name,
},
},
},
......@@ -81,6 +83,35 @@ func (t *Alive) Pre(meta *Meta, v *Visitor) bool {
}
}
}
case *ast.GenDecl:
size := len(node.Specs)
for i := 0; i < size; i++ {
switch vs := node.Specs[i].(type) {
case *ast.ValueSpec:
names := make([]*ast.Ident, 0)
values := make([]ast.Expr, 0)
for _, name := range vs.Names {
names = append(names, &ast.Ident{
Name: alive_prefix + name.Name,
Obj: &ast.Object{
Kind: ast.Var,
Name: alive_prefix + name.Name,
},
})
values = append(values, &ast.BasicLit{
Kind: token.INT,
Value: "1",
})
}
node.Specs = append(node.Specs, &ast.ValueSpec{
Names: names,
Values: values,
})
}
}
}
return true
}
......
......@@ -77,15 +77,6 @@ func (t *LocalVariableAssignments) Pre(meta *Meta, v *Visitor) bool {
if node.Values != nil {
t.globalToMain = append(t.globalToMain, meta.Set(obj, node.Values[i]))
}
alive := &ast.Object{
Kind: ast.Var,
Name: "isalive_" + obj.Name,
}
meta.Add(alive, v.Name())
t.globalToMain = append(t.globalToMain, meta.Set(alive, &ast.BasicLit{
Kind: token.INT,
Value: "1",
}))
}
}
case *ast.AssignStmt:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment