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

Last change on this file since 350 was 350, 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->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],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().EnumDynamicMethodsOrInterfaceMethods( 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 return false;
600 }
601
602 resultType = baseType;
603 return true;
604 }
605
606
607 /////////////////////////////////
608 // 式要素を逆ポーランド式で取得
609 /////////////////////////////////
610
611 char *values[255];
612 long calc[255];
613 long stack[255];
614 int pnum;
615 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
616 for(i=0;i<pnum;i++){
617 if(values[i]) HeapDefaultFree(values[i]);
618 }
619 return false;
620 }
621
622
623
624 ////////////////////////////////
625 // 演算部分のコード生成を開始
626 ////////////////////////////////
627
628 BOOL bError;
629 bError=0;
630
631 int sp;
632 int type_stack[255];
633 LONG_PTR index_stack[255];
634 bool isNothing_stack[255];
635 _int64 i64data;
636 int idCalc;
637 for(i=0,sp=0;i<pnum;i++){
638 idCalc=calc[i]%100;
639
640 if(idCalc){
641 if(type_stack[sp-2]==DEF_OBJECT){
642 if( idCalc == CALC_AS
643 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
644 && index_stack[sp-1] == index_stack[sp-2]
645 || isNothing_stack[sp-2] ){
646 // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
647 }
648 else if( idCalc == CALC_AS
649 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
650 && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
651 )){
652 // ダウンキャストを許可する
653 }
654 else if( idCalc == CALC_AS ){
655 // NumOpe_GetTypeではすべてのキャストを許可する
656 }
657 else{
658 //オーバーロードされたオペレータを呼び出す
659 if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){
660 goto error;
661 }
662
663 continue;
664 }
665 }
666
667 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
668 }
669
670 switch(idCalc){
671 //数値
672 case 0:
673 index_stack[sp]=-1;
674 isNothing_stack[sp] = false;
675
676 char *term;
677 term = values[i];
678
679 if( calc[i+1]%100 == CALC_AS ){
680 // As演算子の右辺値
681 //型名
682 if( compiler.StringToType( term, resultType ) ){
683
684 if( resultType.IsObject() ){
685 if( resultType.GetClass().IsBlittableType() ){
686 // Blittable型のときは基本型として扱う
687 // ※ただし、コンパイル中のメソッドがBlittable型クラスに属していないこと
688 if( UserProc::IsLocalAreaCompiling()
689 && UserProc::CompilingUserProc().HasParentClass()
690 && UserProc::CompilingUserProc().GetParentClass().IsBlittableType() )
691 {
692 // コンパイル中のメソッドがBlittable型クラスに属している
693 }
694 else{
695 resultType = resultType.GetClass().GetBlittableType();
696 }
697 }
698 }
699
700 resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
701 }
702 else{
703 SetError(3, term, cp );
704 goto error;
705 }
706
707 type_stack[sp] = resultType.GetBasicType();
708 index_stack[sp] = resultType.GetIndex();
709 sp++;
710
711 break;
712 }
713
714 if(term[0]=='\"'){
715StrLiteral:
716
717 if( !baseType.IsPointer() ){
718 //要求タイプがオブジェクト、または未定のとき
719 type_stack[sp]=DEF_OBJECT;
720 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
721 *pIsLiteralCalculation = false;
722
723 sp++;
724 break;
725 }
726
727 type_stack[sp]=typeOfPtrChar;
728 *pIsLiteralCalculation = false;
729 }
730 else if((term[0]=='e'||term[0]=='E')&&
731 (term[1]=='x'||term[1]=='X')&&
732 term[2]=='\"'){
733 //拡張版リテラル文字列(エスケープシーケンス可能)
734 goto StrLiteral;
735 }
736 else if(IsVariableTopChar(term[0])||
737 term[0]=='*'||
738 (term[0]=='.'&&IsVariableTopChar(term[1])))
739 {
740 //////////////////
741 // 何らかの識別子
742
743 bool isLiteral = true;
744 if( GetTermType( term, baseType, resultType, isLiteral ) ){
745 type_stack[sp] = resultType.GetBasicType();
746 index_stack[sp] = resultType.GetIndex();
747
748 if( !isLiteral ){
749 *pIsLiteralCalculation = false;
750 }
751
752 sp++;
753 break;
754 }
755
756
757 // Nothing
758 if( lstrcmp( term, "Nothing" ) == 0 ){
759 isNothing_stack[sp] = true;
760
761 type_stack[sp] = DEF_OBJECT;
762 if( baseType.IsObject() ){
763 index_stack[sp] = baseType.GetIndex();
764 }
765 else{
766 index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
767 }
768 *pIsLiteralCalculation = false;
769 sp++;
770 break;
771 }
772
773
774 //////////////
775 // 定数の場合
776 //////////////
777
778 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(term);
779 if(i3){
780 if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( term ) ){
781 //リテラル文字列
782 goto StrLiteral;
783 }
784
785 type_stack[sp]=i3;
786 if(IsRealNumberType(i3)){
787 //実数
788 goto Literal;
789 }
790 else if(IsWholeNumberType(i3)){
791 //整数
792 goto Literal;
793 }
794 else if(Is64Type(i3)){
795 //64ビット整数値
796 goto Literal;
797 }
798 else{
799 SetError(1,NULL,0);
800 goto error;
801 }
802 }
803
804
805 /////////////////////////////////
806 // プロパティ用のメソッド
807 /////////////////////////////////
808
809 //配列要素を排除
810 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
811 GetArrayElement(term,VarName,ArrayElements);
812
813 if(GetSubHash(VarName,0)){
814 SetError();
815 Type tempType;
816 GetReturnTypeOfPropertyMethod(term,NULL,tempType);
817
818 //大きな型への暗黙の変換
819 type_stack[sp]=tempType.GetBasicType();
820
821 index_stack[sp]=tempType.GetIndex();
822 *pIsLiteralCalculation = false;
823
824 sp++;
825 break;
826 }
827
828
829
830 //該当する識別子が見当たらないときはエラー扱いにする
831 bError=1;
832 SetError(3,term,cp);
833 type_stack[sp]=DEF_DOUBLE;
834 }
835 else{
836 //リテラル値
837 int base_type = 0;
838 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
839 type_stack[sp]=GetLiteralValue(term,&i64data,base_type);
840Literal:
841 if((long)i64data==0&&index_stack[sp]==-1) index_stack[sp]=LITERAL_NULL;
842 }
843
844 sp++;
845 break;
846
847 //論理演算子
848 case CALC_XOR:
849 case CALC_OR:
850 case CALC_AND:
851 sp--;
852 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
853 break;
854 case CALC_NOT:
855 //values[sp-1]=Not values[sp-1]
856 //NOT演算子
857 break;
858
859 //比較演算子
860 case CALC_PE: //values[sp-2] <= values[sp-1]
861 case CALC_QE: //values[sp-2] >= values[sp-1]
862 case CALC_P: //values[sp-2] < values[sp-1]
863 case CALC_Q: //values[sp-2] > values[sp-1]
864 case CALC_NOTEQUAL: //values[sp-2] <> values[sp-1]
865 case CALC_EQUAL: //values[sp-2] = values[sp-1]
866 sp--;
867 type_stack[sp-1]=DEF_LONG;
868 break;
869
870 //ビットシフト
871 case CALC_SHL: //values[sp-2] << values[sp-1]
872 case CALC_SHR: //values[sp-2] >> values[sp-1]
873 sp--;
874 break;
875
876 //算術演算
877 case CALC_ADDITION:
878 case CALC_SUBTRACTION:
879 case CALC_PRODUCT:
880 sp--;
881 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
882 break;
883 case CALC_MOD:
884 //values[sp-2]%=values[sp-1]
885 //剰余演算
886 sp--;
887 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
888 break;
889 case CALC_QUOTIENT:
890 //values[sp-2]/=values[sp-1];
891 //除算
892 sp--;
893 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
894 break;
895 case CALC_INTQUOTIENT:
896 //values[sp-2]/=values[sp-1]
897 //整数除算
898 sp--;
899 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
900 break;
901 case CALC_MINUSMARK:
902 //values[sp-1]=-values[sp-1]
903 //符号反転
904 break;
905 case CALC_POWER:
906 //べき乗演算(浮動小数点演算のみ)
907 sp--;
908 //未完成
909 break;
910 case CALC_AS:
911 //キャスト
912 type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST);
913 index_stack[sp-2]=index_stack[sp-1];
914
915 sp--;
916 break;
917
918 case CALC_BYVAL:
919 //ポインタ型→参照型
920 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
921 //ポインタ型ではないとき
922 SetError( 3, NULL, cp );
923 goto error;
924 }
925
926 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
927 break;
928 }
929 }
930
931 if(bError) goto error;
932
933 if(sp!=1){
934 SetError(1,NULL,cp);
935 goto error;
936 }
937
938 if( *pIsLiteralCalculation ){
939 //右辺値が数値の定数式の場合
940 int base_type = 0;
941 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
942 Type tempType;
943 StaticCalculation(true, expression,base_type,&i64data,tempType);
944
945 type_stack[0]=tempType.GetBasicType();
946 index_stack[0]=tempType.GetIndex();
947 }
948 else{
949 //右辺値が数値の定数式ではないとき
950 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
951 }
952
953 resultType.SetType( type_stack[0], index_stack[0] );
954
955 bool isSuccessful = true;
956 goto finish;
957
958
959 //////////////////
960 // エラー処理
961 //////////////////
962
963error:
964 isSuccessful = false;
965 goto finish;
966
967
968finish:
969 for(i=0;i<pnum;i++){
970 if(values[i]) HeapDefaultFree(values[i]);
971 }
972 return isSuccessful;
973}
Note: See TracBrowser for help on using the repository browser.