Exemplo n.º 1
0
  @Override
  public void VisitClassNode(ZClassNode Node) {
    this.CurrentBuilder.Append("sub _Init", this.NameClass(Node.ClassType), "{");
    this.CurrentBuilder.Indent();
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("%o = shift", this.SemiColon);

    @Var ZType SuperType = Node.ClassType.GetSuperType();
    if (!SuperType.Equals(ZClassType._ObjectType)) {
      this.CurrentBuilder.AppendNewLine();
      this.CurrentBuilder.Append("_Init" + this.NameClass(SuperType) + "(%o);");
    }
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("$o{", this.ClassKey(Node.ClassType), "} = ");
    this.CurrentBuilder.AppendInt(Node.ClassType.TypeId);
    this.CurrentBuilder.Append(this.SemiColon);
    @Var int i = 0;
    while (i < Node.GetListSize()) {
      @Var ZFieldNode FieldNode = Node.GetFieldNode(i);
      this.CurrentBuilder.AppendNewLine();
      this.CurrentBuilder.Append("$o{", LibZen._QuoteString(FieldNode.GetName()), "} = ");
      this.GenerateCode(null, FieldNode.InitValueNode());
      this.CurrentBuilder.Append(this.SemiColon);
      i = i + 1;
    }

    i = 0;
    while (i < Node.ClassType.GetFieldSize()) {
      @Var ZClassField ClassField = Node.ClassType.GetFieldAt(i);
      if (ClassField.FieldType.IsFuncType()) {
        this.CurrentBuilder.AppendNewLine();
        this.CurrentBuilder.Append(
            "if (defined $", this.NameMethod(Node.ClassType, ClassField.FieldName), ") {");
        this.CurrentBuilder.Indent();
        this.CurrentBuilder.AppendNewLine();
        this.CurrentBuilder.Append("$o{", LibZen._QuoteString(ClassField.FieldName), "} = $");
        this.CurrentBuilder.Append(
            this.NameMethod(Node.ClassType, ClassField.FieldName), this.SemiColon);
        this.CurrentBuilder.UnIndent();
        this.CurrentBuilder.AppendNewLine();
        this.CurrentBuilder.Append("}");
      }
      i = i + 1;
    }
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.UnIndent();
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("}");
    this.CurrentBuilder.AppendLineFeed();
    this.CurrentBuilder.AppendLineFeed();

    this.CurrentBuilder.Append("sub _New", this.NameClass(Node.ClassType), " {");
    this.CurrentBuilder.Indent();
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("%o = {}", this.SemiColon);
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("_Init" + this.NameClass(Node.ClassType) + "(%o);");
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("return %o;");
    this.CurrentBuilder.UnIndent();
    this.CurrentBuilder.AppendNewLine();
    this.CurrentBuilder.Append("}");
    this.CurrentBuilder.AppendLineFeed();
    this.CurrentBuilder.AppendLineFeed();
  }
Exemplo n.º 2
0
 private String ClassKey(ZType ClassType) {
   return LibZen._QuoteString(this.NameClass(ClassType));
 }