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

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

UserProc::SetParamsAndReturnTypeメソッドをリファクタリング
LexicalAnalysis.hのインクルードを除去した

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