Exemplo n.º 1
0
Arquivo: astree.c Projeto: mtnash/oc
void freeast (astree root) {
   astree child = NULL;
   if (root == NULL) return;
   assert (is_astree (root));
   for (child = root->first; child != NULL;) {
      astree asttofree = child;
      assert (is_astree (asttofree));
      child = child->next;
      freeast (asttofree);
   }
   DEBUGF ('f', "free [%X]-> %d:%d.%d: %s: %p->\"%s\")\n",
           (uintptr_t) root, root->filenr, root->linenr, root->offset,
            get_yytname (root->symbol), root->lexinfo, root->lexinfo);
   memset (root, 0, sizeof (struct astree_rep));
   free (root);
}
Exemplo n.º 2
0
Arquivo: astree.c Projeto: mtnash/oc
astree adopt (astree root, ...) {
   va_list children;
   assert (is_astree (root));
   va_start (children, root);
   for(;;) {
      astree child = va_arg (children, astree);
      if (child == NULL) break;
      assert (is_astree (child));
      if (root->last == NULL) root->first = child;
                         else root->last->next = child;
      root->last = child;
      DEBUGF ('a', "%p (%s) adopting %p (%s)\n",
              root, peek_stringtable(root->lexinfo),
              child, peek_stringtable(child->lexinfo));
   }
   va_end (children);
   return root;
}
Exemplo n.º 3
0
Arquivo: astree.c Projeto: mtnash/oc
void yyprint (FILE *outfile, unsigned short toknum, astree yyvaluep) {
   fprintf (outfile, "%d=%s)\n%*s(",
             toknum, get_yytname (toknum), 9, "");
   if (is_astree (yyvaluep)) {
      dump_node (outfile, yyvaluep, 3);
   }else{
      fprintf (outfile, "yyvaluep = %p", (void*) yyvaluep);
   }
   fflush (NULL);
}
Exemplo n.º 4
0
static void dump_node (FILE *outfile, astree node, int depth) {
   assert (is_astree (node));
   fprintf (outfile, "%p-> astree {%s(%d), %d:%d.%03d, %p->\"%s\",\n",
             (void*) node, get_yytname (node->symbol), node->symbol,
             node->filenr, node->linenr, node->offset,
             node->lexinfo, node->lexinfo);
   fprintf (outfile, "%*sfirst=%p, last=%p, next=%p}",
             depth * 3 + 12, "", (void*) node->first,
             (void*) node->last, (void*) node->next);
}
Exemplo n.º 5
0
Arquivo: astree.c Projeto: mtnash/oc
static void dump_astree_rec (FILE *outfile, astree root, int depth) {
   astree child = NULL;
   if (root == NULL) return;
   assert (is_astree (root));
   //fprintf (outfile, "%*s%s ", depth * 3, "", root->lexinfo);
   dump_node (outfile, root, depth);
   fprintf (outfile, "\n");
   for (child = root->first; child != NULL; child = child->next) {
      dump_astree_rec (outfile, child, depth + 1);
   }
}
Exemplo n.º 6
0
void emit (astree tree) {
   assert (is_astree (tree));
   switch (tree->symbol) {
      case ROOT  : postorder_emit_stmts (tree);       break;
      case ';'   : postorder_emit_semi (tree);        break;
      case '='   : emit_assign (tree);                break;
      case '+'   : postorder_emit_oper (tree, "add"); break;
      case '-'   : postorder_emit_oper (tree, "sub"); break;
      case '*'   : postorder_emit_oper (tree, "mul"); break;
      case '/'   : postorder_emit_oper (tree, "div"); break;
      case '^'   : postorder_emit_oper (tree, "pow"); break;
      case POS   : postorder_emit_oper (tree, "pos"); break;
      case NEG   : postorder_emit_oper (tree, "neg"); break;
      case IDENT : emit_push (tree, "pushvar");       break;
      case NUMBER: emit_push (tree, "pushnum");       break;
      default    : assert (! "emit default");         break;
   }
}
Exemplo n.º 7
0
Arquivo: astree.c Projeto: mtnash/oc
static void dump_node (FILE *outfile, astree node, int depth) {
   assert (is_astree (node));
   while (depth > 0){
       fprintf(outfile,"|  ");
       depth--;
   }
   char *tname = (char *)get_yytname(node->symbol);
   if (strstr(tname, "TOK_") == tname) tname += 4;
   fprintf(outfile,"%s \"%s\" %d.%d.%d",
   tname,peek_stringtable(node->lexinfo),
           node->filenr,node->linenr, node->offset);
  /* fprintf (outfile, "%p-> astree {%s(%d), %d:%d.%03d, %p->\"%s\",\n",
             (void*) node, get_yytname (node->symbol), node->symbol,
             node->filenr, node->linenr, node->offset,
             node->lexinfo, node->lexinfo);
   fprintf (outfile, "%*sfirst=%p, last=%p, next=%p}",
             depth * 3 + 12, "", (void*) node->first,
             (void*) node->last, (void*) node->next);*/
}
Exemplo n.º 8
0
static void dump_astree_rec (FILE *outfile, astree root, int depth) {
   astree child = NULL;
   if (root == NULL) return;
   assert (is_astree (root));
   const char *tname = get_yytname(root->symbol);
   if (strstr (tname, "TOK_") == tname) tname += 4;
   if(depth == 0){
   fprintf (outfile, "%*s%s \"%s\" %d.%d.%03d ", depth * 3, "",
    tname, root->lexinfo, root->filenr, root->linenr, root->offset);
   }
   else{
     int i;
     for(i =0 ; i < depth; ++i){
         fprintf(outfile, "%*s ", 1, "|");
     }
     fprintf (outfile, "%s \"%s\" %d.%d.%03d ", tname, root->lexinfo,
              root->filenr, root->linenr, root->offset);
   }
//   dump_node (outfile, root, depth);
   fprintf (outfile, "\n");
   for (child = root->first; child != NULL; child = child->next) {
      dump_astree_rec (outfile, child, depth + 1);
   }
}