source: dev/trunk/abdev/BasicCompiler_Common/NumOpe_GetType.cpp@ 334

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