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

Blackbox: Handling global variables with sing stmt

New created functions won't take anymore any global variables as
parameters as it is not needed for them.

 * transform/dependencies_rework.go: Modified.
parent 784479ee
Pipeline #28796 failed with stage
in 50 seconds
...@@ -228,6 +228,15 @@ func (infos *FuncInfosBis) isRequired(a []StmtNumber) bool { ...@@ -228,6 +228,15 @@ func (infos *FuncInfosBis) isRequired(a []StmtNumber) bool {
return false return false
} }
func contains(obj *ast.Object, objs []*ast.Object) bool {
for _, value := range objs {
if value == obj {
return true
}
}
return false
}
func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *ast.FuncDecl { func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *ast.FuncDecl {
currentFunc := t.Func[funcDecl.Name.Obj] currentFunc := t.Func[funcDecl.Name.Obj]
throwStmt, keepStmt := []ast.Stmt{}, []ast.Stmt{} throwStmt, keepStmt := []ast.Stmt{}, []ast.Stmt{}
...@@ -247,7 +256,6 @@ func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *a ...@@ -247,7 +256,6 @@ func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *a
List: []*ast.Field{}, List: []*ast.Field{},
}, },
} }
// TODO: Handle if it is a global variables or not.
// Copy function args to the new one created // Copy function args to the new one created
for _, value := range funcDecl.Type.Params.List { for _, value := range funcDecl.Type.Params.List {
for _, name := range value.Names { for _, name := range value.Names {
...@@ -255,10 +263,9 @@ func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *a ...@@ -255,10 +263,9 @@ func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *a
} }
typ.Params.List = append(typ.Params.List, value) typ.Params.List = append(typ.Params.List, value)
} }
// TODO: Handle if it is a global variables or not.
// Inject required variables in the new function in case it is needed in it // Inject required variables in the new function in case it is needed in it
for key, value := range currentFunc.Variables { for key, value := range currentFunc.Variables {
if value.Required { if value.Required && !contains(key, t.GlobalVar) {
name := ast.NewIdent(key.Name) name := ast.NewIdent(key.Name)
args = append(args, name) args = append(args, name)
typ.Params.List = append(typ.Params.List, &ast.Field{ typ.Params.List = append(typ.Params.List, &ast.Field{
......
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