Changeset 715 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Enum.cpp
- Timestamp:
- Aug 5, 2008, 2:59:15 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Enum.cpp
r714 r715 157 157 std::string LexicalAnalyzer::GenerateEnumsSourceCode( const EnumInfoCollection &enums ) 158 158 { 159 char *buffer; 160 int MaxSize,length; 161 MaxSize=65535; 162 buffer=(char *)HeapAlloc(hHeap,0,MaxSize+65535); 163 length=0; 164 165 buffer[0]=0; 159 std::string buffer; 160 buffer.reserve(65536); 166 161 167 162 BOOST_FOREACH( const EnumInfo &enumInfo, enums ) 168 163 { 169 164 BOOST_FOREACH( const std::string &namespaceStr, enumInfo.GetNamespaceScopes() ){ 170 sprintf(buffer+length,"Namespace %s\n",namespaceStr.c_str()); 171 length+=lstrlen(buffer+length); 172 } 173 174 sprintf(buffer+length,"Class Enum %s\n",enumInfo.GetName().c_str()); 175 length+=lstrlen(buffer+length); 176 sprintf(buffer+length,"\tInherits EnumBase<%s>\n",enumInfo.GetName().c_str()); 177 length+=lstrlen(buffer+length); 178 sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPCTSTR)\n",enumInfo.GetName().c_str()); 179 length+=lstrlen(buffer+length); 180 lstrcpy(buffer+length,"\t\tEnumBase(value,lpszName)\n"); 181 length+=lstrlen(buffer+length); 182 lstrcpy(buffer+length,"\tEnd Sub\n"); 183 length+=lstrlen(buffer+length); 184 lstrcpy(buffer+length,"Public\n"); 185 length+=lstrlen(buffer+length); 186 sprintf(buffer+length,"\tSub %s()\n",enumInfo.GetName().c_str()); 187 length+=lstrlen(buffer+length); 188 if( enumInfo.GetMembers().size()){ 189 sprintf(buffer+length,"\t\tEnumBase(%s)\n", 190 enumInfo.GetMembers().begin()->GetName().c_str() ); 191 length+=lstrlen(buffer+length); 192 } 193 lstrcpy(buffer+length,"\tEnd Sub\n"); 194 length+=lstrlen(buffer+length); 195 sprintf(buffer+length,"\tSub ~%s()\n",enumInfo.GetName().c_str()); 196 length+=lstrlen(buffer+length); 197 lstrcpy(buffer+length,"\tEnd Sub\n"); 198 length+=lstrlen(buffer+length); 165 buffer.append("Namespace ").append(namespaceStr) += '\n'; 166 } 167 168 buffer.append("Class Enum ").append(enumInfo.GetName()) += '\n'; 169 buffer.append("\tInherits EnumBase<").append(enumInfo.GetName()).append(">\n"); 170 buffer.append("\tSub ").append(enumInfo.GetName()).append("(value As Long,lpszName As LPCTSTR)\n"); 171 buffer.append("\t\tEnumBase(value,lpszName)\n" 172 "\tEnd Sub\n" 173 "Public\n"); 174 buffer.append("\tSub ").append(enumInfo.GetName()).append("()\n"); 175 if( !enumInfo.GetMembers().empty() ){ 176 buffer.append("\t\tEnumBase(").append(enumInfo.GetMembers().front().GetName()) 177 .append(")\n"); 178 } 179 buffer.append("\tEnd Sub\n"); 199 180 200 181 BOOST_FOREACH( const EnumMember &member, enumInfo.GetMembers() ) 201 182 { 202 sprintf(buffer+length,"\tStatic %s As %s((%s) As Long,\"%s\")\n", 203 member.GetName().c_str(), 204 enumInfo.GetName().c_str(), 205 member.GetValueStr().c_str(), 206 member.GetName().c_str()); 207 length+=lstrlen(buffer+length); 208 } 209 210 lstrcpy(buffer+length,"End Class\n"); 211 length+=lstrlen(buffer+length); 183 buffer.append("\tStatic ") 184 .append(member.GetName()).append(" As ") 185 .append(enumInfo.GetName()).append("((") 186 .append(member.GetValueStr()).append(") As Long,\"") 187 .append(member.GetName()).append("\")\n"); 188 } 189 190 buffer.append("End Class\n"); 212 191 213 192 BOOST_FOREACH( const std::string &namespaceStr, enumInfo.GetNamespaceScopes() ){ 214 lstrcpy( buffer+length, "End Namespace\n" ); 215 length+=lstrlen(buffer+length); 216 } 217 218 219 //バッファ領域が足りなくなった場合はバッファを増量する 220 if(length>MaxSize){ 221 MaxSize+=65535; 222 buffer=(char *)HeapReAlloc(hHeap,0,buffer,MaxSize+65535); 193 buffer.append("End Namespace\n"); 223 194 } 224 195 } … … 229 200 logger << buffer << std::endl; 230 201 #endif 231 232 std::string result = buffer; 233 234 HeapDefaultFree( buffer ); 235 236 return result; 202 return buffer; 237 203 }
Note:
See TracChangeset
for help on using the changeset viewer.