| 1 | #include "stdafx.h"
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include "../common.h"
 | 
|---|
| 4 | #ifdef _AMD64_
 | 
|---|
| 5 | #include "../../compiler_x64/opcode.h"
 | 
|---|
| 6 | #else
 | 
|---|
| 7 | #include "../../compiler_x86/opcode.h"
 | 
|---|
| 8 | #endif
 | 
|---|
| 9 | 
 | 
|---|
| 10 | using namespace ActiveBasic::Compiler;
 | 
|---|
| 11 | 
 | 
|---|
| 12 | 
 | 
|---|
| 13 | void LexicalAnalyzer::CollectClassesForNameOnly( const char *source, Classes &classes )
 | 
|---|
| 14 | {
 | 
|---|
| 15 |     int i, i2;
 | 
|---|
| 16 |     char temporary[VN_SIZE];
 | 
|---|
| 17 | 
 | 
|---|
| 18 |     // 名前空間管理
 | 
|---|
| 19 |     NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
 | 
|---|
| 20 |     namespaceScopes.clear();
 | 
|---|
| 21 | 
 | 
|---|
| 22 |     // Importsされた名前空間の管理
 | 
|---|
| 23 |     NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
 | 
|---|
| 24 |     importedNamespaces.clear();
 | 
|---|
| 25 | 
 | 
|---|
| 26 |     for(i=0;;i++){
 | 
|---|
| 27 |         if(source[i]=='\0') break;
 | 
|---|
| 28 | 
 | 
|---|
| 29 |         if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
 | 
|---|
| 30 |             for(i+=2,i2=0;;i2++,i++){
 | 
|---|
| 31 |                 if( IsCommandDelimitation( source[i] ) ){
 | 
|---|
| 32 |                     temporary[i2]=0;
 | 
|---|
| 33 |                     break;
 | 
|---|
| 34 |                 }
 | 
|---|
| 35 |                 temporary[i2]=source[i];
 | 
|---|
| 36 |             }
 | 
|---|
| 37 |             namespaceScopes.push_back( temporary );
 | 
|---|
| 38 | 
 | 
|---|
| 39 |             continue;
 | 
|---|
| 40 |         }
 | 
|---|
| 41 |         else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
 | 
|---|
| 42 |             if( namespaceScopes.size() <= 0 ){
 | 
|---|
| 43 |                 compiler.errorMessenger.Output(12, "End Namespace", i );
 | 
|---|
| 44 |             }
 | 
|---|
| 45 |             else{
 | 
|---|
| 46 |                 namespaceScopes.pop_back();
 | 
|---|
| 47 |             }
 | 
|---|
| 48 | 
 | 
|---|
| 49 |             i += 2;
 | 
|---|
| 50 |             continue;
 | 
|---|
| 51 |         }
 | 
|---|
| 52 |         else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
 | 
|---|
| 53 |             for(i+=2,i2=0;;i2++,i++){
 | 
|---|
| 54 |                 if( IsCommandDelimitation( source[i] ) ){
 | 
|---|
| 55 |                     temporary[i2]=0;
 | 
|---|
| 56 |                     break;
 | 
|---|
| 57 |                 }
 | 
|---|
| 58 |                 temporary[i2]=source[i];
 | 
|---|
| 59 |             }
 | 
|---|
| 60 |             if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
 | 
|---|
| 61 |             {
 | 
|---|
| 62 |                 compiler.errorMessenger.Output(64,temporary,i );
 | 
|---|
| 63 |             }
 | 
|---|
| 64 | 
 | 
|---|
| 65 |             continue;
 | 
|---|
| 66 |         }
 | 
|---|
| 67 |         else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
 | 
|---|
| 68 |             importedNamespaces.clear();
 | 
|---|
| 69 |             continue;
 | 
|---|
| 70 |         }
 | 
|---|
| 71 | 
 | 
|---|
| 72 |         if(source[i]==1&&(
 | 
|---|
| 73 |             source[i+1]==ESC_CLASS||
 | 
|---|
| 74 |             source[i+1]==ESC_TYPE||
 | 
|---|
| 75 |             source[i+1]==ESC_INTERFACE
 | 
|---|
| 76 |             ))
 | 
|---|
| 77 |         {
 | 
|---|
| 78 |             int nowLine = i;
 | 
|---|
| 79 |             i += 2;
 | 
|---|
| 80 | 
 | 
|---|
| 81 |             Type blittableType;
 | 
|---|
| 82 |             if(memicmp(source+i,"Align(",6)==0){
 | 
|---|
| 83 |                 //アラインメント修飾子
 | 
|---|
| 84 |                 i+=6;
 | 
|---|
| 85 |                 i=JumpStringInPare(source,i)+1;
 | 
|---|
| 86 |             }
 | 
|---|
| 87 |             else if( memicmp( source + i, "Blittable(", 10 ) == 0 ){
 | 
|---|
| 88 |                 // Blittable修飾子
 | 
|---|
| 89 |                 i+=10;
 | 
|---|
| 90 |                 i+=GetStringInPare_RemovePare(temporary,source+i)+1;
 | 
|---|
| 91 |                 compiler.StringToType( temporary, blittableType );
 | 
|---|
| 92 |             }
 | 
|---|
| 93 | 
 | 
|---|
| 94 |             bool isEnum = false;
 | 
|---|
| 95 |             bool isDelegate = false;
 | 
|---|
| 96 |             if( source[i] == 1 && source[i+1] == ESC_ENUM ){
 | 
|---|
| 97 |                 // 列挙型の場合
 | 
|---|
| 98 |                 isEnum = true;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |                 i += 2;
 | 
|---|
| 101 |             }
 | 
|---|
| 102 |             else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
 | 
|---|
| 103 |             {
 | 
|---|
| 104 |                 // デリゲートの場合
 | 
|---|
| 105 |                 isDelegate = true;
 | 
|---|
| 106 | 
 | 
|---|
| 107 |                 i += 2;
 | 
|---|
| 108 |             }
 | 
|---|
| 109 | 
 | 
|---|
| 110 |             for(i2=0;;i++,i2++){
 | 
|---|
| 111 |                 if(!IsVariableChar(source[i])){
 | 
|---|
| 112 |                     temporary[i2]=0;
 | 
|---|
| 113 |                     break;
 | 
|---|
| 114 |                 }
 | 
|---|
| 115 |                 temporary[i2]=source[i];
 | 
|---|
| 116 |             }
 | 
|---|
| 117 | 
 | 
|---|
| 118 |             //クラスを追加
 | 
|---|
| 119 |             CClass *pClass = new CClass( namespaceScopes, importedNamespaces, temporary );
 | 
|---|
| 120 |             if( classes.IsExist( pClass ) )
 | 
|---|
| 121 |             {
 | 
|---|
| 122 |                 // 既に存在している
 | 
|---|
| 123 |                 compiler.errorMessenger.Output(15,pClass->GetName(), nowLine);
 | 
|---|
| 124 | 
 | 
|---|
| 125 |                 delete pClass;
 | 
|---|
| 126 | 
 | 
|---|
| 127 |                 continue;
 | 
|---|
| 128 |             }
 | 
|---|
| 129 | 
 | 
|---|
| 130 |             classes.Put( pClass );
 | 
|---|
| 131 | 
 | 
|---|
| 132 |             if( source[nowLine+1] == ESC_CLASS )
 | 
|---|
| 133 |             {
 | 
|---|
| 134 |                 if( isEnum )
 | 
|---|
| 135 |                 {
 | 
|---|
| 136 |                     pClass->SetClassType( CClass::Enum );
 | 
|---|
| 137 |                 }
 | 
|---|
| 138 |                 else if( isDelegate )
 | 
|---|
| 139 |                 {
 | 
|---|
| 140 |                     pClass->SetClassType( CClass::Delegate );
 | 
|---|
| 141 |                 }
 | 
|---|
| 142 |                 else{
 | 
|---|
| 143 |                     pClass->SetClassType( CClass::Class );
 | 
|---|
| 144 |                 }
 | 
|---|
| 145 |             }
 | 
|---|
| 146 |             else if( source[nowLine+1] == ESC_INTERFACE )
 | 
|---|
| 147 |             {
 | 
|---|
| 148 |                 pClass->SetClassType( CClass::Interface );
 | 
|---|
| 149 |             }
 | 
|---|
| 150 |             else
 | 
|---|
| 151 |             {
 | 
|---|
| 152 |                 pClass->SetClassType( CClass::Structure );
 | 
|---|
| 153 |             }
 | 
|---|
| 154 | 
 | 
|---|
| 155 |             // Blittable型の場合
 | 
|---|
| 156 |             if( !blittableType.IsNull() ){
 | 
|---|
| 157 |                 pClass->SetBlittableType( blittableType );
 | 
|---|
| 158 | 
 | 
|---|
| 159 |                 // Blittable型として登録
 | 
|---|
| 160 |                 compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) );
 | 
|---|
| 161 |             }
 | 
|---|
| 162 |         }
 | 
|---|
| 163 |     }
 | 
|---|
| 164 | }
 | 
|---|
| 165 | 
 | 
|---|
| 166 | 
 | 
|---|
| 167 | class CLoopRefCheck{
 | 
|---|
| 168 |     char **names;
 | 
|---|
| 169 |     int num;
 | 
|---|
| 170 |     void init(){
 | 
|---|
| 171 |         int i;
 | 
|---|
| 172 |         for(i=0;i<num;i++){
 | 
|---|
| 173 |             free(names[i]);
 | 
|---|
| 174 |         }
 | 
|---|
| 175 |         free(names);
 | 
|---|
| 176 |     }
 | 
|---|
| 177 | public:
 | 
|---|
| 178 |     CLoopRefCheck()
 | 
|---|
| 179 |     {
 | 
|---|
| 180 |         names=(char **)malloc(1);
 | 
|---|
| 181 |         num=0;
 | 
|---|
| 182 |     }
 | 
|---|
| 183 |     ~CLoopRefCheck()
 | 
|---|
| 184 |     {
 | 
|---|
| 185 |         init();
 | 
|---|
| 186 |     }
 | 
|---|
| 187 |     void add(const char *lpszInheritsClass)
 | 
|---|
| 188 |     {
 | 
|---|
| 189 |         names=(char **)realloc(names,(num+1)*sizeof(char *));
 | 
|---|
| 190 |         names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);
 | 
|---|
| 191 |         lstrcpy(names[num],lpszInheritsClass);
 | 
|---|
| 192 |         num++;
 | 
|---|
| 193 |     }
 | 
|---|
| 194 |     void del(const char *lpszInheritsClass)
 | 
|---|
| 195 |     {
 | 
|---|
| 196 |         int i;
 | 
|---|
| 197 |         for(i=0;i<num;i++){
 | 
|---|
| 198 |             if(lstrcmp(names[i],lpszInheritsClass)==0){
 | 
|---|
| 199 |                 free(names[i]);
 | 
|---|
| 200 |                 break;
 | 
|---|
| 201 |             }
 | 
|---|
| 202 |         }
 | 
|---|
| 203 |         if(i!=num){
 | 
|---|
| 204 |             num--;
 | 
|---|
| 205 |             for(;i<num;i++){
 | 
|---|
| 206 |                 names[i]=names[i+1];
 | 
|---|
| 207 |             }
 | 
|---|
| 208 |         }
 | 
|---|
| 209 |     }
 | 
