Package st.gravel.support.compiler.ast

Source Code of st.gravel.support.compiler.ast.BlockNode$BlockNode_Factory

package st.gravel.support.compiler.ast;

/*
  This file is automatically generated from typed smalltalk source. Do not edit by hand.
  (C) AG5.com
*/

import java.math.BigInteger;
import st.gravel.support.jvm.NonLocalReturn;
import st.gravel.support.compiler.ast.Expression;
import st.gravel.support.compiler.ast.Expression.Expression_Factory;
import st.gravel.support.compiler.ast.VariableDeclarationNode;
import st.gravel.support.compiler.ast.SequenceNode;
import st.gravel.support.compiler.ast.TypeNode;
import st.gravel.support.compiler.ast.Node;
import st.gravel.support.compiler.ast.Statement;
import st.gravel.support.compiler.ast.NodeVisitor;
import st.gravel.support.compiler.ast.BlockTypeNode;
import st.gravel.support.compiler.ast.SourcePrinter;
import st.gravel.support.compiler.ast.SourcePosition;

public class BlockNode extends Expression implements Cloneable {

  public static BlockNode_Factory factory = new BlockNode_Factory();

  VariableDeclarationNode[] _arguments;

  SequenceNode _body;

  TypeNode _returnType;

  public static class BlockNode_Factory extends Expression_Factory {

    public BlockNode arguments_body_returnType_(final VariableDeclarationNode[] _anArray, final SequenceNode _aSequenceNode, final TypeNode _anUndefinedObject) {
      return ((BlockNode) this.basicNew().initializeArguments_body_returnType_(_anArray, _aSequenceNode, _anUndefinedObject));
    }

    public BlockNode basicNew() {
      BlockNode newInstance = new BlockNode();
      newInstance.initialize();
      return newInstance;
    }

    public BlockNode body_(final SequenceNode _aSequenceNode) {
      return ((BlockNode) this.arguments_body_returnType_(new VariableDeclarationNode[] {}, _aSequenceNode, null));
    }

    public BlockNode expression_(final Node _aNode) {
      return this.arguments_body_returnType_(new VariableDeclarationNode[] {}, SequenceNode.factory.statement_(((Statement) _aNode)), null);
    }

    public BlockNode expression_returnType_(final Node _aNode, final TypeNode _returnType) {
      return this.arguments_body_returnType_(new VariableDeclarationNode[] {}, SequenceNode.factory.statement_(((Statement) _aNode)), _returnType);
    }
  }

  static public BlockNode _arguments_body_returnType_(Object receiver, final VariableDeclarationNode[] _anArray, final SequenceNode _aSequenceNode, final TypeNode _anUndefinedObject) {
    return factory.arguments_body_returnType_(_anArray, _aSequenceNode, _anUndefinedObject);
  }

  static public BlockNode _body_(Object receiver, final SequenceNode _aSequenceNode) {
    return factory.body_(_aSequenceNode);
  }

  static public BlockNode _expression_(Object receiver, final Node _aNode) {
    return factory.expression_(_aNode);
  }

  static public BlockNode _expression_returnType_(Object receiver, final Node _aNode, final TypeNode _returnType) {
    return factory.expression_returnType_(_aNode, _returnType);
  }

  @Override
  public <X> X accept_(final NodeVisitor<X> _visitor) {
    return _visitor.visitBlockNode_(this);
  }

  @Override
  public BlockNode allNodesDo_(final st.gravel.support.jvm.Block1<Object, Node> _aBlock) {
    this.nodesDo_(new st.gravel.support.jvm.Block1<Object, Node>() {

      @Override
      public Object value_(final Node _each) {
        return _each.withAllNodesDo_(_aBlock);
      }
    });
    return this;
  }

  @Override
  public BlockNode allNodesDo_pruneWhere_(final st.gravel.support.jvm.Block1<Object, Node> _aBlock, final st.gravel.support.jvm.Block1<Boolean, Node> _pruneBlock) {
    this.nodesDo_(new st.gravel.support.jvm.Block1<Object, Node>() {

      @Override
      public Object value_(final Node _each) {
        if (!_pruneBlock.value_(_each)) {
          return _each.withAllNodesDo_pruneWhere_(_aBlock, _pruneBlock);
        }
        return BlockNode.this;
      }
    });
    return this;
  }

  public VariableDeclarationNode[] arguments() {
    return _arguments;
  }

  public Statement asSimpleExpression() {
    st.gravel.support.jvm.ObjectExtensions.assert_(this, this.isSimpleExpressionBlock());
    return _body.asSimpleExpression();
  }

  public SequenceNode body() {
    return _body;
  }

  public BlockNode copy() {
    try {
      BlockNode _temp1 = (BlockNode) this.clone();
      _temp1.postCopy();
      return _temp1;
    } catch (CloneNotSupportedException e) {
      throw new RuntimeException(e);
    }
  }

  @Override
  public boolean equals(final Object _anObject) {
    if (!super.equals(_anObject)) {
      return false;
    }
    if (this._arguments == null) {
      if (!(((BlockNode) _anObject)._arguments == null)) {
        return false;
      }
    } else {
      if (!st.gravel.support.jvm.ArrayExtensions.equals_(this._arguments, ((BlockNode) _anObject)._arguments)) {
        return false;
      }
    }
    if (this._body == null) {
      if (!(((BlockNode) _anObject)._body == null)) {
        return false;
      }
    } else {
      if (!st.gravel.support.jvm.ObjectExtensions.equals_(this._body, ((BlockNode) _anObject)._body)) {
        return false;
      }
    }
    if (this._returnType == null) {
      if (!(((BlockNode) _anObject)._returnType == null)) {
        return false;
      }
    } else {
      if (!st.gravel.support.jvm.ObjectExtensions.equals_(this._returnType, ((BlockNode) _anObject)._returnType)) {
        return false;
      }
    }
    return true;
  }

