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 public abstract class JsUnaryOperation extends JsExpressionImpl {
008
009 private JsExpression arg;
010
011 private final JsUnaryOperator op;
012
013 public JsUnaryOperation(JsUnaryOperator op) {
014 this(op, null);
015 }
016
017 public JsUnaryOperation(JsUnaryOperator op, JsExpression arg) {
018 super();
019 this.op = op;
020 this.arg = arg;
021 }
022
023 public JsExpression getArg() {
024 return arg;
025 }
026
027 public JsUnaryOperator getOperator() {
028 return op;
029 }
030
031 public void setArg(JsExpression arg) {
032 this.arg = arg;
033 }
034
035 @Override
036 public void acceptChildren(JsVisitor visitor) {
037 if (op.isModifying()) {
038 // The delete operator is practically like an assignment of undefined, so
039 // for practical purposes we're treating it as an lvalue.
040 visitor.acceptLvalue(arg);
041 }
042 else {
043 visitor.accept(arg);
044 }
045 }
046
047 @Override
048 public void traverse(JsVisitorWithContext v, JsContext ctx) {
049 if (op.isModifying()) {
050 /*
051 * The delete operator is practically like an assignment of undefined, so for practical
052 * purposes we're treating it as an lvalue.
053 */
054 arg = v.acceptLvalue(arg);
055 } else {
056 arg = v.accept(arg);
057 }
058 }
059 }