[322] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 |
|
---|
[448] | 4 | bool Parameter::Equals( const Parameter ¶m, bool isContravariant ) const
|
---|
[383] | 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 |
|
---|
[448] | 27 | if( isContravariant )
|
---|
| 28 | {
|
---|
| 29 | // 反変引数を許可する
|
---|
| 30 | if( this->IsContravariant( param ) )
|
---|
| 31 | {
|
---|
| 32 | // 反変引数だったとき
|
---|
| 33 | return true;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[383] | 37 | return false;
|
---|
| 38 | }
|
---|
[448] | 39 | bool Parameter::Equals( const Types &actualTypeParametersForThisProc, const Parameter ¶m, bool isContravariant ) const
|
---|
[383] | 40 | {
|
---|
[448] | 41 | if( Equals( param, isContravariant ) )
|
---|
[383] | 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 |
|
---|
[448] | 59 | bool Parameters::Equals( const Parameters ¶ms, bool isContravariant ) const
|
---|
[383] | 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++ ){
|
---|
[448] | 67 | if( !(*this)[i]->Equals( *params[i], isContravariant ) ){
|
---|
[383] | 68 | return false;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | return true;
|
---|
| 73 | }
|
---|
[448] | 74 | bool Parameters::Equals( const Types &actualTypeParametersForThisProc, const Parameters ¶ms, bool isContravariant ) const
|
---|
[383] | 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++ ){
|
---|
[448] | 82 | if( !(*this)[i]->Equals( actualTypeParametersForThisProc, *params[i], isContravariant ) ){
|
---|
[383] | 83 | return false;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | return true;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[322] | 90 | bool 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){
|
---|
[422] | 98 | if( sourceOfParams[i] == '\0' )
|
---|
| 99 | {
|
---|
| 100 | break;
|
---|
| 101 | }
|
---|
[322] | 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 | {
|
---|
[465] | 147 | compiler.errorMessenger.Output(29,NULL,nowLine);
|
---|
[322] | 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() ){
|
---|
[465] | 208 | compiler.errorMessenger.Output(3,temporary,nowLine);
|
---|
[322] | 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) );
|
---|
[465] | 221 | compiler.errorMessenger.Output(-103,temporary,nowLine);
|
---|
[322] | 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 |
|
---|
[422] | 232 | if( sourceOfParams[i] == ',' )
|
---|
| 233 | {
|
---|
[322] | 234 | i++;
|
---|
| 235 | continue;
|
---|
| 236 | }
|
---|
[422] | 237 | else if( sourceOfParams[i] == '\0' )
|
---|
| 238 | {
|
---|
| 239 | break;
|
---|
| 240 | }
|
---|
[322] | 241 | else{
|
---|
[465] | 242 | compiler.errorMessenger.Output(1,NULL,nowLine);
|
---|
[322] | 243 | break;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | return true;
|
---|
| 248 | }
|
---|
[325] | 249 |
|
---|
| 250 | std::string Parameters::GetString() const
|
---|
| 251 | {
|
---|
| 252 | std::string result;
|
---|
| 253 |
|
---|
| 254 | const Parameters ¶ms = *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 | }
|
---|