<commit_before><?php
/* This class is part of the XP framework's experiments
 *
 * $Id$
 */
 
  uses('net.xp_framework.tools.vm.CompileError');
 
  /**
   * Emitter
   *
   * @purpose  Abstract base class
   */
  class Emitter extends Object {
    var
      $cat     = NULL,
      $errors  = array();

    /**
     * Emits an array of nodes
     *
     * @access  public
     * @param   net.xp_framework.tools.vm.VNode[] nodes
     */
    function emitAll($nodes) {
      foreach ($nodes as $node) $this->emit($node);
    }
    
    /**
     * Adds an error
     *
     * @access  public
     * @param   &net.xp_framework.tools.vm.CompileError error
     */
    function addError(&$error) {
      $this->errors[]= &$error;
    }
    
    /**
     * Returns whether errors have occured
     *
     * @access  public
     * @return  bool
     */
    function hasErrors() {
      return !empty($this->errors);
    }

    /**
     * Returns whether errors have occured
     *
     * @access  public
     * @return  net.xp_framework.tools.vm.CompileError[]
     */
    function getErrors() {
      return $this->errors;
    }
    
    /**
     * Retrieves result 
     *
     * @access  public
     * @return  string
     */
    function getResult() { }

    /**
     * Emits a single node
     *
     * @access  public
     * @param   &net.xp_framework.tools.vm.VNode node
     */
    function emit(&$node) {
      if (is_a($node, 'ConstantReferenceNode') && !$node->class) {
        switch (strtolower($node->name)) {
          case 'true': $this->emitBoolean(TRUE); return;
          case 'false': $this->emitBoolean(FALSE); return;
          case 'null': $this->emitNull(); return;
        }
      }

      if (is_a($node, 'VNode')) {
        $func= 'emit'.ucfirst(substr(get_class($node), 0, -4));
        if (!method_exists($this, $func)) {
          $this->cat && $this->cat->error('Cannot handle', $node);
          $this->addError(new CompileError(100, 'Cannot handle '.$node->getClassName()));
          return;
        }

        $this->cat && $this->cat->debug($func, '(', $node->getClassName(), ')');
        $this->$func($node);
        return;
      } else if (is_array($node)) {
        $this->emitArray($node);
      } else if ('"' == $node{0}) { // Double-quoted string
        $value= '';
        for ($i= 1, $s= strlen($node)- 1; $i < $s; $i++) {
          if ('\\' == $node{$i}) {
            switch ($node{$i+ 1}) {
              case 'r': $value.= "\r"; break;
              case 'n': $value.= "\n"; break;
              case 't': $value.= "\t"; break;
            }
            $i++;
          } else {
            $value.= $node{$i};
          }
        }
        $this->emitString($value);
      } else if ("'" == $node{0}) { // Single-quoted string
        $this->emitString(substr($node, 1, -1));
      } else if (is_int($node)) {
        $this->emitInteger($node);
      } else if (is_float($node)) {
        $this->emitDouble($node);
      } else switch (strtolower($node)) {
        case 'true': $this->emitBoolean(TRUE); break;
        case 'false': $this->emitBoolean(FALSE); break;
        case 'null': $this->emitNull(); break;
      }
    }<commit_msg>- Add error when unknown node type is encountered - Make this error distinguishable from when an unknown VNode is found<commit_after><?php
/* This class is part of the XP framework's experiments
 *
 * $Id$
 */
 
  uses('net.xp_framework.tools.vm.CompileError');
 
  /**
   * Emitter
   *
   * @purpose  Abstract base class
   */
  class Emitter extends Object {
    var
      $cat     = NULL,
      $errors  = array();

    /**
     * Emits an array of nodes
     *
     * @access  public
     * @param   net.xp_framework.tools.vm.VNode[] nodes
     */
    function emitAll($nodes) {
      foreach ($nodes as $node) $this->emit($node);
    }
    
    /**
     * Adds an error
     *
     * @access  public
     * @param   &net.xp_framework.tools.vm.CompileError error
     */
    function addError(&$error) {
      $this->errors[]= &$error;
    }
    
    /**
     * Returns whether errors have occured
     *
     * @access  public
     * @return  bool
     */
    function hasErrors() {
      return !empty($this->errors);
    }

    /**
     * Returns whether errors have occured
     *
     * @access  public
     * @return  net.xp_framework.tools.vm.CompileError[]
     */
    function getErrors() {
      return $this->errors;
    }
    
    /**
     * Retrieves result 
     *
     * @access  public
     * @return  string
     */
    function getResult() { }

    /**
     * Emits a single node
     *
     * @access  public
     * @param   &net.xp_framework.tools.vm.VNode node
     */
    function emit(&$node) {
      if (is_a($node, 'ConstantReferenceNode') && !$node->class) {
        switch (strtolower($node->name)) {
          case 'true': $this->emitBoolean(TRUE); return;
          case 'false': $this->emitBoolean(FALSE); return;
          case 'null': $this->emitNull(); return;
        }
      }

      if (is_a($node, 'VNode')) {
        $func= 'emit'.ucfirst(substr(get_class($node), 0, -4));
        if (!method_exists($this, $func)) {
          $this->cat && $this->cat->error('No emitter for', $node);
          $this->addError(new CompileError(100, 'No emitter for '.$node->getClassName()));
          return;
        }

        $this->cat && $this->cat->debug($func, '(', $node->getClassName(), ')');
        $this->$func($node);
        return;
      } else if (is_array($node)) {
        $this->emitArray($node);
        return;
      } else if ('"' == $node{0}) { // Double-quoted string
        $value= '';
        for ($i= 1, $s= strlen($node)- 1; $i < $s; $i++) {
          if ('\\' == $node{$i}) {
            switch ($node{$i+ 1}) {
              case 'r': $value.= "\r"; break;
              case 'n': $value.= "\n"; break;
              case 't': $value.= "\t"; break;
            }
            $i++;
          } else {
            $value.= $node{$i};
          }
        }
        $this->emitString($value);
        return;
      } else if ("'" == $node{0}) { // Single-quoted string
        $this->emitString(substr($node, 1, -1));
        return;
      } else if (is_int($node)) {
        $this->emitInteger($node);
        return;
      } else if (is_float($node)) {
        $this->emitDouble($node);
        return;
      }

      $this->cat && $this->cat->error('Cannot handle', $node);
    }
{'fraction_non_alphanumeric': 0.17744196915407384, 'fraction_numerical': 0.003738900140208755, 'mean_word_length': 1.821978021978022, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2018467', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2026, 'n_words': 452}