Changeset 102 in dev


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

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

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/Compile_CallProc.cpp

    r97 r102  
    127127                pobj_c = &varType.GetClass();
    128128                if( NATURAL_TYPE( varType.GetBasicType() ) != DEF_OBJECT ){
    129                     pobj_c=pobj_DBClass->check(ObjectName);
     129                    pobj_c=pobj_DBClass->Find(ObjectName);
    130130                    if( pobj_c ){
    131131                        isStatic = true;
  • BasicCompiler32/NumOpe.cpp

    r97 r102  
    279279
    280280    if( pIsClassName ){
    281         if( pobj_DBClass->check( termFull ) ){
     281        if( pobj_DBClass->Find( termFull ) ){
    282282            *pIsClassName = true;
    283283            return true;
  • BasicCompiler64/Compile_CallProc.cpp

    r97 r102  
    132132                pobj_c = &varType.GetClass();
    133133                if( NATURAL_TYPE( varType.GetBasicType() ) != DEF_OBJECT ){
    134                     pobj_c=pobj_DBClass->check(ObjectName);
     134                    pobj_c=pobj_DBClass->Find(ObjectName);
    135135                    if( pobj_c ){
    136136                        isStatic = true;
  • BasicCompiler64/NumOpe.cpp

    r97 r102  
    280280
    281281    if( pIsClassName ){
    282         if( pobj_DBClass->check( termFull ) ){
     282        if( pobj_DBClass->Find( termFull ) ){
    283283            *pIsClassName = true;
    284284            return true;
  • 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);
  • BasicCompiler_Common/Class.h

    r101 r102  
    115115    }
    116116
    117     bool IsEqualSymbol() const;
     117    const string GetName() const
     118    {
     119        return name;
     120    }
     121
     122    bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     123    bool IsEqualSymbol( const CClass &objClass ) const;
     124    bool IsEqualSymbol( const string &name ) const;
    118125
    119126    bool IsUsing() const;
     
    232239#define MAX_CLASS_HASH 65535
    233240class CDBClass{
    234     int hash(const char *name);
     241    int hash(const char *name) const;
    235242    void DestroyClass(CClass *pobj_c);
    236243public:
     
    240247    ~CDBClass();
    241248
    242     CClass *check(const char *name);
     249    CClass *Find( const string &fullName ) const;
     250    CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
    243251
    244252    CClass *AddClass( const NamespaceScopes &namespaceScopes, const char *name,int nowLine);
  • BasicCompiler_Common/DebugMiddleFile.cpp

    r101 r102  
    2828        (*p)+=lstrlen(buffer+(*p))+1;
    2929
    30         type.SetIndex( (LONG_PTR)pobj_DBClass->check(szClassName) );
     30        type.SetIndex( (LONG_PTR)pobj_DBClass->Find(szClassName) );
    3131    }
    3232    else{
     
    586586        CClass *pClass = NULL;
    587587        if(szParentClassName[0])
    588             pClass=pobj_DBClass->check(szParentClassName);
     588            pClass=pobj_DBClass->Find(szParentClassName);
    589589
    590590        //ID
     
    690690        i2+=lstrlen(buffer+i2)+1;
    691691
    692         pobj_c=pobj_DBClass->check(szClassName);
     692        pobj_c=pobj_DBClass->Find(szClassName);
    693693
    694694        //仮想関数の数
     
    742742            CClass *pobj_InheritsClass = NULL;
    743743            if(szInherits[0]){
    744                 pobj_InheritsClass=pobj_DBClass->check(szInherits);
     744                pobj_InheritsClass=pobj_DBClass->Find(szInherits);
    745745            }
    746746
  • BasicCompiler_Common/NumOpe_GetType.cpp

    r98 r102  
    378378
    379379    if( pIsClassName ){
    380         if( pobj_DBClass->check( termFull ) ){
     380        if( pobj_DBClass->Find( termFull ) ){
    381381            *pIsClassName = true;
    382382            return true;
  • BasicCompiler_Common/Procedure.cpp

    r101 r102  
    512512bool GlobalProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
    513513{
    514     if( namespaceScopes.size() ){
    515         if( GetNamespaceScopes().IsCoverd( namespaceScopes ) ){
    516             if( GetName() == name ){
    517                 return true;
    518             }
    519         }
    520     }
    521     else{
    522         if( GetNamespaceScopes().size() ){
    523             // 名前空間の判断が必要なとき
    524             if( !GetNamespaceScopes().IsUsing()
    525                 && !GetNamespaceScopes().IsLiving() ){
    526                 // この名前空間は暗黙的に参照できないとき
    527                 return false;
    528             }
    529         }
    530         else{
    531             if( GetName() == name ){
    532                 return true;
    533             }
    534         }
    535     }
    536 
    537     return false;
     514    if( GetName() != name ){
     515        return false;
     516    }
     517
     518    return NamespaceScopes::IsSameArea( GetNamespaceScopes(), namespaceScopes );
    538519}
    539520bool GlobalProc::IsEqualSymbol( const GlobalProc &globalProc ) const
  • BasicCompiler_Common/Type.cpp

    r97 r102  
    9696
    9797    //クラス
    98     CClass *pobj_c = pobj_DBClass->check( typeName.c_str() );
     98    CClass *pobj_c = pobj_DBClass->Find( typeName.c_str() );
    9999    if(pobj_c){
    100100        type.pClass = pobj_c;
  • BasicCompiler_Common/hash.cpp

    r101 r102  
    6464    else lstrcpy(name,lpszName);
    6565
    66     if( (string)lpszName == "Test2.Proc3" ){
    67         int test=0;
    68     }
    69 
    7066    char ObjName[VN_SIZE];      //オブジェクト変数
    7167    char NestMember[VN_SIZE];   //入れ子メンバ
     
    8884            }
    8985            else{
    90                 pobj_c=pobj_DBClass->check(ObjName);
     86                pobj_c=pobj_DBClass->Find(ObjName);
    9187                if( pobj_c ){
    9288                    isStatic = true;
     
    186182
    187183UserProc *GetClassMethod( const char *className, const char *methodName ){
    188     CClass *pClass = pobj_DBClass->check( className );
     184    CClass *pClass = pobj_DBClass->Find( className );
    189185    if( pClass ){
    190186        vector<UserProc *> userProcs;
  • BasicCompiler_Common/include/Namespace.h

    r101 r102  
    8686    bool IsCoverd( const string &name ) const;
    8787    bool IsCoverd( const NamespaceScopes &namespaceScopes ) const;
     88
     89    // 指定された名前空間が同一エリアと見なされるかどうかをチェック
     90    static bool IsSameArea( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ){
     91        if( entryNamespaceScopes.size() ){
     92            if( baseNamespaceScopes.IsCoverd( entryNamespaceScopes ) ){
     93                // 包括しているときは同一と見なす
     94                return true;
     95            }
     96        }
     97        else{
     98            if( baseNamespaceScopes.size() ){
     99                // 名前空間の判断が必要なとき
     100                if( baseNamespaceScopes.IsUsing()
     101                    || baseNamespaceScopes.IsLiving() ){
     102                    // Using指定があるとき
     103                    // または
     104                    // 指定された名前空間が現在の名前空間スコープと同一のとき
     105                    return true;
     106                }
     107            }
     108            else{
     109                return true;
     110            }
     111        }
     112
     113        return false;
     114    }
    88115};
Note: See TracChangeset for help on using the changeset viewer.