Skip to content

Commit

Permalink
局部代码完善
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Mar 31, 2024
1 parent 684dd5d commit c638af6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/types/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (check *Checker) unary(x *operand, e *ast.UnaryExpr, op token.Token) {
return
}

if check.tryUnaryOperatorCall(x, e, op) {
if fn := check.tryUnaryOperatorCall(x, e, op); fn != nil {
x.mode = value
return
}
Expand Down Expand Up @@ -786,7 +786,7 @@ func (check *Checker) binary(x *operand, e *ast.BinaryExpr, lhs, rhs ast.Expr, o
return
}

if check.tryBinaryOperatorCall(x, e, lhs, rhs, op) {
if fn := check.tryBinaryOperatorCall(x, e, lhs, rhs, op); fn != nil {
x.mode = value
return
}
Expand Down
33 changes: 29 additions & 4 deletions internal/types/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,39 @@ func (check *Checker) processTypeOperators() {
func (check *Checker) tryUnaryOperatorCall(
x *operand, e *ast.UnaryExpr,
op token.Token,
) bool {
return false // todo(chai)
) *Func {
assert(x.typ != nil)

var ops *typeOperator
switch typ := x.typ.(type) {
case *Named:
ops = typ.obj.ops
default:
// todo(chai)
}
if ops == nil {
return nil
}

switch op {
case token.ADD:
return ops.Unary_ADD
case token.SUB:
return ops.Unary_SUB
case token.XOR:
return ops.Unary_XOR
case token.NOT:
return ops.Unary_NOT
}

unreachable()
return nil
}

func (check *Checker) tryBinaryOperatorCall(
x *operand, e *ast.BinaryExpr,
lhs, rhs ast.Expr,
op token.Token,
) bool {
return false // todo(chai)
) *Func {
return nil // todo(chai)
}

0 comments on commit c638af6

Please sign in to comment.