Changeset 113 in dev


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

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

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/Compile_CallProc.cpp

    r102 r113  
    363363    extern BOOL bDebugCompile;
    364364    extern BOOL bDebugSupportProc;
    365     if(bDebugCompile&&bDebugSupportProc==0&& pDllProc->GetName() != "DebugBreak" ){
     365    if(bDebugCompile&&bDebugSupportProc==0&& pDllProc->IsEqualSymbol( "DebugBreak" ) ){
    366366        Call_DebugSys_SaveContext();
    367367    }
  • BasicCompiler_Common/Compile.cpp

    r107 r113  
    161161
    162162            case ESC_TYPEDEF:
     163                if( UserProc::IsLocalAreaCompiling() ){
     164                    // ローカル領域をコンパイルしているとき
     165                    SetError(65,"TypeDef",cp );
     166                }
     167
    163168                //既に収集済み
    164169                break;
     
    219224                break;
    220225            case ESC_DECLARE:
     226                if( UserProc::IsLocalAreaCompiling() ){
     227                    // ローカル領域をコンパイルしているとき
     228                    SetError(65,"Declare",cp );
     229                }
    221230                break;
    222231
  • BasicCompiler_Common/DebugMiddleFile.cpp

    r108 r113  
    139139    i2+=sizeof(long);
    140140    for(i3=0;i3<(int)Smoothie::Meta::typeDefs.size();i3++){
    141         lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetNewName().c_str() );
     141        lstrcpy(buffer+i2,Smoothie::Meta::typeDefs[i3].GetName().c_str() );
    142142        i2+=lstrlen(buffer+i2)+1;
    143143
     
    509509        i2+=lstrlen(buffer+i2)+1;
    510510
    511         Smoothie::Meta::typeDefs.push_back( TypeDef( temp5, buffer+i2 ) );
     511        // 名前空間に未対応
     512        Smoothie::Meta::typeDefs.push_back( TypeDef( NamespaceScopes(), temp5, buffer+i2 ) );
    512513
    513514        i2+=lstrlen(buffer+i2)+1;
  • BasicCompiler_Common/Procedure.cpp

    r108 r113  
    539539}
    540540
     541bool DllProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
     542{
     543    if( GetName() != name ){
     544        return false;
     545    }
     546    return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
     547}
     548bool DllProc::IsEqualSymbol( const string &fullName ) const
     549{
     550    char AreaName[VN_SIZE] = "";        //オブジェクト変数
     551    char NestName[VN_SIZE] = "";        //入れ子メンバ
     552    bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
     553
     554    if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){
     555        return true;
     556    }
     557
     558    if( isNest ){
     559        // 静的メンバを考慮
     560
     561        char AreaName2[VN_SIZE] = "";       //オブジェクト変数
     562        char NestName2[VN_SIZE] = "";       //入れ子メンバ
     563        bool isNest = SplitMemberName( AreaName, AreaName2, NestName2 );
     564        lstrcat( NestName2, "." );
     565        lstrcat( NestName2, NestName );
     566
     567        return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 );
     568    }
     569
     570    return false;
     571}
     572
     573
    541574bool DllProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){
    542575    int i = 0;
  • BasicCompiler_Common/Procedure.h

    r108 r113  
    311311    ~DllProc(){}
    312312
     313    bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     314    bool IsEqualSymbol( const string &name ) const;
     315
     316    const NamespaceScopes &GetNamespaceScopes() const
     317    {
     318        return namespaceScopes;
     319    }
     320
    313321    virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
    314322
  • BasicCompiler_Common/Subroutine.cpp

    r112 r113  
    441441    extern DllProc **ppDeclareHash;
    442442    if(ppDeclareHash[key]){
    443         DllProc *pTempProc;
    444         pTempProc=ppDeclareHash[key];
     443        DllProc *pTempProc = ppDeclareHash[key];
    445444        while(1){
    446             if( pDllProc->GetName() == pTempProc->GetName() ){
     445            if( pTempProc->IsEqualSymbol( pDllProc->GetNamespaceScopes(), pDllProc->GetName() ) ){
    447446                //重複エラー
    448447                SetError(15,procName,nowLine);
  • 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        }
  • BasicCompiler_Common/TypeDef.h

    r78 r113  
    1313    friend TypeDefCollection;
    1414
    15     string newName;
     15    NamespaceScopes namespaceScopes;
     16
     17    string name;
    1618    string baseName;
    1719    Type baseType;
    1820public:
    19     TypeDef( const string &newName, const string &baseName );
     21    TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName );
    2022    ~TypeDef();
    2123
    22     const string &GetNewName(){
    23         return newName;
     24    const string &GetName() const
     25    {
     26        return name;
    2427    }
    25     const string &GetBaseName(){
     28    const string &GetBaseName() const
     29    {
    2630        return baseName;
    2731    }
    28     const Type &GetBaseType(){
     32    const Type &GetBaseType() const
     33    {
    2934        return baseType;
    3035    }
     36
     37    bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     38    bool IsEqualSymbol( const string &name ) const;
    3139};
    3240
     
    3745    ~TypeDefCollection();
    3846
    39     void Add( const string &newName, const string &baseName );
     47    void Add( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName );
    4048    int GetIndex( const string &typeName ) const;
    4149
    4250private:
    43     void Add( const string &expression, int nowLine );
     51    void Add( const NamespaceScopes &namespaceScopes, const string &expression, int nowLine );
    4452public:
    4553    void Init();
  • BasicCompiler_Common/error.cpp

    r110 r113  
    154154    if(num==63) lstrcpy(msg,"名前空間が正しく閉じられていません。");
    155155    if(num==64) sprintf(msg,"\"%s\" 無効な名前空間です。",tempKeyWord);
     156    if(num==65) sprintf(msg,"ローカル領域で%sは使用できません。",tempKeyWord);
    156157
    157158
  • BasicCompiler_Common/hash.cpp

    r102 r113  
    3535}
    3636
    37 DllProc *GetDeclareHash(char *name){
     37DllProc *GetDeclareHash(char *fullName){
     38    char ObjName[VN_SIZE];      //オブジェクト変数
     39    char NestMember[VN_SIZE];   //入れ子メンバ
     40    bool isObjectMember = SplitMemberName( fullName, ObjName, NestMember );
     41
    3842    //ハッシュ値を取得
    3943    int key;
    40     key=hash_default(name);
     44    key=hash_default(NestMember);
    4145
    4246    //格納位置を取得
     
    4549    pDllProc=ppDeclareHash[key];
    4650    while(pDllProc){
    47         if( pDllProc->GetName() == name ){
     51        // TODO: Declare名前空間対応
     52        if( pDllProc->IsEqualSymbol( fullName ) ){
    4853            break;
    4954        }
Note: See TracChangeset for help on using the changeset viewer.