source: dev/trunk/abdev/BasicCompiler_Common/src/Parameter.cpp@ 422

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

デリゲートのパラメータや戻り値にクラス型を指定できない不具合を修正。

File size: 4.9 KB
Line 
1#include "stdafx.h"
2
3
4bool Parameter::Equals( const Parameter &param ) const
5{
6 if( Type::Equals( param ) )
7 {
8 return true;
9 }
10 else
11 {
12 if( this->isRef && this->GetBasicType() == DEF_ANY &&
13 param.isRef == false && param.IsPointer()
14 ||
15 this->isRef == false && this->IsPointer() &&
16 param.isRef && param.GetBasicType() == DEF_ANY )
17 {
18 /* ByRef var As Any
19
20 var As VoidPtr
21 は同等
22 */
23 return true;
24 }
25 }
26
27 return false;
28}
29bool Parameter::Equals( const Types &actualTypeParametersForThisProc, const Parameter &param ) const
30{
31 if( Equals( param ) )
32 {
33 return true;
34 }
35
36 if( this->IsTypeParameter() )
37 {
38 // 型パラメータだったとき
39 if( actualTypeParametersForThisProc[this->GetFormalTypeIndex()].Equals( param ) )
40 {
41 // 戻り値が等しい
42 return true;
43 }
44 }
45
46 return false;
47}
48
49bool Parameters::Equals( const Parameters &params ) const
50{
51 if( this->size() != params.size() ){
52 return false;
53 }
54
55 int max = (int)this->size();
56 for( int i=0; i<max; i++ ){
57 if( !(*this)[i]->Equals( *params[i] ) ){
58 return false;
59 }
60 }
61
62 return true;
63}
64bool Parameters::Equals( const Types &actualTypeParametersForThisProc, const Parameters &params ) const
65{
66 if( this->size() != params.size() ){
67 return false;
68 }
69
70 int max = (int)this->size();
71 for( int i=0; i<max; i++ ){
72 if( !(*this)[i]->Equals( actualTypeParametersForThisProc, *params[i] ) ){
73 return false;
74 }
75 }
76
77 return true;
78}
79
80bool Parameters::Analyze( const char *sourceOfParams, int nowLine )
81{
82 int i2,i3,sw;
83 char temporary[8192],temp2[VN_SIZE];
84
85 //パラメータ
86 int i = 0;
87 while(1){
88 if( sourceOfParams[i] == '\0' )
89 {
90 break;
91 }
92
93 //ByRef
94 bool isRef;
95 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
96 isRef = false;
97 i+=2;
98 }
99 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
100 isRef = true;
101 i+=2;
102 }
103 else isRef = false;
104
105 //パラメータ名
106 bool isArray = false;
107 Subscripts subscripts;
108 char name[VN_SIZE];
109 sw=0;
110 for(i2=0;;i++,i2++){
111 if(sourceOfParams[i]=='('){
112 if(!sw) sw=1;
113
114 i3=GetStringInPare(name+i2,sourceOfParams+i);
115 i2+=i3-1;
116 i+=i3-1;
117 continue;
118 }
119 if(sourceOfParams[i]=='['){
120 if(!sw) sw=1;
121
122 i3=GetStringInBracket(name+i2,sourceOfParams+i);
123 i2+=i3-1;
124 i+=i3-1;
125 continue;
126 }
127 if(!IsVariableChar(sourceOfParams[i])){
128 name[i2]=0;
129 break;
130 }
131 name[i2]=sourceOfParams[i];
132 }
133 if(sw){
134 //配列パラメータ
135 if( isRef == false )
136 {
137 SetError(29,NULL,nowLine);
138 }
139 isArray = true;
140
141 if((name[i2-2]=='('&&name[i2-1]==')')||
142 (name[i2-2]=='['&&name[i2-1]==']'))
143 {
144 subscripts.push_back( LONG_MAX );
145
146 name[i2-2]=0;
147 }
148 else{
149 GetArrange(name,temp2,subscripts);
150 lstrcpy(name,temp2);
151 }
152
153 i2=lstrlen(name);
154 }
155
156 Type type( DEF_NON );
157 char initValue[8192] = "";
158 if( sourceOfParams[i] == '=' ){
159 i++;
160 i = GetOneParameter( sourceOfParams, i, initValue );
161
162 // TODO: エラー用 fix me!!!
163 //cp = nowLine;
164
165 NumOpe_GetType( initValue, GetStringTypeInfo(), type );
166
167 if( IS_LITERAL(type.GetIndex()) )
168 {
169 type.SetIndex( -1 );
170 }
171 }
172 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
173 // As指定
174 i+=2;
175
176 i2=0;
177 while(sourceOfParams[i]=='*'){
178 temporary[i2]=sourceOfParams[i];
179 i++;
180 i2++;
181 }
182 for(;;i++,i2++){
183 if(!IsVariableChar(sourceOfParams[i])){
184 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
185 temporary[i2++]=sourceOfParams[i++];
186 temporary[i2]=sourceOfParams[i];
187 continue;
188 }
189 temporary[i2]=0;
190 break;
191 }
192 temporary[i2]=sourceOfParams[i];
193 }
194
195 compiler.StringToType( temporary, type );
196
197 if( type.IsNull() ){
198 SetError(3,temporary,nowLine);
199 type.SetBasicType( DEF_PTR_VOID );
200 }
201
202 if( type.IsObject() ){
203 if( type.GetClass().IsBlittableType() ){
204 // Blittable型のときは基本型として扱う
205 type = type.GetClass().GetBlittableType();
206 }
207 }
208 }
209 else{
210 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
211 SetError(-103,temporary,nowLine);
212 }
213
214 Parameter *pParam = new Parameter( name, type, isRef, initValue );
215 if( isArray ){
216 pParam->SetArray( subscripts );
217 }
218
219 //パラメータを追加
220 this->push_back( pParam );
221
222 if( sourceOfParams[i] == ',' )
223 {
224 i++;
225 continue;
226 }
227 else if( sourceOfParams[i] == '\0' )
228 {
229 break;
230 }
231 else{
232 SetError(1,NULL,nowLine);
233 break;
234 }
235 }
236
237 return true;
238}
239
240std::string Parameters::GetString() const
241{
242 std::string result;
243
244 const Parameters &params = *this;
245 BOOST_FOREACH( const Parameter *pParam, params )
246 {
247 if( result.size() )
248 {
249 result += ",";
250 }
251
252 result += pParam->GetVarName() + " As " + compiler.TypeToString( *pParam );
253 }
254 return result;
255}
Note: See TracBrowser for help on using the repository browser.