- Timestamp:
- Mar 2, 2008, 4:36:33 AM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler32/BasicCompiler.vcproj
r404 r406 1349 1349 > 1350 1350 <FileConfiguration 1351 Name="Debug|Win32" 1352 > 1353 <Tool 1354 Name="VCCLCompilerTool" 1355 UsePrecompiledHeader="0" 1356 /> 1357 </FileConfiguration> 1358 <FileConfiguration 1351 1359 Name="Release|Win32" 1352 1360 > -
trunk/abdev/BasicCompiler32/MakePeHdr.cpp
r358 r406 151 151 152 152 //列挙体に関する情報を収集 153 CEnumParent::InitEnum();153 compiler.enumInfoCollection.InitEnum(); 154 154 155 155 //列挙体からクラスコードを生成 156 156 char *temp; 157 temp= CEnumParent::GenerateSourceCode();157 temp=compiler.enumInfoCollection.GenerateSourceCode(); 158 158 AddSourceCode(temp); 159 159 HeapDefaultFree(temp); … … 1659 1659 delete pobj_Reloc; 1660 1660 1661 //列挙体に関する情報の破棄1662 CEnumParent::DestroyEnum();1663 1664 1661 //クラスに関するメモリを解放 1665 1662 compiler.GetObjectModule().meta.GetClasses().Clear(); -
trunk/abdev/BasicCompiler64/BasicCompiler.vcproj
r404 r406 1312 1312 > 1313 1313 <FileConfiguration 1314 Name="Debug|Win32" 1315 > 1316 <Tool 1317 Name="VCCLCompilerTool" 1318 UsePrecompiledHeader="0" 1319 /> 1320 </FileConfiguration> 1321 <FileConfiguration 1314 1322 Name="Release|Win32" 1315 1323 > -
trunk/abdev/BasicCompiler64/MakePeHdr.cpp
r358 r406 140 140 141 141 //列挙体に関する情報を収集 142 CEnumParent::InitEnum();142 compiler.enumInfoCollection.InitEnum(); 143 143 144 144 //列挙体からクラスコードを生成 145 145 char *temp; 146 temp =CEnumParent::GenerateSourceCode();146 temp = compiler.enumInfoCollection.GenerateSourceCode(); 147 147 AddSourceCode(temp); 148 148 HeapDefaultFree(temp); … … 1655 1655 delete pobj_Reloc; 1656 1656 1657 //列挙体に関する情報の破棄1658 CEnumParent::DestroyEnum();1659 1660 1657 //クラスに関するメモリを解放 1661 1658 compiler.GetObjectModule().meta.GetClasses().Clear(); -
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); -
trunk/abdev/BasicCompiler_Common/Enum.h
r322 r406 3 3 #include <Namespace.h> 4 4 5 class CEnumMember{ 5 class EnumMember 6 { 7 std::string name; 8 std::string value; 9 int sourceIndex; 6 10 public: 7 char *m_name; 8 int m_value; 9 CEnumMember(char *name,int value); 10 ~CEnumMember(); 11 EnumMember( const std::string &name, const std::string &value, int sourceIndex ) 12 : name( name ) 13 , value( value ) 14 , sourceIndex( sourceIndex ) 15 { 16 } 17 const std::string &GetName() const 18 { 19 return name; 20 } 21 const std::string &GetValueStr() const 22 { 23 return value; 24 } 25 int GetSourceIndex() const 26 { 27 return sourceIndex; 28 } 11 29 }; 12 30 13 class CEnumParent{14 NamespaceScopes namespaceScopes;15 string name; 31 class EnumInfo 32 : public Symbol 33 { 16 34 17 35 BOOL bConst; 18 36 19 CEnumMember **ppobj_EnumMember; 20 int iEnumMemberNum; 37 std::vector<EnumMember> members; 21 38 public: 22 39 23 CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine); 24 ~CEnumParent(); 25 26 const NamespaceScopes &GetNamespaceScopes() const 40 EnumInfo( const NamespaceScopes &namespaceScopes, const std::string &name ) 41 : Symbol( namespaceScopes, name ) 27 42 { 28 return namespaceScopes;29 }30 const string &GetName() const31 {32 return name;33 43 } 34 44 45 const std::vector<EnumMember> &GetMembers() const 46 { 47 return members; 48 } 49 50 void Collect( const char *buffer, int nowLine ); 51 52 const EnumMember &GetEnumMember( const std::string &memberName ) const 53 { 54 BOOST_FOREACH( const EnumMember &member, members ) 55 { 56 if( member.GetName() == memberName ) 57 { 58 return member; 59 } 60 } 61 throw; 62 } 63 }; 64 65 class EnumInfoCollection 66 : public std::vector<EnumInfo> 67 { 35 68 public: 36 static void InitEnum(void); 37 static void DestroyEnum(void); 69 const EnumInfo *Find( const Symbol &symbol ) const 70 { 71 const EnumInfoCollection &thisEnumInfoCollection = *this; 72 BOOST_FOREACH( const EnumInfo &enumInfo, thisEnumInfoCollection ) 73 { 74 if( enumInfo.IsEqualSymbol( symbol ) ) 75 { 76 return &enumInfo; 77 } 78 } 79 return NULL; 80 }; 38 81 39 static char *GenerateSourceCode(void); 82 void InitEnum(void); 83 char *GenerateSourceCode(void); 40 84 }; 41 extern CEnumParent **ppobj_EnumParent;42 extern int iEnumParentNum; -
trunk/abdev/BasicCompiler_Common/include/Compiler.h
r357 r406 10 10 #include <Delegate.h> 11 11 #include <Exception.h> 12 #include <../Enum.h> 12 13 13 14 class Compiler … … 141 142 std::string globalAreaProcName; 142 143 144 // 列挙型 145 EnumInfoCollection enumInfoCollection; 146 143 147 144 148 bool StringToType( const std::string &typeName, Type &type ); -
trunk/abdev/BasicCompiler_Common/src/Class.cpp
r402 r406 15 15 #include "../../BasicCompiler32/opcode.h" 16 16 #endif 17 18 #include <../Enum.h> 17 19 18 20 … … 1068 1070 } 1069 1071 1072 // コンパイル中クラスとしてセット 1073 compiler.pCompilingClass = &objClass; 1074 1075 const EnumInfo *pEnumInfo = NULL; 1076 if( objClass.IsEnum() ) 1077 { 1078 pEnumInfo = compiler.enumInfoCollection.Find( objClass ); 1079 } 1080 1070 1081 int i=0; 1071 BOOST_FOREACH( CMember *member, objClass.GetStaticMembers() ){ 1082 BOOST_FOREACH( CMember *member, objClass.GetStaticMembers() ) 1083 { 1084 if( pEnumInfo ) 1085 { 1086 cp = pEnumInfo->GetEnumMember( member->GetName() ).GetSourceIndex(); 1087 } 1088 1072 1089 char temporary[VN_SIZE]; 1073 1090 sprintf(temporary,"%s.%s",objClass.GetName().c_str(),member->GetName().c_str()); … … 1082 1099 i++; 1083 1100 } 1101 1102 compiler.pCompilingClass = NULL; 1084 1103 } 1085 1104
Note:
See TracChangeset
for help on using the changeset viewer.