Changeset 103 in dev


Ignore:
Timestamp:
May 2, 2007, 4:08:58 AM (17 years ago)
Author:
dai_9181
Message:

名前空間機能をグローバル変数、定数と列挙型に適用。
一部、クラスの静的メンバと名前空間の相性が悪いコードが潜んでいるため、要改修

Files:
17 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler32/MakePeHdr.cpp

    r100 r103  
    351351
    352352    if(!bDll){
     353        // 名前空間が初期化されているかをチェック
     354        if( Smoothie::Lexical::liveingNamespaceScopes.size() ){
     355            SetError();
     356        }
     357
    353358        //ラベル用のメモリを確保
    354359        extern LABEL *pLabelNames;
     
    445450        HeapDefaultFree(WithInfo.ppName);
    446451        HeapDefaultFree(WithInfo.pWithCp);
     452
     453        // 名前空間が正しく閉じられているかをチェック
     454        if( Smoothie::Lexical::liveingNamespaceScopes.size() ){
     455            SetError(63,NULL,-1);
     456        }
     457
    447458    }
    448459    else{
  • BasicCompiler32/NumOpe.cpp

    r102 r103  
    257257        Type leftType;
    258258        if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
    259             return false;
     259            goto globalArea;
    260260        }
    261261
     
    836836                    //////////////
    837837
    838                     i3 = CDBConst::obj.GetType(term);
     838                    i3 = CDBConst::obj.GetBasicType(term);
    839839                    if(i3){
     840                        if( CDBConst::obj.IsStringPtr( term ) ){
     841                            //リテラル文字列
     842
     843                            double dbl = CDBConst::obj.GetDoubleData(term);
     844                            memcpy(&i64data,&dbl,sizeof(double));
     845
     846                            //バイト数
     847                            i3=lstrlen((char *)i64data);
     848
     849                            memcpy(term,(char *)i64data,i3);
     850                            term[i3]=0;
     851                            goto StrLiteral;
     852                        }
     853
    840854                        type_stack[sp]=i3;
    841855                        if(IsRealNumberType(i3)){
     
    850864                            goto Literal;
    851865                        }
    852                         /*else if(i3==DEF_STRING){
    853                             //リテラル文字列
    854 
    855                             //バイト数
    856                             i3=(int)dbl;
    857 
    858                             memcpy(term,temporary,i3);
    859                             goto StrLiteral;
    860                         }*/
    861866                        else{
    862867                            SetError(300,NULL,cp);
  • BasicCompiler64/Compile_Var.cpp

    r97 r103  
    562562        if(member[0]){
    563563            lstrcpy(temporary,member);
     564
     565            // TODO: 名前空間を考慮したコードになっていない
    564566
    565567            char tempMember[VN_SIZE];
  • BasicCompiler64/MakePeHdr.cpp

    r100 r103  
    302302
    303303    if(!bDll){
     304        // 名前空間が初期化されているかをチェック
     305        if( Smoothie::Lexical::liveingNamespaceScopes.size() ){
     306            SetError();
     307        }
     308
    304309        //ラベル用のメモリを確保
    305310        extern LABEL *pLabelNames;
     
    411416        HeapDefaultFree(WithInfo.ppName);
    412417        HeapDefaultFree(WithInfo.pWithCp);
     418
     419        // 名前空間が正しく閉じられているかをチェック
     420        if( Smoothie::Lexical::liveingNamespaceScopes.size() ){
     421            SetError(63,NULL,-1);
     422        }
     423
    413424    }
    414425    else{
  • BasicCompiler64/NumOpe.cpp

    r102 r103  
    239239    lstrcpy(termLeft,termFull);
    240240
    241     if( (string)term=="DayOfWeek"){
    242         int test=0;
    243     }
    244 
    245241    // パース
    246242    char member[VN_SIZE];
     
    258254        Type leftType;
    259255        if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
    260             return false;
     256            goto globalArea;
    261257        }
    262258
     
    273269        return TermMemberOpe( leftType.GetClass(), baseType, resultType, termFull, termLeft, member );
    274270    }
    275 
     271globalArea:
    276272
    277273    //////////////////////////////////////////////
     
    290286    // グローバル属性エリア
    291287    /////////////////////////////////////////////////////////////////
    292 globalArea:
    293288
    294289    int UseReg=pobj_reg->GetNextReg();
     
    783778                    // 何らかの識別子
    784779
     780    if( (string)term=="ParentArea.NamespaceEnumTest.x"){
     781        int test=0;
     782    }
     783
    785784                    bool isLiteral;
    786785                    if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){
     
    870869                    //////////////
    871870
    872                     i3 = CDBConst::obj.GetType(term);
     871                    i3 = CDBConst::obj.GetBasicType(term);
    873872                    if(i3){
     873                        if( CDBConst::obj.IsStringPtr( term ) ){
     874                            //リテラル文字列
     875
     876                            double dbl = CDBConst::obj.GetDoubleData(term);
     877                            memcpy(&i64data,&dbl,sizeof(double));
     878
     879                            //バイト数
     880                            i3=lstrlen((char *)i64data);
     881
     882                            memcpy(term,(char *)i64data,i3);
     883                            term[i3]=0;
     884                            goto StrLiteral;
     885                        }
     886
    874887                        type_stack[sp] = i3;
    875888                        if(IsRealNumberType(i3)){
  • BasicCompiler_Common/Compile.cpp

    r99 r103  
    222222
    223223            case ESC_NAMESPACE:
     224                Smoothie::Lexical::liveingNamespaceScopes.push_back( Command + 2 );
     225                break;
    224226            case ESC_ENDNAMESPACE:
     227                if( Smoothie::Lexical::liveingNamespaceScopes.size() <= 0 ){
     228                    SetError(12,"End Namespace",cp);
     229                }
     230                Smoothie::Lexical::liveingNamespaceScopes.pop_back();
    225231                break;
    226232
  • BasicCompiler_Common/Const.cpp

    r75 r103  
    77
    88
    9 CConstBase::CConstBase(char *Name){
    10     this->Name = (char *)malloc(lstrlen(Name)+1);
    11     lstrcpy(this->Name, Name);
    12 }
    13 CConstBase::~CConstBase(){
    14     free(Name);
    15     Name=0;
    16 }
    17 
    18 char *CConstBase::GetName(){
    19     return Name;
    20 }
    21 
    22 
    23 
    24 CConst::CConst(char *Name, int Type, _int64 i64data):CConstBase(Name)
    25 {
    26     this->Type = Type;
    27     this->i64data = i64data;
    28 
    29     //連結リストを初期化
    30     pNext = 0;
    31 }
    32 CConst::CConst(char *Name, int value):CConstBase(Name)
    33 {
    34     Type = DEF_LONG;
    35     i64data = value;
    36 
    37     //連結リストを初期化
    38     pNext = 0;
     9bool ConstBase::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
     10{
     11    if( GetName() != name ){
     12        return false;
     13    }
     14    return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
     15}
     16bool ConstBase::IsEqualSymbol( const string &fullName ) const
     17{
     18    char AreaName[VN_SIZE] = "";        //オブジェクト変数
     19    char NestName[VN_SIZE] = "";        //入れ子メンバ
     20    bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
     21
     22    return IsEqualSymbol( NamespaceScopes( AreaName ), NestName );
     23}
     24
     25
     26
     27
     28CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, _int64 i64data)
     29    : ConstBase( namespaceScopes, name )
     30    , type( type )
     31    , i64data( i64data )
     32    , pNext( NULL )
     33{
     34}
     35CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, int value)
     36    : ConstBase( namespaceScopes, name )
     37    , type( Type(DEF_LONG) )
     38    , i64data( value )
     39    , pNext( NULL )
     40{
    3941}
    4042CConst::~CConst(){
     
    4648}
    4749
    48 int CConst::GetType(){
    49     return Type;
     50Type CConst::GetType(){
     51    return type;
    5052}
    5153_int64 CConst::GetWholeData(){
     
    6062
    6163
    62 CConstMacro::CConstMacro(char *Name, char *Expression):CConstBase(Name)
     64CConstMacro::CConstMacro( const NamespaceScopes &namespaceScopes, const string &name, char *Expression)
     65    : ConstBase( namespaceScopes, name )
    6366{
    6467}
     
    99102
    100103void AddConstData(char *Command);
    101 void CDBConst::Add(char *buffer){
     104void CDBConst::Add( const NamespaceScopes &namespaceScopes, char *buffer ){
    102105    int i;
    103106
     
    117120
    118121    //重複チェック
    119     if(GetType(Name)){
     122    if(GetBasicType(Name)){
    120123        SetError(15,Name,cp);
    121124        return;
     
    132135        char *Expression = buffer + i + 1;
    133136
    134         AddConst(Name,Expression);
    135     }
    136 }
    137 
    138 void CDBConst::AddConst(char *Name, CConst *newconst){
    139     int key = hash_default(Name);
     137        AddConst( namespaceScopes, Name,Expression);
     138    }
     139}
     140
     141void CDBConst::AddConst( const string &name, CConst *newconst){
     142    int key = hash_default(name.c_str());
    140143
    141144    //ハッシュリストに追加
     
    152155    }
    153156}
    154 void CDBConst::AddConst(char *Name, char *Expression){
     157void CDBConst::AddConst( const NamespaceScopes &namespaceScopes, const string &name , char *Expression){
    155158    _int64 i64data;
    156159    Type resultType;
     
    164167    //登録を行う
    165168
    166     CConst *newconst = new CConst(Name, resultType.GetBasicType(), i64data);
    167 
    168     AddConst(Name, newconst);
    169 }
    170 void CDBConst::AddConst(char *Name, int value){
    171     CConst *newconst = new CConst(Name, value);
    172 
    173     AddConst(Name, newconst);
    174 }
    175 
    176 CConst *CDBConst::GetObjectPtr(char *Name){
     169    CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data);
     170
     171    AddConst( name, newconst);
     172}
     173void CDBConst::AddConst(const NamespaceScopes &namespaceScopes, const string &name, int value){
     174    CConst *newconst = new CConst( namespaceScopes, name, value);
     175
     176    AddConst(name, newconst);
     177}
     178
     179CConst *CDBConst::GetObjectPtr( const string &name ){
     180    char ObjName[VN_SIZE];      //オブジェクト変数
     181    char NestMember[VN_SIZE];   //入れ子メンバ
     182    bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember );
     183
    177184    //ハッシュ値を取得
    178185    int key;
    179     key=hash_default(Name);
     186    key=hash_default( NestMember );
    180187
    181188    //格納位置を取得
     
    183190    pConst=ppHash[key];
    184191    while(pConst){
    185         if(lstrcmp(pConst->GetName(),Name)==0) break;
     192        if( pConst->IsEqualSymbol( name ) ) break;
    186193
    187194        pConst=pConst->pNext;
     
    192199
    193200
    194 int CDBConst::GetType(char *Name){
     201int CDBConst::GetBasicType(char *Name){
    195202    CConst *pConst = GetObjectPtr(Name);
    196203
    197204    if(!pConst) return 0;
    198205
    199     return pConst->GetType();
     206    return pConst->GetType().GetBasicType();
    200207}
    201208_int64 CDBConst::GetWholeData(char *Name){
     
    213220    return pConst->GetDoubleData();
    214221}
     222bool CDBConst::IsStringPtr( char *Name ){
     223    CConst *pConst = GetObjectPtr(Name);
     224
     225    if(!pConst) return false;
     226
     227    const Type &type = pConst->GetType();
     228
     229    return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING );
     230}
  • BasicCompiler_Common/Const.h

    r7 r103  
    22
    33//定数の基底クラス
    4 class CConstBase{
    5     char *Name;
     4class ConstBase{
     5    const string name;
     6    const NamespaceScopes namespaceScopes;
    67
    78public:
    89
    9     CConstBase(char *Name);
    10     ~CConstBase();
     10    ConstBase( const NamespaceScopes &namespaceScopes, const string &name )
     11        : namespaceScopes( namespaceScopes )
     12        , name( name )
     13    {
     14    }
     15    ~ConstBase()
     16    {
     17    }
    1118
    12     char *GetName();
     19    const string &GetName() const
     20    {
     21        return name;
     22    }
     23
     24    bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     25    bool IsEqualSymbol( const string &name ) const;
    1326};
    1427
    1528//定数
    16 class CConst:public CConstBase{
    17     int Type;
     29class CConst:public ConstBase{
     30    Type type;
    1831    _int64 i64data;
    1932
     
    2134    CConst *pNext;
    2235
    23     CConst(char *Name, int Type, _int64 i64data);
    24     CConst(char *Name, int value);
     36    CConst( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, _int64 i64data);
     37    CConst( const NamespaceScopes &namespaceScopes, const string &name, int value);
    2538    ~CConst();
    2639
    27     int GetType();
     40    Type GetType();
    2841    _int64 GetWholeData();
    2942    double GetDoubleData();
     
    3144
    3245//定数マクロ
    33 class CConstMacro:public CConstBase{
     46class CConstMacro:public ConstBase{
    3447    int ParmNum;
    3548    char **ppParm;
    3649public:
    3750
    38     CConstMacro(char *Name, char *Expression);
     51    CConstMacro( const NamespaceScopes &namespaceScopes, const string &name, char *Expression);
    3952    ~CConstMacro();
    4053};
     
    5770    void Init();
    5871
    59     void Add(char *buffer);
     72    void Add( const NamespaceScopes &namespaceScopes, char *buffer);
    6073private:
    61     void AddConst(char *Name, CConst *newconst);
     74    void AddConst( const string &name, CConst *newconst);
    6275public:
    63     void AddConst(char *Name, char *Expression);
    64     void AddConst(char *Name, int value);
     76    void AddConst( const NamespaceScopes &namespaceScopes, const string &name, char *Expression);
     77    void AddConst( const NamespaceScopes &namespaceScopes, const string &name, int value);
    6578
    6679private:
    67     CConst *GetObjectPtr(char *Name);
     80    CConst *GetObjectPtr( const string &name );
    6881public:
    6982
    70     int GetType(char *Name);
     83    int GetBasicType(char *Name);
    7184    _int64 GetWholeData(char *Name);
    7285    double GetDoubleData(char *Name);
     86    bool IsStringPtr(char *Name);
    7387
    7488
  • BasicCompiler_Common/Enum.cpp

    r92 r103  
    1515
    1616
    17 CEnumParent::CEnumParent(const char *buffer,int nowLine){
     17CEnumParent::CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine)
     18    : namespaceScopes( namespaceScopes )
     19{
    1820    ppobj_EnumMember=(CEnumMember **)HeapAlloc(hHeap,0,1);
    1921    iEnumMemberNum=0;
     
    3840    }
    3941
    40     TypeName=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
    41     lstrcpy(TypeName,temporary);
     42    name = temporary;
    4243
    4344    if(buffer[i]=='\0'){
     
    9394}
    9495CEnumParent::~CEnumParent(){
    95     HeapDefaultFree(TypeName);
    96 
    9796    int i;
    9897    for(i=0;i<iEnumMemberNum;i++){
     
    110109    const char *source = Smoothie::Lexical::source.GetBuffer();
    111110
    112     int i;
    113     for(i=0;;i++){
     111    // 名前空間管理
     112    NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
     113    namespaceScopes.clear();
     114
     115    int i2;
     116    char temporary[VN_SIZE];
     117    for(int i=0;;i++){
    114118        if(source[i]=='\0') break;
     119
     120        if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
     121            for(i+=2,i2=0;;i2++,i++){
     122                if( IsCommandDelimitation( source[i] ) ){
     123                    temporary[i2]=0;
     124                    break;
     125                }
     126                temporary[i2]=source[i];
     127            }
     128            namespaceScopes.push_back( temporary );
     129
     130            continue;
     131        }
     132        else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
     133            if( namespaceScopes.size() <= 0 ){
     134                SetError(12, "End Namespace", i );
     135            }
     136            else{
     137                namespaceScopes.pop_back();
     138            }
     139
     140            i += 2;
     141            continue;
     142        }
    115143
    116144        if(source[i]==1&&source[i+1]==ESC_ENUM){
     
    119147            }
    120148            ppobj_EnumParent=(CEnumParent **)HeapReAlloc(hHeap,0,ppobj_EnumParent,(iEnumParentNum+1)*sizeof(CEnumParent *));
    121             ppobj_EnumParent[iEnumParentNum]=new CEnumParent(source+i,i);
     149            ppobj_EnumParent[iEnumParentNum]=new CEnumParent( namespaceScopes, source+i,i);
    122150            iEnumParentNum++;
    123151        }
     
    133161
    134162char *CEnumParent::GenerateCodes(void){
    135     int i,i2;
    136 
    137163    char *buffer;
    138164    int MaxSize,length;
     
    143169    buffer[0]=0;
    144170
    145     for(i=0;i<iEnumParentNum;i++){
     171    for(int i=0;i<iEnumParentNum;i++){
    146172        CEnumParent *parent;
    147173        parent=ppobj_EnumParent[i];
    148174
    149         sprintf(buffer+length,"Class Enum %s\n",parent->TypeName);
     175        BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){
     176            sprintf(buffer+length,"Namespace %s\n",namespaceStr.c_str());
     177            length+=lstrlen(buffer+length);
     178        }
     179
     180        sprintf(buffer+length,"Class Enum %s\n",parent->GetName().c_str());
    150181        length+=lstrlen(buffer+length);
    151182        lstrcpy(buffer+length,"\tInherits EnumBase\n");
    152183        length+=lstrlen(buffer+length);
    153         sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",parent->TypeName);
     184        sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",parent->GetName().c_str());
    154185        length+=lstrlen(buffer+length);
    155186        lstrcpy(buffer+length,"\t\tEnumBase(value,lpszName)\n");
     
    159190        lstrcpy(buffer+length,"Public\n");
    160191        length+=lstrlen(buffer+length);
    161         sprintf(buffer+length,"\tSub %s()\n",parent->TypeName);
     192        sprintf(buffer+length,"\tSub %s()\n",parent->GetName().c_str());
    162193        length+=lstrlen(buffer+length);
    163194        if(parent->iEnumMemberNum){
     
    169200        lstrcpy(buffer+length,"\tEnd Sub\n");
    170201        length+=lstrlen(buffer+length);
    171         sprintf(buffer+length,"\tSub ~%s()\n",parent->TypeName);
    172         length+=lstrlen(buffer+length);
    173         lstrcpy(buffer+length,"\tEnd Sub\n");
    174         length+=lstrlen(buffer+length);
    175 
     202        sprintf(buffer+length,"\tSub ~%s()\n",parent->GetName().c_str());
     203        length+=lstrlen(buffer+length);
     204        lstrcpy(buffer+length,"\tEnd Sub\n");
     205        length+=lstrlen(buffer+length);
     206
     207        for(int i2=0;i2<parent->iEnumMemberNum;i2++){
     208            CEnumMember *member;
     209            member=parent->ppobj_EnumMember[i2];
     210
     211            sprintf(buffer+length,"\tStatic %s As %s(%d,\"%s\")\n",
     212                member->m_name,
     213                parent->GetName().c_str(),
     214                member->m_value,
     215                member->m_name);
     216            length+=lstrlen(buffer+length);
     217        }
     218
     219        /*
     220        sprintf(buffer+length,"\tOverride Function ToString() As String\n",parent->TypeName);
     221        length+=lstrlen(buffer+length);
     222        lstrcpy(buffer+length,"\t\tSelect Case value\n");
     223        length+=lstrlen(buffer+length);
    176224        for(i2=0;i2<parent->iEnumMemberNum;i2++){
    177225            CEnumMember *member;
    178226            member=parent->ppobj_EnumMember[i2];
    179227
    180             sprintf(buffer+length,"\tStatic %s As %s(%d,\"%s\")\n",
    181                 member->m_name,
    182                 parent->TypeName,
    183                 member->m_value,
    184                 member->m_name);
    185             length+=lstrlen(buffer+length);
    186         }
    187 
    188         /*
    189         sprintf(buffer+length,"\tOverride Function ToString() As String\n",parent->TypeName);
     228            sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);
     229            length+=lstrlen(buffer+length);
     230            sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name);
     231            length+=lstrlen(buffer+length);
     232        }
     233        lstrcpy(buffer+length,"\t\tEnd Select\n");
     234        length+=lstrlen(buffer+length);
     235        lstrcpy(buffer+length,"\tEnd Function\n");
     236        length+=lstrlen(buffer+length);
     237
     238       
     239        sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName);
     240        length+=lstrlen(buffer+length);
     241        lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");
     242        length+=lstrlen(buffer+length);
     243        lstrcpy(buffer+length,"\tEnd Sub\n");
     244        length+=lstrlen(buffer+length);
     245
     246        sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName);
    190247        length+=lstrlen(buffer+length);
    191248        lstrcpy(buffer+length,"\t\tSelect Case value\n");
     
    195252            member=parent->ppobj_EnumMember[i2];
    196253
    197             sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);
    198             length+=lstrlen(buffer+length);
    199             sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name);
     254            sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);
     255            length+=lstrlen(buffer+length);
     256            sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name);
    200257            length+=lstrlen(buffer+length);
    201258        }
    202259        lstrcpy(buffer+length,"\t\tEnd Select\n");
    203260        length+=lstrlen(buffer+length);
    204         lstrcpy(buffer+length,"\tEnd Function\n");
    205         length+=lstrlen(buffer+length);
    206 
    207        
    208         sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName);
    209         length+=lstrlen(buffer+length);
    210         lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");
    211         length+=lstrlen(buffer+length);
    212         lstrcpy(buffer+length,"\tEnd Sub\n");
    213         length+=lstrlen(buffer+length);
    214 
    215         sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName);
    216         length+=lstrlen(buffer+length);
    217         lstrcpy(buffer+length,"\t\tSelect Case value\n");
    218         length+=lstrlen(buffer+length);
    219         for(i2=0;i2<parent->iEnumMemberNum;i2++){
    220             CEnumMember *member;
    221             member=parent->ppobj_EnumMember[i2];
    222 
    223             sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);
    224             length+=lstrlen(buffer+length);
    225             sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name);
    226             length+=lstrlen(buffer+length);
    227         }
    228         lstrcpy(buffer+length,"\t\tEnd Select\n");
    229         length+=lstrlen(buffer+length);
    230261        lstrcpy(buffer+length,"\tEnd Sub\n");
    231262        length+=lstrlen(buffer+length);
     
    240271        lstrcpy(buffer+length,"End Class\n");
    241272        length+=lstrlen(buffer+length);
     273
     274        BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){
     275            lstrcpy( buffer+length, "End Namespace\n" );
     276            length+=lstrlen(buffer+length);
     277        }
    242278
    243279
  • BasicCompiler_Common/Enum.h

    r88 r103  
    1010
    1111class CEnumParent{
    12     char *TypeName;
     12    NamespaceScopes namespaceScopes;
     13    string name;
     14
    1315    BOOL bConst;
    1416
     
    1719public:
    1820
    19     CEnumParent(const char *buffer,int nowLine);
     21    CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine);
    2022    ~CEnumParent();
    2123
     24    const NamespaceScopes &GetNamespaceScopes() const
     25    {
     26        return namespaceScopes;
     27    }
     28    const string &GetName() const
     29    {
     30        return name;
     31    }
    2232
    2333public:
  • BasicCompiler_Common/Intermediate_Step2.cpp

    r100 r103  
    165165    }
    166166}
    167 void AddConstEnum(char *buffer){
     167void AddConstEnum( const NamespaceScopes &namespaceScopes, char *buffer){
    168168    extern int cp;
    169169    int i=0,i2;
     
    235235
    236236        //定数を追加
    237         CDBConst::obj.AddConst(temporary, NextValue);
     237        CDBConst::obj.AddConst( namespaceScopes, temporary, NextValue);
    238238    }
    239239}
     
    243243    ////////////////////////////////////////////
    244244
    245     int i,i2;
     245    int i2;
    246246    char temporary[1024];
     247
     248    // 名前空間管理
     249    NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
     250    namespaceScopes.clear();
    247251
    248252    //定数に関する情報
     
    251255
    252256    extern char *basbuf;
    253     for(i=0;;i++){
     257    for(int i=0;;i++){
    254258        if( basbuf[i] == '\0' ) break;
     259
     260        if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
     261            for(i+=2,i2=0;;i2++,i++){
     262                if( IsCommandDelimitation( basbuf[i] ) ){
     263                    temporary[i2]=0;
     264                    break;
     265                }
     266                temporary[i2]=basbuf[i];
     267            }
     268            namespaceScopes.push_back( temporary );
     269
     270            continue;
     271        }
     272        else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
     273            if( namespaceScopes.size() <= 0 ){
     274                SetError(12, "End Namespace", i );
     275            }
     276            else{
     277                namespaceScopes.pop_back();
     278            }
     279
     280            i += 2;
     281            continue;
     282        }
     283
    255284        if( basbuf[i] == 1 ){
    256285            if(basbuf[i]==1&&basbuf[i+1]==ESC_CONST){
     
    262291
    263292                if(basbuf[i]==1&&basbuf[i+1]==ESC_ENUM){
    264                     AddConstEnum(basbuf+i);
     293                    AddConstEnum( namespaceScopes, basbuf+i);
    265294                    continue;
    266295                }
     
    281310                    temporary[i2]=basbuf[i];
    282311                }
    283                 CDBConst::obj.Add(temporary);
     312                CDBConst::obj.Add( namespaceScopes, temporary);
    284313                if(basbuf[i]=='\0') break;
    285314            }
  • BasicCompiler_Common/NumOpe_GetType.cpp

    r102 r103  
    323323        Type leftType;
    324324        if( !GetTermType( termLeft, leftType, isLiteral, &isClassName ) ){
    325             return false;
     325            goto globalArea;
    326326        }
    327327
     
    658658                    // 何らかの識別子
    659659
     660                        if( (string)term=="ParentArea2.xxxxxx"){
     661                            int test=0;
     662                        }
     663
    660664                    bool isLiteral = true;
    661665                    if( GetTermType( term, resultType, isLiteral ) ){
     
    693697                    //////////////
    694698
    695                     i3 = CDBConst::obj.GetType(term);
     699                    i3 = CDBConst::obj.GetBasicType(term);
    696700                    if(i3){
     701                        if( CDBConst::obj.IsStringPtr( term ) ){
     702                            //リテラル文字列
     703                            goto StrLiteral;
     704                        }
     705
    697706                        type_stack[sp]=i3;
    698707                        if(IsRealNumberType(i3)){
     
    708717                            goto Literal;
    709718                        }
    710                         else if(i3==DEF_STRING){
    711                             //リテラル文字列
    712                             goto StrLiteral;
    713                         }
    714719                        else{
    715720                            SetError(1,NULL,0);
  • BasicCompiler_Common/Variable.cpp

    r75 r103  
     1#include "common.h"
     2
     3bool Variable::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
     4{
     5    if( GetName() != name ){
     6        return false;
     7    }
     8    return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
     9}
     10bool Variable::IsEqualSymbol( const string &fullName ) const
     11{
     12    char AreaName[VN_SIZE] = "";        //オブジェクト変数
     13    char NestName[VN_SIZE] = "";        //入れ子メンバ
     14    bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
     15
     16    if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){
     17        return true;
     18    }
     19
     20    if( isNest ){
     21        // 静的メンバを考慮
     22
     23        char AreaName2[VN_SIZE] = "";       //オブジェクト変数
     24        char NestName2[VN_SIZE] = "";       //入れ子メンバ
     25        bool isNest = SplitMemberName( AreaName, AreaName2, NestName2 );
     26        lstrcat( NestName2, "." );
     27        lstrcat( NestName2, NestName );
     28
     29        return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 );
     30    }
     31
     32    return false;
     33}
  • BasicCompiler_Common/Variable.h

    r100 r103  
    55class Variable : public Type
    66{
     7    const NamespaceScopes namespaceScopes;
    78    string name;
    89    bool isConst;
     
    1415
    1516public:
    16     Variable( const string &name, const Type &type, bool isConst = false, bool isRef = false ):
    17         Type( type ),
    18         name( name ),
    19         isConst( isConst ),
    20         isRef( isRef ),
    21         isArray( false ),
    22         isParameter( false)
     17    Variable( const string &name, const Type &type, bool isConst = false, bool isRef = false )
     18        : Type( type )
     19        , name( name )
     20        , isConst( isConst )
     21        , isRef( isRef )
     22        , isArray( false )
     23        , isParameter( false)
    2324    {
    2425        subScripts[0] = -1;
    2526    }
    26     Variable( const Variable &var ):
    27         Type( var ),
    28         name( var.name ),
    29         isConst( var.isConst ),
    30         isRef( var.isRef ),
    31         isArray( false ),
    32         isParameter( false )
     27    Variable( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, bool isConst = false, bool isRef = false )
     28        : namespaceScopes( namespaceScopes )
     29        , Type( type )
     30        , name( name )
     31        , isConst( isConst )
     32        , isRef( isRef )
     33        , isArray( false )
     34        , isParameter( false)
     35    {
     36        subScripts[0] = -1;
     37    }
     38    Variable( const Variable &var )
     39        : Type( var )
     40        , name( var.name )
     41        , isConst( var.isConst )
     42        , isRef( var.isRef )
     43        , isArray( false )
     44        , isParameter( false )
    3345    {
    3446        subScripts[0] = -1;
     
    4860        return name;
    4961    }
     62
     63    bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
     64    bool IsEqualSymbol( const string &name ) const;
    5065
    5166    void ConstOff(){
     
    150165                && var.ScopeLevel == obj_LexScopes.GetNowLevel()    //現在のスコープと同一レベル
    151166                ){
    152                     if( var.GetName() == varName ){
     167                    if( var.IsEqualSymbol( varName ) ){
    153168                        return true;
    154169                    }
     
    166181                && var.ScopeLevel <= obj_LexScopes.GetNowLevel()    //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
    167182                ){
    168                     if( var.GetName() == varName ){
     183                    if( var.IsEqualSymbol( varName ) ){
    169184                        return &var;
    170185                    }
     
    179194        for( int i=0; i<max; i++ ){
    180195            Variable *pVar = (*this)[i];
    181             if( pVar->GetName() == varName ){
     196            if( pVar->IsEqualSymbol( varName ) ){
    182197                return pVar;
    183198            }
  • BasicCompiler_Common/VariableOpe.cpp

    r97 r103  
    10451045    bool isConst = ( dwFlag & DIMFLAG_CONST ) ? true:false;
    10461046
    1047     Variable *pVar = new Variable( name, type, isConst );
     1047    Variable *pVar = new Variable( Smoothie::Lexical::liveingNamespaceScopes, name, type, isConst );
    10481048
    10491049    if( SubScripts[0] != -1 ){
     
    11721172
    11731173        //定数と2重定義されていないる場合は抜け出す
    1174         if(CDBConst::obj.GetType(VarName)){
     1174        if(CDBConst::obj.GetBasicType(VarName)){
    11751175            return;
    11761176        }
     
    11921192
    11931193    //定数と2重定義されていないかを調べる
    1194     if(CDBConst::obj.GetType(VarName)){
     1194    if(CDBConst::obj.GetBasicType(VarName)){
    11951195        SetError(15,VarName,cp);
    11961196        return;
  • BasicCompiler_Common/calculation.cpp

    r97 r103  
    653653                        /////////
    654654                        StrPtr[pnum]=0;
    655                         type[pnum] = CDBConst::obj.GetType(Parms);
     655                        type[pnum] = CDBConst::obj.GetBasicType(Parms);
    656656                        if(type[pnum]){
    657657                            if(IsRealNumberType(type[pnum])){
     
    900900                    }
    901901                }
     902
     903                if( type_stack[sp-1] == DEF_OBJECT || type_stack[sp-1] == DEF_STRUCT ){
     904                    // リテラル値ではないため抜け出す
     905                    return false;
     906                }
     907
    902908                type_stack[sp-2]=type_stack[sp-1];
    903909                index_stack[sp-2]=index_stack[sp-1];
     
    12991305
    13001306                //定数
    1301                 i3 = CDBConst::obj.GetType(Command+i2);
     1307                i3 = CDBConst::obj.GetBasicType(Command+i2);
    13021308                if(i3==DEF_STRING) return 1;    //文字列
    13031309                if(i3) return 0;            //数値
  • BasicCompiler_Common/error.cpp

    r85 r103  
    151151    if(num==61) sprintf(msg,"\"%s\" は定数です。書き込みアクセスはできません。",tempKeyWord);
    152152    if(num==62) sprintf(msg,"グローバル領域でのReturnは禁止されています。",tempKeyWord);
     153    if(num==63) lstrcpy(msg,"名前空間が正しく閉じられていません。");
    153154
    154155
Note: See TracChangeset for help on using the changeset viewer.