Changeset 103 in dev for BasicCompiler_Common/Const.cpp
- Timestamp:
- May 2, 2007, 4:08:58 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Const.cpp
r75 r103 7 7 8 8 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; 9 bool 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 } 16 bool 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 28 CConst::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 } 35 CConst::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 { 39 41 } 40 42 CConst::~CConst(){ … … 46 48 } 47 49 48 intCConst::GetType(){49 return Type;50 Type CConst::GetType(){ 51 return type; 50 52 } 51 53 _int64 CConst::GetWholeData(){ … … 60 62 61 63 62 CConstMacro::CConstMacro(char *Name, char *Expression):CConstBase(Name) 64 CConstMacro::CConstMacro( const NamespaceScopes &namespaceScopes, const string &name, char *Expression) 65 : ConstBase( namespaceScopes, name ) 63 66 { 64 67 } … … 99 102 100 103 void AddConstData(char *Command); 101 void CDBConst::Add( char *buffer){104 void CDBConst::Add( const NamespaceScopes &namespaceScopes, char *buffer ){ 102 105 int i; 103 106 … … 117 120 118 121 //重複チェック 119 if(Get Type(Name)){122 if(GetBasicType(Name)){ 120 123 SetError(15,Name,cp); 121 124 return; … … 132 135 char *Expression = buffer + i + 1; 133 136 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 141 void CDBConst::AddConst( const string &name, CConst *newconst){ 142 int key = hash_default(name.c_str()); 140 143 141 144 //ハッシュリストに追加 … … 152 155 } 153 156 } 154 void CDBConst::AddConst( char *Name, char *Expression){157 void CDBConst::AddConst( const NamespaceScopes &namespaceScopes, const string &name , char *Expression){ 155 158 _int64 i64data; 156 159 Type resultType; … … 164 167 //登録を行う 165 168 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 } 173 void 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 179 CConst *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 177 184 //ハッシュ値を取得 178 185 int key; 179 key=hash_default( Name);186 key=hash_default( NestMember ); 180 187 181 188 //格納位置を取得 … … 183 190 pConst=ppHash[key]; 184 191 while(pConst){ 185 if( lstrcmp(pConst->GetName(),Name)==0) break;192 if( pConst->IsEqualSymbol( name ) ) break; 186 193 187 194 pConst=pConst->pNext; … … 192 199 193 200 194 int CDBConst::Get Type(char *Name){201 int CDBConst::GetBasicType(char *Name){ 195 202 CConst *pConst = GetObjectPtr(Name); 196 203 197 204 if(!pConst) return 0; 198 205 199 return pConst->GetType() ;206 return pConst->GetType().GetBasicType(); 200 207 } 201 208 _int64 CDBConst::GetWholeData(char *Name){ … … 213 220 return pConst->GetDoubleData(); 214 221 } 222 bool 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.