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

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

静的領域に初期オブジェクトを配置可能にした

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