Mercurial > projects > ddmd
annotate dmd/FuncExp.d @ 114:e28b18c23469
added a module dmd.common for commonly used stuff
it currently holds code for consistency checking of predefined versions
also added a VisualD project file
author | Trass3r |
---|---|
date | Wed, 01 Sep 2010 18:21:58 +0200 |
parents | df6d0f967680 |
children | 9e39c7de8438 |
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 { | |
31 super(loc, TOK.TOKfunction, FuncExp.sizeof); | |
32 this.fd = fd; | |
33 } | |
34 | |
72 | 35 override Expression syntaxCopy() |
0 | 36 { |
56 | 37 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null)); |
0 | 38 } |
39 | |
72 | 40 override Expression semantic(Scope sc) |
0 | 41 { |
42 version (LOGSEMANTIC) { | |
43 printf("FuncExp.semantic(%s)\n", toChars()); | |
44 } | |
45 if (!type) | |
46 { | |
47 fd.semantic(sc); | |
48 | |
49 //fd.parent = sc.parent; | |
50 if (global.errors) | |
51 { | |
52 } | |
53 else | |
54 { | |
55 fd.semantic2(sc); | |
56 if (!global.errors || | |
57 // need to infer return type | |
58 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())) | |
59 { | |
60 fd.semantic3(sc); | |
61 | |
62 if (!global.errors && global.params.useInline) | |
63 fd.inlineScan(); | |
64 } | |
65 } | |
66 | |
67 // need to infer return type | |
68 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()) | |
69 (cast(TypeFunction)fd.type).next = Type.terror; | |
70 | |
71 // Type is a "delegate to" or "pointer to" the function literal | |
72 if (fd.isNested()) | |
73 { | |
74 type = new TypeDelegate(fd.type); | |
75 type = type.semantic(loc, sc); | |
76 } | |
77 else | |
78 { | |
79 type = fd.type.pointerTo(); | |
80 } | |
81 | |
82 fd.tookAddressOf++; | |
83 } | |
84 | |
85 return this; | |
86 } | |
87 | |
72 | 88 override void scanForNestedRef(Scope sc) |
0 | 89 { |
90 assert(false); | |
91 } | |
92 | |
72 | 93 override string toChars() |
0 | 94 { |
58 | 95 return fd.toChars(); |
0 | 96 } |
97 | |
72 | 98 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 99 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
72
diff
changeset
|
100 fd.toCBuffer(buf, hgs); |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
72
diff
changeset
|
101 //buf.writestring(fd.toChars()); |
0 | 102 } |
103 | |
72 | 104 override elem* toElem(IRState* irs) |
0 | 105 { |
106 elem* e; | |
107 Symbol* s; | |
108 | |
109 //printf("FuncExp::toElem() %s\n", toChars()); | |
110 s = fd.toSymbol(); | |
111 e = el_ptr(s); | |
112 if (fd.isNested()) | |
113 { | |
114 elem* ethis = getEthis(loc, irs, fd); | |
115 e = el_pair(TYM.TYullong, ethis, e); | |
116 } | |
117 | |
118 irs.deferToObj.push(cast(void*)fd); | |
119 el_setLoc(e,loc); | |
120 return e; | |
121 } | |
122 | |
72 | 123 override int inlineCost(InlineCostState* ics) |
0 | 124 { |
125 assert(false); | |
126 } | |
127 } | |
128 |