Package org.jruby.ast

Examples of org.jruby.ast.ClassNode


        context.performBooleanBranch(trueBranch, falseBranch);
    }

    public void compileClass(Node node, BodyCompiler context) {
        final ClassNode classNode = (ClassNode) node;

        final Node superNode = classNode.getSuperNode();

        final Node cpathNode = classNode.getCPath();

        CompilerCallback superCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        compile(superNode, context);
                    }
                };
        if (superNode == null) {
            superCallback = null;
        }

        CompilerCallback bodyCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        boolean oldIsAtRoot = isAtRoot;
                        isAtRoot = false;
                        if (classNode.getBodyNode() != null) {
                            compile(classNode.getBodyNode(), context);
                        } else {
                            context.loadNil();
                        }
                        isAtRoot = oldIsAtRoot;
                    }
                };

        CompilerCallback pathCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        if (cpathNode instanceof Colon2Node) {
                            Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
                            if (leftNode != null) {
                                compile(leftNode, context);
                            } else {
                                context.loadNil();
                            }
                        } else if (cpathNode instanceof Colon3Node) {
                            context.loadObject();
                        } else {
                            context.loadNil();
                        }
                    }
                };

        context.defineClass(classNode.getCPath().getName(), classNode.getScope(), superCallback, pathCallback, bodyCallback, null);
    }
View Full Code Here


case 306:
          // line 1134 "DefaultRubyParser.y"
  {
                  Node body = ((Node)yyVals[-1+yyTop]) == null ? NilImplicitNode.NIL : ((Node)yyVals[-1+yyTop]);

                  yyVal = new ClassNode(support.union(((Token)yyVals[-5+yyTop]), ((Token)yyVals[0+yyTop])), ((Colon3Node)yyVals[-4+yyTop]), support.getCurrentScope(), body, ((Node)yyVals[-3+yyTop]));
                  support.popCurrentScope();
              }
  break;
case 307:
          // line 1140 "DefaultRubyParser.y"
View Full Code Here

   * Given the root {@link Node} in a JRuby AST will locate the name of the
   * class defined by that AST.
   * @throws IllegalArgumentException if no class is defined by the supplied AST
   */
  private static String findClassName(Node rootNode) {
    ClassNode classNode = findClassNode(rootNode);
    if (classNode == null) {
      throw new IllegalArgumentException("Unable to determine class name for root node '" + rootNode + "'");
    }
    Colon2Node node = (Colon2Node) classNode.getCPath();
    return node.getName();
  }
View Full Code Here

            for (Node when : caseNode.getCases().childNodes()) inspect(when);
            inspect(caseNode.getElseNode());
            break;
        case CLASSNODE:
            setFlag(node, CLASS);
            ClassNode classNode = (ClassNode)node;
            inspect(classNode.getCPath());
            inspect(classNode.getSuperNode());
            break;
        case CLASSVARNODE:
            setFlag(node, CLASS_VAR);
            break;
        case CONSTDECLNODE:
View Full Code Here

        // otherwise, use normal args compiler
        conditionals.add(getArgsCallback(whenNode.getExpressionNodes()));
    }

    public void compileClass(Node node, BodyCompiler context, boolean expr) {
        final ClassNode classNode = (ClassNode) node;

        final Node superNode = classNode.getSuperNode();

        final Node cpathNode = classNode.getCPath();

        CompilerCallback superCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        compile(superNode, context, true);
                    }
                };
        if (superNode == null) {
            superCallback = null;
        }

        CompilerCallback bodyCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        boolean oldIsAtRoot = isAtRoot;
                        isAtRoot = false;
                        if (classNode.getBodyNode() != null) {
                            compile(classNode.getBodyNode(), context, true);
                        } else {
                            context.loadNil();
                        }
                        isAtRoot = oldIsAtRoot;
                    }
                };

        CompilerCallback pathCallback = new CompilerCallback() {

                    public void call(BodyCompiler context) {
                        if (cpathNode instanceof Colon2Node) {
                            Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
                            if (leftNode != null) {
                                if (leftNode instanceof NilNode) {
                                    context.raiseTypeError("No outer class");
                                } else {
                                    compile(leftNode, context, true);
                                }
                            } else {
                                context.loadNil();
                            }
                        } else if (cpathNode instanceof Colon3Node) {
                            context.loadObject();
                        } else {
                            context.loadNil();
                        }
                    }
                };

        ASTInspector inspector = new ASTInspector();
        inspector.inspect(classNode.getBodyNode());

        context.defineClass(classNode.getCPath().getName(), classNode.getScope(), superCallback, pathCallback, bodyCallback, null, inspector);
        // TODO: don't require pop
        if (!expr) context.consumeCurrentValue();
    }
View Full Code Here

   * Given the root {@link Node} in a JRuby AST will locate the name of the
   * class defined by that AST.
   * @throws IllegalArgumentException if no class is defined by the supplied AST
   */
  private static String findClassName(Node rootNode) {
    ClassNode classNode = findClassNode(rootNode);
    if (classNode == null) {
      throw new IllegalArgumentException("Unable to determine class name for root node '" + rootNode + "'");
    }
    Colon2Node node = (Colon2Node) classNode.getCPath();
    return node.getName();
  }
View Full Code Here

   * Given the root {@link Node} in a JRuby AST will locate the name of the
   * class defined by that AST.
   * @throws IllegalArgumentException if no class is defined by the supplied AST
   */
  private static String findClassName(Node rootNode) {
    ClassNode classNode = findClassNode(rootNode);
    if (classNode == null) {
      throw new IllegalArgumentException("Unable to determine class name for root node '" + rootNode + "'");
    }
    Colon2Node node = (Colon2Node) classNode.getCPath();
    return node.getName();
  }
View Full Code Here

   * Given the root {@link Node} in a JRuby AST will locate the name of the
   * class defined by that AST.
   * @throws IllegalArgumentException if no class is defined by the supplied AST
   */
  private static String findClassName(Node rootNode) {
    ClassNode classNode = findClassNode(rootNode);
    if (classNode == null) {
      throw new IllegalArgumentException("Unable to determine class name for root node '" + rootNode + "'");
    }
    Colon2Node node = (Colon2Node) classNode.getCPath();
    return node.getName();
  }
View Full Code Here

   * Given the root {@link Node} in a JRuby AST will locate the name of the
   * class defined by that AST.
   * @throws IllegalArgumentException if no class is defined by the supplied AST
   */
  private static String findClassName(Node rootNode) {
    ClassNode classNode = findClassNode(rootNode);
    if (classNode == null) {
      throw new IllegalArgumentException("Unable to determine class name for root node '" + rootNode + "'");
    }
    Colon2Node node = (Colon2Node) classNode.getCPath();
    return node.getName();
  }
View Full Code Here

      if (child instanceof ClassNode) {
        return (ClassNode) child;
      }
      else if (child instanceof NewlineNode) {
        NewlineNode nn = (NewlineNode) child;
        ClassNode found = findClassNode(nn.getNextNode());
        if (found != null) {
          return found;
        }
      }
    }
    for (Node child : children) {
      ClassNode found = findClassNode(child);
      if (found != null) {
        return found;
      }
    }
    return null;
View Full Code Here

TOP

Related Classes of org.jruby.ast.ClassNode

Copyright © 2018 www.massapicom. 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.