Skip to content

Commit

Permalink
symb: fixes and improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
GraphR00t committed May 1, 2024
1 parent d51edec commit e37dfe9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions internal/core/symbolic/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type IPseudoSub interface {

func (d *Duration) Add(right Value, node *parse.BinaryExpression, state *State) (Value, error) {
switch {
case ImplementsOrIsMultivalueWithAllValuesImplementing[*Duration](right):
case ImplOrMultivaluesImplementing[*Duration](right):
return ANY_DURATION, nil
case ImplementsOrIsMultivalueWithAllValuesImplementing[*DateTime](right):
case ImplOrMultivaluesImplementing[*DateTime](right):
return ANY_DATETIME, nil
default:
state.addError(MakeSymbolicEvalError(node.Right, state, A_DURATION_CAN_ONLY_BE_ADDED_WITH_A_DURATION_DATE_DATETIME))
Expand All @@ -34,9 +34,9 @@ func (d *Duration) Add(right Value, node *parse.BinaryExpression, state *State)

func (d *Duration) Sub(right Value, node *parse.BinaryExpression, state *State) (Value, error) {
switch {
case ImplementsOrIsMultivalueWithAllValuesImplementing[*Duration](right):
case ImplOrMultivaluesImplementing[*Duration](right):
return ANY_DURATION, nil
case ImplementsOrIsMultivalueWithAllValuesImplementing[*DateTime](right):
case ImplOrMultivaluesImplementing[*DateTime](right):
state.addError(MakeSymbolicEvalError(node.Right, state, A_DURATION_CAN_BE_SUBSTRACTED_FROM_A_DATETIME))
return ANY_DATETIME, nil
default:
Expand All @@ -47,7 +47,7 @@ func (d *Duration) Sub(right Value, node *parse.BinaryExpression, state *State)

func (d *DateTime) Add(other Value, node *parse.BinaryExpression, state *State) (Value, error) {
switch {
case ImplementsOrIsMultivalueWithAllValuesImplementing[*Duration](other):
case ImplOrMultivaluesImplementing[*Duration](other):
return ANY_DATETIME, nil
default:
state.addError(MakeSymbolicEvalError(node.Right, state, A_DATETIME_CAN_ONLY_BE_ADDED_WITH_A_DURATION))
Expand All @@ -57,7 +57,7 @@ func (d *DateTime) Add(other Value, node *parse.BinaryExpression, state *State)

func (d *DateTime) Sub(other Value, node *parse.BinaryExpression, state *State) (Value, error) {
switch {
case ImplementsOrIsMultivalueWithAllValuesImplementing[*Duration](other):
case ImplOrMultivaluesImplementing[*Duration](other):
return ANY_DATETIME, nil
default:
state.addError(MakeSymbolicEvalError(node.Right, state, ONLY_A_DURATION_CAN_BE_SUBSTRACTED_FROM_A_DATETIME))
Expand Down
8 changes: 4 additions & 4 deletions internal/core/symbolic/builtin_comptime_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (t *BoolType) Equal(v CompileTimeType, state RecTestCallState) bool {
}

func (t *BoolType) TestValue(v Value, state RecTestCallState) bool {
return ImplementsOrIsMultivalueWithAllValuesImplementing[*Bool](v)
return ImplOrMultivaluesImplementing[*Bool](v)
}

func (t *BoolType) SymbolicValue() Value {
Expand All @@ -61,7 +61,7 @@ func (t *IntType) Equal(v CompileTimeType, state RecTestCallState) bool {
}

func (t *IntType) TestValue(v Value, state RecTestCallState) bool {
return ImplementsOrIsMultivalueWithAllValuesImplementing[*Int](v)
return ImplOrMultivaluesImplementing[*Int](v)
}

func (t *IntType) SymbolicValue() Value {
Expand All @@ -88,7 +88,7 @@ func (t *FloatType) Equal(v CompileTimeType, state RecTestCallState) bool {
}

func (t *FloatType) TestValue(v Value, state RecTestCallState) bool {
return ImplementsOrIsMultivalueWithAllValuesImplementing[*Float](v)
return ImplOrMultivaluesImplementing[*Float](v)
}

func (t *FloatType) SymbolicValue() Value {
Expand All @@ -115,7 +115,7 @@ func (t *StringType) Equal(v CompileTimeType, state RecTestCallState) bool {
}

func (t *StringType) TestValue(v Value, state RecTestCallState) bool {
return ImplementsOrIsMultivalueWithAllValuesImplementing[*String](v)
return ImplOrMultivaluesImplementing[*String](v)
}

func (t *StringType) SymbolicValue() Value {
Expand Down
10 changes: 5 additions & 5 deletions internal/core/symbolic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ func evalURLExpression(n *parse.URLExpression, state *State, options evalOptions
}
}

if !ImplementsOrIsMultivalueWithAllValuesImplementing[*Host](host) {
if !ImplOrMultivaluesImplementing[*Host](host) {
state.addError(MakeSymbolicEvalError(n.HostPart, state, HOST_PART_SHOULD_HAVE_A_HOST_VALUE))
state.SetMostSpecificNodeValue(n.HostPart, ANY_HOST)
options.setHasShallowErrors()
Expand Down Expand Up @@ -3199,9 +3199,9 @@ func evalUnaryExpression(n *parse.UnaryExpression, state *State, options evalOpt
switch n.Operator {
case parse.NumberNegate:
switch {
case ImplementsOrIsMultivalueWithAllValuesImplementing[*Int](operand):
case ImplOrMultivaluesImplementing[*Int](operand):
return ANY_INT, nil
case ImplementsOrIsMultivalueWithAllValuesImplementing[*Float](operand):
case ImplOrMultivaluesImplementing[*Float](operand):
return ANY_FLOAT, nil
default:
state.addError(MakeSymbolicEvalError(n, state, fmtOperandOfNumberNegateShouldBeIntOrFloat(operand)))
Expand Down Expand Up @@ -3301,14 +3301,14 @@ func evalBinaryExpression(n *parse.BinaryExpression, state *State, options evalO
}
return ANY_BOOL, nil
case parse.Urlof:
if !ImplementsOrIsMultivalueWithAllValuesImplementing[*URL](left) {
if !ImplOrMultivaluesImplementing[*URL](left) {
state.addError(MakeSymbolicEvalError(n.Left, state, fmtLeftOperandOfBinaryShouldBe(n.Operator, "url", Stringify(left))))
}

switch right.(type) {
case *Any, *AnySerializable:
default:
if !ImplementsOrIsMultivalueWithAllValuesImplementing[UrlHolder](right) {
if !ImplOrMultivaluesImplementing[UrlHolder](right) {
state.addWarning(makeSymbolicEvalWarning(n.Right, state, RIGHT_OPERAND_MAY_NOT_HAVE_A_URL))
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/symbolic/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (n *AnyMarkupNode) Test(v Value, state RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()

return ImplementsOrIsMultivalueWithAllValuesImplementing[MarkupNode](v)
return ImplOrMultivaluesImplementing[MarkupNode](v)
}

func (n *AnyMarkupNode) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
Expand Down
6 changes: 3 additions & 3 deletions internal/core/symbolic/narrowing_widening.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,20 +553,20 @@ func findInMultivalue[T Value](v Value) (result T, found bool) {
return
}

func ImplementsOrIsMultivalueWithAllValuesImplementing[T Value](v Value) bool {
func ImplOrMultivaluesImplementing[T Value](v Value) bool {
_, ok := v.(T)
if ok {
return true
}

if mv, ok := v.(IMultivalue); ok {
return mv.OriginalMultivalue().AllValues(func(v Value) bool {
return ImplementsOrIsMultivalueWithAllValuesImplementing[T](v)
return ImplOrMultivaluesImplementing[T](v)
})
}

if rv, ok := v.(*RunTimeValue); ok {
return ImplementsOrIsMultivalueWithAllValuesImplementing[T](rv.OriginalRunTimeValue().super)
return ImplOrMultivaluesImplementing[T](rv.OriginalRunTimeValue().super)
}

return false
Expand Down
2 changes: 1 addition & 1 deletion internal/core/symbolic/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (s *String) IteratorElementValue() Value {
}

func (s *String) UnderlyingString() *String {
return ANY_STRING
return s
}

func (s *String) GetOrBuildString() *String {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/symbolic/value_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (n *PropertyName) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.Pr
}

func (n *PropertyName) UnderlyingString() *String {
return &String{}
return ANY_STRING
}

func (n *PropertyName) WidestOfType() Value {
Expand Down
18 changes: 9 additions & 9 deletions internal/globals/html_ns/symbolic/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ func checkInterpolationValue(value symbolic.Value) (errMsg string) {
}

switch {
case symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[symbolic.StringLike](value),
symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[symbolic.GoString](value),
symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[*HTMLNode](value),
symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[*symbolic.Int](value):
case symbolic.ImplOrMultivaluesImplementing[symbolic.StringLike](value),
symbolic.ImplOrMultivaluesImplementing[symbolic.GoString](value),
symbolic.ImplOrMultivaluesImplementing[*HTMLNode](value),
symbolic.ImplOrMultivaluesImplementing[*symbolic.Int](value):
return ""
}

if list, ok := value.(*symbolic.List); ok {
elem := list.IteratorElementValue()
elem := list.Element()
switch {
case symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[symbolic.StringLike](elem),
symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[symbolic.GoString](value),
symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[*HTMLNode](elem),
symbolic.ImplementsOrIsMultivalueWithAllValuesImplementing[*symbolic.Int](elem):
case symbolic.ImplOrMultivaluesImplementing[symbolic.StringLike](elem),
symbolic.ImplOrMultivaluesImplementing[symbolic.GoString](value),
symbolic.ImplOrMultivaluesImplementing[*HTMLNode](elem),
symbolic.ImplOrMultivaluesImplementing[*symbolic.Int](elem):
return ""
}
}
Expand Down

0 comments on commit e37dfe9

Please sign in to comment.