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

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

smoothieプロジェクトが不要になったため、破棄。

File size: 24.3 KB
RevLine 
[206]1#include "stdafx.h"
2
[193]3#include <Compiler.h>
4
[4]5#include "common.h"
6
7
8int MakeWholeType(int size,int bSigned){
9 switch(size){
10 case 1:
[55]11 if(bSigned) return DEF_SBYTE;
[4]12 else return DEF_BYTE;
13 break;
14 case 2:
15 if(bSigned) return DEF_INTEGER;
16 else return DEF_WORD;
17 break;
18 case 4:
19 if(bSigned) return DEF_LONG;
20 else return DEF_DWORD;
21 break;
22 case 8:
23 if(bSigned) return DEF_INT64;
24 else return DEF_QWORD;
25 break;
26 }
27 return 0;
28}
29
30int AutoBigCast(int BaseType,int CalcType){
31 int type;
32 type=CalcType;
33
[75]34 if(BaseType==0||BaseType==-1){
[4]35 //ベースタイプが未定のとき
36 return type;
37 }
38
39 if(!IsWholeNumberType(type)){
40 //整数型ではないときは暗黙の変換は必要なし
41 return type;
42 }
43
[75]44 if(BaseType==DEF_OBJECT||BaseType==DEF_STRUCT){
[4]45 //ベースタイプがオブジェクトのときは暗黙の変換は必要なし
46 return type;
47 }
48
49 int BaseTypeSize;
[290]50 BaseTypeSize=Type(BaseType,-1).GetSize();
[4]51
52 if(IsRealNumberType(BaseType)){
[290]53 if(Type(CalcType,-1).GetSize()<4)
[4]54 type=MakeWholeType(4,IsSignedType(CalcType));
55 }
[290]56 else if(BaseTypeSize>Type(CalcType,-1).GetSize()){
[4]57 //要求される型のほうがサイズが大きいとき
58 type=MakeWholeType(BaseTypeSize,IsSignedType(CalcType));
59 }
60
61 if(!type){
[5]62 extern int cp;
[4]63 SetError(300,NULL,cp);
64 }
65
66 return type;
67}
68
69BOOL CheckCalcType(int idCalc,int *type,int sp){
70 //演算子の右辺、左辺の型をチェック
71 extern int cp;
72
73 //演算子名を取得
74 char temporary[255];
75 GetCalcName(idCalc,temporary);
76
77 switch(idCalc){
78
79 /////////////////////////////////////
80 // 実数に対する論理演算はエラー
81 /////////////////////////////////////
82
83 case CALC_XOR:
84 case CALC_OR:
85 case CALC_AND:
86 if(IsRealNumberType(type[sp-2])||IsRealNumberType(type[sp-1])){
87 //いずれかの項が実数のとき
88 SetError(45,temporary,cp);
89 return 0;
90 }
91
92 //As以外の演算子に型名が指定されていないかをチェック
93 if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
94 SetError(48,temporary,cp);
95 return 0;
96 }
97 break;
98
99 case CALC_NOT:
100 if(IsRealNumberType(type[sp-1])){
101 //実数のとき
102 SetError(45,temporary,cp);
103 return 0;
104 }
105
106 //As以外の演算子に型名が指定されていないかをチェック
107 if(type[sp-1]&FLAG_CAST){
108 SetError(48,temporary,cp);
109 return 0;
110 }
111 break;
112
113
114
115 /////////////////////////////////////
116 // 比較演算はチェック項目なし
117 /////////////////////////////////////
118
119 case CALC_PE:
120 case CALC_QE:
121 case CALC_NOTEQUAL:
122 case CALC_EQUAL:
123 case CALC_P:
124 case CALC_Q:
125 //As以外の演算子に型名が指定されていないかをチェック
126 if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
127 SetError(48,temporary,cp);
128 return 0;
129 }
130 break;
131
132
133
134 /////////////////////////////////////
135 // 算術演算をチェック
136 /////////////////////////////////////
137
138 case CALC_ADDITION:
139 case CALC_SUBTRACTION:
140 case CALC_PRODUCT:
141 case CALC_QUOTIENT:
142 case CALC_POWER:
143 //As以外の演算子に型名が指定されていないかをチェック
144 if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
145 SetError(48,temporary,cp);
146 return 0;
147 }
148 break;
149
150 case CALC_SHL:
151 case CALC_SHR:
152 case CALC_MOD:
153 case CALC_INTQUOTIENT:
154 if(IsRealNumberType(type[sp-2])||IsRealNumberType(type[sp-1])){
155 //いずれかの項が実数のとき
156 SetError(45,temporary,cp);
157 return 0;
158 }
159
160 //As以外の演算子に型名が指定されていないかをチェック
161 if((type[sp-2]&FLAG_CAST)||(type[sp-1]&FLAG_CAST)){
162 SetError(48,temporary,cp);
163 return 0;
164 }
165 break;
166
167 case CALC_AS:
168 if((type[sp-1]&FLAG_CAST)==0){
169 //型名が指定されていないときはエラー
170 SetError(47,NULL,cp);
171 return 0;
172 }
173 break;
174
[41]175 case CALC_BYVAL:
176 if(type[sp-1]&FLAG_CAST){
177 //型名が指定されていないときはエラー
178 SetError(47,NULL,cp);
179 return 0;
180 }
181 break;
182
[4]183 case CALC_MINUSMARK:
184 //As以外の演算子に型名が指定されていないかをチェック
185 if(type[sp-1]&FLAG_CAST){
186 SetError(48,temporary,cp);
187 return 0;
188 }
189 break;
190 }
191 return 1;
192}
193
[424]194int GetReturnType_OperatorProc(int idCalc,const Type &baseType,int *type_stack,LONG_PTR *index_stack,int &sp){
195 Type leftType( type_stack[sp-2], index_stack[sp-2] );
196 Type rightType( type_stack[sp-1] & (~FLAG_CAST), index_stack[sp-1] );
[4]197
[424]198 //オーバーロードされたオペレータ関数を呼び出す
199 const CClass *pobj_c = &leftType.GetClass();
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){
[424]223 params.push_back( new Parameter( "", rightType ) );
[4]224 }
225
226
227 //オーバーロードを解決
228 char temporary[255];
229 if(idCalc==CALC_EQUAL) lstrcpy(temporary,"==");
230 else GetCalcName(idCalc,temporary);
[424]231 const UserProc *pUserProc = OverloadSolution( temporary, subs, params, baseType, leftType );
[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--;
[424]248 type_stack[sp-1]=pUserProc->ReturnType().GetBasicType();
[75]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
[415]300bool GetMemberTermType( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool *pIsVariable )
[334]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;
[428]310 if( VarName[0] == '\0' )
311 {
312 classType = leftType;
313
314 if( classType.IsObject() )
315 {
316 // 既にuseRegにオブジェクトポインタが格納されており、それに対するインデクサを呼び出す場合
317 // ※「プロパティ値として返ってきたオブジェクトインスタンスのインデクサを呼び出す」場合にここにくる
318 }
319 }
320 else
321 {
322 GetMemberType( leftType, VarName, classType, 0, false );
323 }
324
325 if( classType.IsObject() )
326 {
[334]327 if( !GetReturnTypeOfIndexerGetterProc( classType, resultType ) ){
328 SetError(1,NULL,cp);
329 return false;
330 }
331
332 return true;
333 }
334 }
335
336
337 ///////////////////////////////////////////////////////////////////
338 // メンバを検索
339 ///////////////////////////////////////////////////////////////////
340 if( GetMemberType( leftType, member, resultType, 0, false ) ){
341 // メンバが見つかったとき
[415]342
343 if( pIsVariable )
344 {
345 *pIsVariable = true;
346 }
347
[334]348 return true;
349 }
350
351
352 ///////////////////////////////////////////////////////////////////
353 // 動的メソッドを検索
354 ///////////////////////////////////////////////////////////////////
355 char methodName[VN_SIZE] ,lpPtrOffset[VN_SIZE], dummy[1];
356 char parameter[VN_SIZE];
357 ReferenceKind refType;
[428]358 PareOrBracket pareOrBracket = None;
[334]359 lstrcpy( methodName, member );
[428]360 GetVarFormatString( methodName, parameter, lpPtrOffset, dummy, refType, &pareOrBracket );
[334]361
362 vector<const UserProc *> userProcs;
[350]363 leftType.GetClass().EnumDynamicMethodsOrInterfaceMethods( methodName, userProcs );
[334]364 if(userProcs.size()){
365 //オーバーロードを解決
366 const UserProc *pUserProc = OverloadSolutionWithStrParam(termFull,userProcs,parameter,termLeft);
367
[428]368 if( pUserProc )
369 {
370 if(
371 pUserProc->Params().size() == 0 // 仮引数の個数は0
372 && parameter[0] // 実引数は1つ以上
373 && pUserProc->ReturnType().IsObject() // 戻り値がクラス型の場合
374 && pareOrBracket == Bracket ) // 実引数は[]で囲まれている
375 {
376 // プロパティ値として返ってきたオブジェクトインスタンスのインデクサを呼び出す
377
378 // まずはプロパティ値を取得
379 bool dummyIsVariable;
380 GetMemberTermType( leftType, baseType, resultType, termFull, termLeft, methodName, &dummyIsVariable );
381
382 // 戻り値のオブジェクトインスタンスのインデクサを呼び出す
383 char temporary[VN_SIZE], temp2[VN_SIZE];
384 sprintf( temporary, "[%s]", parameter );
385 sprintf( temp2, "%s.%s", termLeft, methodName );
386 Type classType = resultType;
387 return GetMemberTermType( classType, baseType, resultType, termFull, temp2, temporary, pIsVariable );
388 }
389
[334]390 resultType = pUserProc->ReturnType();
391
392 // 型パラメータを解決
393 ResolveFormalGenericTypeParameter( resultType, leftType, pUserProc );
394
395 return true;
396 }
397 }
398
399 return false;
400}
401
[415]402bool GetTermType( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool *pIsClassName, bool *pIsVariable )
[292]403{
[97]404 char parameter[VN_SIZE];
405
406 // Withを解決
407 char termFull[VN_SIZE];
408 if(term[0]=='.'){
409 GetWithName(termFull);
410 lstrcat(termFull,term);
411 }
412 else lstrcpy(termFull,term);
413
414 char termLeft[VN_SIZE];
415 lstrcpy(termLeft,termFull);
416
417 // パース
418 char member[VN_SIZE];
[206]419 ReferenceKind refType;
420 if( SplitMemberName( termFull, termLeft, member, refType ) ){
[97]421 ///////////////////////////////////////////////////////////////////
422 // オブジェクトとメンバに分解できるとき
423 // termLeft.member
424 ///////////////////////////////////////////////////////////////////
425
426 isLiteral = false;
427
428 // オブジェクト側の型を取得
429 bool isClassName = false;
430 Type leftType;
[331]431 if( GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
[265]432 if( isClassName == false && compiler.GetObjectModule().meta.GetBlittableTypes().IsExist( leftType ) ){
[128]433 // 左側のオブジェクト部分がBlittable型のとき
434
435 char temporary[VN_SIZE];
436 lstrcpy( temporary, termLeft );
437 sprintf( termLeft, "%s(%s)",
[265]438 compiler.GetObjectModule().meta.GetBlittableTypes().Find( leftType ).GetCreateStaticMethodFullName().c_str(),
[128]439 temporary );
440
[331]441 if( !GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
[128]442 goto globalArea;
443 }
444 }
445 }
446 else{
[103]447 goto globalArea;
[97]448 }
449
450 if( isClassName ){
451 // 静的メンバ/メソッドの場合
452 goto globalArea;
453 }
454
455 if( !leftType.HasMember() ){
456 // メンバを持たない型の場合
457 return false;
458 }
459
[415]460 return GetMemberTermType( leftType, baseType, resultType, termFull, termLeft, member, pIsVariable );
[97]461 }
462
463
464 //////////////////////////////////////////////
465 // クラス名かどうかをチェック(静的メンバ用)
466 //////////////////////////////////////////////
467
468 if( pIsClassName ){
[265]469 if( compiler.GetObjectModule().meta.GetClasses().Find( termFull ) ){
[97]470 *pIsClassName = true;
471 return true;
472 }
473 }
474
475
476 /////////////////////////////////////////////////////////////////
477 // グローバル属性
478 /////////////////////////////////////////////////////////////////
479globalArea:
480
481
482 if(lstrcmpi(termFull,"This")==0){
[412]483 if( compiler.pCompilingClass == NULL )
484 {
485 return false;
486 }
487
[97]488 //Thisオブジェクト
[206]489 resultType.SetType( DEF_OBJECT, compiler.pCompilingClass );
[98]490 isLiteral = false;
[97]491 return true;
492 }
493
494
495 //////////////////////////////////////
496 // 関数(DLL、ユーザー定義、組み込み)
497 //////////////////////////////////////
498 char procName[VN_SIZE];
499 char temporary[8192];
500
501 int i2=GetCallProcName(termFull,procName);
502 if(termFull[i2]=='('){
503 int i4=GetStringInPare_RemovePare(parameter,termFull+i2+1);
504
505 void *pProc;
506 int idProc=GetProc(procName,(void **)&pProc);
507
508 if(idProc){
509 //閉じカッコ")"に続く文字がNULLでないとき
510 if(termFull[i2+1+i4+1]!='\0'){
511 SetError(42,NULL,cp);
512 }
513
514
515 ////////////////
516 // 呼び出し
517 ////////////////
518
[331]519 if( !CallProc(idProc,pProc,procName,parameter, baseType, resultType, false ) ){
[97]520 return false;
521 }
522 if( resultType.IsNull() ){
523 //戻り値が存在しないとき
524 return false;
525 }
526
527 isLiteral = false;
528
529 return true;
530 }
[206]531 else
532 {
[265]533 ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find( procName );
[206]534 if( pConstMacro )
535 {
536 if( pConstMacro->GetCalcBuffer( parameter, temporary ) )
537 {
538 /////////////////////////
539 // マクロ関数
540 /////////////////////////
[97]541
[206]542 //閉じカッコ")"に続く文字がNULLでないときはエラーにする
543 if(termFull[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
[97]544
[206]545 //マクロ関数の場合
546 if( !NumOpe_GetType(temporary,Type(),resultType) ){
547 return false;
548 }
[97]549
[206]550 if( !IS_LITERAL( resultType.GetIndex() ) ){
551 //リテラル値ではなかったとき
552 isLiteral = false;
553 }
554
555 return true;
556 }
[97]557 }
558 }
559 }
560
561
562 ////////////////////////////////
563 // インデクサ(getアクセサ)
564 ////////////////////////////////
565
566 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
567 GetArrayElement(termFull,VarName,ArrayElements);
568 if(ArrayElements[0]){
[292]569 Type classType;
570 GetVarType(VarName,classType,false);
571 if( classType.IsObject() ){
572 if( !GetReturnTypeOfIndexerGetterProc( classType, resultType ) ){
[97]573 SetError(1,NULL,cp);
574 return false;
575 }
576
577 isLiteral = false;
578
579 return true;
580 }
581 }
582
583
584 ////////////////////////////////
585 // 変数
586 ////////////////////////////////
587
588 if( GetVarType( termFull, resultType, false ) ){
589 if( resultType.GetBasicType() & FLAG_PTR ){
590 //配列ポインタ
591 resultType.SetBasicType( GetPtrType( resultType.GetBasicType()^FLAG_PTR ) );
592 }
593
594 isLiteral = false;
595
[415]596 if( pIsVariable )
597 {
598 // 変数である
599 *pIsVariable = true;
600 }
601
[97]602 return true;
603 }
604
605
606 /////////////////////////////////
607 // プロパティ用のメソッド
608 /////////////////////////////////
609
610 //配列要素を排除
611 GetArrayElement(termFull,VarName,ArrayElements);
612
613 if(GetSubHash(VarName,0)){
614 GetReturnTypeOfPropertyMethod(termFull,NULL,resultType);
615
616 isLiteral = false;
617
618 return true;
619 }
620
621
622 return false;
623}
624
[415]625bool GetTermType( const char *term, Type &resultType )
626{
627 bool isLiteral;
628 return GetTermType( term, Type(), resultType, isLiteral );
629}
630
631bool GetTermTypeOnlyVariable( const char *term, Type &resultType )
632{
633 bool isLiteral, isVariable = false;
634 bool result = GetTermType( term, Type(), resultType, isLiteral, NULL, &isVariable );
635 return ( result && isVariable );
636}
637
[254]638bool NumOpe_GetType( const char *expression, const Type &baseType, Type &resultType, bool *pIsLiteralCalculation ){
[4]639 extern int cp;
[97]640 int i,i3;
[4]641
[254]642 //リテラル値のみの計算かどうかを判別するためのフラグ
643 bool dummyBool;
644 if( pIsLiteralCalculation == NULL )
645 {
646 pIsLiteralCalculation = &dummyBool;
647 }
648 *pIsLiteralCalculation = true;
649
[75]650 if(expression[0]=='\0'){
[4]651 SetError(1,NULL,cp);
[75]652 return false;
[4]653 }
654
[355]655 if(expression[0]==1&& ( expression[1]==ESC_NEW || expression[1] == ESC_SYSTEM_STATIC_NEW ) ){
[4]656 //New演算子(オブジェクト生成)
[254]657 *pIsLiteralCalculation = false;
[75]658 return Operator_New_GetType(expression+2,baseType, resultType );
[4]659 }
660
[94]661 if( expression[0] == '[' ){
662 if( !baseType.IsPointer() ){
663 return false;
664 }
[4]665
[94]666 resultType = baseType;
667 return true;
668 }
669
670
[4]671 /////////////////////////////////
672 // 式要素を逆ポーランド式で取得
673 /////////////////////////////////
674
675 char *values[255];
676 long calc[255];
677 long stack[255];
678 int pnum;
[75]679 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
[4]680 for(i=0;i<pnum;i++){
681 if(values[i]) HeapDefaultFree(values[i]);
682 }
[75]683 return false;
[4]684 }
685
686
687
688 ////////////////////////////////
689 // 演算部分のコード生成を開始
690 ////////////////////////////////
691
692 BOOL bError;
693 bError=0;
694
695 int sp;
[75]696 int type_stack[255];
[4]697 LONG_PTR index_stack[255];
[79]698 bool isNothing_stack[255];
[4]699 _int64 i64data;
700 int idCalc;
701 for(i=0,sp=0;i<pnum;i++){
702 idCalc=calc[i]%100;
703
704 if(idCalc){
[75]705 if(type_stack[sp-2]==DEF_OBJECT){
[79]706 if( idCalc == CALC_AS
707 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
708 && index_stack[sp-1] == index_stack[sp-2]
709 || isNothing_stack[sp-2] ){
710 // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
[4]711 }
[94]712 else if( idCalc == CALC_AS
713 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
714 && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
715 )){
716 // ダウンキャストを許可する
717 }
[129]718 else if( idCalc == CALC_AS ){
719 // NumOpe_GetTypeではすべてのキャストを許可する
720 }
[79]721 else{
722 //オーバーロードされたオペレータを呼び出す
723 if(!GetReturnType_OperatorProc(idCalc,baseType,type_stack,index_stack,sp)){
724 goto error;
725 }
[4]726
[79]727 continue;
728 }
[4]729 }
730
[75]731 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
[4]732 }
733
734 switch(idCalc){
735 //数値
736 case 0:
737 index_stack[sp]=-1;
[79]738 isNothing_stack[sp] = false;
[4]739
[49]740 char *term;
741 term = values[i];
742
[97]743 if( calc[i+1]%100 == CALC_AS ){
744 // As演算子の右辺値
745 //型名
[198]746 if( compiler.StringToType( term, resultType ) ){
[128]747
748 if( resultType.IsObject() ){
749 if( resultType.GetClass().IsBlittableType() ){
750 // Blittable型のときは基本型として扱う
751 // ※ただし、コンパイル中のメソッドがBlittable型クラスに属していないこと
752 if( UserProc::IsLocalAreaCompiling()
753 && UserProc::CompilingUserProc().HasParentClass()
754 && UserProc::CompilingUserProc().GetParentClass().IsBlittableType() )
755 {
756 // コンパイル中のメソッドがBlittable型クラスに属している
757 }
758 else{
759 resultType = resultType.GetClass().GetBlittableType();
760 }
761 }
762 }
763
[97]764 resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
765 }
766 else{
767 SetError(3, term, cp );
768 goto error;
769 }
770
771 type_stack[sp] = resultType.GetBasicType();
772 index_stack[sp] = resultType.GetIndex();
773 sp++;
774
775 break;
776 }
777
[49]778 if(term[0]=='\"'){
[4]779StrLiteral:
780
[350]781 if( !baseType.IsPointer() ){
[97]782 //要求タイプがオブジェクト、または未定のとき
[75]783 type_stack[sp]=DEF_OBJECT;
[265]784 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
[254]785 *pIsLiteralCalculation = false;
[4]786
[75]787 sp++;
788 break;
[4]789 }
790
[75]791 type_stack[sp]=typeOfPtrChar;
[254]792 *pIsLiteralCalculation = false;
[4]793 }
[49]794 else if((term[0]=='e'||term[0]=='E')&&
795 (term[1]=='x'||term[1]=='X')&&
796 term[2]=='\"'){
[4]797 //拡張版リテラル文字列(エスケープシーケンス可能)
798 goto StrLiteral;
799 }
[49]800 else if(IsVariableTopChar(term[0])||
801 term[0]=='*'||
[334]802 (term[0]=='.'&&IsVariableTopChar(term[1])))
803 {
[4]804 //////////////////
805 // 何らかの識別子
806
[97]807 bool isLiteral = true;
[331]808 if( GetTermType( term, baseType, resultType, isLiteral ) ){
[97]809 type_stack[sp] = resultType.GetBasicType();
810 index_stack[sp] = resultType.GetIndex();
[4]811
[97]812 if( !isLiteral ){
[254]813 *pIsLiteralCalculation = false;
[4]814 }
815
[97]816 sp++;
817 break;
[4]818 }
819
[38]820
[67]821 // Nothing
822 if( lstrcmp( term, "Nothing" ) == 0 ){
[79]823 isNothing_stack[sp] = true;
824
[75]825 type_stack[sp] = DEF_OBJECT;
826 if( baseType.IsObject() ){
827 index_stack[sp] = baseType.GetIndex();
[67]828 }
829 else{
[265]830 index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
[67]831 }
[254]832 *pIsLiteralCalculation = false;
[67]833 sp++;
834 break;
835 }
836
837
[4]838 //////////////
839 // 定数の場合
840 //////////////
841
[265]842 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(term);
[7]843 if(i3){
[265]844 if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( term ) ){
[103]845 //リテラル文字列
846 goto StrLiteral;
847 }
848
[75]849 type_stack[sp]=i3;
[4]850 if(IsRealNumberType(i3)){
851 //実数
852 goto Literal;
853 }
854 else if(IsWholeNumberType(i3)){
855 //整数
856 goto Literal;
857 }
858 else if(Is64Type(i3)){
859 //64ビット整数値
860 goto Literal;
861 }
862 else{
863 SetError(1,NULL,0);
864 goto error;
865 }
866 }
867
868
869 /////////////////////////////////
870 // プロパティ用のメソッド
871 /////////////////////////////////
872
873 //配列要素を排除
[97]874 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
[49]875 GetArrayElement(term,VarName,ArrayElements);
[4]876
877 if(GetSubHash(VarName,0)){
[97]878 SetError();
[75]879 Type tempType;
880 GetReturnTypeOfPropertyMethod(term,NULL,tempType);
[4]881
882 //大きな型への暗黙の変換
[75]883 type_stack[sp]=tempType.GetBasicType();
[4]884
[75]885 index_stack[sp]=tempType.GetIndex();
[254]886 *pIsLiteralCalculation = false;
[4]887
888 sp++;
889 break;
890 }
891
892
893
894 //該当する識別子が見当たらないときはエラー扱いにする
895 bError=1;
[49]896 SetError(3,term,cp);
[75]897 type_stack[sp]=DEF_DOUBLE;
[4]898 }
899 else{
900 //リテラル値
[75]901 int base_type = 0;
902 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
903 type_stack[sp]=GetLiteralValue(term,&i64data,base_type);
[4]904Literal:
905 if((long)i64data==0&&index_stack[sp]==-1) index_stack[sp]=LITERAL_NULL;
906 }
907
908 sp++;
909 break;
910
911 //論理演算子
912 case CALC_XOR:
913 case CALC_OR:
914 case CALC_AND:
915 sp--;
[75]916 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]917 break;
918 case CALC_NOT:
919 //values[sp-1]=Not values[sp-1]
920 //NOT演算子
921 break;
922
923 //比較演算子
924 case CALC_PE: //values[sp-2] <= values[sp-1]
925 case CALC_QE: //values[sp-2] >= values[sp-1]
926 case CALC_P: //values[sp-2] < values[sp-1]
927 case CALC_Q: //values[sp-2] > values[sp-1]
928 case CALC_NOTEQUAL: //values[sp-2] <> values[sp-1]
929 case CALC_EQUAL: //values[sp-2] = values[sp-1]
930 sp--;
[75]931 type_stack[sp-1]=DEF_LONG;
[4]932 break;
933
934 //ビットシフト
935 case CALC_SHL: //values[sp-2] << values[sp-1]
936 case CALC_SHR: //values[sp-2] >> values[sp-1]
937 sp--;
938 break;
939
940 //算術演算
941 case CALC_ADDITION:
942 case CALC_SUBTRACTION:
943 case CALC_PRODUCT:
944 sp--;
[75]945 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]946 break;
947 case CALC_MOD:
948 //values[sp-2]%=values[sp-1]
949 //剰余演算
950 sp--;
[75]951 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]952 break;
953 case CALC_QUOTIENT:
954 //values[sp-2]/=values[sp-1];
955 //除算
956 sp--;
[75]957 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]958 break;
959 case CALC_INTQUOTIENT:
960 //values[sp-2]/=values[sp-1]
961 //整数除算
962 sp--;
[75]963 type_stack[sp-1]=NeutralizationType(type_stack[sp-1],index_stack[sp-1],type_stack[sp],index_stack[sp]);
[4]964 break;
965 case CALC_MINUSMARK:
966 //values[sp-1]=-values[sp-1]
967 //符号反転
968 break;
969 case CALC_POWER:
970 //べき乗演算(浮動小数点演算のみ)
971 sp--;
972 //未完成
973 break;
974 case CALC_AS:
975 //キャスト
[75]976 type_stack[sp-2]=type_stack[sp-1]&(~FLAG_CAST);
[4]977 index_stack[sp-2]=index_stack[sp-1];
978
979 sp--;
980 break;
[41]981
982 case CALC_BYVAL:
983 //ポインタ型→参照型
[75]984 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
[41]985 //ポインタ型ではないとき
986 SetError( 3, NULL, cp );
987 goto error;
988 }
989
[75]990 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
[41]991 break;
[4]992 }
993 }
994
995 if(bError) goto error;
996
997 if(sp!=1){
998 SetError(1,NULL,cp);
999 goto error;
1000 }
1001
[254]1002 if( *pIsLiteralCalculation ){
[4]1003 //右辺値が数値の定数式の場合
[75]1004 int base_type = 0;
1005 if( !baseType.IsNull() ) base_type = baseType.GetBasicType();
1006 Type tempType;
1007 StaticCalculation(true, expression,base_type,&i64data,tempType);
[4]1008
[75]1009 type_stack[0]=tempType.GetBasicType();
1010 index_stack[0]=tempType.GetIndex();
[4]1011 }
1012 else{
1013 //右辺値が数値の定数式ではないとき
1014 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
1015 }
1016
[75]1017 resultType.SetType( type_stack[0], index_stack[0] );
[4]1018
[75]1019 bool isSuccessful = true;
[4]1020 goto finish;
1021
1022
1023 //////////////////
1024 // エラー処理
1025 //////////////////
1026
1027error:
[75]1028 isSuccessful = false;
[4]1029 goto finish;
1030
1031
1032finish:
1033 for(i=0;i<pnum;i++){
1034 if(values[i]) HeapDefaultFree(values[i]);
1035 }
[75]1036 return isSuccessful;
[4]1037}
Note: See TracBrowser for help on using the repository browser.