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
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 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
362bool GetTermType( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool *pIsClassName )
363{
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];
379 ReferenceKind refType;
380 if( SplitMemberName( termFull, termLeft, member, refType ) ){
381 ///////////////////////////////////////////////////////////////////
382 // オブジェクトとメンバに分解できるとき
383 // termLeft.member
384 ///////////////////////////////////////////////////////////////////
385
386 isLiteral = false;
387
388 // オブジェクト側の型を取得
389 bool isClassName = false;
390 Type leftType;
391 if( GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
392 if( isClassName == false && compiler.GetObjectModule().meta.GetBlittableTypes().IsExist( leftType ) ){
393 // 左側のオブジェクト部分がBlittable型のとき
394
395 char temporary[VN_SIZE];
396 lstrcpy( temporary, termLeft );
397 sprintf( termLeft, "%s(%s)",
398 compiler.GetObjectModule().meta.GetBlittableTypes().Find( leftType ).GetCreateStaticMethodFullName().c_str(),
399 temporary );
400
401 if( !GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
402 goto globalArea;
403 }
404 }
405 }
406 else{
407 goto globalArea;
408 }
409
410 if( isClassName ){
411 // 静的メンバ/メソッドの場合
412 goto globalArea;
413 }
414
415 if( !leftType.HasMember() ){
416 // メンバを持たない型の場合
417 return false;
418 }
419
420 return GetMemberTermType( leftType, baseType, resultType, termFull, termLeft, member );
421 }
422
423
424 //////////////////////////////////////////////
425 // クラス名かどうかをチェック(静的メンバ用)
426 //////////////////////////////////////////////
427
428 if( pIsClassName ){
429 if( compiler.GetObjectModule().meta.GetClasses().Find( termFull ) ){
430 *pIsClassName = true;
431 return true;
432 }
433 }
434
435
436 /////////////////////////////////////////////////////////////////
437 // グローバル属性
438 /////////////////////////////////////////////////////////////////
439globalArea:
440
441
442 if(lstrcmpi(termFull,"This")==0){
443 //Thisオブジェクト
444 resultType.SetType( DEF_OBJECT, compiler.pCompilingClass );
445 isLiteral = false;
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
474 if( !CallProc(idProc,pProc,procName,parameter, baseType, resultType, false ) ){
475 return false;
476 }
477 if( resultType.IsNull() ){
478 //戻り値が存在しないとき
479 return false;
480 }
481
482 isLiteral = false;
483
484 return true;
485 }
486 else
487 {
488 ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find( procName );
489 if( pConstMacro )
490 {
491 if( pConstMacro->GetCalcBuffer( parameter, temporary ) )
492 {
493 /////////////////////////
494 // マクロ関数
495 /////////////////////////
496
497 //閉じカッコ")"に続く文字がNULLでないときはエラーにする
498 if(termFull[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
499
500 //マクロ関数の場合
501 if( !NumOpe_GetType(temporary,Type(),resultType) ){
502 return false;
503 }
504
505 if( !IS_LITERAL( resultType.GetIndex() ) ){
506 //リテラル値ではなかったとき
507 isLiteral = false;
508 }
509
510 return true;
511 }
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]){
524 Type classType;
525 GetVarType(VarName,classType,false);
526 if( classType.IsObject() ){
527 if( !GetReturnTypeOfIndexerGetterProc( classType, resultType ) ){
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
574bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType, bool *pIsLiteralCalculation ){
575 extern int cp;
576 int i,i3;
577
578 //リテラル値のみの計算かどうかを判別するためのフラグ
579 bool dummyBool;
580 if( pIsLiteralCalculation == NULL )
581 {
582 pIsLiteralCalculation = &dummyBool;
583 }
584 *pIsLiteralCalculation = true;
585
586 if(expression[0]=='\0'){
587 SetError(1,NULL,cp);
588 return false;
589 }
590
591 if(expression[0]==1&& expression[1]==ESC_NEW ){
592 //New演算子(オブジェクト生成)
593 *pIsLiteralCalculation = false;
594 return Operator_New_GetType(expression+2,baseType, resultType );
595 }
596
597 if( expression[0] == '[' ){
598 if( !baseType.IsPointer() ){
599 SetError(1,NULL,cp);
600 return false;
601 }
602
603 resultType = baseType;
604 return true;
605 }
606
607
608 /////////////////////////////////
609 // 式要素を逆ポーランド式で取得
610 /////////////////////////////////
611
612 char *values[255];
613 long calc[255];
614 long stack[255];
615 int pnum;
616 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
617 for(i=0;i<pnum;i++){
618 if(values[i]) HeapDefaultFree(values[i]);
619 }
620 return false;
621 }
622
623
624
625 ////////////////////////////////
626 // 演算部分のコード生成を開始
627 ////////////////////////////////
628
629 BOOL bError;
630 bError=0;
631
632 int sp;
633 int type_stack[255];
634 LONG_PTR index_stack[255];
635 bool isNothing_stack[255];
636 _int64 i64data;
637 int idCalc;
638 for(i=0,sp=0;i<pnum;i++){
639 idCalc=calc[i]%100;
640
641 if(idCalc){
642 if(type_stack[sp-2]==DEF_OBJECT){
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演算子を呼び出さない
648 }
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 }
655 else if( idCalc == CALC_AS ){
656 // NumOpe_GetTypeではすべてのキャストを許可する
657 }
658 else{
659 //オーバーロードされたオペレータを呼び出す
660 if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){
661 goto error;
662 }
663
664 continue;
665 }
666 }
667
668 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
669 }
670
671 switch(idCalc){
672 //数値
673 case 0:
674 index_stack[sp]=-1;
675 isNothing_stack[sp] = false;
676
677 char *term;
678 term = values[i];
679
680 if( calc[i+1]%100 == CALC_AS ){
681 // As演算子の右辺値
682 //型名
683 if( compiler.StringToType( term, resultType ) ){
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
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
715 if(term[0]=='\"'){
716StrLiteral:
717
718 if( baseType.IsObject() || baseType.IsNull() ){
719 //要求タイプがオブジェクト、または未定のとき
720 type_stack[sp]=DEF_OBJECT;
721 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
722 *pIsLiteralCalculation = false;
723
724 sp++;
725 break;
726 }
727
728 type_stack[sp]=typeOfPtrChar;
729 *pIsLiteralCalculation = false;
730 }
731 else if((term[0]=='e'||term[0]=='E')&&
732 (term[1]=='x'||term[1]=='X')&&
733 term[2]=='\"'){
734 //拡張版リテラル文字列(エスケープシーケンス可能)
735 goto StrLiteral;
736 }
737 else if(IsVariableTopChar(term[0])||
738 term[0]=='*'||
739 (term[0]=='.'&&IsVariableTopChar(term[1])))
740 {
741 //////////////////
742 // 何らかの識別子
743
744 bool isLiteral = true;
745 if( GetTermType( term, baseType, resultType, isLiteral ) ){
746 type_stack[sp] = resultType.GetBasicType();
747 index_stack[sp] = resultType.GetIndex();
748
749 if( !isLiteral ){
750 *pIsLiteralCalculation = false;
751 }
752
753 sp++;
754 break;
755 }
756
757
758 // Nothing
759 if( lstrcmp( term, "Nothing" ) == 0 ){
760 isNothing_stack[sp] = true;
761
762 type_stack[sp] = DEF_OBJECT;
763 if( baseType.IsObject() ){
764 index_stack[sp] = baseType.GetIndex();
765 }
766 else{
767 index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
768 }
769 *pIsLiteralCalculation = false;
770 sp++;
771 break;
772 }
773
774
775 //////////////
776 // 定数の場合
777 //////////////
778
779 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(term);
780 if(i3){
781 if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( term ) ){
782 //リテラル文字列
783 goto StrLiteral;
784 }
785
786 type_stack[sp]=i3;
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 //配列要素を排除
811 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
812 GetArrayElement(term,VarName,ArrayElements);
813
814 if(GetSubHash(VarName,0)){
815 SetError();
816 Type tempType;
817 GetReturnTypeOfPropertyMethod(term,NULL,tempType);
818
819 //大きな型への暗黙の変換
820 type_stack[sp]=tempType.GetBasicType();
821
822 index_stack[sp]=tempType.GetIndex();
823 *pIsLiteralCalculation = false;
824
825 sp++;
826 break;
827 }
828
829
830
831 //該当する識別子が見当たらないときはエラー扱いにする
832 bError=1;
833 SetError(3,term,cp);
834 type_stack[sp]=DEF_DOUBLE;
835 }
836 else{
837 //リテラル値
838 int base_type = 0;
839 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
840 type_stack[sp]=GetLiteralValue(term,&i64data,base_type);
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--;
853 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
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--;
868 type_stack[sp-1]=DEF_LONG;
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--;
882 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
883 break;
884 case CALC_MOD:
885 //values[sp-2]%=values[sp-1]
886 //剰余演算
887 sp--;
888 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
889 break;
890 case CALC_QUOTIENT:
891 //values[sp-2]/=values[sp-1];
892 //除算
893 sp--;
894 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
895 break;
896 case CALC_INTQUOTIENT:
897 //values[sp-2]/=values[sp-1]
898 //整数除算
899 sp--;
900 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
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 //キャスト
913 type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST);
914 index_stack[sp-2]=index_stack[sp-1];
915
916 sp--;
917 break;
918
919 case CALC_BYVAL:
920 //ポインタ型→参照型
921 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
922 //ポインタ型ではないとき
923 SetError( 3, NULL, cp );
924 goto error;
925 }
926
927 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
928 break;
929 }
930 }
931
932 if(bError) goto error;
933
934 if(sp!=1){
935 SetError(1,NULL,cp);
936 goto error;
937 }
938
939 if( *pIsLiteralCalculation ){
940 //右辺値が数値の定数式の場合
941 int base_type = 0;
942 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
943 Type tempType;
944 StaticCalculation(true, expression,base_type,&i64data,tempType);
945
946 type_stack[0]=tempType.GetBasicType();
947 index_stack[0]=tempType.GetIndex();
948 }
949 else{
950 //右辺値が数値の定数式ではないとき
951 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
952 }
953
954 resultType.SetType( type_stack[0], index_stack[0] );
955
956 bool isSuccessful = true;
957 goto finish;
958
959
960 //////////////////
961 // エラー処理
962 //////////////////
963
964error:
965 isSuccessful = false;
966 goto finish;
967
968
969finish:
970 for(i=0;i<pnum;i++){
971 if(values[i]) HeapDefaultFree(values[i]);
972 }
973 return isSuccessful;
974}
Note: See TracBrowser for help on using the repository browser.