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

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