annotate trunk/src/dil/semantic/Symbol.d @ 707:efa5fcb9aa14

Added semantic code related to enums. Added member symbol to EnumMemberDeclaration. Added genAnonEnumID() to IdTable. Added class EnumMember. Wrote code for SemanticPass2.visit(EnumDeclaration). Revised code in SemanticPass1.visit(EnumDeclaration).
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 29 Jan 2008 01:07:39 +0100
parents 1ae72234db26
children 4f971f6382c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
1 /++
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 Author: Aziz Köksal
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 License: GPL3
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 +/
589
de365ddcfbd4 Moved dil.Symbol to dil.semantic.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 580
diff changeset
5 module dil.semantic.Symbol;
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
6
580
fa6d3c52757d Moved SyntaxTree.d to new package 'ast'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 568
diff changeset
7 import dil.ast.Node;
615
a05457530ac2 Added member ident to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 614
diff changeset
8 import dil.lexer.Identifier;
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
9 import common;
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
10
563
c838ed7f2ac9 Added 'override' to some methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
11 /// Symbol IDs.
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
12 enum SYM
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
13 {
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
14 Module,
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
15 Class,
561
302e50e71ec2 Added Interface symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 560
diff changeset
16 Interface,
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
17 Struct,
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
18 Union,
614
8c5b1558244b Added symbol Enum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 589
diff changeset
19 Enum,
707
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
20 EnumMember,
623
e2cd28cfc6ae Added dil.semantic.Template.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 615
diff changeset
21 Template,
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
22 Variable,
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
23 Function,
683
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
24 Alias,
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
25 OverloadSet,
615
a05457530ac2 Added member ident to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 614
diff changeset
26 // Type,
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
27 }
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
28
563
c838ed7f2ac9 Added 'override' to some methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
29 /++
c838ed7f2ac9 Added 'override' to some methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
30 A symbol represents an object with semantic code information.
c838ed7f2ac9 Added 'override' to some methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 561
diff changeset
31 +/
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
32 class Symbol
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
33 {
560
709e223a8eb9 Added code related to symbols.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 407
diff changeset
34 SYM sid;
568
c8861b452eb3 Added members 'node' and 'parent' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 567
diff changeset
35 Symbol parent; /// The parent this symbol belongs to.
683
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
36 Identifier* name; /// The name of this symbol.
568
c8861b452eb3 Added members 'node' and 'parent' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 567
diff changeset
37 /// The AST node that produced this symbol.
c8861b452eb3 Added members 'node' and 'parent' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 567
diff changeset
38 /// Useful for source code location info and retrieval of doc comments.
c8861b452eb3 Added members 'node' and 'parent' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 567
diff changeset
39 Node node;
567
ab9f5020cd02 Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 563
diff changeset
40
683
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
41 this(SYM sid, Identifier* name, Node node)
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
42 {
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
43 this.sid = sid;
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
44 this.name = name;
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
45 this.node = node;
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
46 }
1ae72234db26 Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 623
diff changeset
47
567
ab9f5020cd02 Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 563
diff changeset
48 // A template macro for building isXYZ() methods.
707
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
49 private template isX(char[] kind)
567
ab9f5020cd02 Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 563
diff changeset
50 {
707
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
51 const char[] isX = `bool is`~kind~`(){ return sid == SYM.`~kind~`; }`;
567
ab9f5020cd02 Added 'is-methods' to class Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 563
diff changeset
52 }
707
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
53 mixin(isX!("Module"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
54 mixin(isX!("Class"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
55 mixin(isX!("Interface"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
56 mixin(isX!("Struct"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
57 mixin(isX!("Union"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
58 mixin(isX!("Enum"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
59 mixin(isX!("EnumMember"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
60 mixin(isX!("Template"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
61 mixin(isX!("Variable"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
62 mixin(isX!("Function"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
63 mixin(isX!("Alias"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
64 mixin(isX!("OverloadSet"));
efa5fcb9aa14 Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
65 // mixin(isX!("Type"));
407
5431c0faf3b5 Added modules dil.Scope and dil.Symbol.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
66 }