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

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

System名前空間をImportsしているときにNew演算子にBlittable型を("System." を省略する形で)指定するとコンパイルエラーになるバグを修正。

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