1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include <Compiler.h>
|
---|
4 |
|
---|
5 | #include "common.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | int MakeWholeType(int size,int bSigned){
|
---|
9 | switch(size){
|
---|
10 | case 1:
|
---|
11 | if(bSigned) return DEF_SBYTE;
|
---|
12 | else return DEF_BYTE;
|
---|
13 | break;
|
---|
14 | case 2:
|
---|
15 | if(bSigned) return DEF_INTEGER;
|
---|
16 | else return DEF_WORD;
|
---|
17 | break;
|
---|
18 | case 4:
|
---|
19 | if(bSigned) return DEF_LONG;
|
---|
20 | else return DEF_DWORD;
|
---|
21 | break;
|
---|
22 | case 8:
|
---|
23 | if(bSigned) return DEF_INT64;
|
---|
24 | else return DEF_QWORD;
|
---|
25 | break;
|
---|
26 | }
|
---|
27 | return 0;
|
---|
28 | }
|
---|
29 |
|
---|
30 | int AutoBigCast(int BaseType,int CalcType){
|
---|
31 | int type;
|
---|
32 | type=CalcType;
|
---|
33 |
|
---|
34 | if(BaseType==0||BaseType==-1){
|
---|
35 | //ベースタイプが未定のとき
|
---|
36 | return type;
|
---|
37 | }
|
---|
38 |
|
---|
39 | if(!IsWholeNumberType(type)){
|
---|
40 | //整数型ではないときは暗黙の変換は必要なし
|
---|
41 | return type;
|
---|
42 | }
|
---|
43 |
|
---|
44 | if(BaseType==DEF_OBJECT||BaseType==DEF_STRUCT){
|
---|
45 | //ベースタイプがオブジェクトのときは暗黙の変換は必要なし
|
---|
46 | return type;
|
---|
47 | }
|
---|
48 |
|
---|
49 | int BaseTypeSize;
|
---|
50 | BaseTypeSize=Type(BaseType,-1).GetSize();
|
---|
51 |
|
---|
52 | if(IsRealNumberType(BaseType)){
|
---|
53 | if(Type(CalcType,-1).GetSize()<4)
|
---|
54 | type=MakeWholeType(4,IsSignedType(CalcType));
|
---|
55 | }
|
---|
56 | else if(BaseTypeSize>Type(CalcType,-1).GetSize()){
|
---|
57 | //要求される型のほうがサイズが大きいとき
|
---|
58 | type=MakeWholeType(BaseTypeSize,IsSignedType(CalcType));
|
---|
59 | }
|
---|
60 |
|
---|
61 | if(!type){
|
---|
62 | extern int cp;
|
---|
63 | compiler.errorMessenger.Output(300,NULL,cp);
|
---|
64 | }
|
---|
65 |
|
---|
66 | return type;
|
---|
67 | }
|
---|
68 |
|
---|
69 | BOOL CheckCalcType(int idCalc,int *type,int sp){
|
---|
70 | //演算子の右辺、左辺の型をチェック
|
---|
71 | extern int cp;
|
---|
72 |
|
---|
73 | //演算子名を取得
|
---|
74 | char temporary[255];
|
---|
75 | GetCalcName(idCalc,temporary);
|
---|
76 |
|
---|
77 | switch(idCalc){
|
---|
78 |
|
---|
79 | /////////////////////////////////////
|
---|
80 | // 実数に対する論理演算はエラー
|
---|
81 | /////////////////////////////////////
|
---|
82 |
|
---|
83 | case CALC_XOR:
|
---|
84 | case CALC_OR:
|
---|
85 | case CALC_AND:
|
---|
86 | if(IsRealNumberType(type[sp-2])||IsRealNumberType(type[sp-1])){
|
---|
87 | //いずれかの項が実数のとき
|
---|
88 | compiler.errorMessenger.Output(45,temporary,cp);
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 |
|
---|
92 | //As以外の演算子に型名が指定されていないかをチェック
|
---|
93 | if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
|
---|
94 | compiler.errorMessenger.Output(48,temporary,cp);
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 | break;
|
---|
98 |
|
---|
99 | case CALC_NOT:
|
---|
100 | if(IsRealNumberType(type[sp-1])){
|
---|
101 | //実数のとき
|
---|
102 | compiler.errorMessenger.Output(45,temporary,cp);
|
---|
103 | return 0;
|
---|
104 | }
|
---|
105 |
|
---|
106 | //As以外の演算子に型名が指定されていないかをチェック
|
---|
107 | if(type[sp-1]&FLAG_CAST){
|
---|
108 | compiler.errorMessenger.Output(48,temporary,cp);
|
---|
109 | return 0;
|
---|
110 | }
|
---|
111 | break;
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 | /////////////////////////////////////
|
---|
116 | // 比較演算はチェック項目なし
|
---|
117 | /////////////////////////////////////
|
---|
118 |
|
---|
119 | case CALC_PE:
|
---|
120 | case CALC_QE:
|
---|
121 | case CALC_NOTEQUAL:
|
---|
122 | case CALC_EQUAL:
|
---|
123 | case CALC_P:
|
---|
124 | case CALC_Q:
|
---|
125 | //As以外の演算子に型名が指定されていないかをチェック
|
---|
126 | if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
|
---|
127 | compiler.errorMessenger.Output(48,temporary,cp);
|
---|
128 | return 0;
|
---|
129 | }
|
---|
130 | break;
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | /////////////////////////////////////
|
---|
135 | // 算術演算をチェック
|
---|
136 | /////////////////////////////////////
|
---|
137 |
|
---|
138 | case CALC_ADDITION:
|
---|
139 | case CALC_SUBTRACTION:
|
---|
140 | case CALC_PRODUCT:
|
---|
141 | case CALC_QUOTIENT:
|
---|
142 | case CALC_POWER:
|
---|
143 | //As以外の演算子に型名が指定されていないかをチェック
|
---|
144 | if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
|
---|
145 | compiler.errorMessenger.Output(48,temporary,cp);
|
---|
146 | return 0;
|
---|
147 | }
|
---|
148 | break;
|
---|
149 |
|
---|
150 | case CALC_SHL:
|
---|
151 | case CALC_SHR:
|
---|
152 | case CALC_MOD:
|
---|
153 | case CALC_INTQUOTIENT:
|
---|
154 | if(IsRealNumberType(type[sp-2])||IsRealNumberType(type[sp-1])){
|
---|
155 | //いずれかの項が実数のとき
|
---|
156 | compiler.errorMessenger.Output(45,temporary,cp);
|
---|
157 | return 0;
|
---|
158 | }
|
---|
159 |
|
---|
160 | //As以外の演算子に型名が指定されていないかをチェック
|
---|
161 | if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
|
---|
162 | compiler.errorMessenger.Output(48,temporary,cp);
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 | break;
|
---|
166 |
|
---|
167 | case CALC_AS:
|
---|
168 | if((type[sp-1]&FLAG_CAST)==0){
|
---|
169 | //型名が指定されていないときはエラー
|
---|
170 | compiler.errorMessenger.Output(47,NULL,cp);
|
---|
171 | return 0;
|
---|
172 | }
|
---|
173 | break;
|
---|
174 |
|
---|
175 | case CALC_BYVAL:
|
---|
176 | if(type[sp-1]&FLAG_CAST){
|
---|
177 | //型名が指定されていないときはエラー
|
---|
178 | compiler.errorMessenger.Output(47,NULL,cp);
|
---|
179 | return 0;
|
---|
180 | }
|
---|
181 | break;
|
---|
182 |
|
---|
183 | case CALC_MINUSMARK:
|
---|
184 | //As以外の演算子に型名が指定されていないかをチェック
|
---|
185 | if(type[sp-1]&FLAG_CAST){
|
---|
186 | compiler.errorMessenger.Output(48,temporary,cp);
|
---|
187 | return 0;
|
---|
188 | }
|
---|
189 | break;
|
---|
190 | }
|
---|
191 | return 1;
|
---|
192 | }
|
---|
193 |
|
---|
194 | int GetReturnType_OperatorProc(int idCalc,const Type &baseType,int *type_stack,LONG_PTR *index_stack,int &sp){
|
---|
195 | Type leftType( type_stack[sp-2], index_stack[sp-2] );
|
---|
196 | Type rightType( type_stack[sp-1] & (~FLAG_CAST), index_stack[sp-1] );
|
---|
197 |
|
---|
198 | //オーバーロードされたオペレータ関数を呼び出す
|
---|
199 | const CClass *pobj_c = &leftType.GetClass();
|
---|
200 |
|
---|
201 | std::vector<const UserProc *> subs;
|
---|
202 | pobj_c->GetDynamicMethods().Enum( idCalc, subs );
|
---|
203 | if( subs.size() == 0 ){
|
---|
204 | return 0;
|
---|
205 | }
|
---|
206 |
|
---|
207 |
|
---|
208 | //項の数
|
---|
209 | BOOL bTwoTerm=1;
|
---|
210 | if(idCalc==CALC_AS) bTwoTerm=0;
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|
214 | /////////////////////////////////////////////
|
---|
215 | // オーバーロード解決用のパラメータを設定
|
---|
216 | /////////////////////////////////////////////
|
---|
217 |
|
---|
218 |
|
---|
219 | //_System_LocalThis
|
---|
220 | Parameters params;
|
---|
221 |
|
---|
222 | if(bTwoTerm){
|
---|
223 | params.push_back( new Parameter( "", rightType ) );
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | //オーバーロードを解決
|
---|
228 | char temporary[255];
|
---|
229 | if(idCalc==CALC_EQUAL) lstrcpy(temporary,"==");
|
---|
230 | else GetCalcName(idCalc,temporary);
|
---|
231 | const UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType, leftType );
|
---|
232 |
|
---|
233 | if(bTwoTerm){
|
---|
234 | delete params[0];
|
---|
235 | }
|
---|
236 |
|
---|
237 | if(!pUserProc){
|
---|
238 | return 0;
|
---|
239 | }
|
---|
240 | else{
|
---|
241 | //オーバーロードされていないが、パラメータ個数が一致しないとき
|
---|
242 | if(params.size()!=pUserProc->Params().size()){
|
---|
243 | return 0;
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | sp--;
|
---|
248 | type_stack[sp-1]=pUserProc->ReturnType().GetBasicType();
|
---|
249 | index_stack[sp-1]=pUserProc->ReturnType().GetIndex();
|
---|
250 |
|
---|
251 | return 1;
|
---|
252 | }
|
---|
253 |
|
---|
254 | bool Operator_New_GetType(const char *Parameter,const Type &baseType, Type &resultType ){
|
---|
255 | char TypeName[VN_SIZE],objectSizeStr[VN_SIZE];
|
---|
256 | int i,i2;
|
---|
257 |
|
---|
258 | i=0;
|
---|
259 |
|
---|
260 | if(Parameter[0]=='['){
|
---|
261 | i=GetStringInBracket(objectSizeStr,Parameter);
|
---|
262 |
|
---|
263 | SlideString(objectSizeStr+1,-1);
|
---|
264 | objectSizeStr[i-2]=0;
|
---|
265 | }
|
---|
266 | else objectSizeStr[0]=0;
|
---|
267 |
|
---|
268 | for(i2=0;;i++,i2++){
|
---|
269 | if(Parameter[i]=='(' || Parameter[i]=='['){
|
---|
270 | TypeName[i2]=0;
|
---|
271 | break;
|
---|
272 | }
|
---|
273 | TypeName[i2]=Parameter[i];
|
---|
274 | if(Parameter[i]=='\0'){
|
---|
275 | break;
|
---|
276 | }
|
---|
277 | }
|
---|
278 |
|
---|
279 | if( !compiler.StringToType( TypeName, resultType ) )
|
---|
280 | {
|
---|
281 | compiler.errorMessenger.Output(3,TypeName,cp);
|
---|
282 | return false;
|
---|
283 | }
|
---|
284 |
|
---|
285 | if( !resultType.IsObject() )
|
---|
286 | {
|
---|
287 | compiler.errorMessenger.Output(121,NULL,cp);
|
---|
288 | return false;
|
---|
289 | }
|
---|
290 |
|
---|
291 | if( baseType.IsObject() ){
|
---|
292 | resultType.SetBasicType( DEF_OBJECT );
|
---|
293 | }
|
---|
294 | else{
|
---|
295 | resultType.SetBasicType( DEF_PTR_OBJECT );
|
---|
296 | }
|
---|
297 | return true;
|
---|
298 | }
|
---|
299 |
|
---|
300 | bool GetMemberTermType( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool *pIsVariable )
|
---|
301 | {
|
---|
302 | ////////////////////////////////
|
---|
303 | // インデクサ(getアクセサ)
|
---|
304 | ////////////////////////////////
|
---|
305 |
|
---|
306 | char VarName[VN_SIZE],ArrayElements[VN_SIZE];
|
---|
307 | GetArrayElement(member,VarName,ArrayElements);
|
---|
308 | if(ArrayElements[0]){
|
---|
309 | Type classType;
|
---|
310 | if( VarName[0] == '\0' )
|
---|
311 | {
|
---|
312 | classType = leftType;
|
---|
313 |
|
---|
314 | if( classType.IsObject() )
|
---|
315 | {
|
---|
316 | // 既にuseRegにオブジェクトポインタが格納されており、それに対するインデクサを呼び出す場合
|
---|
317 | // ※「プロパティ値として返ってきたオブジェクトインスタンスのインデクサを呼び出す」場合にここにくる
|
---|
318 | }
|
---|
319 | }
|
---|
320 | else
|
---|
321 | {
|
---|
322 | GetMemberType( leftType, VarName, classType, 0, false );
|
---|
323 | }
|
---|
324 |
|
---|
325 | if( classType.IsObject() )
|
---|
326 | {
|
---|
327 | if( !GetReturnTypeOfIndexerGetterProc( classType, resultType ) ){
|
---|
328 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
329 | return false;
|
---|
330 | }
|
---|
331 |
|
---|
332 | return true;
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | ///////////////////////////////////////////////////////////////////
|
---|
338 | // メンバを検索
|
---|
339 | ///////////////////////////////////////////////////////////////////
|
---|
340 | if( GetMemberType( leftType, member, resultType, 0, false ) ){
|
---|
341 | // メンバが見つかったとき
|
---|
342 |
|
---|
343 | if( pIsVariable )
|
---|
344 | {
|
---|
345 | *pIsVariable = true;
|
---|
346 | }
|
---|
347 |
|
---|
348 | return true;
|
---|
349 | }
|
---|
350 |
|
---|
351 |
|
---|
352 | ///////////////////////////////////////////////////////////////////
|
---|
353 | // 動的メソッドを検索
|
---|
354 | ///////////////////////////////////////////////////////////////////
|
---|
355 | char methodName[VN_SIZE] ,lpPtrOffset[VN_SIZE], dummy[1];
|
---|
356 | char parameter[VN_SIZE];
|
---|
357 | ReferenceKind refType;
|
---|
358 | PareOrBracket pareOrBracket = None;
|
---|
359 | lstrcpy( methodName, member );
|
---|
360 | GetVarFormatString( methodName, parameter, lpPtrOffset, dummy, refType, &pareOrBracket );
|
---|
361 |
|
---|
362 | std::vector<const UserProc *> userProcs;
|
---|
363 | leftType.GetClass().EnumDynamicMethodsOrInterfaceMethods( methodName, userProcs );
|
---|
364 | if(userProcs.size()){
|
---|
365 | //オーバーロードを解決
|
---|
366 | const UserProc *pUserProc = OverloadSolutionWithStrParam(termFull,userProcs,parameter,termLeft);
|
---|
367 |
|
---|
368 | if( pUserProc )
|
---|
369 | {
|
---|
370 | if(
|
---|
371 | pUserProc->Params().size() == 0 // 仮引数の個数は0
|
---|
372 | && parameter[0] // 実引数は1つ以上
|
---|
373 | && pUserProc->ReturnType().IsObject() // 戻り値がクラス型の場合
|
---|
374 | && pareOrBracket == Bracket ) // 実引数は[]で囲まれている
|
---|
375 | {
|
---|
376 | // プロパティ値として返ってきたオブジェクトインスタンスのインデクサを呼び出す
|
---|
377 |
|
---|
378 | // まずはプロパティ値を取得
|
---|
379 | bool dummyIsVariable;
|
---|
380 | GetMemberTermType( leftType, baseType, resultType, termFull, termLeft, methodName, &dummyIsVariable );
|
---|
381 |
|
---|
382 | // 戻り値のオブジェクトインスタンスのインデクサを呼び出す
|
---|
383 | char temporary[VN_SIZE], temp2[VN_SIZE];
|
---|
384 | sprintf( temporary, "[%s]", parameter );
|
---|
385 | sprintf( temp2, "%s.%s", termLeft, methodName );
|
---|
386 | Type classType = resultType;
|
---|
387 | return GetMemberTermType( classType, baseType, resultType, termFull, temp2, temporary, pIsVariable );
|
---|
388 | }
|
---|
389 |
|
---|
390 | resultType = pUserProc->ReturnType();
|
---|
391 |
|
---|
392 | // 型パラメータを解決
|
---|
393 | ResolveFormalGenericTypeParameter( resultType, leftType, pUserProc );
|
---|
394 |
|
---|
395 | return true;
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | return false;
|
---|
400 | }
|
---|
401 |
|
---|
402 | bool GetTermType( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool *pIsClassName, bool *pIsVariable )
|
---|
403 | {
|
---|
404 | char parameter[VN_SIZE];
|
---|
405 |
|
---|
406 | // Withを解決
|
---|
407 | char termFull[VN_SIZE];
|
---|
408 | if(term[0]=='.'){
|
---|
409 | GetWithName(termFull);
|
---|
410 | lstrcat(termFull,term);
|
---|
411 | }
|
---|
412 | else lstrcpy(termFull,term);
|
---|
413 |
|
---|
414 | char termLeft[VN_SIZE];
|
---|
415 | lstrcpy(termLeft,termFull);
|
---|
416 |
|
---|
417 | // パース
|
---|
418 | char member[VN_SIZE];
|
---|
419 | ReferenceKind refType;
|
---|
420 | if( SplitMemberName( termFull, termLeft, member, refType ) ){
|
---|
421 | ///////////////////////////////////////////////////////////////////
|
---|
422 | // オブジェクトとメンバに分解できるとき
|
---|
423 | // termLeft.member
|
---|
424 | ///////////////////////////////////////////////////////////////////
|
---|
425 |
|
---|
426 | isLiteral = false;
|
---|
427 |
|
---|
428 | // オブジェクト側の型を取得
|
---|
429 | bool isClassName = false;
|
---|
430 | Type leftType;
|
---|
431 | if( GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
|
---|
432 | if( isClassName == false && compiler.GetObjectModule().meta.GetBlittableTypes().IsExist( leftType ) ){
|
---|
433 | // 左側のオブジェクト部分がBlittable型のとき
|
---|
434 |
|
---|
435 | char temporary[VN_SIZE];
|
---|
436 | lstrcpy( temporary, termLeft );
|
---|
437 | sprintf( termLeft, "%s(%s)",
|
---|
438 | compiler.GetObjectModule().meta.GetBlittableTypes().Find( leftType ).GetCreateStaticMethodFullName().c_str(),
|
---|
439 | temporary );
|
---|
440 |
|
---|
441 | if( !GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
|
---|
442 | goto globalArea;
|
---|
443 | }
|
---|
444 | }
|
---|
445 | }
|
---|
446 | else{
|
---|
447 | goto globalArea;
|
---|
448 | }
|
---|
449 |
|
---|
450 | if( isClassName ){
|
---|
451 | // 静的メンバ/メソッドの場合
|
---|
452 | goto globalArea;
|
---|
453 | }
|
---|
454 |
|
---|
455 | if( !leftType.HasMember() ){
|
---|
456 | // メンバを持たない型の場合
|
---|
457 | return false;
|
---|
458 | }
|
---|
459 |
|
---|
460 | return GetMemberTermType( leftType, baseType, resultType, termFull, termLeft, member, pIsVariable );
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | //////////////////////////////////////////////
|
---|
465 | // クラス名かどうかをチェック(静的メンバ用)
|
---|
466 | //////////////////////////////////////////////
|
---|
467 |
|
---|
468 | if( pIsClassName )
|
---|
469 | {
|
---|
470 | if( compiler.GetObjectModule().meta.FindClassSupportedTypeDef( termFull ) )
|
---|
471 | {
|
---|
472 | *pIsClassName = true;
|
---|
473 | return true;
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 | /////////////////////////////////////////////////////////////////
|
---|
479 | // グローバル属性
|
---|
480 | /////////////////////////////////////////////////////////////////
|
---|
481 | globalArea:
|
---|
482 |
|
---|
483 |
|
---|
484 | if(lstrcmpi(termFull,"This")==0)
|
---|
485 | {
|
---|
486 | if( !compiler.IsCompilingClass() )
|
---|
487 | {
|
---|
488 | return false;
|
---|
489 | }
|
---|
490 |
|
---|
491 | //Thisオブジェクト
|
---|
492 | resultType.SetType( DEF_OBJECT, &compiler.GetCompilingClass() );
|
---|
493 | isLiteral = false;
|
---|
494 | return true;
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | //////////////////////////////////////
|
---|
499 | // 関数(DLL、ユーザー定義、組み込み)
|
---|
500 | //////////////////////////////////////
|
---|
501 | char procName[VN_SIZE];
|
---|
502 | char temporary[8192];
|
---|
503 |
|
---|
504 | int i2=GetCallProcName(termFull,procName);
|
---|
505 | if(termFull[i2]=='('){
|
---|
506 | int i4=GetStringInPare_RemovePare(parameter,termFull+i2+1);
|
---|
507 |
|
---|
508 | void *pProc;
|
---|
509 | int idProc=GetProc(procName,(void **)&pProc);
|
---|
510 |
|
---|
511 | if(idProc){
|
---|
512 | //閉じカッコ")"に続く文字がNULLでないとき
|
---|
513 | if(termFull[i2+1+i4+1]!='\0'){
|
---|
514 | compiler.errorMessenger.Output(42,NULL,cp);
|
---|
515 | }
|
---|
516 |
|
---|
517 |
|
---|
518 | ////////////////
|
---|
519 | // 呼び出し
|
---|
520 | ////////////////
|
---|
521 |
|
---|
522 | if( !CallProc(idProc,pProc,procName,parameter, baseType, resultType, false ) ){
|
---|
523 | return false;
|
---|
524 | }
|
---|
525 | if( resultType.IsNull() ){
|
---|
526 | //戻り値が存在しないとき
|
---|
527 | return false;
|
---|
528 | }
|
---|
529 |
|
---|
530 | isLiteral = false;
|
---|
531 |
|
---|
532 | return true;
|
---|
533 | }
|
---|
534 | else
|
---|
535 | {
|
---|
536 | ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find(
|
---|
537 | ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( procName )
|
---|
538 | );
|
---|
539 | if( pConstMacro )
|
---|
540 | {
|
---|
541 | if( ActiveBasic::Compiler::LexicalAnalyzer::ConstMacroToExpression( *pConstMacro, parameter, temporary ) )
|
---|
542 | {
|
---|
543 | /////////////////////////
|
---|
544 | // マクロ関数
|
---|
545 | /////////////////////////
|
---|
546 |
|
---|
547 | //閉じカッコ")"に続く文字がNULLでないときはエラーにする
|
---|
548 | if(termFull[i2+1+i4+1]!='\0') compiler.errorMessenger.Output(42,NULL,cp);
|
---|
549 |
|
---|
550 | //マクロ関数の場合
|
---|
551 | if( !NumOpe_GetType(temporary,Type(),resultType) ){
|
---|
552 | return false;
|
---|
553 | }
|
---|
554 |
|
---|
555 | if( !IS_LITERAL( resultType.GetIndex() ) ){
|
---|
556 | //リテラル値ではなかったとき
|
---|
557 | isLiteral = false;
|
---|
558 | }
|
---|
559 |
|
---|
560 | return true;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | }
|
---|
564 | }
|
---|
565 |
|
---|
566 |
|
---|
567 | ////////////////////////////////
|
---|
568 | // インデクサ(getアクセサ)
|
---|
569 | ////////////////////////////////
|
---|
570 |
|
---|
571 | char VarName[VN_SIZE],ArrayElements[VN_SIZE];
|
---|
572 | GetArrayElement(termFull,VarName,ArrayElements);
|
---|
573 | if(ArrayElements[0]){
|
---|
574 | Type classType;
|
---|
575 | GetVarType(VarName,classType,false);
|
---|
576 | if( classType.IsObject() ){
|
---|
577 | if( !GetReturnTypeOfIndexerGetterProc( classType, resultType ) ){
|
---|
578 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
579 | return false;
|
---|
580 | }
|
---|
581 |
|
---|
582 | isLiteral = false;
|
---|
583 |
|
---|
584 | return true;
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 |
|
---|
589 | ////////////////////////////////
|
---|
590 | // 変数
|
---|
591 | ////////////////////////////////
|
---|
592 |
|
---|
593 | if( GetVarType( termFull, resultType, false ) ){
|
---|
594 | if( resultType.GetBasicType() & FLAG_PTR ){
|
---|
595 | //配列ポインタ
|
---|
596 | resultType.SetBasicType( GetPtrType( resultType.GetBasicType()^FLAG_PTR ) );
|
---|
597 | }
|
---|
598 |
|
---|
599 | isLiteral = false;
|
---|
600 |
|
---|
601 | if( pIsVariable )
|
---|
602 | {
|
---|
603 | // 変数である
|
---|
604 | *pIsVariable = true;
|
---|
605 | }
|
---|
606 |
|
---|
607 | return true;
|
---|
608 | }
|
---|
609 |
|
---|
610 |
|
---|
611 | /////////////////////////////////
|
---|
612 | // プロパティ用のメソッド
|
---|
613 | /////////////////////////////////
|
---|
614 |
|
---|
615 | //配列要素を排除
|
---|
616 | GetArrayElement(termFull,VarName,ArrayElements);
|
---|
617 |
|
---|
618 | if(GetSubHash(VarName,0)){
|
---|
619 | GetReturnTypeOfPropertyMethod(termFull,NULL,resultType);
|
---|
620 |
|
---|
621 | isLiteral = false;
|
---|
622 |
|
---|
623 | return true;
|
---|
624 | }
|
---|
625 |
|
---|
626 |
|
---|
627 | return false;
|
---|
628 | }
|
---|
629 |
|
---|
630 | bool GetTermType( const char *term, Type &resultType )
|
---|
631 | {
|
---|
632 | bool isLiteral;
|
---|
633 | return GetTermType( term, Type(), resultType, isLiteral );
|
---|
634 | }
|
---|
635 |
|
---|
636 | bool GetTermTypeOnlyVariable( const char *term, Type &resultType )
|
---|
637 | {
|
---|
638 | bool isLiteral, isVariable = false;
|
---|
639 | bool result = GetTermType( term, Type(), resultType, isLiteral, NULL, &isVariable );
|
---|
640 | return ( result && isVariable );
|
---|
641 | }
|
---|
642 |
|
---|
643 | bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType, bool *pIsLiteralCalculation ){
|
---|
644 | extern int cp;
|
---|
645 | int i,i3;
|
---|
646 |
|
---|
647 | //リテラル値のみの計算かどうかを判別するためのフラグ
|
---|
648 | bool dummyBool;
|
---|
649 | if( pIsLiteralCalculation == NULL )
|
---|
650 | {
|
---|
651 | pIsLiteralCalculation = &dummyBool;
|
---|
652 | }
|
---|
653 | *pIsLiteralCalculation = true;
|
---|
654 |
|
---|
655 | if(expression[0]=='\0'){
|
---|
656 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
657 | return false;
|
---|
658 | }
|
---|
659 |
|
---|
660 | if(expression[0]==1&& ( expression[1]==ESC_NEW || expression[1] == ESC_SYSTEM_STATIC_NEW ) ){
|
---|
661 | //New演算子(オブジェクト生成)
|
---|
662 | *pIsLiteralCalculation = false;
|
---|
663 | return Operator_New_GetType(expression+2,baseType, resultType );
|
---|
664 | }
|
---|
665 |
|
---|
666 | if( expression[0] == '[' ){
|
---|
667 | if( !baseType.IsPointer() ){
|
---|
668 | return false;
|
---|
669 | }
|
---|
670 |
|
---|
671 | resultType = baseType;
|
---|
672 | return true;
|
---|
673 | }
|
---|
674 |
|
---|
675 |
|
---|
676 | /////////////////////////////////
|
---|
677 | // 式要素を逆ポーランド式で取得
|
---|
678 | /////////////////////////////////
|
---|
679 |
|
---|
680 | char *values[255];
|
---|
681 | long calc[255];
|
---|
682 | long stack[255];
|
---|
683 | int pnum;
|
---|
684 | if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
|
---|
685 | for(i=0;i<pnum;i++){
|
---|
686 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
687 | }
|
---|
688 | return false;
|
---|
689 | }
|
---|
690 |
|
---|
691 |
|
---|
692 |
|
---|
693 | ////////////////////////////////
|
---|
694 | // 演算部分のコード生成を開始
|
---|
695 | ////////////////////////////////
|
---|
696 |
|
---|
697 | BOOL bError;
|
---|
698 | bError=0;
|
---|
699 |
|
---|
700 | int sp;
|
---|
701 | int type_stack[255];
|
---|
702 | LONG_PTR index_stack[255];
|
---|
703 | bool isNothing_stack[255];
|
---|
704 | _int64 i64data;
|
---|
705 | int idCalc;
|
---|
706 | for(i=0,sp=0;i<pnum;i++){
|
---|
707 | idCalc=calc[i]%100;
|
---|
708 |
|
---|
709 | if(idCalc){
|
---|
710 | if(type_stack[sp-2]==DEF_OBJECT){
|
---|
711 | if( idCalc == CALC_AS
|
---|
712 | && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
|
---|
713 | && index_stack[sp-1] == index_stack[sp-2]
|
---|
714 | || isNothing_stack[sp-2] ){
|
---|
715 | // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
|
---|
716 | }
|
---|
717 | else if( idCalc == CALC_AS
|
---|
718 | && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
|
---|
719 | && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
|
---|
720 | )){
|
---|
721 | // ダウンキャストを許可する
|
---|
722 | }
|
---|
723 | else if( idCalc == CALC_AS ){
|
---|
724 | // NumOpe_GetTypeではすべてのキャストを許可する
|
---|
725 | }
|
---|
726 | else{
|
---|
727 | //オーバーロードされたオペレータを呼び出す
|
---|
728 | if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){
|
---|
729 | goto error;
|
---|
730 | }
|
---|
731 |
|
---|
732 | continue;
|
---|
733 | }
|
---|
734 | }
|
---|
735 |
|
---|
736 | if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
|
---|
737 | }
|
---|
738 |
|
---|
739 | switch(idCalc){
|
---|
740 | //数値
|
---|
741 | case 0:
|
---|
742 | index_stack[sp]=-1;
|
---|
743 | isNothing_stack[sp] = false;
|
---|
744 |
|
---|
745 | char *term;
|
---|
746 | term = values[i];
|
---|
747 |
|
---|
748 | if( calc[i+1]%100 == CALC_AS ){
|
---|
749 | // As演算子の右辺値
|
---|
750 | //型名
|
---|
751 | if( compiler.StringToType( term, resultType ) ){
|
---|
752 |
|
---|
753 | if( resultType.IsObject() ){
|
---|
754 | if( resultType.GetClass().IsBlittableType() ){
|
---|
755 | // Blittable型のときは基本型として扱う
|
---|
756 | // ※ただし、コンパイル中のメソッドがBlittable型クラスに属していないこと
|
---|
757 | if( compiler.IsLocalAreaCompiling()
|
---|
758 | && compiler.GetCompilingUserProc().HasParentClass()
|
---|
759 | && compiler.GetCompilingUserProc().GetParentClass().IsBlittableType() )
|
---|
760 | {
|
---|
761 | // コンパイル中のメソッドがBlittable型クラスに属している
|
---|
762 | }
|
---|
763 | else{
|
---|
764 | resultType = resultType.GetClass().GetBlittableType();
|
---|
765 | }
|
---|
766 | }
|
---|
767 | }
|
---|
768 |
|
---|
769 | resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
|
---|
770 | }
|
---|
771 | else{
|
---|
772 | compiler.errorMessenger.Output(3, term, cp );
|
---|
773 | goto error;
|
---|
774 | }
|
---|
775 |
|
---|
776 | type_stack[sp] = resultType.GetBasicType();
|
---|
777 | index_stack[sp] = resultType.GetIndex();
|
---|
778 | sp++;
|
---|
779 |
|
---|
780 | break;
|
---|
781 | }
|
---|
782 |
|
---|
783 | if(term[0]=='\"'){
|
---|
784 | StrLiteral:
|
---|
785 |
|
---|
786 | if( !baseType.IsPointer() ){
|
---|
787 | //要求タイプがオブジェクト、または未定のとき
|
---|
788 | type_stack[sp]=DEF_OBJECT;
|
---|
789 | index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
|
---|
790 | *pIsLiteralCalculation = false;
|
---|
791 |
|
---|
792 | sp++;
|
---|
793 | break;
|
---|
794 | }
|
---|
795 |
|
---|
796 | type_stack[sp]=typeOfPtrChar;
|
---|
797 | *pIsLiteralCalculation = false;
|
---|
798 | }
|
---|
799 | else if((term[0]=='e'||term[0]=='E')&&
|
---|
800 | (term[1]=='x'||term[1]=='X')&&
|
---|
801 | term[2]=='\"'){
|
---|
802 | //拡張版リテラル文字列(エスケープシーケンス可能)
|
---|
803 | goto StrLiteral;
|
---|
804 | }
|
---|
805 | else if(IsVariableTopChar(term[0])||
|
---|
806 | term[0]=='*'||
|
---|
807 | (term[0]=='.'&&IsVariableTopChar(term[1])))
|
---|
808 | {
|
---|
809 | //////////////////
|
---|
810 | // 何らかの識別子
|
---|
811 |
|
---|
812 | bool isLiteral = true;
|
---|
813 | if( GetTermType( term, baseType, resultType, isLiteral ) ){
|
---|
814 | type_stack[sp] = resultType.GetBasicType();
|
---|
815 | index_stack[sp] = resultType.GetIndex();
|
---|
816 |
|
---|
817 | if( !isLiteral ){
|
---|
818 | *pIsLiteralCalculation = false;
|
---|
819 | }
|
---|
820 |
|
---|
821 | sp++;
|
---|
822 | break;
|
---|
823 | }
|
---|
824 |
|
---|
825 |
|
---|
826 | // Nothing
|
---|
827 | if( lstrcmp( term, "Nothing" ) == 0 ){
|
---|
828 | isNothing_stack[sp] = true;
|
---|
829 |
|
---|
830 | type_stack[sp] = DEF_OBJECT;
|
---|
831 | if( baseType.IsObject() ){
|
---|
832 | index_stack[sp] = baseType.GetIndex();
|
---|
833 | }
|
---|
834 | else{
|
---|
835 | index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
|
---|
836 | }
|
---|
837 | *pIsLiteralCalculation = false;
|
---|
838 | sp++;
|
---|
839 | break;
|
---|
840 | }
|
---|
841 |
|
---|
842 |
|
---|
843 | //////////////
|
---|
844 | // 定数の場合
|
---|
845 | //////////////
|
---|
846 |
|
---|
847 | i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(
|
---|
848 | ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
|
---|
849 | );
|
---|
850 | if(i3){
|
---|
851 | if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term ) ) ){
|
---|
852 | //リテラル文字列
|
---|
853 | goto StrLiteral;
|
---|
854 | }
|
---|
855 |
|
---|
856 | type_stack[sp]=i3;
|
---|
857 | if(IsRealNumberType(i3)){
|
---|
858 | //実数
|
---|
859 | goto Literal;
|
---|
860 | }
|
---|
861 | else if(IsWholeNumberType(i3)){
|
---|
862 | //整数
|
---|
863 | goto Literal;
|
---|
864 | }
|
---|
865 | else if(Is64Type(i3)){
|
---|
866 | //64ビット整数値
|
---|
867 | goto Literal;
|
---|
868 | }
|
---|
869 | else{
|
---|
870 | compiler.errorMessenger.Output(1,NULL,0);
|
---|
871 | goto error;
|
---|
872 | }
|
---|
873 | }
|
---|
874 |
|
---|
875 |
|
---|
876 | /////////////////////////////////
|
---|
877 | // プロパティ用のメソッド
|
---|
878 | /////////////////////////////////
|
---|
879 |
|
---|
880 | //配列要素を排除
|
---|
881 | char VarName[VN_SIZE],ArrayElements[VN_SIZE];
|
---|
882 | GetArrayElement(term,VarName,ArrayElements);
|
---|
883 |
|
---|
884 | if(GetSubHash(VarName,0)){
|
---|
885 | compiler.errorMessenger.OutputFatalError();
|
---|
886 | Type tempType;
|
---|
887 | GetReturnTypeOfPropertyMethod(term,NULL,tempType);
|
---|
888 |
|
---|
889 | //大きな型への暗黙の変換
|
---|
890 | type_stack[sp]=tempType.GetBasicType();
|
---|
891 |
|
---|
892 | index_stack[sp]=tempType.GetIndex();
|
---|
893 | *pIsLiteralCalculation = false;
|
---|
894 |
|
---|
895 | sp++;
|
---|
896 | break;
|
---|
897 | }
|
---|
898 |
|
---|
899 |
|
---|
900 |
|
---|
901 | //該当する識別子が見当たらないときはエラー扱いにする
|
---|
902 | bError=1;
|
---|
903 | compiler.errorMessenger.Output(3,term,cp);
|
---|
904 | type_stack[sp]=DEF_DOUBLE;
|
---|
905 | }
|
---|
906 | else{
|
---|
907 | //リテラル値
|
---|
908 | int base_type = 0;
|
---|
909 | if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
|
---|
910 | type_stack[sp]=GetLiteralValue(term,&i64data,base_type);
|
---|
911 | Literal:
|
---|
912 | if((long)i64data==0&&index_stack[sp]==-1) index_stack[sp]=LITERAL_NULL;
|
---|
913 | }
|
---|
914 |
|
---|
915 | sp++;
|
---|
916 | break;
|
---|
917 |
|
---|
918 | //論理演算子
|
---|
919 | case CALC_XOR:
|
---|
920 | case CALC_OR:
|
---|
921 | case CALC_AND:
|
---|
922 | sp--;
|
---|
923 | type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
|
---|
924 | break;
|
---|
925 | case CALC_NOT:
|
---|
926 | //values[sp-1]=Not values[sp-1]
|
---|
927 | //NOT演算子
|
---|
928 | break;
|
---|
929 |
|
---|
930 | //比較演算子
|
---|
931 | case CALC_PE: //values[sp-2] <= values[sp-1]
|
---|
932 | case CALC_QE: //values[sp-2] >= values[sp-1]
|
---|
933 | case CALC_P: //values[sp-2] < values[sp-1]
|
---|
934 | case CALC_Q: //values[sp-2] > values[sp-1]
|
---|
935 | case CALC_NOTEQUAL: //values[sp-2] <> values[sp-1]
|
---|
936 | case CALC_EQUAL: //values[sp-2] = values[sp-1]
|
---|
937 | sp--;
|
---|
938 | type_stack[sp-1]=DEF_LONG;
|
---|
939 | break;
|
---|
940 |
|
---|
941 | //ビットシフト
|
---|
942 | case CALC_SHL: //values[sp-2] << values[sp-1]
|
---|
943 | case CALC_SHR: //values[sp-2] >> values[sp-1]
|
---|
944 | sp--;
|
---|
945 | break;
|
---|
946 |
|
---|
947 | //算術演算
|
---|
948 | case CALC_ADDITION:
|
---|
949 | case CALC_SUBTRACTION:
|
---|
950 | case CALC_PRODUCT:
|
---|
951 | sp--;
|
---|
952 | type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
|
---|
953 | break;
|
---|
954 | case CALC_MOD:
|
---|
955 | //values[sp-2]%=values[sp-1]
|
---|
956 | //剰余演算
|
---|
957 | sp--;
|
---|
958 | type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
|
---|
959 | break;
|
---|
960 | case CALC_QUOTIENT:
|
---|
961 | //values[sp-2]/=values[sp-1];
|
---|
962 | //除算
|
---|
963 | sp--;
|
---|
964 | type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
|
---|
965 | break;
|
---|
966 | case CALC_INTQUOTIENT:
|
---|
967 | //values[sp-2]/=values[sp-1]
|
---|
968 | //整数除算
|
---|
969 | sp--;
|
---|
970 | type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
|
---|
971 | break;
|
---|
972 | case CALC_MINUSMARK:
|
---|
973 | //values[sp-1]=-values[sp-1]
|
---|
974 | //符号反転
|
---|
975 | break;
|
---|
976 | case CALC_POWER:
|
---|
977 | //べき乗演算(浮動小数点演算のみ)
|
---|
978 | sp--;
|
---|
979 | //未完成
|
---|
980 | break;
|
---|
981 | case CALC_AS:
|
---|
982 | //キャスト
|
---|
983 | type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST);
|
---|
984 | index_stack[sp-2]=index_stack[sp-1];
|
---|
985 |
|
---|
986 | sp--;
|
---|
987 | break;
|
---|
988 |
|
---|
989 | case CALC_BYVAL:
|
---|
990 | //ポインタ型→参照型
|
---|
991 | if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
|
---|
992 | //ポインタ型ではないとき
|
---|
993 | compiler.errorMessenger.Output( 3, NULL, cp );
|
---|
994 | goto error;
|
---|
995 | }
|
---|
996 |
|
---|
997 | type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
|
---|
998 | break;
|
---|
999 | }
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | if(bError) goto error;
|
---|
1003 |
|
---|
1004 | if(sp!=1){
|
---|
1005 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
1006 | goto error;
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | if( *pIsLiteralCalculation ){
|
---|
1010 | //右辺値が数値の定数式の場合
|
---|
1011 | int base_type = 0;
|
---|
1012 | if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
|
---|
1013 | Type tempType;
|
---|
1014 | StaticCalculation(true, expression,base_type,&i64data,tempType);
|
---|
1015 |
|
---|
1016 | type_stack[0]=tempType.GetBasicType();
|
---|
1017 | index_stack[0]=tempType.GetIndex();
|
---|
1018 | }
|
---|
1019 | else{
|
---|
1020 | //右辺値が数値の定数式ではないとき
|
---|
1021 | if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | resultType.SetType( type_stack[0], index_stack[0] );
|
---|
1025 |
|
---|
1026 | bool isSuccessful = true;
|
---|
1027 | goto finish;
|
---|
1028 |
|
---|
1029 |
|
---|
1030 | //////////////////
|
---|
1031 | // エラー処理
|
---|
1032 | //////////////////
|
---|
1033 |
|
---|
1034 | error:
|
---|
1035 | isSuccessful = false;
|
---|
1036 | goto finish;
|
---|
1037 |
|
---|
1038 |
|
---|
1039 | finish:
|
---|
1040 | for(i=0;i<pnum;i++){
|
---|
1041 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
1042 | }
|
---|
1043 | return isSuccessful;
|
---|
1044 | }
|
---|