001/* 002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 */ 009 010package org.eclipse.golo.compiler.ir; 011 012import org.eclipse.golo.runtime.OperatorType; 013 014public class UnaryOperation extends ExpressionStatement { 015 016 private final OperatorType type; 017 private ExpressionStatement expressionStatement; 018 019 UnaryOperation(OperatorType type, ExpressionStatement expressionStatement) { 020 super(); 021 this.type = type; 022 setExpressionStatement(expressionStatement); 023 } 024 025 public ExpressionStatement getExpressionStatement() { 026 return expressionStatement; 027 } 028 029 private void setExpressionStatement(ExpressionStatement statement) { 030 this.expressionStatement = statement; 031 makeParentOf(statement); 032 } 033 034 public OperatorType getType() { 035 return type; 036 } 037 038 @Override 039 public void accept(GoloIrVisitor visitor) { 040 visitor.visitUnaryOperation(this); 041 } 042 043 @Override 044 public void walk(GoloIrVisitor visitor) { 045 expressionStatement.accept(visitor); 046 } 047 048 @Override 049 protected void replaceElement(GoloElement original, GoloElement newElement) { 050 if (expressionStatement.equals(original)) { 051 setExpressionStatement((ExpressionStatement) newElement); 052 } else { 053 throw cantReplace(original, newElement); 054 } 055 } 056}