source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Parameter.cpp@ 465

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

Messenger/ErrorMessengerクラスを導入。SetError関数によるエラー生成を廃止した。

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