Changeset 103 in dev for BasicCompiler_Common/Const.cpp


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.