|---|
| 210 |     BOOL check(const CClass &inheritsClass) const
 | 
|---|
| 211 |     {
 | 
|---|
| 212 |         //ループ継承チェック
 | 
|---|
| 213 |         int i;
 | 
|---|
| 214 |         for(i=0;i<num;i++){
 | 
|---|
| 215 |             if( inheritsClass.GetName() == names[i] ){
 | 
|---|
| 216 |                 return 1;
 | 
|---|
| 217 |             }
 | 
|---|
| 218 |         }
 | 
|---|
| 219 |         return 0;
 | 
|---|
| 220 |     }
 | 
|---|
| 221 | };
 | 
|---|
| 222 | CLoopRefCheck *pobj_LoopRefCheck;
 | 
|---|
| 223 | 
 | 
|---|
| 224 | bool MemberVar_LoopRefCheck(const CClass &objClass){
 | 
|---|
| 225 |     if( objClass.HasSuperClass() )
 | 
|---|
| 226 |     {
 | 
|---|
| 227 |         // 基底クラスをチェック
 | 
|---|
| 228 |         if( MemberVar_LoopRefCheck( objClass.GetSuperClass() ) == false )
 | 
|---|
| 229 |         {
 | 
|---|
| 230 |             return false;
 | 
|---|
| 231 |         }
 | 
|---|
| 232 |     }
 | 
|---|
| 233 | 
 | 
|---|
| 234 |     bool result = true;
 | 
|---|
| 235 |     BOOST_FOREACH( Member *pMember, objClass.GetDynamicMembers() ){
 | 
|---|
| 236 |         if(pMember->GetType().IsStruct()){
 | 
|---|
| 237 |             //循環参照でないかをチェック
 | 
|---|
| 238 |             if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
 | 
|---|
| 239 |                 extern int cp;
 | 
|---|
| 240 |                 compiler.errorMessenger.Output(124,pMember->GetType().GetClass().GetName(),cp);
 | 
|---|
| 241 |                 return false;
 | 
|---|
| 242 |             }
 | 
|---|
| 243 | 
 | 
|---|
| 244 |             pobj_LoopRefCheck->add(objClass.GetName().c_str());
 | 
|---|
| 245 | 
 | 
|---|
| 246 |             bool tempResult = MemberVar_LoopRefCheck(pMember->GetType().GetClass());
 | 
|---|
| 247 |             if( result )
 | 
|---|
| 248 |             {
 | 
|---|
| 249 |                 result = tempResult;
 | 
|---|
| 250 |             }
 | 
|---|
| 251 | 
 | 
|---|
| 252 |             pobj_LoopRefCheck->del(objClass.GetName().c_str());
 | 
|---|
| 253 |         }
 | 
|---|
| 254 |     }
 | 
|---|
| 255 | 
 | 
|---|
| 256 |     return result;
 | 
|---|
| 257 | }
 | 
|---|
| 258 | 
 | 
|---|
| 259 | void OverrideErrorCheck( const DynamicMethod::OverrideResult &result )
 | 
|---|
| 260 | {
 | 
|---|
| 261 |     switch( result.enumType )
 | 
|---|
| 262 |     {
 | 
|---|
| 263 |     case DynamicMethod::OverrideResult::Successful:
 | 
|---|
| 264 |         break;
 | 
|---|
| 265 |     case DynamicMethod::OverrideResult::NotVirtual:
 | 
|---|
| 266 |         compiler.errorMessenger.Output(136, result.pMethod->GetUserProc().GetName(), cp);
 | 
|---|
| 267 |         break;
 | 
|---|
| 268 |     case DynamicMethod::OverrideResult::NotUseOverrideModifier:
 | 
|---|
| 269 |         compiler.errorMessenger.Output(127, result.pMethod->GetUserProc().GetName(), cp);
 | 
|---|
| 270 |         break;
 | 
|---|
| 271 |     case DynamicMethod::OverrideResult::DifferentAccesibility:
 | 
|---|
| 272 |         compiler.errorMessenger.Output(128, result.pMethod->GetUserProc().GetName(), cp);
 | 
|---|
| 273 |         break;
 | 
|---|
| 274 |     default:
 | 
|---|
| 275 |         throw;
 | 
|---|
| 276 |     }
 | 
|---|
| 277 | }
 | 
|---|
| 278 | 
 | 
|---|
| 279 | Member *LexicalAnalyzer::CreateMember( const CClass &_class, Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine )
 | 
|---|
| 280 | {
 | 
|---|
| 281 |     extern int cp;
 | 
|---|
| 282 | 
 | 
|---|
| 283 |     //構文を解析
 | 
|---|
| 284 |     char VarName[VN_SIZE];
 | 
|---|
| 285 |     char initBuffer[VN_SIZE];
 | 
|---|
| 286 |     char lpszConstructParameter[VN_SIZE];
 | 
|---|
| 287 |     Subscripts subscripts;
 | 
|---|
| 288 |     Type type;
 | 
|---|
| 289 |     if( !GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter) )
 | 
|---|
| 290 |     {
 | 
|---|
| 291 |         return NULL;
 | 
|---|
| 292 |     }
 | 
|---|
| 293 | 
 | 
|---|
| 294 |     //重複チェック
 | 
|---|
| 295 |     if( _class.DupliCheckAll( VarName ) ){
 | 
|---|
| 296 |         compiler.errorMessenger.Output(15,VarName,cp);
 | 
|---|
| 297 |     }
 | 
|---|
| 298 | 
 | 
|---|
| 299 |     Member *pMember = new Member( accessibility, VarName, type, isConst, subscripts, initBuffer, lpszConstructParameter );
 | 
|---|
| 300 |     pMember->source_code_address = nowLine;
 | 
|---|
| 301 |     return pMember;
 | 
|---|
| 302 | }
 | 
|---|
| 303 | 
 | 
|---|
| 304 | void LexicalAnalyzer::AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
 | 
|---|
| 305 |     bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine)
 | 
|---|
| 306 | {
 | 
|---|
| 307 |     if( isAutoGeneration )
 | 
|---|
| 308 |     {
 | 
|---|
| 309 |         // コード自動生成
 | 
|---|
| 310 |         pUserProc->ThisIsAutoGenerationProc();
 | 
|---|
| 311 |     }
 | 
|---|
| 312 | 
 | 
|---|
| 313 | 
 | 
|---|
| 314 |     ////////////////////////////////////////////////////////////
 | 
|---|
| 315 |     // コンストラクタ、デストラクタの場合の処理
 | 
|---|
| 316 |     ////////////////////////////////////////////////////////////
 | 
|---|
| 317 |     BOOL fConstructor=0,bDestructor=0;
 | 
|---|
| 318 | 
 | 
|---|
| 319 |     if( pUserProc->GetName() == pobj_c->GetName() ){
 | 
|---|
| 320 |         //コンストラクタの場合
 | 
|---|
| 321 | 
 | 
|---|
| 322 |         //標準コンストラクタ(引数なし)
 | 
|---|
| 323 |         if(pUserProc->Params().size()==0) fConstructor=1;
 | 
|---|
| 324 | 
 | 
|---|
| 325 |         //強制的にConst修飾子をつける
 | 
|---|
| 326 |         isConst = true;
 | 
|---|
| 327 |     }
 | 
|---|
| 328 |     else if(pUserProc->GetName()[0]=='~'){
 | 
|---|
| 329 |         //デストラクタの場合はその名前が正しいかチェックを行う
 | 
|---|
| 330 |         if(lstrcmp(pUserProc->GetName().c_str()+1,pobj_c->GetName().c_str())!=0)
 | 
|---|
| 331 |             compiler.errorMessenger.Output(117,NULL,nowLine);
 | 
|---|
| 332 |         else
 | 
|---|
| 333 |             bDestructor=1;
 | 
|---|
| 334 |     }
 | 
|---|
| 335 |     if(fConstructor||bDestructor){
 | 
|---|
| 336 |         // コンストラクタ、デストラクタのアクセシビリティをチェック
 | 
|---|
| 337 | 
 | 
|---|
| 338 |         //強制的にConst修飾子をつける
 | 
|---|
| 339 |         isConst = true;
 | 
|---|
| 340 |     }
 | 
|---|
| 341 | 
 | 
|---|
| 342 |     if( fConstructor == 1 )
 | 
|---|
| 343 |         pobj_c->SetConstructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
 | 
|---|
| 344 |     else if( bDestructor )
 | 
|---|
| 345 |         pobj_c->SetDestructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
 | 
|---|
| 346 | 
 | 
|---|
| 347 | 
 | 
|---|
| 348 | 
 | 
|---|
| 349 |     //////////////////
 | 
|---|
| 350 |     // 重複チェック
 | 
|---|
| 351 |     //////////////////
 | 
|---|
| 352 | 
 | 
|---|
| 353 |     if(pobj_c->DupliCheckMember( pUserProc->GetName().c_str() )){
 | 
|---|
| 354 |         compiler.errorMessenger.Output(15,pUserProc->GetName(),nowLine);
 | 
|---|
| 355 |         return;
 | 
|---|
| 356 |     }
 | 
|---|
| 357 | 
 | 
|---|
| 358 |     //メソッド
 | 
|---|
| 359 |     BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetDynamicMethods() )
 | 
|---|
| 360 |     {
 | 
|---|
| 361 |         //基底クラスと重複する場合はオーバーライドを行う
 | 
|---|
| 362 |         if( pMethod->GetInheritsClassPtr() ) continue;
 | 
|---|
| 363 | 
 | 
|---|
| 364 |         if( pMethod->GetUserProc().IsEqualForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ) )
 | 
|---|
| 365 |         {
 | 
|---|
| 366 |             //関数名、パラメータ、戻り値が合致したとき
 | 
|---|
| 367 |             compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine);
 | 
|---|
| 368 |             return;
 | 
|---|
| 369 |         }
 | 
|---|
| 370 |     }
 | 
|---|
| 371 | 
 | 
|---|
| 372 |     //仮想関数の場合
 | 
|---|
| 373 |     if( isAbstract ) pUserProc->CompleteCompile();
 | 
|---|
| 374 | 
 | 
|---|
| 375 |     // メソッドのオーバーライド
 | 
|---|
| 376 |     DynamicMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc );
 | 
|---|
| 377 |     if( pMethodForOverride )
 | 
|---|
| 378 |     {
 | 
|---|
| 379 |         DynamicMethod::OverrideResult result;
 | 
|---|
| 380 |         result.enumType = pMethodForOverride->Override( pUserProc, accessibility, isOverride );
 | 
|---|
| 381 |         result.pMethod = pMethodForOverride;
 | 
|---|
| 382 |         OverrideErrorCheck( result );
 | 
|---|
| 383 | 
 | 
|---|
| 384 |         pUserProc->SetMethod( pMethodForOverride );
 | 
|---|
| 385 |         return;
 | 
|---|
| 386 |     }
 | 
|---|
| 387 |     else
 | 
|---|
| 388 |     {
 | 
|---|
| 389 |         // インターフェイス メソッドのオーバーライド
 | 
|---|
| 390 |         BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() )
 | 
