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
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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 super(loc, TOK.TOKfunction, FuncExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this.fd = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
35 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
37 return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
40 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 printf("FuncExp.semantic(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 fd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 //fd.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 fd.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (!global.errors ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 // need to infer return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 (fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 fd.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if (!global.errors && global.params.useInline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 fd.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 // need to infer return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (global.errors && fd.type && fd.type.ty == TY.Tfunction && !fd.type.nextOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 (cast(TypeFunction)fd.type).next = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 // Type is a "delegate to" or "pointer to" the function literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 if (fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 type = new TypeDelegate(fd.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 type = fd.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 fd.tookAddressOf++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
88 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
93 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
58
ecf732dfe11e Statement.error
korDen
parents: 56
diff changeset
95 return fd.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
98 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
104 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 //printf("FuncExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 s = fd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 e = el_ptr(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 elem* ethis = getEthis(loc, irs, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 e = el_pair(TYM.TYullong, ethis, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 irs.deferToObj.push(cast(void*)fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
123 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128