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

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

CClass::GetStaticDefiningStringAsMemberOffsetsメソッドを追加。
エラーコード142を追加。

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