|---|
| 391 |         {
 | 
|---|
| 392 |             if( interfaceName[0] )
 | 
|---|
| 393 |             {
 | 
|---|
| 394 |                 if( pInterface->GetClass().GetName() != interfaceName )
 | 
|---|
| 395 |                 {
 | 
|---|
| 396 |                     // 指定されたインターフェイス名と整合しないとき
 | 
|---|
| 397 |                     continue;
 | 
|---|
| 398 |                 }
 | 
|---|
| 399 |             }
 | 
|---|
| 400 | 
 | 
|---|
| 401 |             if( !pInterface->GetClass().IsReady() ){
 | 
|---|
| 402 |                 // インターフェイスが未解析のとき
 | 
|---|
| 403 |                 LexicalAnalyzer::LookaheadClass(
 | 
|---|
| 404 |                     pInterface->GetClass().GetName().c_str(),
 | 
|---|
| 405 |                     compiler.GetObjectModule().meta.GetClasses()
 | 
|---|
| 406 |                 );
 | 
|---|
| 407 |             }
 | 
|---|
| 408 | 
 | 
|---|
| 409 |             DynamicMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc );
 | 
|---|
| 410 |             if( pMethodForOverride )
 | 
|---|
| 411 |             {
 | 
|---|
| 412 |                 DynamicMethod::OverrideResult result;
 | 
|---|
| 413 |                 result.enumType = pMethodForOverride->Override( pUserProc, accessibility, isOverride );
 | 
|---|
| 414 |                 result.pMethod = pMethodForOverride;
 | 
|---|
| 415 |                 OverrideErrorCheck( result );
 | 
|---|
| 416 | 
 | 
|---|
| 417 |                 pUserProc->SetMethod( pMethodForOverride );
 | 
|---|
| 418 |                 return;
 | 
|---|
| 419 |             }
 | 
|---|
| 420 |         }
 | 
|---|
| 421 |     }
 | 
|---|
| 422 | 
 | 
|---|
| 423 |     if( interfaceName[0] )
 | 
|---|
| 424 |     {
 | 
|---|
| 425 |         compiler.errorMessenger.Output(139,interfaceName,nowLine);
 | 
|---|
| 426 |     }
 | 
|---|
| 427 | 
 | 
|---|
| 428 |     if( isVirtual ){
 | 
|---|
| 429 |         pobj_c->AddVtblNum( 1 );
 | 
|---|
| 430 |     }
 | 
|---|
| 431 | 
 | 
|---|
| 432 |     if( isOverride ){
 | 
|---|
| 433 |         compiler.errorMessenger.Output(12,"Override",nowLine);
 | 
|---|
| 434 |     }
 | 
|---|
| 435 | 
 | 
|---|
| 436 |     if(bStatic){
 | 
|---|
| 437 |         pobj_c->GetStaticMethods().AddStatic( pUserProc, accessibility );
 | 
|---|
| 438 |     }
 | 
|---|
| 439 |     else{
 | 
|---|
| 440 |         pobj_c->GetDynamicMethods().Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);
 | 
|---|
| 441 |     }
 | 
|---|
| 442 | }
 | 
|---|
| 443 | 
 | 
|---|
| 444 | bool LexicalAnalyzer::Inherits( CClass &_class, const char *inheritNames, int nowLine ){
 | 
|---|
| 445 |     int i = 0;
 | 
|---|
| 446 |     bool isInheritsClass = false;
 | 
|---|
| 447 |     while( true ){
 | 
|---|
| 448 | 
 | 
|---|
| 449 |         char temporary[VN_SIZE];
 | 
|---|
| 450 |         for( int i2=0;; i++, i2++ ){
 | 
|---|
| 451 |             if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
 | 
|---|
| 452 |                 temporary[i2] = 0;
 | 
|---|
| 453 |                 break;
 | 
|---|
| 454 |             }
 | 
|---|
| 455 |             temporary[i2] = inheritNames[i];
 | 
|---|
| 456 |         }
 | 
|---|
| 457 | 
 | 
|---|
| 458 |         // ジェネリクス構文を分解
 | 
|---|
| 459 |         char className[VN_SIZE];
 | 
|---|
| 460 |         Jenga::Common::Strings typeParameterStrings;
 | 
|---|
| 461 |         SplitGenericClassInstance( temporary, className, typeParameterStrings );
 | 
|---|
| 462 | 
 | 
|---|
| 463 |         // 型パラメータ文字列から型データを取得
 | 
|---|
| 464 |         Types actualTypeParameters;
 | 
|---|
| 465 |         BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
 | 
|---|
| 466 |         {
 | 
|---|
| 467 |             Type type;
 | 
|---|
| 468 |             compiler.StringToType( typeParameterStr, type );
 | 
|---|
| 469 |             actualTypeParameters.push_back( type );
 | 
|---|
| 470 |         }
 | 
|---|
| 471 | 
 | 
|---|
| 472 |         //継承元クラスを取得
 | 
|---|
| 473 |         const CClass *pInheritsClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
 | 
|---|
| 474 |             LexicalAnalyzer::FullNameToSymbol( className )
 | 
|---|
| 475 |         );
 | 
|---|
| 476 |         if( !pInheritsClass ){
 | 
|---|
| 477 |             compiler.errorMessenger.Output(106,className,nowLine);
 | 
|---|
| 478 |             return false;
 | 
|---|
| 479 |         }
 | 
|---|
| 480 | 
 | 
|---|
| 481 |         if( pInheritsClass->IsClass() ){
 | 
|---|
| 482 |             // クラスを継承する
 | 
|---|
| 483 |             isInheritsClass = true;
 | 
|---|
| 484 | 
 | 
|---|
| 485 |             //ループ継承でないかをチェック
 | 
|---|
| 486 |             if( !LexicalAnalyzer::LoopRefCheck(*pInheritsClass) )
 | 
|---|
| 487 |             {
 | 
|---|
| 488 |                 compiler.errorMessenger.Output(123,pInheritsClass->GetName(),nowLine);
 | 
|---|
| 489 |                 return false;
 | 
|---|
| 490 |             }
 | 
|---|
| 491 | 
 | 
|---|
| 492 |             if( !pInheritsClass->IsReady() ){
 | 
|---|
| 493 |                 //継承先が読み取られていないとき
 | 
|---|
| 494 |                 LexicalAnalyzer::LookaheadClass(
 | 
|---|
| 495 |                     pInheritsClass->GetName().c_str(),
 | 
|---|
| 496 |                     compiler.GetObjectModule().meta.GetClasses()
 | 
|---|
| 497 |                 );
 | 
|---|
| 498 |             }
 | 
|---|
| 499 | 
 | 
|---|
| 500 |             if( !_class.InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){
 | 
|---|
| 501 |                 return false;
 | 
|---|
| 502 |             }
 | 
|---|
| 503 |         }
 | 
|---|
| 504 |         else{
 | 
|---|
| 505 |             compiler.errorMessenger.Output(135,pInheritsClass->GetFullName().c_str(),nowLine);
 | 
|---|
| 506 |             return false;
 | 
|---|
| 507 |         }
 | 
|---|
| 508 | 
 | 
|---|
| 509 |         if( inheritNames[i] == '\0' ){
 | 
|---|
| 510 |             break;
 | 
|---|
| 511 |         }
 | 
|---|
| 512 |         i++;
 | 
|---|
| 513 |     }
 | 
|---|
| 514 | 
 | 
|---|
| 515 |     if( !isInheritsClass ){
 | 
|---|
| 516 |         const CClass *pObjectClass = compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
 | 
|---|
| 517 |         //ループ継承でないかをチェック
 | 
|---|
| 518 |         if( !LexicalAnalyzer::LoopRefCheck( *pObjectClass ) )
 | 
|---|
| 519 |         {
 | 
|---|
| 520 |             compiler.errorMessenger.Output(123,pObjectClass->GetName(),nowLine);
 | 
|---|
| 521 |             return false;
 | 
|---|
| 522 |         }
 | 
|---|
| 523 | 
 | 
|---|
| 524 |         if( !pObjectClass->IsReady() ){
 | 
|---|
| 525 |             //継承先が読み取られていないとき
 | 
|---|
| 526 |             LexicalAnalyzer::LookaheadClass(
 | 
|---|
| 527 |                 pObjectClass->GetName().c_str(),
 | 
|---|
| 528 |                 compiler.GetObjectModule().meta.GetClasses()
 | 
|---|
| 529 |             );
 | 
|---|
| 530 |         }
 | 
|---|
| 531 | 
 | 
|---|
| 532 |         // クラスを一つも継承していないとき
 | 
|---|
| 533 |         if( !_class.InheritsClass( *pObjectClass, Types(), nowLine ) ){
 | 
|---|
| 534 |             return false;
 | 
|---|
| 535 |         }
 | 
|---|
| 536 |     }
 | 
|---|
| 537 | 
 | 
|---|
| 538 |     return true;
 | 
|---|
| 539 | }
 | 
|---|
| 540 | 
 | 
|---|
| 541 | void LexicalAnalyzer::Implements( CClass &_class, Interface *pInterface, std::vector<DynamicMethod::OverrideResult> &overrideResults )
 | 
|---|
| 542 | {
 | 
|---|
| 543 |     _class.AddInterface( pInterface );
 | 
|---|
| 544 | 
 | 
|---|
| 545 | 
 | 
|---|
| 546 |     /////////////////////////////////////////////////////////////////
 | 
|---|
| 547 |     // 基底クラスのメソッドからインターフェイスメソッドを再実装する
 | 
|---|
| 548 |     /////////////////////////////////////////////////////////////////
 | 
|---|
| 549 |     BOOST_FOREACH( CMethod *pMethod, _class.GetDynamicMethods() )
 | 
|---|
| 550 |     {
 | 
|---|
| 551 |         DynamicMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );
 | 
|---|
| 552 |         if( pMethodForOverride )
 | 
|---|
| 553 |         {
 | 
|---|
| 554 |             DynamicMethod::OverrideResult result;
 | 
|---|
| 555 |             result.enumType = pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false );
 | 
|---|
| 556 |             result.pMethod = pMethod;
 | 
|---|
| 557 |             overrideResults.push_back( result );
 | 
|---|
| 558 | 
 | 
|---|
| 559 |             // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する)
 | 
|---|
| 560 |             pMethod->SetNotUseMark( true );
 | 
|---|
| 561 |         }
 | 
|---|
| 562 |     }
 | 
|---|
| 563 | 
 | 
|---|
| 564 | 
 | 
|---|
| 565 |     /////////////////////////////////////////////////////////////////
 | 
|---|
| 566 |     // キャストメソッドを追加(内部コードは自動生成すること)
 | 
|---|
| 567 |     // ※COMインターフェイスは除外すること
 | 
|---|
| 568 |     /////////////////////////////////////////////////////////////////
 | 
|---|
| 569 |     if( pInterface->GetClass().IsInterface() )
 | 
