Commit e971f683 authored by Hugo Moreau's avatar Hugo Moreau
Browse files

Blackbox: Handling single statements

Useless statement are now placed in a function in order to be blackboxed
later.

 * main.go,
   transform/dependencies_rework.go: Modified.
parent 15b0fe85
Pipeline #28762 failed with stage
in 51 seconds
......@@ -689,6 +689,7 @@ func main() {
os.Exit(1)
}
handleBlackboxBlocks(src, variables)
return
// Check if all constraints are respected
info := &types.Info{
......
......@@ -228,35 +228,64 @@ func (infos *FuncInfosBis) isRequired(a []StmtNumber) bool {
return false
}
func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) {
func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *ast.FuncDecl {
currentFunc := t.Func[funcDecl.Name.Obj]
throwStmt, keepStmt := []ast.Stmt{}, []ast.Stmt{}
for key, value := range funcDecl.Body.List {
currentFunc.postStmt(t, meta, []StmtNumber{StmtNumber{key, false}}, false, value)
if !currentFunc.postStmt(t, meta, []StmtNumber{StmtNumber{key, false}}, false, value) {
throwStmt = append(throwStmt, value)
} else {
keepStmt = append(keepStmt, value)
}
}
if len(keepStmt) != 0 {
ident := ast.NewIdent("g2p_bb_" + funcDecl.Name.Name)
args := []ast.Expr{}
for _, value := range funcDecl.Type.Params.List {
for _, name := range value.Names {
args = append(args, name)
}
}
keepStmt = append(keepStmt, &ast.ExprStmt{
X: &ast.CallExpr{
Fun: ident,
Args: args,
},
})
funcDecl.Body.List = keepStmt
return &ast.FuncDecl{
Name: ident,
Type: funcDecl.Type,
Body: &ast.BlockStmt{
List: throwStmt,
},
}
}
return nil
}
func (infos *FuncInfosBis) postStmt(t *DependenciesRework, meta *Meta, number []StmtNumber, if_or_else bool, stmt ast.Node) {
func (infos *FuncInfosBis) postStmt(t *DependenciesRework, meta *Meta, number []StmtNumber, if_or_else bool, stmt ast.Node) bool {
if stmt == nil {
return
return false
}
if infos.isRequired(number) {
t.insertCommentBefore(meta, stmt, "REQUIRED")
// t.insertCommentBefore(meta, stmt, "REQUIRED")
return true
}
res := false
switch stmt := stmt.(type) {
case *ast.BlockStmt:
for key, value := range stmt.List {
infos.postStmt(t, meta, append(number, StmtNumber{key, if_or_else}), false, value)
res = res || infos.postStmt(t, meta, append(number, StmtNumber{key, if_or_else}), false, value)
}
return
return res
case *ast.ForStmt:
infos.postStmt(t, meta, number, false, stmt.Body)
return
return infos.postStmt(t, meta, number, false, stmt.Body)
case *ast.IfStmt:
infos.postStmt(t, meta, number, false, stmt.Body)
infos.postStmt(t, meta, number, true, stmt.Else)
return
res = res || infos.postStmt(t, meta, number, false, stmt.Body)
return res || infos.postStmt(t, meta, number, true, stmt.Else)
default:
return
return false
}
}
......@@ -269,7 +298,9 @@ func (t *DependenciesRework) Post(meta *Meta, v *Visitor) bool {
for _, val := range node.Decls {
switch val := val.(type) {
case *ast.FuncDecl:
t.postFuncDecl(meta, val)
if bb := t.postFuncDecl(meta, val); bb != nil {
node.Decls = append(node.Decls, bb)
}
}
}
var output []byte
......
Supports Markdown
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