[376] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
| 5 | #include <jenga/include/smoothie/LexicalAnalysis.h>
|
---|
| 6 |
|
---|
| 7 | #include <Source.h>
|
---|
| 8 | #include <Class.h>
|
---|
| 9 | #include <Compiler.h>
|
---|
| 10 | #include <NamespaceSupporter.h>
|
---|
| 11 |
|
---|
| 12 | #include "../common.h"
|
---|
| 13 | #ifdef _AMD64_
|
---|
| 14 | #include "../../BasicCompiler64/opcode.h"
|
---|
| 15 | #else
|
---|
| 16 | #include "../../BasicCompiler32/opcode.h"
|
---|
| 17 | #endif
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | class CLoopRefCheck{
|
---|
| 21 | char **names;
|
---|
| 22 | int num;
|
---|
| 23 | void init(){
|
---|
| 24 | int i;
|
---|
| 25 | for(i=0;i<num;i++){
|
---|
| 26 | free(names[i]);
|
---|
| 27 | }
|
---|
| 28 | free(names);
|
---|
| 29 | }
|
---|
| 30 | public:
|
---|
| 31 | CLoopRefCheck()
|
---|
| 32 | {
|
---|
| 33 | names=(char **)malloc(1);
|
---|
| 34 | num=0;
|
---|
| 35 | }
|
---|
| 36 | ~CLoopRefCheck()
|
---|
| 37 | {
|
---|
| 38 | init();
|
---|
| 39 | }
|
---|
| 40 | void add(const char *lpszInheritsClass)
|
---|
| 41 | {
|
---|
| 42 | names=(char **)realloc(names,(num+1)*sizeof(char *));
|
---|
| 43 | names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);
|
---|
| 44 | lstrcpy(names[num],lpszInheritsClass);
|
---|
| 45 | num++;
|
---|
| 46 | }
|
---|
| 47 | void del(const char *lpszInheritsClass)
|
---|
| 48 | {
|
---|
| 49 | int i;
|
---|
| 50 | for(i=0;i<num;i++){
|
---|
| 51 | if(lstrcmp(names[i],lpszInheritsClass)==0){
|
---|
| 52 | free(names[i]);
|
---|
| 53 | break;
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | if(i!=num){
|
---|
| 57 | num--;
|
---|
| 58 | for(;i<num;i++){
|
---|
| 59 | names[i]=names[i+1];
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | BOOL check(const CClass &inheritsClass) const
|
---|
| 64 | {
|
---|
| 65 | //ループ継承チェック
|
---|
| 66 | int i;
|
---|
| 67 | for(i=0;i<num;i++){
|
---|
| 68 | if( inheritsClass.GetName() == names[i] ){
|
---|
| 69 | return 1;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | return 0;
|
---|
| 73 | }
|
---|
| 74 | };
|
---|
| 75 | CLoopRefCheck *pobj_LoopRefCheck;
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | void Classes::CollectClassesForNameOnly( const BasicSource &source )
|
---|
| 79 | {
|
---|
| 80 | int i, i2;
|
---|
| 81 | char temporary[VN_SIZE];
|
---|
| 82 |
|
---|
| 83 | // 名前空間管理
|
---|
| 84 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 85 | namespaceScopes.clear();
|
---|
| 86 |
|
---|
| 87 | // Importsされた名前空間の管理
|
---|
| 88 | NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
| 89 | importedNamespaces.clear();
|
---|
| 90 |
|
---|
| 91 | for(i=0;;i++){
|
---|
| 92 | if(source[i]=='\0') break;
|
---|
| 93 |
|
---|
| 94 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
| 95 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 96 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 97 | temporary[i2]=0;
|
---|
| 98 | break;
|
---|
| 99 | }
|
---|
| 100 | temporary[i2]=source[i];
|
---|
| 101 | }
|
---|
| 102 | namespaceScopes.push_back( temporary );
|
---|
| 103 |
|
---|
| 104 | continue;
|
---|
| 105 | }
|
---|
| 106 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 107 | if( namespaceScopes.size() <= 0 ){
|
---|
| 108 | SmoothieException::Throw(12, "End Namespace", i );
|
---|
| 109 | }
|
---|
| 110 | else{
|
---|
| 111 | namespaceScopes.pop_back();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | i += 2;
|
---|
| 115 | continue;
|
---|
| 116 | }
|
---|
| 117 | else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
|
---|
| 118 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 119 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 120 | temporary[i2]=0;
|
---|
| 121 | break;
|
---|
| 122 | }
|
---|
| 123 | temporary[i2]=source[i];
|
---|
| 124 | }
|
---|
| 125 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
| 126 | {
|
---|
| 127 | SmoothieException::Throw(64,temporary,i );
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | continue;
|
---|
| 131 | }
|
---|
| 132 | else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
| 133 | importedNamespaces.clear();
|
---|
| 134 | continue;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | if(source[i]==1&&(
|
---|
| 138 | source[i+1]==ESC_CLASS||
|
---|
| 139 | source[i+1]==ESC_TYPE||
|
---|
| 140 | source[i+1]==ESC_INTERFACE
|
---|
| 141 | ))
|
---|
| 142 | {
|
---|
| 143 | int nowLine = i;
|
---|
| 144 | i += 2;
|
---|
| 145 |
|
---|
| 146 | Type blittableType;
|
---|
| 147 | if(memicmp(source.GetBuffer()+i,"Align(",6)==0){
|
---|
| 148 | //アラインメント修飾子
|
---|
| 149 | i+=6;
|
---|
| 150 | i=JumpStringInPare(source.GetBuffer(),i)+1;
|
---|
| 151 | }
|
---|
| 152 | else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){
|
---|
| 153 | // Blittable修飾子
|
---|
| 154 | i+=10;
|
---|
| 155 | i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1;
|
---|
| 156 | compiler.StringToType( temporary, blittableType );
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | bool isEnum = false;
|
---|
| 160 | bool isDelegate = false;
|
---|
| 161 | if( source[i] == 1 && source[i+1] == ESC_ENUM ){
|
---|
| 162 | // 列挙型の場合
|
---|
| 163 | isEnum = true;
|
---|
| 164 |
|
---|
| 165 | i += 2;
|
---|
| 166 | }
|
---|
| 167 | else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
|
---|
| 168 | {
|
---|
| 169 | // デリゲートの場合
|
---|
| 170 | isDelegate = true;
|
---|
| 171 |
|
---|
| 172 | i += 2;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | for(i2=0;;i++,i2++){
|
---|
| 176 | if(!IsVariableChar(source[i])){
|
---|
| 177 | temporary[i2]=0;
|
---|
| 178 | break;
|
---|
| 179 | }
|
---|
| 180 | temporary[i2]=source[i];
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | //クラスを追加
|
---|
| 184 | CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine);
|
---|
| 185 | if( pClass ){
|
---|
| 186 | if( source[nowLine+1] == ESC_CLASS ){
|
---|
| 187 | if( isEnum )
|
---|
| 188 | {
|
---|
| 189 | pClass->SetClassType( CClass::Enum );
|
---|
| 190 | }
|
---|
| 191 | else if( isDelegate )
|
---|
| 192 | {
|
---|
| 193 | pClass->SetClassType( CClass::Delegate );
|
---|
| 194 | }
|
---|
| 195 | else{
|
---|
| 196 | pClass->SetClassType( CClass::Class );
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 | else if( source[nowLine+1] == ESC_INTERFACE ){
|
---|
| 200 | pClass->SetClassType( CClass::Interface );
|
---|
| 201 | }
|
---|
| 202 | else{
|
---|
| 203 | pClass->SetClassType( CClass::Structure );
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | // Blittable型の場合
|
---|
| 208 | if( !blittableType.IsNull() ){
|
---|
| 209 | pClass->SetBlittableType( blittableType );
|
---|
| 210 |
|
---|
| 211 | // Blittable型として登録
|
---|
| 212 | compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) );
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | bool Classes::MemberVar_LoopRefCheck(const CClass &objClass){
|
---|
| 219 | bool result = true;
|
---|
| 220 | BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){
|
---|
| 221 | if(pMember->GetType().IsStruct()){
|
---|
| 222 | //循環参照でないかをチェック
|
---|
| 223 | if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
|
---|
| 224 | extern int cp;
|
---|
| 225 | SetError(124,pMember->GetType().GetClass().GetName(),cp);
|
---|
| 226 | return false;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | pobj_LoopRefCheck->add(objClass.GetName().c_str());
|
---|
| 230 |
|
---|
| 231 | bool tempResult = MemberVar_LoopRefCheck(pMember->GetType().GetClass());
|
---|
| 232 | if( result )
|
---|
| 233 | {
|
---|
| 234 | result = tempResult;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | pobj_LoopRefCheck->del(objClass.GetName().c_str());
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | return result;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | void Classes::GetClass_recur(const char *lpszInheritsClass){
|
---|
| 245 | extern char *basbuf;
|
---|
| 246 | int i,i2,i3,sub_address,top_pos;
|
---|
| 247 | char temporary[8192];
|
---|
| 248 |
|
---|
| 249 | // 名前空間管理
|
---|
| 250 | NamespaceScopes backupNamespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 251 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 252 | namespaceScopes.clear();
|
---|
| 253 |
|
---|
| 254 | // Importsされた名前空間の管理
|
---|
| 255 | NamespaceScopesCollection backupImportedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
| 256 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
| 257 |
|
---|
| 258 | // 呼び出し元でコンパイル中のクラスポインタをバックアップ
|
---|
| 259 | const CClass *pBackCompilingClass = compiler.pCompilingClass;
|
---|
| 260 |
|
---|
| 261 | for(i=0;;i++){
|
---|
| 262 | if(basbuf[i]=='\0') break;
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | // 名前空間
|
---|
| 266 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
|
---|
| 267 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 268 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 269 | temporary[i2]=0;
|
---|
| 270 | break;
|
---|
| 271 | }
|
---|
| 272 | temporary[i2]=basbuf[i];
|
---|
| 273 | }
|
---|
| 274 | namespaceScopes.push_back( temporary );
|
---|
| 275 |
|
---|
| 276 | continue;
|
---|
| 277 | }
|
---|
| 278 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 279 | if( namespaceScopes.size() <= 0 ){
|
---|
| 280 | SetError(12, "End Namespace", i );
|
---|
| 281 | }
|
---|
| 282 | else{
|
---|
| 283 | namespaceScopes.pop_back();
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | i += 2;
|
---|
| 287 | continue;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
|
---|
| 291 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 292 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 293 | temporary[i2]=0;
|
---|
| 294 | break;
|
---|
| 295 | }
|
---|
| 296 | temporary[i2]=basbuf[i];
|
---|
| 297 | }
|
---|
| 298 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
| 299 | {
|
---|
| 300 | SmoothieException::Throw(64,temporary,i );
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | continue;
|
---|
| 304 | }
|
---|
| 305 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
| 306 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
| 307 | continue;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
|
---|
| 313 | //////////////////////////
|
---|
| 314 | // インターフェイス
|
---|
| 315 | //////////////////////////
|
---|
| 316 |
|
---|
| 317 | top_pos=i;
|
---|
| 318 |
|
---|
| 319 | i+=2;
|
---|
| 320 |
|
---|
| 321 | //インターフェイス名を取得
|
---|
| 322 | GetCommandToken( temporary, basbuf, i );
|
---|
| 323 |
|
---|
| 324 | char className[VN_SIZE];
|
---|
| 325 | Jenga::Common::Strings typeParameters;
|
---|
| 326 | SplitGenericClassInstance( temporary, className, typeParameters );
|
---|
| 327 |
|
---|
[378] | 328 | CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
|
---|
[376] | 329 | if(!pobj_c) continue;
|
---|
| 330 |
|
---|
[379] | 331 | compiler.pCompilingClass = pobj_c;
|
---|
| 332 |
|
---|
[376] | 333 | if(lpszInheritsClass){
|
---|
| 334 | if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
|
---|
| 335 | //継承先先読み用
|
---|
| 336 | continue;
|
---|
| 337 | }
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | if(pobj_c->IsReady()){
|
---|
| 341 | //既に先読みされているとき
|
---|
| 342 | continue;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | /////////////////////////////////////////////////////////
|
---|
| 346 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
| 347 | BOOST_FOREACH( const std::string &typeParameter, typeParameters )
|
---|
| 348 | {
|
---|
| 349 | pobj_c->AddFormalGenericType( GenericType( typeParameter, Type(DEF_OBJECT,*GetObjectClassPtr()) ) );
|
---|
| 350 | }
|
---|
| 351 | /////////////////////////////////////////////////////////
|
---|
| 352 |
|
---|
| 353 | pobj_c->Readed();
|
---|
| 354 |
|
---|
| 355 | pobj_c->SetConstructorMemberSubIndex( -1 );
|
---|
| 356 | pobj_c->SetDestructorMemberSubIndex( -1 );
|
---|
| 357 |
|
---|
| 358 | if( memcmp( basbuf+i+1, "__COM", 5 ) == 0 && IsCommandDelimitation( basbuf[i+1+5] ) )
|
---|
| 359 | {
|
---|
| 360 | // COMインターフェイス
|
---|
| 361 | pobj_c->SetClassType( CClass::ComInterface );
|
---|
| 362 |
|
---|
| 363 | i += 6;
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
|
---|
| 367 | //継承を行う場合
|
---|
| 368 | for(i+=3,i2=0;;i++,i2++){
|
---|
| 369 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 370 | temporary[i2]=0;
|
---|
| 371 | break;
|
---|
| 372 | }
|
---|
| 373 | temporary[i2]=basbuf[i];
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
| 377 | SetError(105,temporary,i);
|
---|
| 378 | goto Interface_InheritsError;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | //継承元クラスを取得
|
---|
| 382 | const Classes &classes = *this;
|
---|
| 383 | const CClass *pInheritsClass = classes.Find(temporary);
|
---|
| 384 | if( !pInheritsClass ){
|
---|
| 385 | SetError(106,temporary,i);
|
---|
| 386 | goto Interface_InheritsError;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | //継承させる
|
---|
| 390 | if( !pobj_c->InheritsClass( *pInheritsClass, Types(), i ) ){
|
---|
| 391 | goto Interface_InheritsError;
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
| 394 | else{
|
---|
| 395 | //継承無し
|
---|
| 396 | if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
|
---|
| 397 | {
|
---|
| 398 | // TODO: ここに来ないことが実証できたらこの分岐は消す
|
---|
| 399 | Jenga::Throw( "GetClass_recur内の例外" );
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 | Interface_InheritsError:
|
---|
| 403 |
|
---|
| 404 | //メンバ変数、関数を取得
|
---|
| 405 | while(1){
|
---|
| 406 | i++;
|
---|
| 407 |
|
---|
| 408 | //エラー
|
---|
| 409 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
|
---|
| 410 | SetError(22,"Interface",i);
|
---|
| 411 | i--;
|
---|
| 412 | break;
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
| 416 | SetError(111,NULL,i);
|
---|
| 417 | break;
|
---|
| 418 | }
|
---|
| 419 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
|
---|
| 420 | {
|
---|
| 421 | SetError(137, NULL, i );
|
---|
| 422 | break;
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | sub_address=i;
|
---|
| 426 |
|
---|
| 427 | for(i2=0;;i++,i2++){
|
---|
| 428 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 429 | temporary[i2]=0;
|
---|
| 430 | break;
|
---|
| 431 | }
|
---|
| 432 | temporary[i2]=basbuf[i];
|
---|
| 433 | }
|
---|
| 434 | if(temporary[0]=='\0'){
|
---|
| 435 | if(basbuf[i]=='\0'){
|
---|
| 436 | i--;
|
---|
| 437 | SetError(22,"Interface",top_pos);
|
---|
| 438 | break;
|
---|
| 439 | }
|
---|
| 440 | continue;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | //End Interface記述の場合
|
---|
| 444 | if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
|
---|
| 445 |
|
---|
| 446 | if(!(temporary[0]==1&&(
|
---|
| 447 | temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
|
---|
| 448 | ))){
|
---|
| 449 | SetError(1,NULL,i);
|
---|
| 450 | break;
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | //メンバ関数を追加
|
---|
| 454 | pobj_c->AddMethod(pobj_c,
|
---|
| 455 | Prototype::Public, //Publicアクセス権
|
---|
| 456 | 0, // bStatic
|
---|
| 457 | false, // isConst
|
---|
| 458 | true, // isAbstract
|
---|
| 459 | true, // isVirtual
|
---|
| 460 | false, // isOverride
|
---|
| 461 | false, // isAutoGeneration
|
---|
| 462 | temporary,
|
---|
| 463 | sub_address
|
---|
| 464 | );
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
| 469 | //////////////////////////
|
---|
| 470 | // クラス
|
---|
| 471 | //////////////////////////
|
---|
| 472 |
|
---|
| 473 | top_pos=i;
|
---|
| 474 |
|
---|
| 475 | const DWORD dwClassType=basbuf[i+1];
|
---|
| 476 |
|
---|
| 477 | i+=2;
|
---|
| 478 |
|
---|
| 479 | int iAlign=0;
|
---|
| 480 | if(memicmp(basbuf+i,"Align(",6)==0){
|
---|
| 481 | //アラインメント修飾子
|
---|
| 482 | i+=6;
|
---|
| 483 | i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
|
---|
| 484 | iAlign=atoi(temporary);
|
---|
| 485 |
|
---|
| 486 | if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
|
---|
| 487 | SetError(51,NULL,i);
|
---|
| 488 | }
|
---|
| 489 | else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
|
---|
| 490 | // Blittable修飾子
|
---|
| 491 | i+=10;
|
---|
| 492 | i=JumpStringInPare(basbuf,i)+1;
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM )
|
---|
| 496 | {
|
---|
| 497 | // 列挙型の場合
|
---|
| 498 | i += 2;
|
---|
| 499 | }
|
---|
| 500 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_DELEGATE )
|
---|
| 501 | {
|
---|
| 502 | // デリゲートの場合
|
---|
| 503 | i += 2;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | //クラス名を取得
|
---|
| 507 | GetCommandToken( temporary, basbuf, i );
|
---|
| 508 |
|
---|
| 509 | char className[VN_SIZE];
|
---|
| 510 | Jenga::Common::Strings typeParameters;
|
---|
| 511 | SplitGenericClassInstance( temporary, className, typeParameters );
|
---|
| 512 |
|
---|
| 513 | CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
|
---|
| 514 | if(!pobj_c) continue;
|
---|
| 515 |
|
---|
| 516 | compiler.pCompilingClass = pobj_c;
|
---|
| 517 |
|
---|
| 518 | if(lpszInheritsClass){
|
---|
| 519 | if( pobj_c->GetName() != lpszInheritsClass ){
|
---|
| 520 | //継承先先読み用
|
---|
| 521 | continue;
|
---|
| 522 | }
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | if(pobj_c->IsReady()){
|
---|
| 526 | //既に先読みされているとき
|
---|
| 527 | continue;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 |
|
---|
| 531 | /////////////////////////////////////////////////////////
|
---|
| 532 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
| 533 | BOOST_FOREACH( const std::string &typeParameter, typeParameters )
|
---|
| 534 | {
|
---|
| 535 | pobj_c->AddFormalGenericType( GenericType( typeParameter, Type(DEF_OBJECT,*GetObjectClassPtr()) ) );
|
---|
| 536 | }
|
---|
| 537 | /////////////////////////////////////////////////////////
|
---|
| 538 |
|
---|
| 539 |
|
---|
| 540 | pobj_c->SetFixedAlignment( iAlign );
|
---|
| 541 |
|
---|
| 542 | pobj_c->Readed();
|
---|
| 543 |
|
---|
| 544 | pobj_c->SetConstructorMemberSubIndex( -1 );
|
---|
| 545 | pobj_c->SetDestructorMemberSubIndex( -1 );
|
---|
| 546 |
|
---|
| 547 | //アクセス制限の初期値をセット
|
---|
| 548 | Prototype::Accessibility accessibility;
|
---|
| 549 | if(dwClassType==ESC_CLASS){
|
---|
| 550 | accessibility = Prototype::Private;
|
---|
| 551 | }
|
---|
| 552 | else{
|
---|
| 553 | accessibility = Prototype::Public;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | if( pobj_c->GetName() == "Object"
|
---|
| 557 | || dwClassType == ESC_TYPE )
|
---|
| 558 | {
|
---|
| 559 | // 何も継承しない
|
---|
| 560 |
|
---|
| 561 | if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
|
---|
| 562 | {
|
---|
| 563 | // TODO: ここに来ないことが実証できたらこの分岐は消す
|
---|
| 564 | Jenga::Throw( "GetClass_recur内の例外" );
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 | else{
|
---|
| 568 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS)
|
---|
| 569 | {
|
---|
| 570 | // クラス継承先が指定されているとき
|
---|
| 571 | i += 3;
|
---|
| 572 | GetCommandToken( temporary, basbuf, i );
|
---|
| 573 |
|
---|
| 574 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
| 575 | SetError(105,temporary,i);
|
---|
| 576 | goto InheritsError;
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 | else
|
---|
| 580 | {
|
---|
| 581 | // 何の指定もないときはObjectクラスを継承する
|
---|
| 582 | lstrcpy( temporary, "Object" );
|
---|
| 583 | }
|
---|
| 584 | pobj_c->Inherits( temporary, i );
|
---|
| 585 |
|
---|
| 586 | if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
|
---|
| 587 | {
|
---|
| 588 | // インターフェイス実装を行う場合
|
---|
| 589 | i += 3;
|
---|
| 590 | GetCommandToken( temporary, basbuf, i );
|
---|
| 591 |
|
---|
| 592 | pobj_c->Implements( temporary, i );
|
---|
| 593 | }
|
---|
| 594 | }
|
---|
| 595 | InheritsError:
|
---|
| 596 |
|
---|
| 597 | //メンバとメソッドを取得
|
---|
| 598 | while(1){
|
---|
| 599 | i++;
|
---|
| 600 |
|
---|
| 601 | //エラー
|
---|
| 602 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
| 603 | SetError(22,"Class",i);
|
---|
| 604 | i--;
|
---|
| 605 | break;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
| 609 | SetError(111,NULL,i);
|
---|
| 610 | break;
|
---|
| 611 | }
|
---|
| 612 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
|
---|
| 613 | {
|
---|
| 614 | SetError(137, NULL, i );
|
---|
| 615 | break;
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | //Static修飾子
|
---|
| 619 | BOOL bStatic;
|
---|
| 620 | if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
|
---|
| 621 | bStatic=1;
|
---|
| 622 | i+=2;
|
---|
| 623 | }
|
---|
| 624 | else bStatic=0;
|
---|
| 625 |
|
---|
| 626 | //Const修飾子
|
---|
| 627 | bool isConst = false;
|
---|
| 628 | if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
|
---|
| 629 | isConst = true;
|
---|
| 630 | i += 2;
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | if(basbuf[i]==1&&(
|
---|
| 634 | basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
|
---|
| 635 | basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
|
---|
| 636 | )){
|
---|
| 637 | i3=basbuf[i+1];
|
---|
| 638 | sub_address=i;
|
---|
| 639 | }
|
---|
| 640 | else i3=0;
|
---|
| 641 |
|
---|
| 642 | bool isVirtual = false, isAbstract = false, isOverride = false;
|
---|
| 643 | if(i3==ESC_ABSTRACT){
|
---|
| 644 | isAbstract=1;
|
---|
| 645 | isVirtual=1;
|
---|
| 646 | i+=2;
|
---|
| 647 |
|
---|
| 648 | i3=basbuf[i+1];
|
---|
| 649 | }
|
---|
| 650 | else if(i3==ESC_VIRTUAL){
|
---|
| 651 | isAbstract=0;
|
---|
| 652 | isVirtual=1;
|
---|
| 653 | i+=2;
|
---|
| 654 |
|
---|
| 655 | i3=basbuf[i+1];
|
---|
| 656 | }
|
---|
| 657 | else if(i3==ESC_OVERRIDE){
|
---|
| 658 | isOverride=1;
|
---|
| 659 | isVirtual=1;
|
---|
| 660 |
|
---|
| 661 | i+=2;
|
---|
| 662 |
|
---|
| 663 | i3=basbuf[i+1];
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | for(i2=0;;i++,i2++){
|
---|
| 667 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 668 | temporary[i2]=0;
|
---|
| 669 | break;
|
---|
| 670 | }
|
---|
| 671 | temporary[i2]=basbuf[i];
|
---|
| 672 | }
|
---|
| 673 | if(temporary[0]=='\0'){
|
---|
| 674 | if(basbuf[i]=='\0'){
|
---|
| 675 |
|
---|
| 676 | if(dwClassType==ESC_CLASS)
|
---|
| 677 | SetError(22,"Class",top_pos);
|
---|
| 678 | else
|
---|
| 679 | SetError(22,"Type",top_pos);
|
---|
| 680 |
|
---|
| 681 | i--;
|
---|
| 682 | break;
|
---|
| 683 | }
|
---|
| 684 | continue;
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | //End Class記述の場合
|
---|
| 688 | if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
|
---|
| 689 | if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
|
---|
| 690 |
|
---|
| 691 | //アクセスを変更
|
---|
| 692 | if(lstrcmpi(temporary,"Private")==0){
|
---|
| 693 | accessibility = Prototype::Private;
|
---|
| 694 | continue;
|
---|
| 695 | }
|
---|
| 696 | if(lstrcmpi(temporary,"Public")==0){
|
---|
| 697 | accessibility = Prototype::Public;
|
---|
| 698 | continue;
|
---|
| 699 | }
|
---|
| 700 | if(lstrcmpi(temporary,"Protected")==0){
|
---|
| 701 | accessibility = Prototype::Protected;
|
---|
| 702 | continue;
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | extern int cp;
|
---|
| 706 | if(i3==0){
|
---|
| 707 | if(bStatic){
|
---|
| 708 | //静的メンバを追加
|
---|
| 709 | cp=i; //エラー用
|
---|
| 710 | pobj_c->AddStaticMember( accessibility, isConst, false, temporary, i);
|
---|
| 711 | }
|
---|
| 712 | else{
|
---|
| 713 | //メンバを追加
|
---|
| 714 | cp=i; //エラー用
|
---|
| 715 | pobj_c->AddMember( accessibility, isConst, false, temporary, i );
|
---|
| 716 |
|
---|
| 717 |
|
---|
| 718 | if(pobj_c->GetDynamicMembers()[pobj_c->GetDynamicMembers().size()-1]->GetType().IsStruct()){
|
---|
| 719 | if( !pobj_c->GetDynamicMembers()[pobj_c->GetDynamicMembers().size()-1]->GetType().GetClass().IsReady() ){
|
---|
| 720 | //参照先が読み取られていないとき
|
---|
| 721 | GetClass_recur(pobj_c->GetDynamicMembers()[pobj_c->GetDynamicMembers().size()-1]->GetType().GetClass().GetName().c_str());
|
---|
| 722 | }
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 |
|
---|
| 726 | if(pobj_c->GetDynamicMembers()[pobj_c->GetDynamicMembers().size()-1]->GetType().IsStruct()){
|
---|
| 727 | //循環参照のチェック
|
---|
| 728 | pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
|
---|
| 729 | if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers()[pobj_c->GetDynamicMembers().size()-1]->GetType().GetClass())){
|
---|
| 730 | //エラー回避
|
---|
| 731 | Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
|
---|
| 732 | type.SetBasicType( DEF_PTR_VOID );
|
---|
| 733 | }
|
---|
| 734 | pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
|
---|
| 735 | }
|
---|
| 736 | }
|
---|
| 737 | }
|
---|
| 738 | else{
|
---|
| 739 | //メソッドを追加
|
---|
| 740 | cp=i; //エラー用
|
---|
| 741 | pobj_c->AddMethod(pobj_c,
|
---|
| 742 | accessibility,
|
---|
| 743 | bStatic,
|
---|
| 744 | isConst,
|
---|
| 745 | isAbstract,
|
---|
| 746 | isVirtual,
|
---|
| 747 | isOverride,
|
---|
| 748 | false,
|
---|
| 749 | temporary,
|
---|
| 750 | sub_address);
|
---|
| 751 |
|
---|
| 752 | if( isAbstract ) continue;
|
---|
| 753 |
|
---|
| 754 | for(;;i++){
|
---|
| 755 | if(basbuf[i]=='\0'){
|
---|
| 756 | i--;
|
---|
| 757 | break;
|
---|
| 758 | }
|
---|
| 759 | if(basbuf[i-1]!='*'&&
|
---|
| 760 | basbuf[i]==1&&(
|
---|
| 761 | basbuf[i+1]==ESC_SUB||
|
---|
| 762 | basbuf[i+1]==ESC_FUNCTION||
|
---|
| 763 | basbuf[i+1]==ESC_MACRO||
|
---|
| 764 | basbuf[i+1]==ESC_TYPE||
|
---|
| 765 | basbuf[i+1]==ESC_CLASS||
|
---|
| 766 | basbuf[i+1]==ESC_INTERFACE||
|
---|
| 767 | basbuf[i+1]==ESC_ENUM)){
|
---|
| 768 | GetDefaultNameFromES(i3,temporary);
|
---|
| 769 | SetError(22,temporary,i);
|
---|
| 770 | }
|
---|
| 771 | if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
|
---|
| 772 | i+=2;
|
---|
| 773 | break;
|
---|
| 774 | }
|
---|
| 775 | }
|
---|
| 776 | }
|
---|
| 777 | }
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 |
|
---|
| 781 | // 呼び出し元でコンパイル中のクラスポインタを元に戻す
|
---|
| 782 | compiler.pCompilingClass = pBackCompilingClass;
|
---|
| 783 |
|
---|
| 784 | // 名前空間を元に戻す
|
---|
| 785 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes;
|
---|
| 786 |
|
---|
| 787 | // インポートされた名前空間を元に戻す
|
---|
| 788 | compiler.GetNamespaceSupporter().GetImportedNamespaces() = backupImportedNamespaces;
|
---|
| 789 | }
|
---|
| 790 |
|
---|
| 791 | void Classes::LookaheadClass( const char *className )
|
---|
| 792 | {
|
---|
| 793 | pobj_LoopRefCheck->add( className );
|
---|
| 794 | compiler.GetObjectModule().meta.GetClasses().GetClass_recur( className );
|
---|
| 795 | pobj_LoopRefCheck->del( className );
|
---|
| 796 | }
|
---|
| 797 |
|
---|
| 798 | bool Classes::LoopRefCheck( const CClass &objClass )
|
---|
| 799 | {
|
---|
| 800 | if( pobj_LoopRefCheck->check( objClass ) )
|
---|
| 801 | {
|
---|
| 802 | return false;
|
---|
| 803 | }
|
---|
| 804 |
|
---|
| 805 | return true;
|
---|
| 806 | }
|
---|
| 807 |
|
---|
| 808 | void Classes::GetAllClassInfo(void){
|
---|
| 809 | //ループ継承チェック用のクラス
|
---|
| 810 | pobj_LoopRefCheck=new CLoopRefCheck();
|
---|
| 811 |
|
---|
| 812 | //クラスを取得
|
---|
| 813 | GetClass_recur(0);
|
---|
| 814 |
|
---|
| 815 | delete pobj_LoopRefCheck;
|
---|
| 816 | pobj_LoopRefCheck=0;
|
---|
| 817 |
|
---|
| 818 | // イテレータの準備
|
---|
| 819 | this->Iterator_Init();
|
---|
| 820 | }
|
---|