Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
72 | 1 module dmd.FuncExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.backend.elem; | |
6 import dmd.OutBuffer; | |
7 import dmd.Loc; | |
8 import dmd.Scope; | |
9 import dmd.InlineCostState; | |
10 import dmd.IRState; | |
11 import dmd.HdrGenState; | |
12 import dmd.FuncLiteralDeclaration; | |
0 | 13 import dmd.TOK; |
14 import dmd.TypeFunction; | |
15 import dmd.TypeDelegate; | |
16 import dmd.TY; | |
17 import dmd.Type; | |
18 import dmd.Global; | |
19 | |
20 import dmd.backend.Util; | |
21 import dmd.codegen.Util; | |
22 import dmd.backend.TYM; | |
72 | 23 import dmd.backend.Symbol; |
24 | |
0 | 25 class FuncExp : Expression |
26 { | |
27 FuncLiteralDeclaration fd; | |
28 | |
29 this(Loc loc, FuncLiteralDeclaration fd) | |
30 { | |
178 | 31 register(); |
0 | 32 super(loc, TOK.TOKfunction, FuncExp.sizeof); |
33 this.fd = fd; | |
34 } | |
35 | |
72 | 36 override Expression syntaxCopy() |
0 | 37 { |
56 | 38 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null)); |
0 | 39 } |
40 | |
72 | 41 override Expression semantic(Scope sc) |
0 | 42 { |
43 version (LOGSEMANTIC) { | |
44 printf("FuncExp.semantic(%s)\n", toChars()); | |
45 } | |
46 if (!type) | |
47 { | |
48 fd.semantic(sc); | |
49 | |
50 //fd.parent = sc.parent; | |
51 if (global.errors) | |
52 { | |
53 } | |
54 else | |
55 { | |
56 fd.semantic2(sc); | |
57 if (!global.errors || | |
58 // need to infer return type | |
59 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())) | |
60 { | |
61 fd.semantic3(sc); | |
62 | |
63 if (!global.errors && global.params.useInline) | |
64 fd.inlineScan(); | |
65 } | |
66 } | |
67 | |
68 // need to infer return type | |
69 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()) | |
70 (cast(TypeFunction)fd.type).next = Type.terror; | |
71 | |
72 // Type is a "delegate to" or "pointer to" the function literal | |
73 if (fd.isNested()) | |
74 { | |
75 type = new TypeDelegate(fd.type); | |
76 type = type.semantic(loc, sc); | |
77 } | |
78 else | |
79 { | |
80 type = fd.type.pointerTo(); | |
81 } | |
82 | |
83 fd.tookAddressOf++; | |
84 } | |
85 | |
86 return this; | |
87 } | |
88 | |
72 | 89 override void scanForNestedRef(Scope sc) |
0 | 90 { |
123 | 91 //printf("FuncExp.scanForNestedRef(%s)\n", toChars()); |
92 //fd.parent = sc.parent; | |
0 | 93 } |
94 | |
72 | 95 override string toChars() |
0 | 96 { |
58 | 97 return fd.toChars(); |
0 | 98 } |
99 | |
72 | 100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 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 | 104 } |
105 | |
72 | 106 override elem* toElem(IRState* irs) |
0 | 107 { |
108 elem* e; | |
109 Symbol* s; | |
110 | |
111 //printf("FuncExp::toElem() %s\n", toChars()); | |
112 s = fd.toSymbol(); | |
113 e = el_ptr(s); | |
114 if (fd.isNested()) | |
115 { | |
116 elem* ethis = getEthis(loc, irs, fd); | |
117 e = el_pair(TYM.TYullong, ethis, e); | |
118 } | |
119 | |
120 irs.deferToObj.push(cast(void*)fd); | |
121 el_setLoc(e,loc); | |
122 return e; | |
123 } | |
124 | |
72 | 125 override int inlineCost(InlineCostState* ics) |
0 | 126 { |
123 | 127 // Right now, this makes the function be output to the .obj file twice. |
128 return COST_MAX; | |
0 | 129 } |
130 } | |
131 |