source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/NumOpe_GetType.cpp@ 440

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

[403]の修正をNumOpe_GetTypeにも適用した。

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