edb91c4d06f28ada11e32529d15e162a286590ef
[sdk] / compiler / libec2 / src / specifiers.ec
1 import "astNode"
2
3 // Specifiers
4 public class ASTSpecifier : ASTNode
5 {
6 public:
7    SpecifierType type;
8   /*    struct
9       {
10          //ExtDecl extDecl;
11          //Symbol symbol;
12          //OldList * templateArgs;
13       };
14       struct
15       {
16          Identifier id;
17          OldList * list;
18          OldList * baseSpecs;
19          OldList * definitions;
20          bool addNameSpace;
21          Context ctx;
22          ExtDecl extDeclStruct;
23       };
24       Expression expression;
25       NewSpecifier _class;
26       TemplateParameter templateParameter;
27    };
28       */
29 };
30
31 public class SpecsList : ASTList<ASTSpecifier>
32 {
33    void printSep()
34    {
35       Print(" ");
36    }
37
38    SpecsList ::parse()
39    {
40       SpecsList specs = null;
41       bool gotSpec = false;
42       while(true)
43       {
44          peekToken();
45          if(nextToken.type.isSpecifier)
46          {
47             readToken();
48             if(!specs) specs = { };
49             specs.Add(SpecBase { specifier = token.type });
50             if(!token.type.isQualifier)
51                gotSpec = true;
52          }
53          else if(nextToken.type == IDENTIFIER)
54          {
55             bool isType = false;
56             if(isType || !gotSpec)
57             {
58                readToken();
59                if(!specs) specs = { };
60                specs.Add(SpecName { name = CopyString(token.text) });
61                gotSpec = true;
62             }
63             else
64                break;
65          }
66          else
67             break;
68       }
69       return specs;
70    }
71 }
72
73 public class SpecBase : ASTSpecifier
74 {
75    TokenType specifier;
76
77    void print()
78    {
79       specifier.print();
80    }
81 }
82
83 public class SpecName : ASTSpecifier
84 {
85    String name;
86
87    void print()
88    {
89       if(name) Print(name);
90    }
91 }
92
93 /*
94 public class Attribute : struct
95 {
96 public:
97    Attribute prev, next;
98    Location loc;
99    String attr;
100    Expression exp;
101 }
102
103 public class Attrib : struct
104 {
105 public:
106    Location loc;
107    int type;
108    OldList * attribs;
109 }
110
111 public class ExtDecl : struct
112 {
113 public:
114    Location loc;
115    ExtDeclType type;
116    union
117    {
118       String s;
119       Attrib attr;
120    };
121 }
122 */
123
124 /*
125 public class Enumerator : struct
126 {
127 public:
128    Enumerator prev, next;
129    Location loc;
130    Identifier id;
131    Expression exp;
132 };
133 */