Changeset 102 in dev for BasicCompiler_Common/Class.cpp


Ignore:
Timestamp:
Apr 29, 2007, 2:34:04 AM (17 years ago)
Author:
dai_9181
Message:

名前空間機能をクラスに適用。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/Class.cpp

    r101 r102  
    194194}
    195195
    196 bool CClass::IsEqualSymbol() const
    197 {
    198     return false;
     196bool CClass::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
     197{
     198    if( GetName() != name ){
     199        return false;
     200    }
     201
     202    return NamespaceScopes::IsSameArea( GetNamespaceScopes(), namespaceScopes );
     203}
     204bool CClass::IsEqualSymbol( const CClass &objClass ) const
     205{
     206    return IsEqualSymbol( objClass.GetNamespaceScopes(), objClass.GetName() );
     207}
     208bool CClass::IsEqualSymbol( const string &fullName ) const
     209{
     210    char AreaName[VN_SIZE] = "";        //オブジェクト変数
     211    char NestName[VN_SIZE] = "";        //入れ子メンバ
     212    bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
     213
     214    return IsEqualSymbol( NamespaceScopes( AreaName ), NestName );
    199215}
    200216
     
    735751
    736752
    737 int CDBClass::hash(const char *name){
     753int CDBClass::hash(const char *name) const{
    738754    int key;
    739755
     
    789805}
    790806
    791 CClass *CDBClass::check(const char *name){
     807CClass *CDBClass::Find( const string &fullName ) const
     808{
     809    char AreaName[VN_SIZE] = "";        //オブジェクト変数
     810    char NestName[VN_SIZE] = "";        //入れ子メンバ
     811    bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
     812
    792813    int key;
    793     key=hash(name);
     814    key=hash(NestName);
    794815
    795816    if(pobj_ClassHash[key]){
     
    797818        pobj_c=pobj_ClassHash[key];
    798819        while(1){
    799             if(lstrcmp(name,pobj_c->name)==0){
    800                 //重複した場合
     820            if( pobj_c->IsEqualSymbol( fullName ) ){
     821                //名前空間とクラス名が一致した
     822                return pobj_c;
     823            }
     824
     825            if(pobj_c->pobj_NextClass==0) break;
     826            pobj_c=pobj_c->pobj_NextClass;
     827        }
     828    }
     829    return NULL;
     830}
     831CClass *CDBClass::Find( const NamespaceScopes &namespaceScopes, const string &name ) const
     832{
     833    int key;
     834    key=hash(name.c_str());
     835
     836    if(pobj_ClassHash[key]){
     837        CClass *pobj_c;
     838        pobj_c=pobj_ClassHash[key];
     839        while(1){
     840            if( pobj_c->IsEqualSymbol( namespaceScopes, name ) ){
     841                //名前空間とクラス名が一致した
    801842                return pobj_c;
    802843            }
     
    838879        pobj_c2=pobj_ClassHash[key];
    839880        while(1){
    840             if(lstrcmp(name,pobj_c2->name)==0){
    841                 //重複した場合
     881            if( pobj_c2->IsEqualSymbol( namespaceScopes, name ) ){
     882                //名前空間及びクラス名が重複した場合
    842883                SetError(15,name,nowLine);
    843884                return 0;
     
    11001141    char temporary[8192];
    11011142
     1143    // 名前空間管理
     1144    NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
     1145    namespaceScopes.clear();
     1146
    11021147    for(i=0;;i++){
    11031148        if(basbuf[i]=='\0') break;
    11041149
    1105         CClass *pobj_c;
     1150
     1151        // 名前空間
     1152        if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
     1153            for(i+=2,i2=0;;i2++,i++){
     1154                if( IsCommandDelimitation( basbuf[i] ) ){
     1155                    temporary[i2]=0;
     1156                    break;
     1157                }
     1158                temporary[i2]=basbuf[i];
     1159            }
     1160            namespaceScopes.push_back( temporary );
     1161
     1162            continue;
     1163        }
     1164        else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
     1165            if( namespaceScopes.size() <= 0 ){
     1166                SetError(12, "End Namespace", i );
     1167            }
     1168            else{
     1169                namespaceScopes.pop_back();
     1170            }
     1171
     1172            i += 2;
     1173            continue;
     1174        }
     1175
     1176
    11061177
    11071178        if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
     
    11171188            GetIdentifierToken( temporary, basbuf, i );
    11181189
    1119             pobj_c=pobj_DBClass->check(temporary);
     1190            CClass *pobj_c=pobj_DBClass->Find(namespaceScopes, temporary);
    11201191            if(!pobj_c) continue;
    11211192
     
    11551226
    11561227                //継承元クラスを取得
    1157                 CClass *pInheritsClass = check(temporary);
     1228                CClass *pInheritsClass = Find(temporary);
    11581229                if( !pInheritsClass ){
    11591230                    SetError(106,temporary,i);
     
    12631334            GetIdentifierToken( temporary, basbuf, i );
    12641335
    1265             pobj_c=pobj_DBClass->check(temporary);
     1336            CClass *pobj_c=pobj_DBClass->Find(namespaceScopes, temporary);
    12661337            if(!pobj_c) continue;
    12671338
     
    13201391
    13211392                //継承元クラスを取得
    1322                 CClass *pInheritsClass = check(temporary);
     1393                CClass *pInheritsClass = Find(temporary);
    13231394                if( !pInheritsClass ){
    13241395                    SetError(106,temporary,i);
     
    13281399                if( pInheritsClass->IsInterface() ){
    13291400                    // クラスを継承していないとき
    1330                     CClass *pObjectClass = check("Object");
     1401                    CClass *pObjectClass = Find("Object");
    13311402                    if( !pObjectClass ){
    13321403                        SetError(106,"Object",i);
Note: See TracChangeset for help on using the changeset viewer.