Mercurial > projects > dil
comparison trunk/src/dil/semantic/Symbol.d @ 798:c24be8d4f6ab
Added documentation comments.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 01 Mar 2008 02:53:06 +0100 |
parents | f4b9680c0e16 |
children |
comparison
equal
deleted
inserted
replaced
797:cf2ad5df025c | 798:c24be8d4f6ab |
---|---|
6 | 6 |
7 import dil.ast.Node; | 7 import dil.ast.Node; |
8 import dil.lexer.Identifier; | 8 import dil.lexer.Identifier; |
9 import common; | 9 import common; |
10 | 10 |
11 /// Symbol IDs. | 11 /// Enumeration of Symbol IDs. |
12 enum SYM | 12 enum SYM |
13 { | 13 { |
14 Module, | 14 Module, |
15 Class, | 15 Class, |
16 Interface, | 16 Interface, |
24 Alias, | 24 Alias, |
25 OverloadSet, | 25 OverloadSet, |
26 // Type, | 26 // Type, |
27 } | 27 } |
28 | 28 |
29 /++ | 29 /// A symbol represents an object with semantic code information. |
30 A symbol represents an object with semantic code information. | |
31 +/ | |
32 class Symbol | 30 class Symbol |
33 { | 31 { /// Enumeration of symbol statuses. |
34 enum Status : ushort | 32 enum Status : ushort |
35 { | 33 { |
36 Declared, /// The symbol has been declared. | 34 Declared, /// The symbol has been declared. |
37 Completing, /// The symbol is being processed. | 35 Completing, /// The symbol is being processed. |
38 Complete /// The symbol is complete. | 36 Complete /// The symbol is complete. |
44 Identifier* name; /// The name of this symbol. | 42 Identifier* name; /// The name of this symbol. |
45 /// The syntax tree node that produced this symbol. | 43 /// The syntax tree node that produced this symbol. |
46 /// Useful for source code location info and retrieval of doc comments. | 44 /// Useful for source code location info and retrieval of doc comments. |
47 Node node; | 45 Node node; |
48 | 46 |
47 /// Constructs a Symbol object. | |
48 /// Params: | |
49 /// sid = the symbol's ID. | |
50 /// name = the symbol's name. | |
51 /// node = the symbol's node. | |
49 this(SYM sid, Identifier* name, Node node) | 52 this(SYM sid, Identifier* name, Node node) |
50 { | 53 { |
51 this.sid = sid; | 54 this.sid = sid; |
52 this.name = name; | 55 this.name = name; |
53 this.node = node; | 56 this.node = node; |
54 } | 57 } |
55 | 58 |
59 /// Change the status to Status.Completing. | |
56 void setCompleting() | 60 void setCompleting() |
57 { status = Status.Completing; } | 61 { status = Status.Completing; } |
58 | 62 |
63 /// Change the status to Status.Complete. | |
59 void setComplete() | 64 void setComplete() |
60 { status = Status.Complete; } | 65 { status = Status.Complete; } |
61 | 66 |
67 /// Returns true if the symbol is being completed. | |
62 bool isCompleting() | 68 bool isCompleting() |
63 { return status == Status.Completing; } | 69 { return status == Status.Completing; } |
64 | 70 |
71 /// Returns true if the symbols is complete. | |
65 bool isComplete() | 72 bool isComplete() |
66 { return status == Status.Complete; } | 73 { return status == Status.Complete; } |
67 | 74 |
68 // A template macro for building isXYZ() methods. | 75 /// A template macro for building isXYZ() methods. |
69 private template isX(char[] kind) | 76 private template isX(char[] kind) |
70 { | 77 { |
71 const char[] isX = `bool is`~kind~`(){ return sid == SYM.`~kind~`; }`; | 78 const char[] isX = `bool is`~kind~`(){ return sid == SYM.`~kind~`; }`; |
72 } | 79 } |
73 mixin(isX!("Module")); | 80 mixin(isX!("Module")); |
82 mixin(isX!("Function")); | 89 mixin(isX!("Function")); |
83 mixin(isX!("Alias")); | 90 mixin(isX!("Alias")); |
84 mixin(isX!("OverloadSet")); | 91 mixin(isX!("OverloadSet")); |
85 // mixin(isX!("Type")); | 92 // mixin(isX!("Type")); |
86 | 93 |
94 /// Casts the symbol to Class. | |
87 Class to(Class)() | 95 Class to(Class)() |
88 { | 96 { |
89 assert(mixin(`this.sid == mixin("SYM." ~ typeof(Class).stringof)`)); | 97 assert(mixin(`this.sid == mixin("SYM." ~ typeof(Class).stringof)`)); |
90 return cast(Class)cast(void*)this; | 98 return cast(Class)cast(void*)this; |
91 } | 99 } |