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

Subversion Repositories c16

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

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

powered by: WebSVN 2.1.0

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