annotate dmd/FuncExp.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents cd48cb899aee
children eb38fdcb3e62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
1 module dmd.FuncExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 93
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
5 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
6 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
7 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
8 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
9 import dmd.InlineCostState;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
10 import dmd.InterState;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
11 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
12 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
13 import dmd.FuncLiteralDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.TYM;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
24 import dmd.backend.Symbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
25
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
26 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
27
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 class FuncExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
30 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 FuncLiteralDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this(Loc loc, FuncLiteralDeclaration fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 123
diff changeset
36 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 super(loc, TOK.TOKfunction, FuncExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this.fd = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
41 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
43 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
46 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 printf("FuncExp.semantic(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 fd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 //fd.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 fd.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if (!global.errors ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 // need to infer return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 fd.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (!global.errors && global.params.useInline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 fd.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 // need to infer return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 (cast(TypeFunction)fd.type).next = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 // Type is a "delegate to" or "pointer to" the function literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 type = new TypeDelegate(fd.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 type = fd.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 fd.tookAddressOf++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
93
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
94 Expression interpret(InterState istate)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
95 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
96 version (LOG) {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
97 writef("FuncExp::interpret() %s\n", toChars());
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
98 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
99 return this;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
100
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
101 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
103 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
105 //printf("FuncExp.scanForNestedRef(%s)\n", toChars());
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
106 //fd.parent = sc.parent;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
109 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
58
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
111 return fd.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
114 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
116 fd.toCBuffer(buf, hgs);
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
117 //buf.writestring(fd.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
120 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 //printf("FuncExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 s = fd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 e = el_ptr(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 if (fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 elem* ethis = getEthis(loc, irs, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 e = el_pair(TYM.TYullong, ethis, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 irs.deferToObj.push(cast(void*)fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
139 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
141 // Right now, this makes the function be output to the .obj file twice.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
142 return COST_MAX;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145