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

Last change on this file since 402 was 402, checked in by dai_9181, 16 years ago

UserProc::SetParamsAndReturnTypeメソッドをリファクタリング
LexicalAnalysis.hのインクルードを除去した

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