|---|
| 570 |     {
 | 
|---|
| 571 |         // Function Operator() As ITest
 | 
|---|
| 572 | 
 | 
|---|
| 573 |         char methodName[255] = { 1, ESC_OPERATOR, CALC_AS, '\0' };
 | 
|---|
| 574 | 
 | 
|---|
| 575 |         //関数ハッシュへ登録
 | 
|---|
| 576 |         UserProc *pUserProc = new UserProc(
 | 
|---|
| 577 |             NamespaceScopes(),
 | 
|---|
| 578 |             NamespaceScopesCollection(),
 | 
|---|
| 579 |             methodName,
 | 
|---|
| 580 |             Procedure::Function,
 | 
|---|
| 581 |             false,
 | 
|---|
| 582 |             false,
 | 
|---|
| 583 |             false );
 | 
|---|
| 584 |         pUserProc->SetParentClass( &_class );
 | 
|---|
| 585 | 
 | 
|---|
| 586 |         Parameters params;
 | 
|---|
| 587 |         params.push_back( new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) );
 | 
|---|
| 588 |         pUserProc->SetRealParams( params );
 | 
|---|
| 589 | 
 | 
|---|
| 590 |         pUserProc->SetReturnType( Type( DEF_OBJECT, pInterface->GetClass() ) );
 | 
|---|
| 591 |         pUserProc->_paramStr = "";
 | 
|---|
| 592 |         pUserProc->Using();
 | 
|---|
| 593 | 
 | 
|---|
| 594 |         // 関数を追加
 | 
|---|
| 595 |         if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
 | 
|---|
| 596 |         {
 | 
|---|
| 597 |             // 既に存在している
 | 
|---|
| 598 |             compiler.errorMessenger.Output(15,pUserProc->GetName(),-1);
 | 
|---|
| 599 | 
 | 
|---|
| 600 |             delete pUserProc;
 | 
|---|
| 601 |         }
 | 
|---|
| 602 |         else
 | 
|---|
| 603 |         {
 | 
|---|
| 604 |             compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
 | 
|---|
| 605 |         }
 | 
|---|
| 606 | 
 | 
|---|
| 607 |         LexicalAnalyzer::AddMethod(
 | 
|---|
| 608 |             &_class,
 | 
|---|
| 609 |             pUserProc,
 | 
|---|
| 610 |             Prototype::Public,
 | 
|---|
| 611 |             0,
 | 
|---|
| 612 |             false,          // isConst
 | 
|---|
| 613 |             false,          // isAbstract
 | 
|---|
| 614 |             false,          // isVirtual
 | 
|---|
| 615 |             false,          // isOverride
 | 
|---|
| 616 |             "",
 | 
|---|
| 617 |             true,           // isAutoGeneration
 | 
|---|
| 618 |             -1
 | 
|---|
| 619 |         );
 | 
|---|
| 620 |     }
 | 
|---|
| 621 | }
 | 
|---|
| 622 | 
 | 
|---|
| 623 | bool LexicalAnalyzer::Implements( CClass &_class, const char *interfaceNames, int nowLine )
 | 
|---|
| 624 | {
 | 
|---|
| 625 |     Jenga::Common::Strings paramStrs;
 | 
|---|
| 626 |     SplitParameter( interfaceNames, paramStrs );
 | 
|---|
| 627 |     
 | 
|---|
| 628 |     BOOST_FOREACH( const std::string ¶mStr, paramStrs )
 | 
|---|
| 629 |     {
 | 
|---|
| 630 |         char className[VN_SIZE];
 | 
|---|
| 631 |         Jenga::Common::Strings typeParameterStrings;
 | 
|---|
| 632 |         SplitGenericClassInstance( paramStr.c_str(), className, typeParameterStrings );
 | 
|---|
| 633 | 
 | 
|---|
| 634 |         Types actualTypeParameters;
 | 
|---|
| 635 |         BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
 | 
|---|
| 636 |         {
 | 
|---|
| 637 |             Type type;
 | 
|---|
| 638 |             compiler.StringToType( typeParameterStr, type );
 | 
|---|
| 639 |             actualTypeParameters.push_back( type );
 | 
|---|
| 640 |         }
 | 
|---|
| 641 | 
 | 
|---|
| 642 |         //継承元クラスを取得
 | 
|---|
| 643 |         const CClass *pInterfaceClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
 | 
|---|
| 644 |             LexicalAnalyzer::FullNameToSymbol( className )
 | 
|---|
| 645 |         );
 | 
|---|
| 646 |         if( !pInterfaceClass ){
 | 
|---|
| 647 |             compiler.errorMessenger.Output(106,paramStr.c_str(),nowLine);
 | 
|---|
| 648 |             continue;
 | 
|---|
| 649 |         }
 | 
|---|
| 650 | 
 | 
|---|
| 651 |         if( !pInterfaceClass->IsReady() ){
 | 
|---|
| 652 |             // インターフェイスが未解析のとき
 | 
|---|
| 653 |             LexicalAnalyzer::LookaheadClass(
 | 
|---|
| 654 |                 pInterfaceClass->GetName().c_str(),
 | 
|---|
| 655 |                 compiler.GetObjectModule().meta.GetClasses()
 | 
|---|
| 656 |             );
 | 
|---|
| 657 |         }
 | 
|---|
| 658 | 
 | 
|---|
| 659 |         if( pInterfaceClass->IsInterface() || pInterfaceClass->IsComInterface() )
 | 
|---|
| 660 |         {
 | 
|---|
| 661 |             // インターフェイスを継承する
 | 
|---|
| 662 |             std::vector<DynamicMethod::OverrideResult> overrideResults;
 | 
|---|
| 663 |             Implements(
 | 
|---|
| 664 |                 _class,
 | 
|---|
| 665 |                 new ::Interface( pInterfaceClass, actualTypeParameters ),
 | 
|---|
| 666 |                 overrideResults
 | 
|---|
| 667 |             );
 | 
|---|
| 668 | 
 | 
|---|
| 669 |             // エラーチェック
 | 
|---|
| 670 |             BOOST_FOREACH( const DynamicMethod::OverrideResult result, overrideResults )
 | 
|---|
| 671 |             {
 | 
|---|
| 672 |                 OverrideErrorCheck( result );
 | 
|---|
| 673 |             }
 | 
|---|
| 674 |         }
 | 
|---|
| 675 |         else
 | 
|---|
| 676 |         {
 | 
|---|
| 677 |             // インターフェイスではないとき
 | 
|---|
| 678 |             compiler.errorMessenger.Output(138,pInterfaceClass->GetName().c_str(),nowLine );
 | 
|---|
| 679 |         }
 | 
|---|
| 680 |     }
 | 
|---|
| 681 | 
 | 
|---|
| 682 |     return true;
 | 
|---|
| 683 | }
 | 
|---|
| 684 | 
 | 
|---|
| 685 | void GetClass_recur( const char *lpszInheritsClass, Classes &classes )
 | 
|---|
| 686 | {
 | 
|---|
| 687 |     extern char *basbuf;
 | 
|---|
| 688 |     int i,i2,i3,sub_address,top_pos;
 | 
|---|
| 689 |     char temporary[8192];
 | 
|---|
| 690 | 
 | 
|---|
| 691 |     // 名前空間管理
 | 
|---|
| 692 |     NamespaceScopes backupNamespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
 | 
|---|
| 693 |     NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
 | 
|---|
| 694 |     namespaceScopes.clear();
 | 
|---|
| 695 | 
 | 
|---|
| 696 |     // Importsされた名前空間の管理
 | 
|---|
| 697 |     NamespaceScopesCollection backupImportedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
 | 
|---|
| 698 |     compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
 | 
|---|
| 699 | 
 | 
|---|
| 700 |     // 呼び出し元でコンパイル中のクラスポインタをバックアップ
 | 
|---|
| 701 |     const CClass *pBackCompilingClass = compiler.IsCompilingClass()
 | 
|---|
| 702 |         ? &compiler.GetCompilingClass()
 | 
|---|
| 703 |         : NULL;
 | 
|---|
| 704 | 
 | 
|---|
| 705 |     for(i=0;;i++){
 | 
|---|
| 706 |         if(basbuf[i]=='\0') break;
 | 
|---|
| 707 | 
 | 
|---|
| 708 | 
 | 
|---|
| 709 |         // 名前空間
 | 
|---|
| 710 |         if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
 | 
|---|
| 711 |             for(i+=2,i2=0;;i2++,i++){
 | 
|---|
| 712 |                 if( IsCommandDelimitation( basbuf[i] ) ){
 | 
|---|
| 713 |                     temporary[i2]=0;
 | 
|---|
| 714 |                     break;
 | 
|---|
| 715 |                 }
 | 
|---|
| 716 |                 temporary[i2]=basbuf[i];
 | 
|---|
| 717 |             }
 | 
|---|
| 718 |             namespaceScopes.push_back( temporary );
 | 
|---|
| 719 | 
 | 
|---|
| 720 |             continue;
 | 
|---|
| 721 |         }
 | 
|---|
| 722 |         else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
 | 
|---|
| 723 |             if( namespaceScopes.size() <= 0 ){
 | 
|---|
| 724 |                 compiler.errorMessenger.Output(12, "End Namespace", i );
 | 
|---|
| 725 |             }
 | 
|---|
| 726 |             else{
 | 
|---|
| 727 |                 namespaceScopes.pop_back();
 | 
|---|
| 728 |             }
 | 
|---|
| 729 | 
 | 
|---|
| 730 |             i += 2;
 | 
|---|
| 731 |             continue;
 | 
|---|
| 732 |         }
 | 
|---|
| 733 | 
 | 
|---|
| 734 |         else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
 | 
|---|
| 735 |             for(i+=2,i2=0;;i2++,i++){
 | 
|---|
| 736 |                 if( IsCommandDelimitation( basbuf[i] ) ){
 | 
|---|
| 737 |                     temporary[i2]=0;
 | 
|---|
| 738 |                     break;
 | 
|---|
| 739 |                 }
 | 
|---|
| 740 |                 temporary[i2]=basbuf[i];
 | 
|---|
| 741 |             }
 | 
|---|
| 742 |             if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
 | 
|---|
| 743 |             {
 | 
|---|
| 744 |                 compiler.errorMessenger.Output(64,temporary,i );
 | 
|---|
| 745 |             }
 | 
|---|
| 746 | 
 | 
|---|
| 747 |             continue;
 | 
|---|
| 748 |         }
 | 
|---|
| 749 |         else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
 | 
|---|
| 750 |             compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
 | 
|---|
| 751 |             continue;
 | 
|---|
| 752 |         }
 | 
|---|
| 753 | 
 | 
|---|
| 754 | 
 | 
|---|
| 755 | 
 | 
|---|
| 756 |         if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
 | 
|---|
| 757 |             //////////////////////////
 | 
|---|
| 758 |             // インターフェイス
 | 
|---|
| 759 |             //////////////////////////
 | 
|---|
| 760 | 
 | 
|---|
| 761 |             top_pos=i;
 | 
|---|
| 762 | 
 | 
|---|
| 763 |             i+=2;
 | 
|---|
| 764 | 
 | 
|---|
| 765 |             //インターフェイス名を取得
 | 
|---|
| 766 |             GetCommandToken( temporary, basbuf, i );
 | 
|---|
| 767 | 
 | 
|---|
| 768 |             char className[VN_SIZE];
 | 
