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

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

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

File size: 22.4 KB
RevLine 
[206]1#include "stdafx.h"
2
[182]3#include <jenga/include/smoothie/Smoothie.h>
4#include <jenga/include/smoothie/LexicalAnalysis.h>
5
[193]6#include <Compiler.h>
7
[4]8#include "common.h"
9
10
11int MakeWholeType(int size,int bSigned){
12 switch(size){
13 case 1:
[55]14 if(bSigned) return DEF_SBYTE;
[4]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
[75]37 if(BaseType==0||BaseType==-1){
[4]38 //ベースタイプが未定のとき
39 return type;
40 }
41
42 if(!IsWholeNumberType(type)){
43 //整数型ではないときは暗黙の変換は必要なし
44 return type;
45 }
46
[75]47 if(BaseType==DEF_OBJECT||BaseType==DEF_STRUCT){
[4]48 //ベースタイプがオブジェクトのときは暗黙の変換は必要なし
49 return type;
50 }
51
52 int BaseTypeSize;
[290]53 BaseTypeSize=Type(BaseType,-1).GetSize();
[4]54
55 if(IsRealNumberType(BaseType)){
[290]56 if(Type(CalcType,-1).GetSize()<4)
[4]57 type=MakeWholeType(4,IsSignedType(CalcType));
58 }
[290]59 else if(BaseTypeSize>Type(CalcType,-1).GetSize()){
[4]60 //要求される型のほうがサイズが大きいとき
61 type=MakeWholeType(BaseTypeSize,IsSignedType(CalcType));
62 }
63
64 if(!type){
[5]65 extern int cp;
[4]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
[41]178 case CALC_BYVAL:
179 if(type[sp-1]&FLAG_CAST){
180 //型名が指定されていないときはエラー
181 SetError(47,NULL,cp);
182 return 0;
183 }
184 break;
185
[4]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
[75]197int GetReturnType_OperatorProc(int idCalc,const Type &baseType,int *type,LONG_PTR *index_stack,int &sp){
[4]198 //オーバーロードされたオペレータ関数の戻り値を取得
199 CClass *pobj_c;
200 pobj_c=(CClass *)index_stack[sp-2];
201
[206]202 std::vector<const UserProc *> subs;
[342]203 pobj_c->GetDynamicMethods().Enum( idCalc, subs );
[50]204 if( subs.size() == 0 ){
[4]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
[75]221 Parameters params;
[4]222
223 if(bTwoTerm){
[75]224 params.push_back( new Parameter( "", Type( type[sp-1], index_stack[sp-1] ) ) );
[4]225 }
226
227
228 //オーバーロードを解決
229 char temporary[255];
230 if(idCalc==CALC_EQUAL) lstrcpy(temporary,"==");
231 else GetCalcName(idCalc,temporary);
[206]232 const UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType );
[4]233
[75]234 if(bTwoTerm){
235 delete params[0];
236 }
[50]237
[75]238 if(!pUserProc){
[4]239 return 0;
240 }
241 else{
242 //オーバーロードされていないが、パラメータ個数が一致しないとき
[75]243 if(params.size()!=pUserProc->Params().size()){
[4]244 return 0;
245 }
246 }
247
248 sp--;
[75]249 type[sp-1]=pUserProc->ReturnType().GetBasicType();
250 index_stack[sp-1]=pUserProc->ReturnType().GetIndex();
[4]251
252 return 1;
253}
254
[75]255bool Operator_New_GetType(const char *Parameter,const Type &baseType, Type &resultType ){
[355]256 char TypeName[VN_SIZE],objectSizeStr[VN_SIZE];
[64]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++){
[355]270 if(Parameter[i]=='(' || Parameter[i]=='['){
[64]271 TypeName[i2]=0;
272 break;
273 }
274 TypeName[i2]=Parameter[i];
275 if(Parameter[i]=='\0'){
276 break;
277 }
278 }
279
[198]280 if( !compiler.StringToType( TypeName, resultType ) ){
[75]281 return false;
282 }
[64]283
[75]284 if( baseType.IsObject() ){
285 resultType.SetBasicType( DEF_OBJECT );
[64]286 }
[75]287 else{
288 resultType.SetBasicType( DEF_PTR_OBJECT );
289 }
290 return true;
[64]291}
292
[334]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;
[350]334 leftType.GetClass().EnumDynamicMethodsOrInterfaceMethods( methodName, userProcs );
[334]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
[331]352bool GetTermType( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool *pIsClassName )
[292]353{
[97]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];
[206]369 ReferenceKind refType;
370 if( SplitMemberName( termFull, termLeft, member, refType ) ){
[97]371 ///////////////////////////////////////////////////////////////////
372 // オブジェクトとメンバに分解できるとき
373 // termLeft.member
374 ///////////////////////////////////////////////////////////////////
375
376 isLiteral = false;
377
378 // オブジェクト側の型を取得
379 bool isClassName = false;
380 Type leftType;
[331]381 if( GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
[265]382 if( isClassName == false && compiler.GetObjectModule().meta.GetBlittableTypes().IsExist( leftType ) ){
[128]383 // 左側のオブジェクト部分がBlittable型のとき
384
385 char temporary[VN_SIZE];
386 lstrcpy( temporary, termLeft );
387 sprintf( termLeft, "%s(%s)",
[265]388 compiler.GetObjectModule().meta.GetBlittableTypes().Find( leftType ).GetCreateStaticMethodFullName().c_str(),
[128]389 temporary );
390
[331]391 if( !GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
[128]392 goto globalArea;
393 }
394 }
395 }
396 else{
[103]397 goto globalArea;
[97]398 }
399
400 if( isClassName ){
401 // 静的メンバ/メソッドの場合
402 goto globalArea;
403 }
404
405 if( !leftType.HasMember() ){
406 // メンバを持たない型の場合
407 return false;
408 }
409
[334]410 return GetMemberTermType( leftType, baseType, resultType, termFull, termLeft, member );
[97]411 }
412
413
414 //////////////////////////////////////////////
415 // クラス名かどうかをチェック(静的メンバ用)
416 //////////////////////////////////////////////
417
418 if( pIsClassName ){
[265]419 if( compiler.GetObjectModule().meta.GetClasses().Find( termFull ) ){
[97]420 *pIsClassName = true;
421 return true;
422 }
423 }
424
425
426 /////////////////////////////////////////////////////////////////
427 // グローバル属性
428 /////////////////////////////////////////////////////////////////
429globalArea:
430
431
432 if(lstrcmpi(termFull,"This")==0){
433 //Thisオブジェクト
[206]434 resultType.SetType( DEF_OBJECT, compiler.pCompilingClass );
[98]435 isLiteral = false;
[97]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
[331]464 if( !CallProc(idProc,pProc,procName,parameter, baseType, resultType, false ) ){
[97]465 return false;
466 }
467 if( resultType.IsNull() ){
468 //戻り値が存在しないとき
469 return false;
470 }
471
472 isLiteral = false;
473
474 return true;
475 }
[206]476 else
477 {
[265]478 ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find( procName );
[206]479 if( pConstMacro )
480 {
481 if( pConstMacro->GetCalcBuffer( parameter, temporary ) )
482 {
483 /////////////////////////
484 // マクロ関数
485 /////////////////////////
[97]486
[206]487 //閉じカッコ")"に続く文字がNULLでないときはエラーにする
488 if(termFull[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
[97]489
[206]490 //マクロ関数の場合
491 if( !NumOpe_GetType(temporary,Type(),resultType) ){
492 return false;
493 }
[97]494
[206]495 if( !IS_LITERAL( resultType.GetIndex() ) ){
496 //リテラル値ではなかったとき
497 isLiteral = false;
498 }
499
500 return true;
501 }
[97]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]){
[292]514 Type classType;
515 GetVarType(VarName,classType,false);
516 if( classType.IsObject() ){
517 if( !GetReturnTypeOfIndexerGetterProc( classType, resultType ) ){
[97]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
[254]564bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType, bool *pIsLiteralCalculation ){
[4]565 extern int cp;
[97]566 int i,i3;
[4]567
[254]568 //リテラル値のみの計算かどうかを判別するためのフラグ
569 bool dummyBool;
570 if( pIsLiteralCalculation == NULL )
571 {
572 pIsLiteralCalculation = &dummyBool;
573 }
574 *pIsLiteralCalculation = true;
575
[75]576 if(expression[0]=='\0'){
[4]577 SetError(1,NULL,cp);
[75]578 return false;
[4]579 }
580
[355]581 if(expression[0]==1&& ( expression[1]==ESC_NEW || expression[1] == ESC_SYSTEM_STATIC_NEW ) ){
[4]582 //New演算子(オブジェクト生成)
[254]583 *pIsLiteralCalculation = false;
[75]584 return Operator_New_GetType(expression+2,baseType, resultType );
[4]585 }
586
[94]587 if( expression[0] == '[' ){
588 if( !baseType.IsPointer() ){
589 return false;
590 }
[4]591
[94]592 resultType = baseType;
593 return true;
594 }
595
596
[4]597 /////////////////////////////////
598 // 式要素を逆ポーランド式で取得
599 /////////////////////////////////
600
601 char *values[255];
602 long calc[255];
603 long stack[255];
604 int pnum;
[75]605 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
[4]606 for(i=0;i<pnum;i++){
607 if(values[i]) HeapDefaultFree(values[i]);
608 }
[75]609 return false;
[4]610 }
611
612
613
614 ////////////////////////////////
615 // 演算部分のコード生成を開始
616 ////////////////////////////////
617
618 BOOL bError;
619 bError=0;
620
621 int sp;
[75]622 int type_stack[255];
[4]623 LONG_PTR index_stack[255];
[79]624 bool isNothing_stack[255];
[4]625 _int64 i64data;
626 int idCalc;
627 for(i=0,sp=0;i<pnum;i++){
628 idCalc=calc[i]%100;
629
630 if(idCalc){
[75]631 if(type_stack[sp-2]==DEF_OBJECT){
[79]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演算子を呼び出さない
[4]637 }
[94]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 }
[129]644 else if( idCalc == CALC_AS ){
645 // NumOpe_GetTypeではすべてのキャストを許可する
646 }
[79]647 else{
648 //オーバーロードされたオペレータを呼び出す
649 if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){
650 goto error;
651 }
[4]652
[79]653 continue;
654 }
[4]655 }
656
[75]657 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
[4]658 }
659
660 switch(idCalc){
661 //数値
662 case 0:
663 index_stack[sp]=-1;
[79]664 isNothing_stack[sp] = false;
[4]665
[49]666 char *term;
667 term = values[i];
668
[97]669 if( calc[i+1]%100 == CALC_AS ){
670 // As演算子の右辺値
671 //型名
[198]672 if( compiler.StringToType( term, resultType ) ){
[128]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
[97]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
[49]704 if(term[0]=='\"'){
[4]705StrLiteral:
706
[350]707 if( !baseType.IsPointer() ){
[97]708 //要求タイプがオブジェクト、または未定のとき
[75]709 type_stack[sp]=DEF_OBJECT;
[265]710 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
[254]711 *pIsLiteralCalculation = false;
[4]712
[75]713 sp++;
714 break;
[4]715 }
716
[75]717 type_stack[sp]=typeOfPtrChar;
[254]718 *pIsLiteralCalculation = false;
[4]719 }
[49]720 else if((term[0]=='e'||term[0]=='E')&&
721 (term[1]=='x'||term[1]=='X')&&
722 term[2]=='\"'){
[4]723 //拡張版リテラル文字列(エスケープシーケンス可能)
724 goto StrLiteral;
725 }
[49]726 else if(IsVariableTopChar(term[0])||
727 term[0]=='*'||
[334]728 (term[0]=='.'&&IsVariableTopChar(term[1])))
729 {
[4]730 //////////////////
731 // 何らかの識別子
732
[97]733 bool isLiteral = true;
[331]734 if( GetTermType( term, baseType, resultType, isLiteral ) ){
[97]735 type_stack[sp] = resultType.GetBasicType();
736 index_stack[sp] = resultType.GetIndex();
[4]737
[97]738 if( !isLiteral ){
[254]739 *pIsLiteralCalculation = false;
[4]740 }
741
[97]742 sp++;
743 break;
[4]744 }
745
[38]746
[67]747 // Nothing
748 if( lstrcmp( term, "Nothing" ) == 0 ){
[79]749 isNothing_stack[sp] = true;
750
[75]751 type_stack[sp] = DEF_OBJECT;
752 if( baseType.IsObject() ){
753 index_stack[sp] = baseType.GetIndex();
[67]754 }
755 else{
[265]756 index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
[67]757 }
[254]758 *pIsLiteralCalculation = false;
[67]759 sp++;
760 break;
761 }
762
763
[4]764 //////////////
765 // 定数の場合
766 //////////////
767
[265]768 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(term);
[7]769 if(i3){
[265]770 if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( term ) ){
[103]771 //リテラル文字列
772 goto StrLiteral;
773 }
774
[75]775 type_stack[sp]=i3;
[4]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 //配列要素を排除
[97]800 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
[49]801 GetArrayElement(term,VarName,ArrayElements);
[4]802
803 if(GetSubHash(VarName,0)){
[97]804 SetError();
[75]805 Type tempType;
806 GetReturnTypeOfPropertyMethod(term,NULL,tempType);
[4]807
808 //大きな型への暗黙の変換
[75]809 type_stack[sp]=tempType.GetBasicType();
[4]810
[75]811 index_stack[sp]=tempType.GetIndex();
[254]812 *pIsLiteralCalculation = false;
[4]813
814 sp++;
815 break;
816 }
817
818
819
820 //該当する識別子が見当たらないときはエラー扱いにする
821 bError=1;
[49]822 SetError(3,term,cp);
[75]823 type_stack[sp]=DEF_DOUBLE;
[4]824 }
825 else{
826 //リテラル値
[75]827 int base_type = 0;
828 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
829 type_stack[sp]=GetLiteralValue(term,&i64data,base_type);
[4]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--;
[75]842 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]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--;
[75]857 type_stack[sp-1]=DEF_LONG;
[4]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--;
[75]871 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]872 break;
873 case CALC_MOD:
874 //values[sp-2]%=values[sp-1]
875 //剰余演算
876 sp--;
[75]877 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]878 break;
879 case CALC_QUOTIENT:
880 //values[sp-2]/=values[sp-1];
881 //除算
882 sp--;
[75]883 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]884 break;
885 case CALC_INTQUOTIENT:
886 //values[sp-2]/=values[sp-1]
887 //整数除算
888 sp--;
[75]889 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]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 //キャスト
[75]902 type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST);
[4]903 index_stack[sp-2]=index_stack[sp-1];
904
905 sp--;
906 break;
[41]907
908 case CALC_BYVAL:
909 //ポインタ型→参照型
[75]910 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
[41]911 //ポインタ型ではないとき
912 SetError( 3, NULL, cp );
913 goto error;
914 }
915
[75]916 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
[41]917 break;
[4]918 }
919 }
920
921 if(bError) goto error;
922
923 if(sp!=1){
924 SetError(1,NULL,cp);
925 goto error;
926 }
927
[254]928 if( *pIsLiteralCalculation ){
[4]929 //右辺値が数値の定数式の場合
[75]930 int base_type = 0;
931 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
932 Type tempType;
933 StaticCalculation(true, expression,base_type,&i64data,tempType);
[4]934
[75]935 type_stack[0]=tempType.GetBasicType();
936 index_stack[0]=tempType.GetIndex();
[4]937 }
938 else{
939 //右辺値が数値の定数式ではないとき
940 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
941 }
942
[75]943 resultType.SetType( type_stack[0], index_stack[0] );
[4]944
[75]945 bool isSuccessful = true;
[4]946 goto finish;
947
948
949 //////////////////
950 // エラー処理
951 //////////////////
952
953error:
[75]954 isSuccessful = false;
[4]955 goto finish;
956
957
958finish:
959 for(i=0;i<pnum;i++){
960 if(values[i]) HeapDefaultFree(values[i]);
961 }
[75]962 return isSuccessful;
[4]963}
Note: See TracBrowser for help on using the repository browser.