source: dev/trunk/abdev/BasicCompiler_Common/Object.cpp@ 238

Last change on this file since 238 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

File size: 3.0 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "../BasicCompiler_Common/common.h"
6
7#ifdef _AMD64_
8#include "../BasicCompiler64/opcode.h"
9#else
10#include "../BasicCompiler32/opcode.h"
11#endif
12
13extern HANDLE hHeap;
14
15void CallConstructor( const char *ObjectName,const Subscripts &subscripts,const Type &type,const char *Parameter){
16 if( !type.IsObject() ){
17 return;
18 }
19
20 /////////////////////////////////////
21 // クラスオブジェクトの場合
22 // ※コンストラクタの呼び出し
23 /////////////////////////////////////
24
25 const UserProc *pUserProc = GetMethodHash(ObjectName,type.GetClass().GetName().c_str(),Parameter);
26 if(!pUserProc){
27 if(Parameter[0]) SetError(113,type.GetClass().GetName().c_str(),cp);
28 return;
29 }
30
31
32 char temporary[VN_SIZE];
33
34 if( subscripts.size() > 0 ){
35 int ss[MAX_ARRAYDIM];
36 memset(ss,0,MAX_ARRAYDIM*sizeof(int));
37 while(1){
38 int i3;
39 for(i3=0; i3<(int)subscripts.size(); i3++){
40 if(ss[i3]>subscripts[i3]){
41 ss[i3]=0;
42 ss[i3+1]++;
43 }
44 else break;
45 }
46 if( i3 == subscripts.size() )
47 {
48 break;
49 }
50 sprintf(temporary,"%s[%d",ObjectName,ss[0]);
51 for(i3=1; i3<(int)subscripts.size(); i3++){
52 sprintf(temporary+lstrlen(temporary),",%d",ss[i3]);
53 }
54 lstrcat(temporary,"]");
55
56 Type dummyType;
57 sprintf(temporary+lstrlen(temporary),".%s",type.GetClass().GetName().c_str());
58 CallProc( PROC_DEFAULT,
59 pUserProc,
60 temporary,
61 Parameter,
62 dummyType );
63
64 ss[0]++;
65
66
67 //ネイティブコードバッファの再確保
68 ReallocNativeCodeBuffer();
69 }
70 }
71 else{
72 Type dummyType;
73 sprintf(temporary,"%s.%s",ObjectName,type.GetClass().GetName().c_str());
74 CallProc( PROC_DEFAULT,
75 pUserProc,
76 temporary,
77 Parameter,
78 dummyType );
79 }
80}
81
82bool Operator_New( const char *expression, const Type &baseType, Type &resultType ){
83 char CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE];
84 int i,i2;
85
86 i=0;
87
88 if(expression[0]=='['){
89 i=GetStringInBracket(objectSizeStr,expression);
90
91 SlideString(objectSizeStr+1,-1);
92 objectSizeStr[i-2]=0;
93 }
94 else objectSizeStr[0]=0;
95
96 char typeName[VN_SIZE];
97 for(i2=0;;i++,i2++){
98 if(expression[i]=='('){
99 typeName[i2]=0;
100
101 //コンストラクタに渡すパラメータを取得
102 i2=GetStringInPare(CreateParameter,expression+i);
103 RemoveStringPare(CreateParameter);
104 i+=i2;
105 if(expression[i]!='\0'){
106 SetError(42,NULL,cp);
107 return false;
108 }
109 break;
110 }
111 typeName[i2]=expression[i];
112 if(expression[i]=='\0'){
113 CreateParameter[0]=0;
114 break;
115 }
116 }
117
118 if( !compiler.StringToType( typeName, resultType ) ){
119 SetError(3,typeName,cp);
120 return false;
121 }
122
123 if( !resultType.IsObject() ){
124 ////////////////////////
125 // 通常のデータ型の場合
126 ////////////////////////
127
128 SetError(121,NULL,cp);
129 return false;
130 }
131
132 Operator_New( resultType.GetClass(), objectSizeStr, CreateParameter, baseType );
133
134 if( !baseType.IsObject() ){
135 // オブジェクトポインタ向け
136 resultType.SetBasicType( DEF_PTR_OBJECT );
137 }
138
139 return true;
140}
Note: See TracBrowser for help on using the repository browser.