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