Changeset 406 in dev for trunk/abdev/BasicCompiler_Common/Enum.cpp
- Timestamp:
- Mar 2, 2008, 4:36:33 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/Enum.cpp
r402 r406 8 8 #include "common.h" 9 9 10 CEnumParent **ppobj_EnumParent; 11 int iEnumParentNum; 12 13 CEnumMember::CEnumMember(char *name,int value){ 14 m_name=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1); 15 lstrcpy(m_name,name); 16 17 m_value=value; 18 } 19 CEnumMember::~CEnumMember(){ 20 if(m_name) HeapDefaultFree(m_name); 21 } 22 23 24 CEnumParent::CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine) 25 : namespaceScopes( namespaceScopes ) 10 void EnumInfo::Collect( const char *buffer,int nowLine) 26 11 { 27 ppobj_EnumMember=(CEnumMember **)HeapAlloc(hHeap,0,1); 28 iEnumMemberNum=0; 29 30 int i=0,i2; 12 this->members.clear(); 13 14 int i=nowLine,i2; 31 15 32 16 if(!(buffer[i]==1&&buffer[i+1]==ESC_ENUM)) return; … … 47 31 } 48 32 49 name = temporary;50 51 33 if(buffer[i]=='\0'){ 52 34 SetError(22,"Enum",nowLine); … … 54 36 } 55 37 56 int NextValue=0; 38 int currentValue = 0; 39 bool isUseCurrentValue = true; 40 std::string currentValueStr; 41 std::string lastMemberName; 42 char temp2[VN_SIZE]; 57 43 while(1){ 58 44 i++; … … 79 65 } 80 66 81 if(buffer[i]!='='){ 82 NextValue++; 83 } 84 else{ 85 char temp2[VN_SIZE]; 86 for(i++,i2=0;;i2++,i++){ 87 if(IsCommandDelimitation(buffer[i])){ 88 temp2[i2]=0; 89 break; 90 } 91 temp2[i2]=buffer[i]; 92 } 93 NextValue=atoi(temp2); 67 if( buffer[i] != '=' ) 68 { 69 if( isUseCurrentValue ) 70 { 71 currentValue++; 72 73 sprintf( temp2, "%d", currentValue ); 74 currentValueStr = temp2; 75 } 76 else 77 { 78 currentValueStr = lastMemberName + "+1"; 79 } 80 } 81 else 82 { 83 i++; 84 GetCommandToken( temp2, buffer, i ); 85 86 _int64 i64data; 87 if( StaticCalculation( false, temp2, 0, &i64data, Type() ) ) 88 { 89 currentValue = static_cast<int>(i64data); 90 91 sprintf( temp2, "%d", currentValue ); 92 currentValueStr = temp2; 93 } 94 else 95 { 96 // 取得できなかった(なんらかの識別子を含む可能性あり) 97 isUseCurrentValue = false; 98 99 currentValueStr = temp2; 100 } 94 101 } 95 102 96 103 //メンバを追加 97 ppobj_EnumMember=(CEnumMember **)HeapReAlloc(hHeap,0,ppobj_EnumMember,(iEnumMemberNum+1)*sizeof(CEnumMember *));98 ppobj_EnumMember[iEnumMemberNum]=new CEnumMember(temporary,NextValue); 99 iEnumMemberNum++;104 this->members.push_back( EnumMember( temporary, currentValueStr, i ) ); 105 106 lastMemberName = temporary; 100 107 } 101 108 } 102 CEnumParent::~CEnumParent(){ 103 int i; 104 for(i=0;i<iEnumMemberNum;i++){ 105 delete ppobj_EnumMember[i]; 106 } 107 HeapDefaultFree(ppobj_EnumMember); 108 } 109 110 111 112 void CEnumParent::InitEnum(void){ 113 ppobj_EnumParent=(CEnumParent **)HeapAlloc(hHeap,0,1); 114 iEnumParentNum=0; 109 110 111 void EnumInfoCollection::InitEnum(void) 112 { 113 this->clear(); 115 114 116 115 const char *source = compiler.GetObjectModule().GetCurrentSource().GetBuffer(); … … 153 152 if(source[i-2]==1&&source[i-1]==ESC_CONST) continue; 154 153 } 155 ppobj_EnumParent=(CEnumParent **)HeapReAlloc(hHeap,0,ppobj_EnumParent,(iEnumParentNum+1)*sizeof(CEnumParent *)); 156 ppobj_EnumParent[iEnumParentNum]=new CEnumParent( namespaceScopes, source+i,i); 157 iEnumParentNum++; 154 155 i2 = i + 2; 156 GetCommandToken( temporary, source, i2 ); 157 158 // 追加 159 this->push_back( EnumInfo( namespaceScopes, temporary ) ); 160 161 // 収集 162 this->back().Collect( source, i ); 158 163 } 159 164 } 160 165 } 161 void CEnumParent::DestroyEnum(void){ 162 int i; 163 for(i=0;i<iEnumParentNum;i++){ 164 delete ppobj_EnumParent[i]; 165 } 166 HeapDefaultFree(ppobj_EnumParent); 167 } 168 169 char *CEnumParent::GenerateSourceCode(void){ 166 167 char *EnumInfoCollection::GenerateSourceCode(void){ 170 168 char *buffer; 171 169 int MaxSize,length; … … 176 174 buffer[0]=0; 177 175 178 for(int i=0;i<iEnumParentNum;i++){ 179 CEnumParent *parent; 180 parent=ppobj_EnumParent[i]; 181 182 BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){ 176 const EnumInfoCollection &thisEnumInfoCollection = *this; 177 BOOST_FOREACH( const EnumInfo &enumInfo, thisEnumInfoCollection ) 178 { 179 BOOST_FOREACH( const string &namespaceStr, enumInfo.GetNamespaceScopes() ){ 183 180 sprintf(buffer+length,"Namespace %s\n",namespaceStr.c_str()); 184 181 length+=lstrlen(buffer+length); 185 182 } 186 183 187 sprintf(buffer+length,"Class Enum %s\n", parent->GetName().c_str());184 sprintf(buffer+length,"Class Enum %s\n",enumInfo.GetName().c_str()); 188 185 length+=lstrlen(buffer+length); 189 186 lstrcpy(buffer+length,"\tInherits EnumBase\n"); 190 187 length+=lstrlen(buffer+length); 191 sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n", parent->GetName().c_str());188 sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",enumInfo.GetName().c_str()); 192 189 length+=lstrlen(buffer+length); 193 190 lstrcpy(buffer+length,"\t\tEnumBase(value,lpszName)\n"); … … 197 194 lstrcpy(buffer+length,"Public\n"); 198 195 length+=lstrlen(buffer+length); 199 sprintf(buffer+length,"\tSub %s()\n",parent->GetName().c_str()); 200 length+=lstrlen(buffer+length); 201 if(parent->iEnumMemberNum){ 202 sprintf(buffer+length,"\t\tEnumBase(%d,\"%s\")\n", 203 parent->ppobj_EnumMember[0]->m_value, 204 parent->ppobj_EnumMember[0]->m_name); 205 length+=lstrlen(buffer+length); 206 } 207 lstrcpy(buffer+length,"\tEnd Sub\n"); 208 length+=lstrlen(buffer+length); 209 sprintf(buffer+length,"\tSub ~%s()\n",parent->GetName().c_str()); 210 length+=lstrlen(buffer+length); 211 lstrcpy(buffer+length,"\tEnd Sub\n"); 212 length+=lstrlen(buffer+length); 213 214 for(int i2=0;i2<parent->iEnumMemberNum;i2++){ 196 sprintf(buffer+length,"\tSub %s()\n",enumInfo.GetName().c_str()); 197 length+=lstrlen(buffer+length); 198 if( enumInfo.GetMembers().size()){ 199 sprintf(buffer+length,"\t\tEnumBase(%s)\n", 200 enumInfo.GetMembers().begin()->GetName().c_str() ); 201 length+=lstrlen(buffer+length); 202 } 203 lstrcpy(buffer+length,"\tEnd Sub\n"); 204 length+=lstrlen(buffer+length); 205 sprintf(buffer+length,"\tSub ~%s()\n",enumInfo.GetName().c_str()); 206 length+=lstrlen(buffer+length); 207 lstrcpy(buffer+length,"\tEnd Sub\n"); 208 length+=lstrlen(buffer+length); 209 210 BOOST_FOREACH( const EnumMember &member, enumInfo.GetMembers() ) 211 { 212 sprintf(buffer+length,"\tStatic %s As %s((%s) As Long,\"%s\")\n", 213 member.GetName().c_str(), 214 enumInfo.GetName().c_str(), 215 member.GetValueStr().c_str(), 216 member.GetName().c_str()); 217 length+=lstrlen(buffer+length); 218 } 219 220 sprintf(buffer+length,"\tFunction Operator or (enumBase As %s) As %s\n",enumInfo.GetName().c_str(),enumInfo.GetName().c_str()); 221 length+=lstrlen(buffer+length); 222 sprintf(buffer+length,"\t\tReturn New %s(This.value or enumBase.value, \"custom\")\n",enumInfo.GetName().c_str()); 223 length+=lstrlen(buffer+length); 224 lstrcpy(buffer+length,"\tEnd Function\n"); 225 length+=lstrlen(buffer+length); 226 227 sprintf(buffer+length,"\tFunction Operator and (enumBase As %s) As %s\n",enumInfo.GetName().c_str(),enumInfo.GetName().c_str()); 228 length+=lstrlen(buffer+length); 229 sprintf(buffer+length,"\t\tReturn New %s(This.value and enumBase.value, \"custom\")\n",enumInfo.GetName().c_str()); 230 length+=lstrlen(buffer+length); 231 lstrcpy(buffer+length,"\tEnd Function\n"); 232 length+=lstrlen(buffer+length); 233 234 /* 235 sprintf(buffer+length,"\tOverride Function ToString() As String\n",enumInfo.TypeName); 236 length+=lstrlen(buffer+length); 237 lstrcpy(buffer+length,"\t\tSelect Case value\n"); 238 length+=lstrlen(buffer+length); 239 for(i2=0;i2<enumInfo.iEnumMemberNum;i2++){ 215 240 CEnumMember *member; 216 member=parent->ppobj_EnumMember[i2]; 217 218 sprintf(buffer+length,"\tStatic %s As %s(%d,\"%s\")\n", 219 member->m_name, 220 parent->GetName().c_str(), 221 member->m_value, 222 member->m_name); 223 length+=lstrlen(buffer+length); 224 } 225 226 sprintf(buffer+length,"\tFunction Operator or (enumBase As %s) As %s\n",parent->GetName().c_str(),parent->GetName().c_str()); 227 length+=lstrlen(buffer+length); 228 sprintf(buffer+length,"\t\tReturn New %s(This.value or enumBase.value, \"custom\")\n",parent->GetName().c_str()); 241 member=enumInfo.ppobj_EnumMember[i2]; 242 243 sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value); 244 length+=lstrlen(buffer+length); 245 sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name); 246 length+=lstrlen(buffer+length); 247 } 248 lstrcpy(buffer+length,"\t\tEnd Select\n"); 229 249 length+=lstrlen(buffer+length); 230 250 lstrcpy(buffer+length,"\tEnd Function\n"); 231 251 length+=lstrlen(buffer+length); 232 252 233 sprintf(buffer+length,"\tFunction Operator and (enumBase As %s) As %s\n",parent->GetName().c_str(),parent->GetName().c_str());234 length+=lstrlen(buffer+length);235 sprintf(buffer+length,"\t\tReturn New %s(This.value and enumBase.value, \"custom\")\n",parent->GetName().c_str());236 l ength+=lstrlen(buffer+length);237 l strcpy(buffer+length,"\tEnd Function\n");238 l ength+=lstrlen(buffer+length);239 240 /* 241 sprintf(buffer+length,"\t Override Function ToString() As String\n",parent->TypeName);253 254 sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",enumInfo.TypeName); 255 length+=lstrlen(buffer+length); 256 lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n"); 257 length+=lstrlen(buffer+length); 258 lstrcpy(buffer+length,"\tEnd Sub\n"); 259 length+=lstrlen(buffer+length); 260 261 sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",enumInfo.TypeName); 242 262 length+=lstrlen(buffer+length); 243 263 lstrcpy(buffer+length,"\t\tSelect Case value\n"); 244 264 length+=lstrlen(buffer+length); 245 for(i2=0;i2< parent->iEnumMemberNum;i2++){265 for(i2=0;i2<enumInfo.iEnumMemberNum;i2++){ 246 266 CEnumMember *member; 247 member= parent->ppobj_EnumMember[i2];248 249 sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);250 length+=lstrlen(buffer+length); 251 sprintf(buffer+length,"\t\t\t\t Return \"%s\"\n",member->m_name);267 member=enumInfo.ppobj_EnumMember[i2]; 268 269 sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name); 270 length+=lstrlen(buffer+length); 271 sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",enumInfo.TypeName,member->m_name); 252 272 length+=lstrlen(buffer+length); 253 273 } 254 274 lstrcpy(buffer+length,"\t\tEnd Select\n"); 255 275 length+=lstrlen(buffer+length); 256 lstrcpy(buffer+length,"\tEnd Function\n"); 257 length+=lstrlen(buffer+length); 258 259 260 sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName); 261 length+=lstrlen(buffer+length); 262 lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n"); 263 length+=lstrlen(buffer+length); 264 lstrcpy(buffer+length,"\tEnd Sub\n"); 265 length+=lstrlen(buffer+length); 266 267 sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName); 268 length+=lstrlen(buffer+length); 269 lstrcpy(buffer+length,"\t\tSelect Case value\n"); 270 length+=lstrlen(buffer+length); 271 for(i2=0;i2<parent->iEnumMemberNum;i2++){ 272 CEnumMember *member; 273 member=parent->ppobj_EnumMember[i2]; 274 275 sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name); 276 length+=lstrlen(buffer+length); 277 sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name); 278 length+=lstrlen(buffer+length); 279 } 280 lstrcpy(buffer+length,"\t\tEnd Select\n"); 281 length+=lstrlen(buffer+length); 282 lstrcpy(buffer+length,"\tEnd Sub\n"); 283 length+=lstrlen(buffer+length); 284 285 sprintf(buffer+length,"\tSub Operator= (value As Long)\n",parent->TypeName); 276 lstrcpy(buffer+length,"\tEnd Sub\n"); 277 length+=lstrlen(buffer+length); 278 279 sprintf(buffer+length,"\tSub Operator= (value As Long)\n",enumInfo.TypeName); 286 280 length+=lstrlen(buffer+length); 287 281 lstrcpy(buffer+length,"\t\tm_Value=value\n"); … … 293 287 length+=lstrlen(buffer+length); 294 288 295 BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){289 BOOST_FOREACH( const string &namespaceStr, enumInfo.GetNamespaceScopes() ){ 296 290 lstrcpy( buffer+length, "End Namespace\n" ); 297 291 length+=lstrlen(buffer+length);
Note:
See TracChangeset
for help on using the changeset viewer.