lang: Plumb through the unified state facility
This commit is contained in:
@@ -49,6 +49,7 @@ import (
|
||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||
"github.com/purpleidea/mgmt/lang/interpolate"
|
||||
"github.com/purpleidea/mgmt/lang/parser"
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
"github.com/purpleidea/mgmt/lang/unification"
|
||||
"github.com/purpleidea/mgmt/pgraph"
|
||||
"github.com/purpleidea/mgmt/util"
|
||||
@@ -290,6 +291,7 @@ func (obj *GAPI) Cli(info *gapi.Info) (*gapi.Deploy, error) {
|
||||
AST: iast,
|
||||
Solver: solver,
|
||||
Strategy: unificationStrategy,
|
||||
UnifiedState: types.NewUnifiedState(),
|
||||
Debug: debug,
|
||||
Logf: unificationLogf,
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ import (
|
||||
"github.com/purpleidea/mgmt/lang/interpolate"
|
||||
"github.com/purpleidea/mgmt/lang/interpret"
|
||||
"github.com/purpleidea/mgmt/lang/parser"
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
"github.com/purpleidea/mgmt/lang/unification"
|
||||
"github.com/purpleidea/mgmt/pgraph"
|
||||
"github.com/purpleidea/mgmt/util"
|
||||
@@ -467,6 +468,7 @@ func TestAstFunc1(t *testing.T) {
|
||||
unifier := &unification.Unifier{
|
||||
AST: iast,
|
||||
Solver: solver,
|
||||
UnifiedState: types.NewUnifiedState(),
|
||||
Debug: testing.Verbose(),
|
||||
Logf: xlogf,
|
||||
}
|
||||
@@ -1043,6 +1045,7 @@ func TestAstFunc2(t *testing.T) {
|
||||
unifier := &unification.Unifier{
|
||||
AST: iast,
|
||||
Solver: solver,
|
||||
UnifiedState: types.NewUnifiedState(),
|
||||
Debug: testing.Verbose(),
|
||||
Logf: xlogf,
|
||||
}
|
||||
@@ -1851,6 +1854,7 @@ func TestAstFunc3(t *testing.T) {
|
||||
unifier := &unification.Unifier{
|
||||
AST: iast,
|
||||
Solver: solver,
|
||||
UnifiedState: types.NewUnifiedState(),
|
||||
Debug: testing.Verbose(),
|
||||
Logf: xlogf,
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import (
|
||||
"github.com/purpleidea/mgmt/lang/interpolate"
|
||||
"github.com/purpleidea/mgmt/lang/interpret"
|
||||
"github.com/purpleidea/mgmt/lang/parser"
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
"github.com/purpleidea/mgmt/lang/unification"
|
||||
_ "github.com/purpleidea/mgmt/lang/unification/solvers" // import so the solvers register
|
||||
"github.com/purpleidea/mgmt/pgraph"
|
||||
@@ -261,6 +262,7 @@ func (obj *Lang) Init(ctx context.Context) error {
|
||||
AST: obj.ast,
|
||||
Solver: solver,
|
||||
Strategy: obj.Data.UnificationStrategy,
|
||||
UnifiedState: types.NewUnifiedState(),
|
||||
Debug: obj.Debug,
|
||||
Logf: logf,
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ type Init struct {
|
||||
// overall cleaner unification algorithm in place.
|
||||
Strategy map[string]string
|
||||
|
||||
// UnifiedState stores a common representation of our unification vars.
|
||||
UnifiedState *types.UnifiedState
|
||||
|
||||
Debug bool
|
||||
Logf func(format string, v ...interface{})
|
||||
}
|
||||
|
||||
@@ -863,6 +863,7 @@ func TestUnification1(t *testing.T) {
|
||||
unifier := &unification.Unifier{
|
||||
AST: xast,
|
||||
Solver: solver,
|
||||
UnifiedState: types.NewUnifiedState(),
|
||||
Debug: debug,
|
||||
Logf: logf,
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||
"github.com/purpleidea/mgmt/lang/types"
|
||||
)
|
||||
|
||||
// Unifier holds all the data that the Unify function will need for it to run.
|
||||
@@ -52,6 +53,9 @@ type Unifier struct {
|
||||
// overall cleaner unification algorithm in place.
|
||||
Strategy map[string]string
|
||||
|
||||
// UnifiedState stores a common representation of our unification vars.
|
||||
UnifiedState *types.UnifiedState
|
||||
|
||||
Debug bool
|
||||
Logf func(format string, v ...interface{})
|
||||
}
|
||||
@@ -75,12 +79,16 @@ func (obj *Unifier) Unify(ctx context.Context) error {
|
||||
if obj.Solver == nil {
|
||||
return fmt.Errorf("the Solver is missing")
|
||||
}
|
||||
if obj.UnifiedState == nil {
|
||||
return fmt.Errorf("the UnifiedState table is missing")
|
||||
}
|
||||
if obj.Logf == nil {
|
||||
return fmt.Errorf("the Logf function is missing")
|
||||
}
|
||||
|
||||
init := &Init{
|
||||
Strategy: obj.Strategy,
|
||||
UnifiedState: obj.UnifiedState,
|
||||
Logf: obj.Logf,
|
||||
Debug: obj.Debug,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user