Commit 784479ee authored by Hugo Moreau's avatar Hugo Moreau
Browse files

Blackbox: Handling local variables dependencies

Local variables was not recovered in the newly created to-be-blackboxed
functions, so it created missing variables errors.

 * transform/dependencies_rework.go : Modified.
parent e971f683
......@@ -239,23 +239,46 @@ func (t *DependenciesRework) postFuncDecl(meta *Meta, funcDecl *ast.FuncDecl) *a
}
}
if len(keepStmt) != 0 {
// TODO: Handle return statements and type of function and bb function
ident := ast.NewIdent("g2p_bb_" + funcDecl.Name.Name)
args := []ast.Expr{}
typ := &ast.FuncType{
Params: &ast.FieldList{
List: []*ast.Field{},
},
}
// TODO: Handle if it is a global variables or not.
// Copy function args to the new one created
for _, value := range funcDecl.Type.Params.List {
for _, name := range value.Names {
args = append(args, name)
}
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
for key, value := range currentFunc.Variables {
if value.Required {
name := ast.NewIdent(key.Name)
args = append(args, name)
typ.Params.List = append(typ.Params.List, &ast.Field{
Names: []*ast.Ident{name},
Type: ast.NewIdent("int"), // TODO: Handling none integer variables
})
}
}
// Inject the created function call in our function statements
keepStmt = append(keepStmt, &ast.ExprStmt{
X: &ast.CallExpr{
Fun: ident,
Args: args,
},
})
// Return the new function to add in the file.
funcDecl.Body.List = keepStmt
return &ast.FuncDecl{
Name: ident,
Type: funcDecl.Type,
Type: typ,
Body: &ast.BlockStmt{
List: throwStmt,
},
......
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