From 898cd45abf92980bb869c1695f5edfc6bc686346 Mon Sep 17 00:00:00 2001 From: Bobby Lat Date: Wed, 6 Nov 2024 11:15:47 +0800 Subject: [PATCH] refactor: use the same expression bulider for all bitwise op --- src/awst_build/eb/bytes-expression-builder.ts | 53 ++++--------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/src/awst_build/eb/bytes-expression-builder.ts b/src/awst_build/eb/bytes-expression-builder.ts index ae5e3144..1f520455 100644 --- a/src/awst_build/eb/bytes-expression-builder.ts +++ b/src/awst_build/eb/bytes-expression-builder.ts @@ -194,11 +194,11 @@ export class BytesExpressionBuilder extends InstanceExpressionBuilder, typeArgs: ReadonlyArray, sourceLocation: SourceLocation): NodeBuilder { - const [other] = requireExpressionsOfType(args, [bytesPType], sourceLocation) - return new BytesExpressionBuilder( - nodeFactory.bytesBinaryOperation({ - wtype: wtypes.bytesWType, - left: this.expr, - right: other, - op: BytesBinaryOperator.bitAnd, - sourceLocation, - }), - ) - } -} - -export class BitwiseOrExpressionBuilder extends FunctionBuilder { - constructor(private expr: awst.Expression) { - super(expr.sourceLocation) - } - - call(args: ReadonlyArray, typeArgs: ReadonlyArray, sourceLocation: SourceLocation): NodeBuilder { - const [other] = requireExpressionsOfType(args, [bytesPType], sourceLocation) - return new BytesExpressionBuilder( - nodeFactory.bytesBinaryOperation({ - wtype: wtypes.bytesWType, - left: this.expr, - right: other, - op: BytesBinaryOperator.bitOr, - sourceLocation, - }), - ) - } -} - -export class BitwiseXorExpressionBuilder extends FunctionBuilder { - constructor(private expr: awst.Expression) { +export class BitwiseOpExpressionBuilder extends FunctionBuilder { + constructor( + private expr: awst.Expression, + private op: BytesBinaryOperator, + ) { super(expr.sourceLocation) } @@ -329,7 +294,7 @@ export class BitwiseXorExpressionBuilder extends FunctionBuilder { wtype: wtypes.bytesWType, left: this.expr, right: other, - op: BytesBinaryOperator.bitXor, + op: this.op, sourceLocation, }), )