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