OpenCores
URL https://opencores.org/ocsvn/c16/c16/trunk

Subversion Repositories c16

[/] [c16/] [trunk/] [compiler/] [List.hh] - Diff between revs 26 and 29

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 26 Rev 29
// List.hh
// List.hh
#ifndef __LIST_HH_DEFINED__
#ifndef __LIST_HH_DEFINED__
#define __LIST_HH_DEFINED__
#define __LIST_HH_DEFINED__
 
 
 
#include 
 
 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class Node
class Node
{
{
public:
public:
   Node(const char * ntype);
   Node(const char * ntype);
   virtual void Emit(FILE * out);
   virtual void Emit(FILE * out);
   void EmitStart(FILE * out);
   void EmitStart(FILE * out);
   void EmitEnd(FILE * out);
   void EmitEnd(FILE * out);
   static void EmitIndent(FILE * out);
   static void EmitIndent(FILE * out);
   static int GetSemanticErrors()     { return semantic_errors; };
   static int GetSemanticErrors()     { return semantic_errors; };
   static void Error()                { ++semantic_errors;      };
   static void Error()                { ++semantic_errors;      };
   const char * GetNodeType() const   { return node_type;       };
   const char * GetNodeType() const   { return node_type;       };
protected:
protected:
   const char * node_type;
   const char * node_type;
   static int indent;
   static int indent;
   static int semantic_errors;
   static int semantic_errors;
};
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template 
template 
class List : public Node
class List : public Node
{
{
public:
public:
   List(C * h, List * t)
   List(C * h, List * t)
   : Node(list_name(h, t)),
   : Node(list_name(h, t)),
     head(h), tail(t) {};
     head(h), tail(t) {};
   virtual void Emit(FILE * out);
   virtual void Emit(FILE * out);
   C * Head()         { return head; };
   C * Head()         { return head; };
   List * Tail()   { return tail; };
   List * Tail()   { return tail; };
   void ForceEnd()    { tail = 0;    };
   void ForceEnd()    { tail = 0;    };
   List * Reverse()
   List * Reverse()
      {
      {
        List * ret = 0;
        List * ret = 0;
        for (List * l = this; l; l = l->tail)
        for (List * l = this; l; l = l->tail)
            {
            {
               ret = new List(l->head, ret);
               ret = new List(l->head, ret);
            }
            }
        return ret;
        return ret;
      };
      };
   static int Length(const List * l)
   static int Length(const List * l)
      {
      {
        int ret = 0;
        int ret = 0;
        for (; l; l = l->tail)   ret++;
        for (; l; l = l->tail)   ret++;
        return ret;
        return ret;
      };
      };
 
 
   void List::EmitList(FILE * out)
   void EmitList(FILE * out)
      {
      {
        EmitStart(out);
        EmitStart(out);
        for (List * l = this; l; l = l->tail)
        for (List * l = this; l; l = l->tail)
            if (l->Head())   l->Head()->Emit(out);
            if (l->Head())   l->Head()->Emit(out);
        EmitEnd(out);
        EmitEnd(out);
      };
      };
 
 
   List * List::SetHead(C * hd)
   List * SetHead(C * hd)
      {
      {
        assert(head == 0);
        assert(head == 0);
        head = hd;
        head = hd;
        return this;
        return this;
      };
      };
   static const char * list_name(C * h, List * t)
   static const char * list_name(C * h, List * t)
      {
      {
        if (h == 0)
        if (h == 0)
           {
           {
             for (; t; t = t->tail)   if (h = t->head)   break;
             for (; t; t = t->tail)   if (h = t->head)   break;
           }
           }
        if (h == 0)   return "List";
        if (h == 0)   return "List";
        char * cp = new char[strlen(h->GetNodeType()) + 10];
        char * cp = new char[strlen(h->GetNodeType()) + 10];
        sprintf(cp, "List<%s>", h->GetNodeType());
        sprintf(cp, "List<%s>", h->GetNodeType());
        return cp;
        return cp;
      };
      };
private:
private:
   C       * head;
   C       * head;
   List * tail;
   List * tail;
};
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class DeclItem;               typedef List    Declarator;
class DeclItem;               typedef List    Declarator;
class Initializer;            typedef List InitializerList;
class Initializer;            typedef List InitializerList;
class Enumerator;             typedef List EnumeratorList;
class Enumerator;             typedef List EnumeratorList;
class InitDeclarator;         typedef List InitDeclaratorList;
class InitDeclarator;         typedef List InitDeclaratorList;
class Ptr;                    typedef List Pointer;
class Ptr;                    typedef List Pointer;
class Identifier;             typedef List IdentifierList;
class Identifier;             typedef List IdentifierList;
class Declaration;            typedef List DeclarationList;
class Declaration;            typedef List DeclarationList;
class Statement;              typedef List StatementList;
class Statement;              typedef List StatementList;
class TypeSpecifier;          typedef List TypeSpecifierList;
class TypeSpecifier;          typedef List TypeSpecifierList;
class ParameterDeclaration;   typedef List
class ParameterDeclaration;   typedef List
                                          ParameterDeclarationList;
                                          ParameterDeclarationList;
class StructDeclarator;       typedef List
class StructDeclarator;       typedef List
                                           StructDeclaratorList;
                                           StructDeclaratorList;
class StructDeclaration;      typedef List
class StructDeclaration;      typedef List
                                           StructDeclarationList;
                                           StructDeclarationList;
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.