|---|
| 769 |             Jenga::Common::Strings typeParameters;
 | 
|---|
| 770 |             Jenga::Common::Strings typeParameterBaseClassNames;
 | 
|---|
| 771 |             SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
 | 
|---|
| 772 | 
 | 
|---|
| 773 |             CClass *pobj_c = const_cast<CClass *>( classes.FindEx( Symbol( namespaceScopes, className ) ) );
 | 
|---|
| 774 |             if(!pobj_c) continue;
 | 
|---|
| 775 | 
 | 
|---|
| 776 |             compiler.SetCompilingClass( pobj_c );
 | 
|---|
| 777 | 
 | 
|---|
| 778 |             if(lpszInheritsClass){
 | 
|---|
| 779 |                 if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
 | 
|---|
| 780 |                     //継承先先読み用
 | 
|---|
| 781 |                     continue;
 | 
|---|
| 782 |                 }
 | 
|---|
| 783 |             }
 | 
|---|
| 784 | 
 | 
|---|
| 785 |             if(pobj_c->IsReady()){
 | 
|---|
| 786 |                 //既に先読みされているとき
 | 
|---|
| 787 |                 continue;
 | 
|---|
| 788 |             }
 | 
|---|
| 789 | 
 | 
|---|
| 790 |             /////////////////////////////////////////////////////////
 | 
|---|
| 791 |             // ☆★☆ ジェネリクスサポート ☆★☆
 | 
|---|
| 792 |             for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
 | 
|---|
| 793 |             {
 | 
|---|
| 794 |                 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
 | 
|---|
| 795 |                 if( typeParameterBaseClassNames[i2].size() )
 | 
|---|
| 796 |                 {
 | 
|---|
| 797 |                     if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
 | 
|---|
| 798 |                     {
 | 
|---|
| 799 |                         compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
 | 
|---|
| 800 |                     }
 | 
|---|
| 801 |                     else if( !baseType.IsObject() )
 | 
|---|
| 802 |                     {
 | 
|---|
| 803 |                         compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
 | 
|---|
| 804 |                     }
 | 
|---|
| 805 |                 }
 | 
|---|
| 806 | 
 | 
|---|
| 807 |                 pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
 | 
|---|
| 808 |             }
 | 
|---|
| 809 |             /////////////////////////////////////////////////////////
 | 
|---|
| 810 | 
 | 
|---|
| 811 |             pobj_c->Readed();
 | 
|---|
| 812 | 
 | 
|---|
| 813 |             pobj_c->SetConstructorMemberSubIndex( -1 );
 | 
|---|
| 814 |             pobj_c->SetDestructorMemberSubIndex( -1 );
 | 
|---|
| 815 | 
 | 
|---|
| 816 |             if( memcmp( basbuf+i+1, "__COM", 5 ) == 0 && IsCommandDelimitation( basbuf[i+1+5] ) )
 | 
|---|
| 817 |             {
 | 
|---|
| 818 |                 // COMインターフェイス
 | 
|---|
| 819 |                 pobj_c->SetClassType( CClass::ComInterface );
 | 
|---|
| 820 | 
 | 
|---|
| 821 |                 i += 6;
 | 
|---|
| 822 |             }
 | 
|---|
| 823 | 
 | 
|---|
| 824 |             if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
 | 
|---|
| 825 |                 //継承を行う場合
 | 
|---|
| 826 |                 for(i+=3,i2=0;;i++,i2++){
 | 
|---|
| 827 |                     if(IsCommandDelimitation(basbuf[i])){
 | 
|---|
| 828 |                         temporary[i2]=0;
 | 
|---|
| 829 |                         break;
 | 
|---|
| 830 |                     }
 | 
|---|
| 831 |                     temporary[i2]=basbuf[i];
 | 
|---|
| 832 |                 }
 | 
|---|
| 833 | 
 | 
|---|
| 834 |                 if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
 | 
|---|
| 835 |                     compiler.errorMessenger.Output(105,temporary,i);
 | 
|---|
| 836 |                     goto Interface_InheritsError;
 | 
|---|
| 837 |                 }
 | 
|---|
| 838 | 
 | 
|---|
| 839 |                 //継承元クラスを取得
 | 
|---|
| 840 |                 const CClass *pInheritsClass = compiler.GetObjectModule().meta.FindClassSupportedTypeDef(
 | 
|---|
| 841 |                     LexicalAnalyzer::FullNameToSymbol( temporary )
 | 
|---|
| 842 |                 );
 | 
|---|
| 843 |                 if( !pInheritsClass ){
 | 
|---|
| 844 |                     compiler.errorMessenger.Output(106,temporary,i);
 | 
|---|
| 845 |                     goto Interface_InheritsError;
 | 
|---|
| 846 |                 }
 | 
|---|
| 847 | 
 | 
|---|
| 848 |                 //ループ継承でないかをチェック
 | 
|---|
| 849 |                 if( !LexicalAnalyzer::LoopRefCheck( *pInheritsClass ) )
 | 
|---|
| 850 |                 {
 | 
|---|
| 851 |                     compiler.errorMessenger.Output(123,pInheritsClass->GetName(),i);
 | 
|---|
| 852 |                     goto Interface_InheritsError;
 | 
|---|
| 853 |                 }
 | 
|---|
| 854 | 
 | 
|---|
| 855 |                 //継承させる
 | 
|---|
| 856 |                 if( !pobj_c->InheritsClass( *pInheritsClass, Types(), i ) ){
 | 
|---|
| 857 |                     goto Interface_InheritsError;
 | 
|---|
| 858 |                 }
 | 
|---|
| 859 |             }
 | 
|---|
| 860 |             else{
 | 
|---|
| 861 |                 //継承無し
 | 
|---|
| 862 |                 if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
 | 
|---|
| 863 |                 {
 | 
|---|
| 864 |                     // TODO: ここに来ないことが実証できたらこの分岐は消す
 | 
|---|
| 865 |                     Jenga::Throw( "GetClass_recur内の例外" );
 | 
|---|
| 866 |                 }
 | 
|---|
| 867 |             }
 | 
|---|
| 868 | Interface_InheritsError:
 | 
|---|
| 869 | 
 | 
|---|
| 870 |             //メンバ変数、関数を取得
 | 
|---|
| 871 |             while(1){
 | 
|---|
| 872 |                 i++;
 | 
|---|
| 873 | 
 | 
|---|
| 874 |                 //エラー
 | 
|---|
| 875 |                 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
 | 
|---|
| 876 |                     compiler.errorMessenger.Output(22,"Interface",i);
 | 
|---|
| 877 |                     i--;
 | 
|---|
| 878 |                     break;
 | 
|---|
| 879 |                 }
 | 
|---|
| 880 | 
 | 
|---|
| 881 |                 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
 | 
|---|
| 882 |                     compiler.errorMessenger.Output(111,NULL,i);
 | 
|---|
| 883 |                     break;
 | 
|---|
| 884 |                 }
 | 
|---|
| 885 |                 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
 | 
|---|
| 886 |                 {
 | 
|---|
| 887 |                     compiler.errorMessenger.Output(137, NULL, i );
 | 
|---|
| 888 |                     break;
 | 
|---|
| 889 |                 }
 | 
|---|
| 890 | 
 | 
|---|
| 891 |                 sub_address=i;
 | 
|---|
| 892 | 
 | 
|---|
| 893 |                 for(i2=0;;i++,i2++){
 | 
|---|
| 894 |                     if(IsCommandDelimitation(basbuf[i])){
 | 
|---|
| 895 |                         temporary[i2]=0;
 | 
|---|
| 896 |                         break;
 | 
|---|
| 897 |                     }
 | 
|---|
| 898 |                     temporary[i2]=basbuf[i];
 | 
|---|
| 899 |                 }
 | 
|---|
| 900 |                 if(temporary[0]=='\0'){
 | 
|---|
| 901 |                     if(basbuf[i]=='\0'){
 | 
|---|
| 902 |                         i--;
 | 
|---|
| 903 |                         compiler.errorMessenger.Output(22,"Interface",top_pos);
 | 
|---|
| 904 |                         break;
 | 
|---|
| 905 |                     }
 | 
|---|
| 906 |                     continue;
 | 
|---|
| 907 |                 }
 | 
|---|
| 908 | 
 | 
|---|
| 909 |                 //End Interface記述の場合
 | 
|---|
| 910 |                 if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
 | 
|---|
| 911 | 
 | 
|---|
| 912 |                 if(!(temporary[0]==1&&(
 | 
|---|
| 913 |                     temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
 | 
|---|
| 914 |                     ))){
 | 
|---|
| 915 |                     compiler.errorMessenger.Output(1,NULL,i);
 | 
|---|
| 916 |                     break;
 | 
|---|
| 917 |                 }
 | 
|---|
| 918 | 
 | 
|---|
| 919 |                 //関数ハッシュへ登録
 | 
|---|
| 920 |                 char interfaceName[VN_SIZE] = "";
 | 
|---|
| 921 |                 UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,true,pobj_c, false, interfaceName );
 | 
|---|
| 922 |                 if( pUserProc )
 | 
|---|
| 923 |                 {
 | 
|---|
| 924 |                     // 関数を追加
 | 
|---|
| 925 |                     if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
 | 
|---|
| 926 |                     {
 | 
|---|
| 927 |                         // 既に存在している
 | 
|---|
| 928 |                         compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
 | 
|---|
| 929 | 
 | 
|---|
| 930 |                         delete pUserProc;
 | 
|---|
| 931 |                     }
 | 
|---|
| 932 |                     else
 | 
|---|
| 933 |                     {
 | 
|---|
| 934 |                         compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
 | 
|---|
| 935 |                     }
 | 
|---|
| 936 | 
 | 
|---|
| 937 |                     //メンバ関数を追加
 | 
|---|
| 938 |                     LexicalAnalyzer::AddMethod(pobj_c,
 | 
|---|
| 939 |                         pUserProc,
 | 
|---|
| 940 |                         Prototype::Public,  //Publicアクセス権
 | 
|---|
| 941 |                         0,                  // bStatic
 | 
|---|
| 942 |                         false,              // isConst
 | 
|---|
| 943 |                         true,               // isAbstract
 | 
|---|
| 944 |                         true,               // isVirtual
 | 
|---|
| 945 |                         false,              // isOverride
 | 
|---|
| 946 |                         interfaceName,
 | 
|---|
| 947 |                         false,              // isAutoGeneration
 | 
|---|
| 948 |                         sub_address
 | 
|---|
| 949 |                         );
 | 
|---|
| 950 |                 }
 | 
|---|
| 951 |             }
 | 
|---|
| 952 |         }
 | 
|---|
| 953 | 
 | 
|---|
| 954 |         if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
 | 
|---|
| 955 |             //////////////////////////
 | 
|---|
| 956 |             // クラス
 | 
|---|
| 957 |             //////////////////////////
 | 
|---|
| 958 | 
 | 
|---|
| 959 |             top_pos=i;
 | 
|---|
| 960 | 
 | 
|---|
| 961 |             const DWORD dwClassType=basbuf[i+1];
 | 
|---|
| 962 | 
 | 
|---|
| 963 |             i+=2;
 | 
|---|
| 964 | 
 | 
