comparison gen/aa.cpp @ 399:0e6b4d65d3f8

Give error messages for invalid casts. This required passing Loc information to certain functions. Fixes nocompile/b/bug_cgcs_354_A/B.
author Christian Kamm <kamm incasoftware de>
date Sat, 26 Jul 2008 17:19:16 +0200
parents a9697749e898
children d3d3519b72e8
comparison
equal deleted inserted replaced
398:811f82dfddbd 399:0e6b4d65d3f8
12 #include "gen/irstate.h" 12 #include "gen/irstate.h"
13 #include "gen/dvalue.h" 13 #include "gen/dvalue.h"
14 14
15 // makes sure the key value lives in memory so it can be passed to the runtime functions without problems 15 // makes sure the key value lives in memory so it can be passed to the runtime functions without problems
16 // returns the pointer 16 // returns the pointer
17 static LLValue* to_pkey(DValue* key) 17 static LLValue* to_pkey(Loc& loc, DValue* key)
18 { 18 {
19 Type* keytype = key->getType(); 19 Type* keytype = key->getType();
20 bool needmem = !DtoIsPassedByRef(keytype); 20 bool needmem = !DtoIsPassedByRef(keytype);
21 LLValue* pkey; 21 LLValue* pkey;
22 if (key->isIm()) { 22 if (key->isIm()) {
36 pkey = key->getRVal(); 36 pkey = key->getRVal();
37 } 37 }
38 else { 38 else {
39 LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); 39 LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint());
40 DVarValue* var = new DVarValue(keytype, tmp, true); 40 DVarValue* var = new DVarValue(keytype, tmp, true);
41 DtoAssign(var, key); 41 DtoAssign(loc, var, key);
42 return tmp; 42 return tmp;
43 } 43 }
44 44
45 // give memory 45 // give memory
46 if (needmem) { 46 if (needmem) {
60 return DtoTypeInfoOf(keytype, false); 60 return DtoTypeInfoOf(keytype, false);
61 } 61 }
62 62
63 ///////////////////////////////////////////////////////////////////////////////////// 63 /////////////////////////////////////////////////////////////////////////////////////
64 64
65 DValue* DtoAAIndex(Type* type, DValue* aa, DValue* key) 65 DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key)
66 { 66 {
67 // call: 67 // call:
68 // extern(C) void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize) 68 // extern(C) void* _aaGet(AA* aa, TypeInfo keyti, void* pkey, size_t valuesize)
69 69
70 // first get the runtime function 70 // first get the runtime function
81 81
82 // valuesize param 82 // valuesize param
83 LLValue* valsize = DtoConstSize_t(getABITypeSize(DtoType(type))); 83 LLValue* valsize = DtoConstSize_t(getABITypeSize(DtoType(type)));
84 84
85 // pkey param 85 // pkey param
86 LLValue* pkey = to_pkey(key); 86 LLValue* pkey = to_pkey(loc, key);
87 pkey = DtoBitCast(pkey, funcTy->getParamType(3)); 87 pkey = DtoBitCast(pkey, funcTy->getParamType(3));
88 88
89 // call runtime 89 // call runtime
90 LLValue* ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index")->get(); 90 LLValue* ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index")->get();
91 91
97 return new DVarValue(type, ret, true); 97 return new DVarValue(type, ret, true);
98 } 98 }
99 99
100 ///////////////////////////////////////////////////////////////////////////////////// 100 /////////////////////////////////////////////////////////////////////////////////////
101 101
102 DValue* DtoAAIn(Type* type, DValue* aa, DValue* key) 102 DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key)
103 { 103 {
104 // call: 104 // call:
105 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey) 105 // extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey)
106 106
107 // first get the runtime function 107 // first get the runtime function
119 // keyti param 119 // keyti param
120 LLValue* keyti = to_keyti(key); 120 LLValue* keyti = to_keyti(key);
121 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 121 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
122 122
123 // pkey param 123 // pkey param
124 LLValue* pkey = to_pkey(key); 124 LLValue* pkey = to_pkey(loc, key);
125 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); 125 pkey = DtoBitCast(pkey, funcTy->getParamType(2));
126 126
127 // call runtime 127 // call runtime
128 LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in")->get(); 128 LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in")->get();
129 129
135 return new DImValue(type, ret); 135 return new DImValue(type, ret);
136 } 136 }
137 137
138 ///////////////////////////////////////////////////////////////////////////////////// 138 /////////////////////////////////////////////////////////////////////////////////////
139 139
140 void DtoAARemove(DValue* aa, DValue* key) 140 void DtoAARemove(Loc& loc, DValue* aa, DValue* key)
141 { 141 {
142 // call: 142 // call:
143 // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey) 143 // extern(C) void _aaDel(AA aa, TypeInfo keyti, void* pkey)
144 144
145 // first get the runtime function 145 // first get the runtime function
157 // keyti param 157 // keyti param
158 LLValue* keyti = to_keyti(key); 158 LLValue* keyti = to_keyti(key);
159 keyti = DtoBitCast(keyti, funcTy->getParamType(1)); 159 keyti = DtoBitCast(keyti, funcTy->getParamType(1));
160 160
161 // pkey param 161 // pkey param
162 LLValue* pkey = to_pkey(key); 162 LLValue* pkey = to_pkey(loc, key);
163 pkey = DtoBitCast(pkey, funcTy->getParamType(2)); 163 pkey = DtoBitCast(pkey, funcTy->getParamType(2));
164 164
165 // build arg vector 165 // build arg vector
166 LLSmallVector<LLValue*, 3> args; 166 LLSmallVector<LLValue*, 3> args;
167 args.push_back(aaval); 167 args.push_back(aaval);