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

Subversion Repositories c16

[/] [c16/] [trunk/] [compiler/] [List.hh] - Blame information for rev 33

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jsauermann
// List.hh
2
#ifndef __LIST_HH_DEFINED__
3
#define __LIST_HH_DEFINED__
4
 
5 29 jsauermann
#include 
6
 
7 2 jsauermann
//-----------------------------------------------------------------------------
8
class Node
9
{
10
public:
11
   Node(const char * ntype);
12
 
13
   virtual void Emit(FILE * out);
14
   void EmitStart(FILE * out);
15
   void EmitEnd(FILE * out);
16
 
17
   static void EmitIndent(FILE * out);
18
   static int GetSemanticErrors()     { return semantic_errors; };
19
   static void Error()                { ++semantic_errors;      };
20
   const char * GetNodeType() const   { return node_type;       };
21
 
22
protected:
23
   const char * node_type;
24
 
25
   static int indent;
26
   static int semantic_errors;
27
};
28
//-----------------------------------------------------------------------------
29
template 
30
class List : public Node
31
{
32
public:
33
   List(C * h, List * t)
34
   : Node(list_name(h, t)),
35
     head(h), tail(t) {};
36
 
37
   virtual void Emit(FILE * out);
38
 
39
   C * Head()         { return head; };
40
   List * Tail()   { return tail; };
41
   void ForceEnd()    { tail = 0;    };
42
 
43
   List * Reverse()
44
      {
45
        List * ret = 0;
46
        for (List * l = this; l; l = l->tail)
47
            {
48
               ret = new List(l->head, ret);
49
            }
50
        return ret;
51
      };
52
 
53
   static int Length(const List * l)
54
      {
55
        int ret = 0;
56
        for (; l; l = l->tail)   ret++;
57
        return ret;
58
      };
59
 
60 29 jsauermann
   void EmitList(FILE * out)
61 2 jsauermann
      {
62
        EmitStart(out);
63
        for (List * l = this; l; l = l->tail)
64
            if (l->Head())   l->Head()->Emit(out);
65
        EmitEnd(out);
66
      };
67
 
68 29 jsauermann
   List * SetHead(C * hd)
69 2 jsauermann
      {
70
        assert(head == 0);
71
        head = hd;
72
        return this;
73
      };
74
 
75
   static const char * list_name(C * h, List * t)
76
      {
77
        if (h == 0)
78
           {
79
             for (; t; t = t->tail)   if (h = t->head)   break;
80
           }
81
 
82
        if (h == 0)   return "List";
83
        char * cp = new char[strlen(h->GetNodeType()) + 10];
84
        sprintf(cp, "List<%s>", h->GetNodeType());
85
        return cp;
86
      };
87
 
88
private:
89
   C       * head;
90
   List * tail;
91
};
92
//-----------------------------------------------------------------------------
93
 
94
class DeclItem;               typedef List    Declarator;
95
class Initializer;            typedef List InitializerList;
96
class Enumerator;             typedef List EnumeratorList;
97
class InitDeclarator;         typedef List InitDeclaratorList;
98
class Ptr;                    typedef List Pointer;
99
class Identifier;             typedef List IdentifierList;
100
class Declaration;            typedef List DeclarationList;
101
class Statement;              typedef List StatementList;
102
class TypeSpecifier;          typedef List TypeSpecifierList;
103
class ParameterDeclaration;   typedef List
104
                                          ParameterDeclarationList;
105
class StructDeclarator;       typedef List
106
                                           StructDeclaratorList;
107
class StructDeclaration;      typedef List
108
                                           StructDeclarationList;
109
#endif

powered by: WebSVN 2.1.0

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