|---|
| 965 |             int iAlign=0;
 | 
|---|
| 966 |             if(memicmp(basbuf+i,"Align(",6)==0){
 | 
|---|
| 967 |                 //アラインメント修飾子
 | 
|---|
| 968 |                 i+=6;
 | 
|---|
| 969 |                 i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
 | 
|---|
| 970 |                 iAlign=atoi(temporary);
 | 
|---|
| 971 | 
 | 
|---|
| 972 |                 if( dwClassType != ESC_TYPE )
 | 
|---|
| 973 |                 {
 | 
|---|
| 974 |                     compiler.errorMessenger.Output(140,NULL,i);
 | 
|---|
| 975 |                 }
 | 
|---|
| 976 | 
 | 
|---|
| 977 |                 if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
 | 
|---|
| 978 |                     compiler.errorMessenger.Output(51,NULL,i);
 | 
|---|
| 979 |             }
 | 
|---|
| 980 |             else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
 | 
|---|
| 981 |                 // Blittable修飾子
 | 
|---|
| 982 |                 i+=10;
 | 
|---|
| 983 |                 i=JumpStringInPare(basbuf,i)+1;
 | 
|---|
| 984 | 
 | 
|---|
| 985 |                 if( dwClassType != ESC_CLASS )
 | 
|---|
| 986 |                 {
 | 
|---|
| 987 |                     compiler.errorMessenger.Output(141,NULL,i);
 | 
|---|
| 988 |                 }
 | 
|---|
| 989 |             }
 | 
|---|
| 990 | 
 | 
|---|
| 991 |             if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM )
 | 
|---|
| 992 |             {
 | 
|---|
| 993 |                 // 列挙型の場合
 | 
|---|
| 994 |                 i += 2;
 | 
|---|
| 995 |             }
 | 
|---|
| 996 |             else if( basbuf[i] == 1 && basbuf[i+1] == ESC_DELEGATE )
 | 
|---|
| 997 |             {
 | 
|---|
| 998 |                 // デリゲートの場合
 | 
|---|
| 999 |                 i += 2;
 | 
|---|
| 1000 |             }
 | 
|---|
| 1001 | 
 | 
|---|
| 1002 |             //クラス名を取得
 | 
|---|
| 1003 |             GetCommandToken( temporary, basbuf, i );
 | 
|---|
| 1004 | 
 | 
|---|
| 1005 |             char className[VN_SIZE];
 | 
|---|
| 1006 |             Jenga::Common::Strings typeParameters;
 | 
|---|
| 1007 |             Jenga::Common::Strings typeParameterBaseClassNames;
 | 
|---|
| 1008 |             SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
 | 
|---|
| 1009 | 
 | 
|---|
| 1010 |             CClass *pobj_c =  const_cast<CClass *>( classes.FindEx( Symbol( namespaceScopes, className ) ) );
 | 
|---|
| 1011 |             if(!pobj_c) continue;
 | 
|---|
| 1012 | 
 | 
|---|
| 1013 |             compiler.SetCompilingClass( pobj_c );
 | 
|---|
| 1014 | 
 | 
|---|
| 1015 |             if(lpszInheritsClass){
 | 
|---|
| 1016 |                 if( pobj_c->GetName() != lpszInheritsClass ){
 | 
|---|
| 1017 |                     //継承先先読み用
 | 
|---|
| 1018 |                     continue;
 | 
|---|
| 1019 |                 }
 | 
|---|
| 1020 |             }
 | 
|---|
| 1021 | 
 | 
|---|
| 1022 |             if( lstrcmp(className,"Control")==0)
 | 
|---|
| 1023 |             {
 | 
|---|
| 1024 |                 int test=0;
 | 
|---|
| 1025 |             }
 | 
|---|
| 1026 | 
 | 
|---|
| 1027 |             if(pobj_c->IsReady()){
 | 
|---|
| 1028 |                 //既に先読みされているとき
 | 
|---|
| 1029 |                 continue;
 | 
|---|
| 1030 |             }
 | 
|---|
| 1031 | 
 | 
|---|
| 1032 | 
 | 
|---|
| 1033 |             /////////////////////////////////////////////////////////
 | 
|---|
| 1034 |             // ☆★☆ ジェネリクスサポート ☆★☆
 | 
|---|
| 1035 |             for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
 | 
|---|
| 1036 |             {
 | 
|---|
| 1037 |                 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
 | 
|---|
| 1038 |                 if( typeParameterBaseClassNames[i2].size() )
 | 
|---|
| 1039 |                 {
 | 
|---|
| 1040 |                     if( !compiler.StringToType( typeParameterBaseClassNames[i2], baseType ) )
 | 
|---|
| 1041 |                     {
 | 
|---|
| 1042 |                         compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
 | 
|---|
| 1043 |                     }
 | 
|---|
| 1044 |                     else if( !baseType.IsObject() )
 | 
|---|
| 1045 |                     {
 | 
|---|
| 1046 |                         compiler.errorMessenger.Output(106,typeParameterBaseClassNames[i2],i);
 | 
|---|
| 1047 |                     }
 | 
|---|
| 1048 |                 }
 | 
|---|
| 1049 | 
 | 
|---|
| 1050 |                 pobj_c->AddFormalGenericType( GenericType( typeParameters[i2], baseType ) );
 | 
|---|
| 1051 |             }
 | 
|---|
| 1052 |             /////////////////////////////////////////////////////////
 | 
|---|
| 1053 | 
 | 
|---|
| 1054 | 
 | 
|---|
| 1055 |             pobj_c->SetFixedAlignment( iAlign );
 | 
|---|
| 1056 | 
 | 
|---|
| 1057 |             pobj_c->Readed();
 | 
|---|
| 1058 | 
 | 
|---|
| 1059 |             pobj_c->SetConstructorMemberSubIndex( -1 );
 | 
|---|
| 1060 |             pobj_c->SetDestructorMemberSubIndex( -1 );
 | 
|---|
| 1061 | 
 | 
|---|
| 1062 |             //アクセス制限の初期値をセット
 | 
|---|
| 1063 |             Prototype::Accessibility accessibility;
 | 
|---|
| 1064 |             if(dwClassType==ESC_CLASS){
 | 
|---|
| 1065 |                 accessibility = Prototype::Private;
 | 
|---|
| 1066 |             }
 | 
|---|
| 1067 |             else{
 | 
|---|
| 1068 |                 accessibility = Prototype::Public;
 | 
|---|
| 1069 |             }
 | 
|---|
| 1070 | 
 | 
|---|
| 1071 |             if( pobj_c->GetName() == "Object"
 | 
|---|
| 1072 |                 || dwClassType == ESC_TYPE )
 | 
|---|
| 1073 |             {
 | 
|---|
| 1074 |                 // 何も継承しない
 | 
|---|
| 1075 | 
 | 
|---|
| 1076 |                 if( &pobj_c->GetSuperClass() || pobj_c->GetVtblNum() )
 | 
|---|
| 1077 |                 {
 | 
|---|
| 1078 |                     // TODO: ここに来ないことが実証できたらこの分岐は消す
 | 
|---|
| 1079 |                     Jenga::Throw( "GetClass_recur内の例外" );
 | 
|---|
| 1080 |                 }
 | 
|---|
| 1081 |             }
 | 
|---|
| 1082 |             else{
 | 
|---|
| 1083 |                 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS)
 | 
|---|
| 1084 |                 {
 | 
|---|
| 1085 |                     // クラス継承先が指定されているとき
 | 
|---|
| 1086 |                     i += 3;
 | 
|---|
| 1087 |                     GetCommandToken( temporary, basbuf, i );
 | 
|---|
| 1088 | 
 | 
|---|
| 1089 |                     if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
 | 
|---|
| 1090 |                         compiler.errorMessenger.Output(105,temporary,i);
 | 
|---|
| 1091 |                         goto InheritsError;
 | 
|---|
| 1092 |                     }
 | 
|---|
| 1093 |                 }
 | 
|---|
| 1094 |                 else
 | 
|---|
| 1095 |                 {
 | 
|---|
| 1096 |                     // 何の指定もないときはObjectクラスを継承する
 | 
|---|
| 1097 |                     lstrcpy( temporary, "Object" );
 | 
|---|
| 1098 |                 }
 | 
|---|
| 1099 |                 LexicalAnalyzer::Inherits( *pobj_c, temporary, i );
 | 
|---|
| 1100 | 
 | 
|---|
| 1101 |                 if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
 | 
|---|
| 1102 |                 {
 | 
|---|
| 1103 |                     // インターフェイス実装を行う場合
 | 
|---|
| 1104 |                     i += 3;
 | 
|---|
| 1105 |                     GetCommandToken( temporary, basbuf, i );
 | 
|---|
| 1106 | 
 | 
|---|
| 1107 |                     LexicalAnalyzer::Implements( *pobj_c, temporary, i );
 | 
|---|
| 1108 |                 }
 | 
|---|
| 1109 |             }
 | 
|---|
| 1110 | InheritsError:
 | 
|---|
| 1111 | 
 | 
|---|
| 1112 |             //メンバとメソッドを取得
 | 
|---|
| 1113 |             while(1){
 | 
|---|
| 1114 |                 i++;
 | 
|---|
| 1115 | 
 | 
|---|
| 1116 |                 //エラー
 | 
|---|
| 1117 |                 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
 | 
|---|
| 1118 |                     compiler.errorMessenger.Output(22,"Class",i);
 | 
|---|
| 1119 |                     i--;
 | 
|---|
| 1120 |                     break;
 | 
|---|
| 1121 |                 }
 | 
|---|
| 1122 | 
 | 
|---|
| 1123 |                 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
 | 
|---|
| 1124 |                     compiler.errorMessenger.Output(111,NULL,i);
 | 
|---|
| 1125 |                     break;
 | 
|---|
| 1126 |                 }
 | 
|---|
| 1127 |                 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPLEMENTS )
 | 
|---|
| 1128 |                 {
 | 
|---|
| 1129 |                     compiler.errorMessenger.Output(137, NULL, i );
 | 
|---|
| 1130 |                     break;
 | 
|---|
| 1131 |                 }
 | 
|---|
| 1132 | 
 | 
|---|
| 1133 |                 //Static修飾子
 | 
|---|
| 1134 |                 BOOL bStatic;
 | 
|---|
| 1135 |                 if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
 | 
|---|
| 1136 |                     bStatic=1;
 | 
|---|
| 1137 |                     i+=2;
 | 
|---|
| 1138 |                 }
 | 
|---|
| 1139 |                 else bStatic=0;
 | 
|---|
| 1140 | 
 | 
|---|
| 1141 |                 //Const修飾子
 | 
|---|
| 1142 |                 bool isConst = false;
 | 
|---|
| 1143 |                 if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
 | 
|---|
| 1144 |                     isConst = true;
 | 
|---|
| 1145 |                     i += 2;
 | 
|---|
| 1146 |                 }
 | 
|---|
| 1147 | 
 | 
|---|
| 1148 |                 if(basbuf[i]==1&&(
 | 
|---|
| 1149 |                     basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
 | 
|---|
| 1150 |                     basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
 | 
|---|
| 1151 |                     )){
 | 
|---|
| 1152 |                     i3=basbuf[i+1];
 | 
|---|
| 1153 |                     sub_address=i;
 | 
|---|
| 1154 |                 }
 | 
