001 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
002 // for details. All rights reserved. Use of this source code is governed by a
003 // BSD-style license that can be found in the LICENSE file.
004
005 package com.google.dart.compiler.backend.js.ast;
006
007 import org.jetbrains.annotations.Nullable;
008
009 public final class JsBinaryOperation extends JsExpressionImpl {
010 private JsExpression arg1;
011 private JsExpression arg2;
012 private final JsBinaryOperator op;
013
014 public JsBinaryOperation(JsBinaryOperator op) {
015 this(op, null, null);
016 }
017
018 public JsBinaryOperation(JsBinaryOperator op, @Nullable JsExpression arg1, @Nullable JsExpression arg2) {
019 this.op = op;
020 this.arg1 = arg1;
021 this.arg2 = arg2;
022 }
023
024 public JsExpression getArg1() {
025 return arg1;
026 }
027
028 public JsExpression getArg2() {
029 return arg2;
030 }
031
032 public JsBinaryOperator getOperator() {
033 return op;
034 }
035
036 @Override
037 public void accept(JsVisitor v) {
038 v.visitBinaryExpression(this);
039 }
040
041 @Override
042 public void acceptChildren(JsVisitor visitor) {
043 if (op.isAssignment()) {
044 visitor.acceptLvalue(arg1);
045 }
046 else {
047 visitor.accept(arg1);
048 }
049 visitor.accept(arg2);
050 }
051 }