  public BlockNode_Factory factory() {
    return factory;
  }

  @Override
  public int hashCode() {
    return (((super.hashCode() ^ java.util.Arrays.hashCode(_arguments)) ^ (_body == null ? 0 : _body.hashCode())) ^ (_returnType == null ? 0 : _returnType.hashCode()));
  }

  public BlockNode initializeArguments_body_returnType_(final VariableDeclarationNode[] _anArray, final SequenceNode _aSequenceNode, final TypeNode _anUndefinedObject) {
    _arguments = _anArray;
    _body = _aSequenceNode;
    _returnType = _anUndefinedObject;
    this.initialize();
    return this;
  }

  @Override
  public BlockNode innerSourceOn_(final StringBuilder _aStream) {
    _aStream.append('[');
    if (_arguments.length != 0) {
      for (final VariableDeclarationNode _arg : _arguments) {
        _aStream.append(':');
        _arg.sourceOn_(_aStream);
        _aStream.append(' ');
      }
      _aStream.append('|');
    }
    _body.sourceOn_(_aStream);
    _aStream.append(']');
    return this;
  }

  @Override
  public boolean isBlockNode() {
    return true;
  }

  @Override
  public boolean isBlockNodeWithReturnStatements() {
    final Object _temp1 = new Object();
    try {
      _body.allNodesDo_(new st.gravel.support.jvm.Block1<Object, Node>() {

        @Override
        public Object value_(final Node _node) {
          if (_node.isReturnNode()) {
            throw new NonLocalReturn(true, _temp1);
          }
          return BlockNode.this;
        }
      });
      return false;
    } catch (NonLocalReturn nlr) {
      if (nlr.marker == _temp1) {
        return (boolean) nlr.returnValue;
      } else {
        throw nlr;
      }
    }
  }

  public boolean isComplex() {
    return _body.isComplex();
  }

  public boolean isSimpleExpressionBlock() {
    return this.body().isSimpleExpressionSequence();
  }

  @Override
  public BlockNode localVarNamesDo_(final st.gravel.support.jvm.Block1<Object, String> _aBlock) {
    return this;
  }

  @Override
  public boolean needsBrackets() {
    return false;
  }

  @Override
  public BlockNode nodesDo_(final st.gravel.support.jvm.Block1<Object, Node> _aBlock) {
    _aBlock.value_(_body);
    return this;
  }

  public int numArgs() {
    return _arguments.length;
  }

  @Override
  public int precedence() {
    return 0;
  }

  @Override
  public BlockNode prettySourceOn_(final StringBuilder _aStream) {
    SourcePrinter.factory.on_(_aStream).visit_(this);
    return this;
  }

  @Override
  public BlockNode printOn_(final StringBuilder _aStream) {
    final String _title;
    _title = this.factory().toString();
    _aStream.append(st.gravel.support.jvm.CharacterExtensions.isVowel(_title.charAt(0)) ? "an " : "a ");
    _aStream.append(_title);
    _aStream.append('[');
    this.sourceOn_(_aStream);
    _aStream.append(']');
    return this;
  }

  @Override
  public BlockNode pvtSetSourcePosition_(final SourcePosition _aSourcePosition) {
    _sourcePosition = _aSourcePosition;
    return this;
  }

  @Override
  public boolean referencesSelfOrInstanceType() {
    return (_returnType != null) && _returnType.referencesSelfOrInstanceType();
  }

  public TypeNode returnType() {
    return _returnType;
  }

  public BlockTypeNode signature() {
    return BlockTypeNode.factory.arguments_returnType_(st.gravel.support.jvm.ArrayExtensions.collect_(_arguments, ((st.gravel.support.jvm.Block1<TypeNode, VariableDeclarationNode>) (new st.gravel.support.jvm.Block1<TypeNode, VariableDeclarationNode>() {

      @Override
      public TypeNode value_(final VariableDeclarationNode _each) {
        return (TypeNode) _each.type();
      }
    }))), _returnType);
  }

  @Override
  public BlockNode sourceOn_(final StringBuilder _aStream) {
    if (!this.needsBrackets()) {
      return BlockNode.this.innerSourceOn_(_aStream);
    }
    _aStream.append('(');
    this.innerSourceOn_(_aStream);
    _aStream.append(')');
    return this;
  }

  @Override
  public BlockNode withAllNodesDo_(final st.gravel.support.jvm.Block1<Object, Node> _aBlock) {
    _aBlock.value_(this);
    this.allNodesDo_(_aBlock);
    return this;
  }

  @Override
  public BlockNode withAllNodesDo_pruneWhere_(final st.gravel.support.jvm.Block1<Object, Node> _aBlock, final st.gravel.support.jvm.Block1<Boolean, Node> _pruneBlock) {
    _aBlock.value_(this);
    this.allNodesDo_pruneWhere_(_aBlock, _pruneBlock);
    return this;
  }

  @Override
  public BlockNode withSourcePosition_(final SourcePosition _aSourcePosition) {
    if (_sourcePosition == _aSourcePosition) {
      return BlockNode.this;
    }
    return this.copy().pvtSetSourcePosition_(_aSourcePosition);
  }
}
TOP

Related Classes of st.gravel.support.compiler.ast.BlockNode$BlockNode_Factory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.