|---|
| 1155 |                 else i3=0;
 | 
|---|
| 1156 | 
 | 
|---|
| 1157 |                 bool isVirtual = false, isAbstract = false, isOverride = false;
 | 
|---|
| 1158 |                 if(i3==ESC_ABSTRACT){
 | 
|---|
| 1159 |                     isAbstract=1;
 | 
|---|
| 1160 |                     isVirtual=1;
 | 
|---|
| 1161 |                     i+=2;
 | 
|---|
| 1162 | 
 | 
|---|
| 1163 |                     i3=basbuf[i+1];
 | 
|---|
| 1164 |                 }
 | 
|---|
| 1165 |                 else if(i3==ESC_VIRTUAL){
 | 
|---|
| 1166 |                     isAbstract=0;
 | 
|---|
| 1167 |                     isVirtual=1;
 | 
|---|
| 1168 |                     i+=2;
 | 
|---|
| 1169 | 
 | 
|---|
| 1170 |                     i3=basbuf[i+1];
 | 
|---|
| 1171 |                 }
 | 
|---|
| 1172 |                 else if(i3==ESC_OVERRIDE){
 | 
|---|
| 1173 |                     isOverride=1;
 | 
|---|
| 1174 |                     isVirtual=1;
 | 
|---|
| 1175 | 
 | 
|---|
| 1176 |                     i+=2;
 | 
|---|
| 1177 | 
 | 
|---|
| 1178 |                     i3=basbuf[i+1];
 | 
|---|
| 1179 |                 }
 | 
|---|
| 1180 | 
 | 
|---|
| 1181 |                 for(i2=0;;i++,i2++){
 | 
|---|
| 1182 |                     if(IsCommandDelimitation(basbuf[i])){
 | 
|---|
| 1183 |                         temporary[i2]=0;
 | 
|---|
| 1184 |                         break;
 | 
|---|
| 1185 |                     }
 | 
|---|
| 1186 |                     temporary[i2]=basbuf[i];
 | 
|---|
| 1187 |                 }
 | 
|---|
| 1188 |                 if(temporary[0]=='\0'){
 | 
|---|
| 1189 |                     if(basbuf[i]=='\0'){
 | 
|---|
| 1190 | 
 | 
|---|
| 1191 |                         if(dwClassType==ESC_CLASS)
 | 
|---|
| 1192 |                             compiler.errorMessenger.Output(22,"Class",top_pos);
 | 
|---|
| 1193 |                         else
 | 
|---|
| 1194 |                             compiler.errorMessenger.Output(22,"Type",top_pos);
 | 
|---|
| 1195 | 
 | 
|---|
| 1196 |                         i--;
 | 
|---|
| 1197 |                         break;
 | 
|---|
| 1198 |                     }
 | 
|---|
| 1199 |                     continue;
 | 
|---|
| 1200 |                 }
 | 
|---|
| 1201 | 
 | 
|---|
| 1202 |                 //End Class記述の場合
 | 
|---|
| 1203 |                 if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
 | 
|---|
| 1204 |                 if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
 | 
|---|
| 1205 | 
 | 
|---|
| 1206 |                 //アクセスを変更
 | 
|---|
| 1207 |                 if(lstrcmpi(temporary,"Private")==0){
 | 
|---|
| 1208 |                     accessibility = Prototype::Private;
 | 
|---|
| 1209 |                     continue;
 | 
|---|
| 1210 |                 }
 | 
|---|
| 1211 |                 if(lstrcmpi(temporary,"Public")==0){
 | 
|---|
| 1212 |                     accessibility = Prototype::Public;
 | 
|---|
| 1213 |                     continue;
 | 
|---|
| 1214 |                 }
 | 
|---|
| 1215 |                 if(lstrcmpi(temporary,"Protected")==0){
 | 
|---|
| 1216 |                     accessibility = Prototype::Protected;
 | 
|---|
| 1217 |                     continue;
 | 
|---|
| 1218 |                 }
 | 
|---|
| 1219 | 
 | 
|---|
| 1220 |                 extern int cp;
 | 
|---|
| 1221 |                 if(i3==0){
 | 
|---|
| 1222 |                     cp=i;   //エラー用
 | 
|---|
| 1223 |                     Member *pMember = LexicalAnalyzer::CreateMember( *pobj_c, accessibility, isConst, false, temporary, i );
 | 
|---|
| 1224 |                     if( pMember )
 | 
|---|
| 1225 |                     {
 | 
|---|
| 1226 |                         if(bStatic)
 | 
|---|
| 1227 |                         {
 | 
|---|
| 1228 |                             //静的メンバを追加
 | 
|---|
| 1229 |                             pobj_c->AddStaticMember( pMember );
 | 
|---|
| 1230 |                         }
 | 
|---|
| 1231 |                         else
 | 
|---|
| 1232 |                         {
 | 
|---|
| 1233 |                             //メンバを追加
 | 
|---|
| 1234 |                             pobj_c->AddDynamicMember( pMember );
 | 
|---|
| 1235 | 
 | 
|---|
| 1236 | 
 | 
|---|
| 1237 |                             if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
 | 
|---|
| 1238 |                                 if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
 | 
|---|
| 1239 |                                     //参照先が読み取られていないとき
 | 
|---|
| 1240 |                                     GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes );
 | 
|---|
| 1241 |                                 }
 | 
|---|
| 1242 |                             }
 | 
|---|
| 1243 | 
 | 
|---|
| 1244 | 
 | 
|---|
| 1245 |                             if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
 | 
|---|
| 1246 |                                 //循環参照のチェック
 | 
|---|
| 1247 |                                 pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
 | 
|---|
| 1248 |                                 if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
 | 
|---|
| 1249 |                                     //エラー回避
 | 
|---|
| 1250 |                                     Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
 | 
|---|
| 1251 |                                     type.SetBasicType( DEF_PTR_VOID );
 | 
|---|
| 1252 |                                 }
 | 
|---|
| 1253 |                                 pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
 | 
|---|
| 1254 |                             }
 | 
|---|
| 1255 |                         }
 | 
|---|
| 1256 |                     }
 | 
|---|
| 1257 |                 }
 | 
|---|
| 1258 |                 else{
 | 
|---|
| 1259 |                     //関数ハッシュへ登録
 | 
|---|
| 1260 |                     char interfaceName[VN_SIZE] = "";
 | 
|---|
| 1261 |                     UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,isVirtual,pobj_c, (bStatic!=0), interfaceName );
 | 
|---|
| 1262 |                     if( pUserProc )
 | 
|---|
| 1263 |                     {
 | 
|---|
| 1264 |                         // 関数を追加
 | 
|---|
| 1265 |                         if( compiler.GetObjectModule().meta.GetUserProcs().IsExist( pUserProc ) )
 | 
|---|
| 1266 |                         {
 | 
|---|
| 1267 |                             // 既に存在している
 | 
|---|
| 1268 |                             compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
 | 
|---|
| 1269 | 
 | 
|---|
| 1270 |                             delete pUserProc;
 | 
|---|
| 1271 |                         }
 | 
|---|
| 1272 |                         else
 | 
|---|
| 1273 |                         {
 | 
|---|
| 1274 |                             compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
 | 
|---|
| 1275 |                         }
 | 
|---|
| 1276 | 
 | 
|---|
| 1277 |                         //メソッドを追加
 | 
|---|
| 1278 |                         cp=i;   //エラー用
 | 
|---|
| 1279 |                         LexicalAnalyzer::AddMethod(pobj_c,
 | 
|---|
| 1280 |                             pUserProc,
 | 
|---|
| 1281 |                             accessibility,
 | 
|---|
| 1282 |                             bStatic,
 | 
|---|
| 1283 |                             isConst,
 | 
|---|
| 1284 |                             isAbstract,
 | 
|---|
| 1285 |                             isVirtual,
 | 
|---|
| 1286 |                             isOverride,
 | 
|---|
| 1287 |                             interfaceName,
 | 
|---|
| 1288 |                             false,
 | 
|---|
| 1289 |                             sub_address);
 | 
|---|
| 1290 |                     }
 | 
|---|
| 1291 | 
 | 
|---|
| 1292 |                     if( isAbstract ) continue;
 | 
|---|
| 1293 | 
 | 
|---|
| 1294 |                     for(;;i++){
 | 
|---|
| 1295 |                         if(basbuf[i]=='\0'){
 | 
|---|
| 1296 |                             i--;
 | 
|---|
| 1297 |                             break;
 | 
|---|
| 1298 |                         }
 | 
|---|
| 1299 |                         if(basbuf[i-1]!='*'&&
 | 
|---|
| 1300 |                             basbuf[i]==1&&(
 | 
|---|
| 1301 |                             basbuf[i+1]==ESC_SUB||
 | 
|---|
| 1302 |                             basbuf[i+1]==ESC_FUNCTION||
 | 
|---|
| 1303 |                             basbuf[i+1]==ESC_MACRO||
 | 
|---|
| 1304 |                             basbuf[i+1]==ESC_TYPE||
 | 
|---|
| 1305 |                             basbuf[i+1]==ESC_CLASS||
 | 
|---|
| 1306 |                             basbuf[i+1]==ESC_INTERFACE||
 | 
|---|
| 1307 |                             basbuf[i+1]==ESC_ENUM)){
 | 
|---|
| 1308 |                             GetDefaultNameFromES(i3,temporary);
 | 
|---|
| 1309 |                             compiler.errorMessenger.Output(22,temporary,i);
 | 
|---|
| 1310 |                         }
 | 
|---|
| 1311 |                         if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
 | 
|---|
| 1312 |                             i+=2;
 | 
|---|
| 1313 |                             break;
 | 
|---|
| 1314 |                         }
 | 
|---|
| 1315 |                     }
 | 
|---|
| 1316 |                 }
 | 
|---|
| 1317 |             }
 | 
|---|
| 1318 |         }
 | 
|---|
| 1319 |     }
 | 
|---|
| 1320 | 
 | 
|---|
| 1321 |     // 呼び出し元でコンパイル中のクラスポインタを元に戻す
 | 
|---|
| 1322 |     compiler.SetCompilingClass( pBackCompilingClass );
 | 
|---|
| 1323 | 
 | 
|---|
| 1324 |     // 名前空間を元に戻す
 | 
|---|
| 1325 |     compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = backupNamespaceScopes;
 | 
|---|
| 1326 | 
 | 
|---|
| 1327 |     // インポートされた名前空間を元に戻す
 | 
|---|
| 1328 |     compiler.GetNamespaceSupporter().GetImportedNamespaces() = backupImportedNamespaces;
 | 
|---|
| 1329 | }
 | 
|---|
| 1330 | 
 | 
|---|
| 1331 | void LexicalAnalyzer::LookaheadClass( const char *className, Classes &classes )
 | 
|---|
| 1332 | {
 | 
|---|
| 1333 |     pobj_LoopRefCheck->add( className );
 | 
|---|
| 1334 |     GetClass_recur( className, classes );
 | 
|---|
| 1335 |     pobj_LoopRefCheck->del( className );
 | 
|---|
| 1336 | }
 | 
