Changeset 113 in dev for BasicCompiler_Common/TypeDef.cpp


Ignore:
Timestamp:
May 10, 2007, 12:27:41 PM (17 years ago)
Author:
dai_9181
Message:

TypeDef、Declareの名前空間対応を行った。
TypeDef、Declareをローカル領域で使用した際、エラーを表示するようにした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/TypeDef.cpp

    r96 r113  
    22
    33
    4 TypeDef::TypeDef( const string &newName, const string &baseName ):
    5     newName( newName ),
    6     baseName( baseName )
     4TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName )
     5    : namespaceScopes( namespaceScopes )
     6    , name( name )
     7    , baseName( baseName )
    78{
    89    if( !Type::StringToType( baseName, baseType ) ){
     
    1415}
    1516
     17bool TypeDef::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
     18{
     19    if( GetName() != name ){
     20        return false;
     21    }
     22    return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
     23}
     24bool TypeDef::IsEqualSymbol( const string &fullName ) const
     25{
     26    char AreaName[VN_SIZE] = "";        //オブジェクト変数
     27    char NestName[VN_SIZE] = "";        //入れ子メンバ
     28    bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
     29
     30    if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){
     31        return true;
     32    }
     33
     34    if( isNest ){
     35        // 静的メンバを考慮
     36
     37        char AreaName2[VN_SIZE] = "";       //オブジェクト変数
     38        char NestName2[VN_SIZE] = "";       //入れ子メンバ
     39        bool isNest = SplitMemberName( AreaName, AreaName2, NestName2 );
     40        lstrcat( NestName2, "." );
     41        lstrcat( NestName2, NestName );
     42
     43        return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 );
     44    }
     45
     46    return false;
     47}
     48
     49
    1650
    1751TypeDefCollection::TypeDefCollection(){
     
    1953TypeDefCollection::~TypeDefCollection(){
    2054}
    21 void TypeDefCollection::Add( const string &newName, const string &baseName ){
    22     TypeDef typeDef( newName, baseName );
     55void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName ){
     56    TypeDef typeDef( namespaceScopes, name, baseName );
    2357    this->push_back( typeDef );
    2458}
     
    2660    int max = (int)(*this).size();
    2761    for( int i=0; i<max; i++ ){
    28         if( (*this)[i].newName == typeName ){
     62        if( (*this)[i].IsEqualSymbol( typeName ) ){
    2963            return i;
    3064        }
     
    3367}
    3468
    35 void TypeDefCollection::Add( const string &expression, int nowLine ){
     69void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &expression, int nowLine ){
    3670    int i;
    3771    char temporary[VN_SIZE];
     
    98132    cp = nowLine;
    99133
    100     Smoothie::Meta::typeDefs.Add(temporary,pTemp);
     134    Add( namespaceScopes, temporary, pTemp );
    101135}
    102136
     
    105139    clear();
    106140
    107     int i=-1;
     141    // 名前空間管理
     142    NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
     143    namespaceScopes.clear();
     144
     145    // Importsされた名前空間の管理
     146    NamespaceScopesCollection &importedNamespaces = Smoothie::Meta::importedNamespaces;
     147    importedNamespaces.clear();
     148
     149    int i=-1, i2;
     150    char temporary[VN_SIZE];
    108151    while(1){
     152        extern char *basbuf;
     153
    109154        i++;
    110155
    111         extern char *basbuf;
     156        if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
     157            for(i+=2,i2=0;;i2++,i++){
     158                if( IsCommandDelimitation( basbuf[i] ) ){
     159                    temporary[i2]=0;
     160                    break;
     161                }
     162                temporary[i2]=basbuf[i];
     163            }
     164            namespaceScopes.push_back( temporary );
     165
     166            continue;
     167        }
     168        else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
     169            if( namespaceScopes.size() <= 0 ){
     170                SetError(12, "End Namespace", i );
     171            }
     172            else{
     173                namespaceScopes.pop_back();
     174            }
     175
     176            i += 2;
     177            continue;
     178        }
     179        else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
     180            for(i+=2,i2=0;;i2++,i++){
     181                if( IsCommandDelimitation( basbuf[i] ) ){
     182                    temporary[i2]=0;
     183                    break;
     184                }
     185                temporary[i2]=basbuf[i];
     186            }
     187            importedNamespaces.Imports( temporary );
     188
     189            continue;
     190        }
     191        else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
     192            importedNamespaces.clear();
     193            continue;
     194        }
     195
    112196        if( basbuf[i]==1 ){
    113197            char temporary[VN_SIZE];
     
    122206                    if(basbuf[i]=='\0') break;
    123207                }
    124                 Add(temporary,i);
     208                Add( namespaceScopes, temporary, i );
    125209
    126210                continue;
     
    136220                    if(basbuf[i]=='\0') break;
    137221                }
    138                 Smoothie::Meta::typeDefs.Add(temporary,"Long");
     222                Add( namespaceScopes, temporary, "Long" );
    139223            }
    140224        }
Note: See TracChangeset for help on using the changeset viewer.