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

Last change on this file since 420 was 383, checked in by dai_9181, 17 years ago

ジェネリクスインターフェイス実装時のオーバーロード解決ロジックを改良。(型パラメータを引数に持つメソッドのオーバーロードをミスしてしまうバグを修正)

File size: 4.9 KB
RevLine 
[322]1#include "stdafx.h"
2
3
[383]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
[322]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 if(sourceOfParams[i]!='('){
88 SetError(1,NULL,nowLine);
89 return 0;
90 }
91 i++;
92 while(1){
93 if(sourceOfParams[i]==')') break;
94
95 //ByRef
96 bool isRef;
97 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
98 isRef = false;
99 i+=2;
100 }
101 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
102 isRef = true;
103 i+=2;
104 }
105 else isRef = false;
106
107 //パラメータ名
108 bool isArray = false;
109 Subscripts subscripts;
110 char name[VN_SIZE];
111 sw=0;
112 for(i2=0;;i++,i2++){
113 if(sourceOfParams[i]=='('){
114 if(!sw) sw=1;
115
116 i3=GetStringInPare(name+i2,sourceOfParams+i);
117 i2+=i3-1;
118 i+=i3-1;
119 continue;
120 }
121 if(sourceOfParams[i]=='['){
122 if(!sw) sw=1;
123
124 i3=GetStringInBracket(name+i2,sourceOfParams+i);
125 i2+=i3-1;
126 i+=i3-1;
127 continue;
128 }
129 if(!IsVariableChar(sourceOfParams[i])){
130 name[i2]=0;
131 break;
132 }
133 name[i2]=sourceOfParams[i];
134 }
135 if(sw){
136 //配列パラメータ
137 if( isRef == false )
138 {
139 SetError(29,NULL,nowLine);
140 }
141 isArray = true;
142
143 if((name[i2-2]=='('&&name[i2-1]==')')||
144 (name[i2-2]=='['&&name[i2-1]==']'))
145 {
146 subscripts.push_back( LONG_MAX );
147
148 name[i2-2]=0;
149 }
150 else{
151 GetArrange(name,temp2,subscripts);
152 lstrcpy(name,temp2);
153 }
154
155 i2=lstrlen(name);
156 }
157
158 Type type( DEF_NON );
159 char initValue[8192] = "";
160 if( sourceOfParams[i] == '=' ){
161 i++;
162 i = GetOneParameter( sourceOfParams, i, initValue );
163
164 // TODO: エラー用 fix me!!!
165 //cp = nowLine;
166
167 NumOpe_GetType( initValue, GetStringTypeInfo(), type );
168
169 if( IS_LITERAL(type.GetIndex()) )
170 {
171 type.SetIndex( -1 );
172 }
173 }
174 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
175 // As指定
176 i+=2;
177
178 i2=0;
179 while(sourceOfParams[i]=='*'){
180 temporary[i2]=sourceOfParams[i];
181 i++;
182 i2++;
183 }
184 for(;;i++,i2++){
185 if(!IsVariableChar(sourceOfParams[i])){
186 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
187 temporary[i2++]=sourceOfParams[i++];
188 temporary[i2]=sourceOfParams[i];
189 continue;
190 }
191 temporary[i2]=0;
192 break;
193 }
194 temporary[i2]=sourceOfParams[i];
195 }
196
197 compiler.StringToType( temporary, type );
198
199 if( type.IsNull() ){
200 SetError(3,temporary,nowLine);
201 type.SetBasicType( DEF_PTR_VOID );
202 }
203
204 if( type.IsObject() ){
205 if( type.GetClass().IsBlittableType() ){
206 // Blittable型のときは基本型として扱う
207 type = type.GetClass().GetBlittableType();
208 }
209 }
210 }
211 else{
212 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
213 SetError(-103,temporary,nowLine);
214 }
215
216 Parameter *pParam = new Parameter( name, type, isRef, initValue );
217 if( isArray ){
218 pParam->SetArray( subscripts );
219 }
220
221 //パラメータを追加
222 this->push_back( pParam );
223
224 if(sourceOfParams[i]==','){
225 i++;
226 continue;
227 }
228 else if(sourceOfParams[i]==')') continue;
229 else{
230 SetError(1,NULL,nowLine);
231 break;
232 }
233 }
234
235 return true;
236}
[325]237
238std::string Parameters::GetString() const
239{
240 std::string result;
241
242 const Parameters &params = *this;
243 BOOST_FOREACH( const Parameter *pParam, params )
244 {
245 if( result.size() )
246 {
247 result += ",";
248 }
249
250 result += pParam->GetVarName() + " As " + compiler.TypeToString( *pParam );
251 }
252 return result;
253}
Note: See TracBrowser for help on using the repository browser.