|---|
| 1337 | 
 | 
|---|
| 1338 | bool LexicalAnalyzer::LoopRefCheck( const CClass &objClass )
 | 
|---|
| 1339 | {
 | 
|---|
| 1340 |     if( pobj_LoopRefCheck->check( objClass ) )
 | 
|---|
| 1341 |     {
 | 
|---|
| 1342 |         return false;
 | 
|---|
| 1343 |     }
 | 
|---|
| 1344 | 
 | 
|---|
| 1345 |     return true;
 | 
|---|
| 1346 | }
 | 
|---|
| 1347 | 
 | 
|---|
| 1348 | void LexicalAnalyzer::CollectClasses( const char *source, Classes &classes ){
 | 
|---|
| 1349 |     //ループ継承チェック用のクラス
 | 
|---|
| 1350 |     pobj_LoopRefCheck=new CLoopRefCheck();
 | 
|---|
| 1351 | 
 | 
|---|
| 1352 |     //クラスを取得
 | 
|---|
| 1353 |     GetClass_recur( 0, classes );
 | 
|---|
| 1354 | 
 | 
|---|
| 1355 |     delete pobj_LoopRefCheck;
 | 
|---|
| 1356 |     pobj_LoopRefCheck=0;
 | 
|---|
| 1357 | 
 | 
|---|
| 1358 |     // イテレータの準備
 | 
|---|
| 1359 |     classes.Iterator_Init();
 | 
|---|
| 1360 | }
 | 
|---|
| 1361 | 
 | 
|---|
| 1362 | void LexicalAnalyzer::TemplateExpand_ResolveMethod( const CMethod *pBaseMethod, const Types &actualTypes, CClass *pNewClass )
 | 
|---|
| 1363 | {
 | 
|---|
| 1364 |     UserProc *pUserProc = new UserProc(
 | 
|---|
| 1365 |         pBaseMethod->GetUserProc(),
 | 
|---|
| 1366 |         pNewClass
 | 
|---|
| 1367 |     );
 | 
|---|
| 1368 |     pUserProc->Using();
 | 
|---|
| 1369 |     pUserProc->GetParameters().clear();
 | 
|---|
| 1370 |     pUserProc->RealParams().clear();
 | 
|---|
| 1371 | 
 | 
|---|
| 1372 |     // パラメータのジェネリック型を解決
 | 
|---|
| 1373 |     BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().Params() )
 | 
|---|
| 1374 |     {
 | 
|---|
| 1375 |         Type type = pParam->IsTypeParameter()
 | 
|---|
| 1376 |             ? actualTypes[pParam->GetFormalTypeIndex()]
 | 
|---|
| 1377 |             : *pParam;
 | 
|---|
| 1378 |         type.SetPtrLevel( pParam->PtrLevel() );
 | 
|---|
| 1379 | 
 | 
|---|
| 1380 |         pUserProc->GetParameters().push_back( new Parameter( *pParam, type ) );
 | 
|---|
| 1381 |     }
 | 
|---|
| 1382 |     BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().RealParams() )
 | 
|---|
| 1383 |     {
 | 
|---|
| 1384 |         Type type = pParam->IsTypeParameter()
 | 
|---|
| 1385 |             ? actualTypes[pParam->GetFormalTypeIndex()]
 | 
|---|
| 1386 |             : *pParam;
 | 
|---|
| 1387 |         type.SetPtrLevel( pParam->PtrLevel() );
 | 
|---|
| 1388 | 
 | 
|---|
| 1389 |         pUserProc->RealParams().push_back( new Parameter( *pParam, type ) );
 | 
|---|
| 1390 |     }
 | 
|---|
| 1391 | 
 | 
|---|
| 1392 |     // 戻り値のジェネリック型を解決
 | 
|---|
| 1393 |     if( pUserProc->ReturnType().IsTypeParameter() )
 | 
|---|
| 1394 |     {
 | 
|---|
| 1395 |         Type type = actualTypes[pUserProc->ReturnType().GetFormalTypeIndex()];
 | 
|---|
| 1396 |         type.SetPtrLevel( pUserProc->ReturnType().PtrLevel() );
 | 
|---|
| 1397 |         pUserProc->SetReturnType( type );
 | 
|---|
| 1398 |     }
 | 
|---|
| 1399 | 
 | 
|---|
| 1400 |     compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
 | 
|---|
| 1401 |     compiler.GetObjectModule().meta.GetUserProcs().Iterator_Init();
 | 
|---|
| 1402 | 
 | 
|---|
| 1403 |     LexicalAnalyzer::AddMethod(
 | 
|---|
| 1404 |         pNewClass,
 | 
|---|
| 1405 |         pUserProc,
 | 
|---|
| 1406 |         pBaseMethod->GetAccessibility(),
 | 
|---|
| 1407 |         pBaseMethod->IsStatic(),
 | 
|---|
| 1408 |         pBaseMethod->IsConst(),
 | 
|---|
| 1409 |         pBaseMethod->IsAbstract(),
 | 
|---|
| 1410 |         pBaseMethod->IsVirtual(),
 | 
|---|
| 1411 |         false,
 | 
|---|
| 1412 |         "",
 | 
|---|
| 1413 |         false,
 | 
|---|
| 1414 |         -1
 | 
|---|
| 1415 |     );
 | 
|---|
| 1416 | }
 | 
|---|
| 1417 | 
 | 
|---|
| 1418 | const CClass *LexicalAnalyzer::TemplateExpand( CClass &_class, const Types &actualTypes )
 | 
|---|
| 1419 | {
 | 
|---|
| 1420 |     // 展開済みのクラスがあればそれを返す
 | 
|---|
| 1421 |     BOOST_FOREACH( const ExpandedTemplateClass *pExpandedTemplateClass, _class.expandedTemplateClasses )
 | 
|---|
| 1422 |     {
 | 
|---|
| 1423 |         if( pExpandedTemplateClass->GetActualTypes().IsEquals( actualTypes ) )
 | 
|---|
| 1424 |         {
 | 
|---|
| 1425 |             return &pExpandedTemplateClass->GetClass();
 | 
|---|
| 1426 |         }
 | 
|---|
| 1427 |     }
 | 
|---|
| 1428 | 
 | 
|---|
| 1429 | 
 | 
|---|
| 1430 |     /////////////////////////////////////////////////////////////////
 | 
|---|
| 1431 |     // 未展開の場合は新たに展開する
 | 
|---|
| 1432 |     /////////////////////////////////////////////////////////////////
 | 
|---|
| 1433 | 
 | 
|---|
| 1434 |     // クラスをコピー
 | 
|---|
| 1435 |     CClass *pNewClass = new CClass(
 | 
|---|
| 1436 |         _class.GetNamespaceScopes(),
 | 
|---|
| 1437 |         _class.GetImportedNamespaces(),
 | 
|---|
| 1438 |         _class.GetName(),
 | 
|---|
| 1439 |         _class.GetClassType(),
 | 
|---|
| 1440 |         _class.GetFormalGenericTypes(),
 | 
|---|
| 1441 |         actualTypes,
 | 
|---|
| 1442 |         _class.GetConstructorMemberSubIndex(),
 | 
|---|
| 1443 |         _class.GetDestructorMemberSubIndex(),
 | 
|---|
| 1444 |         0,
 | 
|---|
| 1445 |         _class.GetFixedAlignment()
 | 
|---|
| 1446 |     );
 | 
|---|
| 1447 | 
 | 
|---|
| 1448 |     // 基底クラス
 | 
|---|
| 1449 |     pNewClass->SetSuperClass( &_class.GetSuperClass() );
 | 
|---|
| 1450 | 
 | 
|---|
| 1451 |     // インターフェイスのジェネリック型を解決
 | 
|---|
| 1452 |     BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
 | 
|---|
| 1453 |     {
 | 
|---|
| 1454 |         pNewClass->AddInterface( new ::Interface( &pInterface->GetClass(), actualTypes ) );
 | 
|---|
| 1455 |     }
 | 
|---|
| 1456 | 
 | 
|---|
| 1457 |     // メンバのジェネリック型を解決
 | 
|---|
| 1458 |     BOOST_FOREACH( const Member *pMember, _class.GetDynamicMembers() )
 | 
|---|
| 1459 |     {
 | 
|---|
| 1460 |         Type type = pMember->GetType();
 | 
|---|
| 1461 |         if( type.IsTypeParameter() )
 | 
|---|
| 1462 |         {
 | 
|---|
| 1463 |             // ジェネリック型だったときは値型に変換
 | 
|---|
| 1464 |             type = actualTypes[type.GetFormalTypeIndex()];
 | 
|---|
| 1465 |             type.SetPtrLevel( pMember->GetType().PtrLevel() );
 | 
|---|
| 1466 |         }
 | 
|---|
| 1467 | 
 | 
|---|
| 1468 |         pNewClass->GetDynamicMembers().push_back(
 | 
|---|
| 1469 |             new Member( *pMember, type )
 | 
|---|
| 1470 |         );
 | 
|---|
| 1471 |     }
 | 
|---|
| 1472 | 
 | 
|---|
| 1473 |     // クラス メソッドのジェネリック型を解決
 | 
|---|
| 1474 |     BOOST_FOREACH( const CMethod *pMethod, _class.GetDynamicMethods() )
 | 
|---|
| 1475 |     {
 | 
|---|
| 1476 |         if( pMethod->GetUserProc().GetParentClassPtr() == &_class )
 | 
|---|
| 1477 |         {
 | 
|---|
| 1478 |             // ターゲットクラス内で実装されるメソッドの場合
 | 
|---|
| 1479 | 
 | 
|---|
| 1480 |             TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
 | 
|---|
| 1481 |         }
 | 
|---|
| 1482 |         else
 | 
|---|
| 1483 |         {
 | 
|---|
| 1484 |             DynamicMethod *pNewDynamicMethod = new DynamicMethod( *pMethod );
 | 
|---|
| 1485 |             pNewClass->GetDynamicMethods().push_back( pNewDynamicMethod );
 | 
|---|
| 1486 |         }
 | 
|---|
| 1487 |     }
 | 
|---|
| 1488 | 
 | 
|---|
| 1489 |     // インターフェイス メソッドのジェネリック型を解決
 | 
|---|
| 1490 |     BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
 | 
|---|
| 1491 |     {
 | 
|---|
| 1492 |         BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() )
 | 
|---|
| 1493 |         {
 | 
|---|
| 1494 |             TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
 | 
|---|
| 1495 |         }
 | 
|---|
| 1496 |     }
 | 
|---|
| 1497 | 
 | 
|---|
| 1498 |     pNewClass->SetVtblNum( _class.GetVtblNum() );
 | 
|---|
| 1499 | 
 | 
|---|
| 1500 |     // 展開済みクラスとして登録
 | 
|---|
| 1501 |     _class.expandedTemplateClasses.push_back( new ExpandedTemplateClass( pNewClass, actualTypes ) );
 | 
|---|
| 1502 | 
 | 
|---|
| 1503 |     pNewClass->Readed();
 | 
|---|
| 1504 | 
 | 
|---|
| 1505 |     return pNewClass;
 | 
|---|
| 1506 | }
 | 
|---|