Skip to content

Commit 3ce2991

Browse files
committed
Cleanup
1 parent 0fd9ec8 commit 3ce2991

4 files changed

Lines changed: 22 additions & 36 deletions

File tree

converters/bash/converter.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (c *converter) ProgramEnd() error {
7070
"local _l=$(_slh ${2})",
7171
"local _n=$(eval \"echo \\${${1}}\")",
7272
"while [ ${_i} -lt ${_l} ]; do",
73-
fmt.Sprintf("local _v=%s", c.sliceEvaluationString("${2}", "${_i}", false)),
73+
fmt.Sprintf("local _v=%s", c.sliceEvaluationString("${2}", "${_i}")),
7474
c.sliceAssignmentString("${_n}", "${_i}", "${_v}", false),
7575
"_i=$(expr ${_i} + 1)",
7676
"done",
@@ -373,36 +373,35 @@ func (c *converter) SliceInstantiation(values []string, valueUsed bool) (string,
373373
return helper, nil
374374
}
375375

376-
func (c *converter) SliceEvaluation(name string, index string, valueUsed bool, global bool) (string, error) {
376+
func (c *converter) SliceEvaluation(name string, index string, valueUsed bool) (string, error) {
377377
helper := c.nextHelperVar()
378378
c.VarAssignment(
379379
helper,
380-
c.sliceEvaluationString(name, index, global),
380+
c.sliceEvaluationString(name, index),
381381
false,
382382
)
383383
return c.VarEvaluation(helper, valueUsed, false)
384384
}
385385

386-
func (c *converter) SliceLen(name string, valueUsed bool, global bool) (string, error) {
386+
func (c *converter) SliceLen(name string, valueUsed bool) (string, error) {
387387
helper := c.nextHelperVar()
388388
c.sliceLenHelperRequired = true
389-
// TODO: Is global flag even required here? Because value is already passed to function.
389+
390390
c.VarAssignment(helper, c.sliceLenString(name), false)
391391

392392
return c.VarEvaluation(helper, valueUsed, false)
393393
}
394394

395-
func (c *converter) StringSubscript(value string, index string, valueUsed bool, global bool) (string, error) {
395+
func (c *converter) StringSubscript(value string, index string, valueUsed bool) (string, error) {
396396
helper := c.nextHelperVar()
397397

398-
// TODO: Is global flag even required here? Because value is already passed to function.
399398
c.VarAssignment(helper, fmt.Sprintf("$(_ssh %s %s)", value, index), false) // https://www.baeldung.com/linux/bash-substring#1-using-thecut-command
400399
c.stringSubscriptHelperRequired = true
401400

402401
return c.varEvaluationString(helper, false), nil
403402
}
404403

405-
func (c *converter) StringLen(value string, valueUsed bool, global bool) (string, error) {
404+
func (c *converter) StringLen(value string, valueUsed bool) (string, error) {
406405
helper := c.nextHelperVar()
407406

408407
c.VarAssignment(helper, value, false)
@@ -510,13 +509,13 @@ func (c *converter) varEvaluationString(name string, global bool) string {
510509
}
511510

512511
func (c *converter) sliceAssignmentString(name string, index string, value string, global bool) string {
513-
// TODO: Is global flag even required here? Because value is already passed to function.
512+
514513
return fmt.Sprintf("eval %s_%s=\"%s\"", name, index, value)
515514
}
516515

517-
func (c *converter) sliceEvaluationString(name string, index string, global bool) string {
516+
func (c *converter) sliceEvaluationString(name string, index string) string {
518517
return fmt.Sprintf("$(eval \"echo \\${%s_%s}\")",
519-
name, // TODO: Is global flag even required here? Because value is already passed to function.
518+
name,
520519
index,
521520
)
522521
}

converters/batch/converter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func (c *converter) SliceInstantiation(values []string, valueUsed bool) (string,
519519
return helper, nil
520520
}
521521

522-
func (c *converter) SliceEvaluation(name string, index string, valueUsed bool, global bool) (string, error) {
522+
func (c *converter) SliceEvaluation(name string, index string, valueUsed bool) (string, error) {
523523
helper := c.nextHelperVar()
524524

525525
// A for-loop is required because the evaluation wouldn't work with the following code as expected.
@@ -545,7 +545,7 @@ func (c *converter) SliceEvaluation(name string, index string, valueUsed bool, g
545545
return c.VarEvaluation(helper, valueUsed, false)
546546
}
547547

548-
func (c *converter) SliceLen(name string, valueUsed bool, global bool) (string, error) {
548+
func (c *converter) SliceLen(name string, valueUsed bool) (string, error) {
549549
helper := c.nextHelperVar()
550550
c.sliceLenHelperRequired = true
551551

@@ -555,7 +555,7 @@ func (c *converter) SliceLen(name string, valueUsed bool, global bool) (string,
555555
return c.VarEvaluation(helper, valueUsed, false)
556556
}
557557

558-
func (c *converter) StringSubscript(value string, index string, valueUsed bool, global bool) (string, error) {
558+
func (c *converter) StringSubscript(value string, index string, valueUsed bool) (string, error) {
559559
helper := c.nextHelperVar()
560560
c.stringSubscriptHelperRequired = true
561561

@@ -565,7 +565,7 @@ func (c *converter) StringSubscript(value string, index string, valueUsed bool,
565565
return c.varEvaluationString(helper, false), nil
566566
}
567567

568-
func (c *converter) StringLen(value string, valueUsed bool, global bool) (string, error) {
568+
func (c *converter) StringLen(value string, valueUsed bool) (string, error) {
569569
helper := c.nextHelperVar()
570570
c.stringLenHelperRequired = true
571571

transpiler/converter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ type Converter interface {
8484
LogicalOperation(left string, operator parser.LogicalOperator, right string, valueType parser.ValueType, valueUsed bool) (string, error)
8585
VarEvaluation(name string, valueUsed bool, global bool) (string, error)
8686
SliceInstantiation(values []string, valueUsed bool) (string, error)
87-
SliceEvaluation(name string, index string, valueUsed bool, global bool) (string, error)
88-
SliceLen(name string, valueUsed bool, global bool) (string, error)
89-
StringSubscript(value string, index string, valueUsed bool, global bool) (string, error)
90-
StringLen(value string, valueUsed bool, global bool) (string, error)
87+
SliceEvaluation(name string, index string, valueUsed bool) (string, error)
88+
SliceLen(name string, valueUsed bool) (string, error)
89+
StringSubscript(value string, index string, valueUsed bool) (string, error)
90+
StringLen(value string, valueUsed bool) (string, error)
9191
Group(value string, valueUsed bool) (string, error)
9292
FuncCall(name string, args []string, returnTypes []parser.ValueType, valueUsed bool) ([]string, error)
9393
AppCall(calls []AppCall, valueUsed bool) (string, error)

transpiler/transpiler.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ func New() transpiler {
3939
return transpiler{}
4040
}
4141

42-
func expressionGlobal(expr parser.Expression) bool {
43-
global := false
44-
45-
// If expression implements Global interface, is global value.
46-
if t, ok := expr.(parser.Global); ok {
47-
global = t.Global()
48-
}
49-
return global
50-
}
51-
5242
func (t *transpiler) Transpile(path string, converter Converter) (string, error) {
5343
p := parser.New()
5444
ast, err := p.Parse(path)
@@ -445,8 +435,7 @@ func (t *transpiler) evaluateSliceEvaluation(evaluation parser.SliceEvaluation,
445435
if err != nil {
446436
return expressionResult{}, err
447437
}
448-
global := expressionGlobal(value)
449-
s, err := t.converter.SliceEvaluation(valueString, result.firstValue(), valueUsed, global)
438+
s, err := t.converter.SliceEvaluation(valueString, result.firstValue(), valueUsed)
450439

451440
if err != nil {
452441
return expressionResult{}, err
@@ -466,8 +455,7 @@ func (t *transpiler) evaluateStringSubscript(subscript parser.StringSubscript, v
466455
if err != nil {
467456
return expressionResult{}, err
468457
}
469-
global := expressionGlobal(value)
470-
s, err := t.converter.StringSubscript(str.firstValue(), indexResult.firstValue(), valueUsed, global)
458+
s, err := t.converter.StringSubscript(str.firstValue(), indexResult.firstValue(), valueUsed)
471459

472460
if err != nil {
473461
return expressionResult{}, err
@@ -658,13 +646,12 @@ func (t *transpiler) evaluateLen(len parser.Len, valueUsed bool) (expressionResu
658646
if err != nil {
659647
return expressionResult{}, err
660648
}
661-
global := expressionGlobal(expr)
662649
s := ""
663650

664651
if valueType.IsString() {
665-
s, err = t.converter.StringLen(result.firstValue(), valueUsed, global)
652+
s, err = t.converter.StringLen(result.firstValue(), valueUsed)
666653
} else {
667-
s, err = t.converter.SliceLen(result.firstValue(), valueUsed, global)
654+
s, err = t.converter.SliceLen(result.firstValue(), valueUsed)
668655
}
669656

670657
if err != nil {

0 commit comments

Comments
 (0)