annotate dmd/FuncExp.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents 9e39c7de8438
children cd48cb899aee
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;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
10 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
11 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
12 import dmd.FuncLiteralDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.TYM;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
23 import dmd.backend.Symbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
24
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 class FuncExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 FuncLiteralDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 this(Loc loc, FuncLiteralDeclaration fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 123
diff changeset
31 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 super(loc, TOK.TOKfunction, FuncExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 this.fd = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
36 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
38 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null));
0
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 semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 printf("FuncExp.semantic(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 fd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 //fd.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 fd.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 if (!global.errors ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 // need to infer return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 fd.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (!global.errors && global.params.useInline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 fd.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 // need to infer return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 (cast(TypeFunction)fd.type).next = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 // Type is a "delegate to" or "pointer to" the function literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 type = new TypeDelegate(fd.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 type = fd.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 fd.tookAddressOf++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
89 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
91 //printf("FuncExp.scanForNestedRef(%s)\n", toChars());
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
92 //fd.parent = sc.parent;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
95 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
58
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
97 return fd.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
102 fd.toCBuffer(buf, hgs);
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
103 //buf.writestring(fd.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
106 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 //printf("FuncExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 s = fd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 e = el_ptr(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 elem* ethis = getEthis(loc, irs, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 e = el_pair(TYM.TYullong, ethis, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 irs.deferToObj.push(cast(void*)fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
125 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
127 // Right now, this makes the function be output to the .obj file twice.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
128 return COST_MAX;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131