/* Generated by JTB 1.5.1 */
package grammars.q.visitor;

import static grammars.q.syntaxtree.NodeConstants.*;
import grammars.q.Token;
import grammars.q.syntaxtree.*;
import grammars.q.visitor.signature.NodeFieldsSignature;

@SuppressWarnings("javadoc")
public class DepthFirstRetVisitor<R> implements IRetVisitor<R> {


  @Override
  public R visit(final NodeChoice n) {
    /* You have to adapt which data is returned (result variables below are just examples) */
    final R nRes = n.choice.accept(this);
    return nRes;
  }

  @Override
  public R visit(final NodeList n) {
    /* You have to adapt which data is returned (result variables below are just examples) */
    R nRes = null;
    for (INode e : n.nodes) {
      @SuppressWarnings("unused")
      final R sRes = e.accept(this);
    }
    return nRes;
  }

  @Override
  public R visit(final NodeListOptional n) {
    /* You have to adapt which data is returned (result variables below are just examples) */
    if (n.present()) {
      R nRes = null;
      for (INode e : n.nodes) {
        @SuppressWarnings("unused")
        R sRes = e.accept(this);
      }
      return nRes;
    }
    return null;
  }

  @Override
  public R visit(final NodeOptional n) {
    /* You have to adapt which data is returned (result variables below are just examples) */
    if (n.present()) {
      final R nRes = n.node.accept(this);
      return nRes;
    }
    return null;
  }

  @Override
  public R visit(final NodeSequence n) {
    /* You have to adapt which data is returned (result variables below are just examples) */
    R nRes = null;
    for (INode e : n.nodes) {
      @SuppressWarnings("unused")
      R subRet = e.accept(this);
    }
    return nRes;
  }

  @Override
  public R visit(final Token n) {
    /* You have to adapt which data is returned (result variables below are just examples) */
    R nRes = null;
    @SuppressWarnings("unused")
    final String tkIm = n.image;
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_CLASSDECLARATION, JTB_USER_CLASSDECLARATION })
  public R visit(final classDeclaration n) {
    R nRes = null;
    final Token n0 = n.f0;
    nRes = n0.accept(this);
    final className n1 = n.f1;
    nRes = n1.accept(this);
    final Token n2 = n.f2;
    nRes = n2.accept(this);
    final NodeListOptional n3 = n.f3;
    if (n3.present()) {
      for (int i = 0; i < n3.size(); i++) {
        final INode nloeai = n3.elementAt(i);
        final NodeChoice nch = (NodeChoice) nloeai;
        final INode ich = nch.choice;
        switch (nch.which) {
          case 0:
            nRes = ich.accept(this);
            break;
          case 1:
            nRes = ich.accept(this);
            break;
          default:
            // should not occur !!!
            throw new ShouldNotOccurException(nch);
        }
      }
    }
    final Token n4 = n.f4;
    nRes = n4.accept(this);
    final Token n5 = n.f5;
    nRes = n5.accept(this);
    final jc_0 n6 = n.f6;
    nRes = n6.accept(this);
    final Token n7 = n.f7;
    nRes = n7.accept(this);
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_CLASSNAME, JTB_USER_CLASSNAME })
  public R visit(final className n) {
    R nRes = null;
    final Token n0 = n.f0;
    nRes = n0.accept(this);
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_METHOD, JTB_USER_METHOD })
  public R visit(final method n) {
    R nRes = null;
    final methodName n0 = n.f0;
    nRes = n0.accept(this);
    final Token n1 = n.f1;
    nRes = n1.accept(this);
    final NodeList n2 = n.f2;
    for (int i = 0; i < n2.size(); i++) {
      final INode lsteai = n2.elementAt(i);
      nRes = lsteai.accept(this);
    }
    final Token n3 = n.f3;
    nRes = n3.accept(this);
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_METHODNAME, JTB_USER_METHODNAME })
  public R visit(final methodName n) {
    R nRes = null;
    final Token n0 = n.f0;
    nRes = n0.accept(this);
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_INSTRUCTION, JTB_USER_INSTRUCTION })
  public R visit(final instruction n) {
    R nRes = null;
    final NodeChoice nch = n.f0;
    final INode ich = nch.choice;
    switch (nch.which) {
      case 0:
        final NodeSequence seq = (NodeSequence) ich;
        final INode nd = seq.elementAt(0);
        nRes = nd.accept(this);
        final INode nd1 = seq.elementAt(1);
        nRes = nd1.accept(this);
        break;
      case 1:
        nRes = ich.accept(this);
        break;
      default:
        // should not occur !!!
        throw new ShouldNotOccurException(nch);
    }
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_BP_JUAL, JTB_USER_BP_JUAL })
  public R visit(final bp_jual n) {
    R nRes = null;
    final Token n0 = n.f0;
    nRes = n0.accept(this);
    return nRes;
  }

  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_BP_HM, JTB_USER_BP_HM })
  public R visit(final bp_hm n) {
    R nRes = null;
    final Token n0 = n.f0;
    nRes = n0.accept(this);
    return nRes;
  }

  @SuppressWarnings("unused")
  @Override
  @NodeFieldsSignature({ 0, JTB_SIG_JC_0, JTB_USER_JC_0 })
  public R visit(final jc_0 n) {
    R nRes = null;
    /* empty node, nothing that can be generated so far */
    return nRes;
  }

@SuppressWarnings("javadoc")
  public static class ShouldNotOccurException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    public ShouldNotOccurException() {
      super();
    }

    public ShouldNotOccurException(final NodeChoice ch) {
      super("Invalid switch value (" + ch.which + ") or fall-through");
    }

  }

}
