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

Last change on this file since 829 was 829, checked in by イグトランス (egtra), 12 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

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