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

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