annotate basic/Attribute.d @ 144:6e6355fb5f0f

- Parsing nested attributes. - Creating classes and interfaces in AST. - Updated AstPrinter to print attributes, classes and interfaces.
author Anders Johnsen <skabet@gmail.com>
date Mon, 21 Jul 2008 17:41:40 +0200
parents d76cc5cad4fc
children 6ec686d9c87d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
1 module basic.Attribute;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
2
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
3 import tango.core.BitManip;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
4 import Integer = tango.text.convert.Integer;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
5
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
6 import tango.io.Stdout;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
7
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
8 enum Protection : uint
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
9 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
10 Private = 1<<0,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
11 Public = 1<<1,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
12 Package = 1<<2,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
13 Protected = 1<<3,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
14 Export = 1<<4,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
15 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
16
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
17 enum Extern : uint
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
18 {
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
19 C = 1<<12,
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
20 CPlusPlus = 1<<13,
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
21 D = 1<<14,
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
22 Windows = 1<<15,
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
23 Pascal = 1<<16,
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
24 System = 1<<17,
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
25 }
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
26
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
27 struct Attribute
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
28 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
29
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
30 void setProtection(Protection p)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
31 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
32 att &= 0xFFFFFFE0;
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
33 att |= p;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
34 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
35
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
36 Protection getProtection()
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
37 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
38 Protection p = Protection.Public;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
39 switch(bsf(0xF0000000 | att))
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
40 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
41 case 0:
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
42 p = Protection.Private;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
43 break;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
44 case 1:
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
45 p = Protection.Public;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
46 break;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
47 case 2:
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
48 p = Protection.Package;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
49 break;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
50 case 3:
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
51 p = Protection.Protected;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
52 break;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
53 case 4:
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
54 p = Protection.Export;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
55 break;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
56 default:
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
57 break;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
58 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
59 return p;
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
60 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
61
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
62 void setExtern(Extern e)
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
63 {
143
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
64 att &= 0xFF7C0FFF;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
65 att |= e;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
66 }
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
67
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
68 Extern getExtern()
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
69 {
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
70 Extern e = Extern.D;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
71 switch(bsf(0xF0000000 | att >> 12))
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
72 {
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
73 case 0:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
74 e = Extern.C;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
75 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
76 case 1:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
77 e = Extern.CPlusPlus;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
78 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
79 case 2:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
80 e = Extern.D;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
81 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
82 case 3:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
83 e = Extern.Windows;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
84 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
85 case 4:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
86 e = Extern.Pascal;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
87 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
88 case 5:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
89 e = Extern.System;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
90 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
91 default:
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
92 break;
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
93 }
d76cc5cad4fc Added partial support for switches.
Anders Johnsen <skabet@gmail.com>
parents: 140
diff changeset
94 return e;
140
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
95 }
927ae00bd9d2 Added support for extern keyword. Being ignored atm though. Also changed ast/Module, so that you can get a list of only vars, functions or structs.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
96
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
97 void setStatic() { att |= Static; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
98 bool getStatic() { return att & Static ? true : false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
99 void setFinal() { att |= Final; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
100 bool getFinal() { return att & Final ? true : false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
101 void setConst() { att |= Const; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
102 bool getConst() { return att & Const ? true : false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
103 void setAbstract() { att |= Abstract; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
104 bool getAbstract() { return att & Abstract ? true : false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
105 void setOverride() { att |= Override; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
106 bool getOverride() { return att & Override ? true : false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
107 void setDepracted() { att |= Depracted; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
108 bool getDepracted() { return att & Depracted ? true : false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
109 void setAuto() { att |= Auto; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 143
diff changeset
110 bool getAuto() { return att & Auto ? true : false; }
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
111
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
112 char[] toString()
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
113 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
114 return Integer.toString(att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
115 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
116
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
117 private:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
118 uint att;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
119
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
120
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
121 static const uint Static = 1<<5;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
122 static const uint Final = 1<<6;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
123 static const uint Const = 1<<7;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
124 static const uint Abstract = 1<<8;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
125 static const uint Override = 1<<9;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
126 static const uint Depracted = 1<<10;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
127 static const uint Auto = 1<<11;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents:
diff changeset
128 }