[4] | 1 | #include "common.h"
|
---|
| 2 |
|
---|
| 3 | CEnumParent **ppobj_EnumParent;
|
---|
| 4 | int iEnumParentNum;
|
---|
| 5 |
|
---|
| 6 | CEnumMember::CEnumMember(char *name,int value){
|
---|
| 7 | m_name=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1);
|
---|
| 8 | lstrcpy(m_name,name);
|
---|
| 9 |
|
---|
| 10 | m_value=value;
|
---|
| 11 | }
|
---|
| 12 | CEnumMember::~CEnumMember(){
|
---|
| 13 | if(m_name) HeapDefaultFree(m_name);
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 |
|
---|
[75] | 17 | CEnumParent::CEnumParent(char *buffer,int nowLine){
|
---|
[4] | 18 | ppobj_EnumMember=(CEnumMember **)HeapAlloc(hHeap,0,1);
|
---|
| 19 | iEnumMemberNum=0;
|
---|
| 20 |
|
---|
| 21 | int i=0,i2;
|
---|
| 22 |
|
---|
| 23 | if(!(buffer[i]==1&&buffer[i+1]==ESC_ENUM)) return;
|
---|
| 24 | i+=2;
|
---|
| 25 |
|
---|
| 26 | //列挙体の名前を取得
|
---|
| 27 | char temporary[VN_SIZE];
|
---|
| 28 | for(i2=0;;i++,i2++){
|
---|
| 29 | if(IsCommandDelimitation(buffer[i])){
|
---|
| 30 | temporary[i2]=0;
|
---|
| 31 | break;
|
---|
| 32 | }
|
---|
| 33 | if(!IsVariableChar(buffer[i])){
|
---|
| 34 | SetError(1,NULL,i);
|
---|
| 35 | break;
|
---|
| 36 | }
|
---|
| 37 | temporary[i2]=buffer[i];
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | TypeName=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
| 41 | lstrcpy(TypeName,temporary);
|
---|
| 42 |
|
---|
| 43 | if(buffer[i]=='\0'){
|
---|
[75] | 44 | SetError(22,"Enum",nowLine);
|
---|
[4] | 45 | return;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | int NextValue=0;
|
---|
| 49 | while(1){
|
---|
| 50 | i++;
|
---|
| 51 |
|
---|
| 52 | if(buffer[i]==1&&buffer[i+1]==ESC_ENDENUM) break;
|
---|
| 53 |
|
---|
| 54 | for(i2=0;;i2++,i++){
|
---|
| 55 | if(IsCommandDelimitation(buffer[i])){
|
---|
| 56 | temporary[i2]=0;
|
---|
| 57 | break;
|
---|
| 58 | }
|
---|
| 59 | if(buffer[i]=='='){
|
---|
| 60 | temporary[i2]=0;
|
---|
| 61 | break;
|
---|
| 62 | }
|
---|
| 63 | temporary[i2]=buffer[i];
|
---|
| 64 | }
|
---|
| 65 | if(temporary[0]=='\0'){
|
---|
| 66 | if(buffer[i]=='\0'){
|
---|
[75] | 67 | SetError(22,"Enum",nowLine);
|
---|
[4] | 68 | break;
|
---|
| 69 | }
|
---|
| 70 | continue;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if(buffer[i]!='='){
|
---|
| 74 | NextValue++;
|
---|
| 75 | }
|
---|
| 76 | else{
|
---|
| 77 | char temp2[VN_SIZE];
|
---|
| 78 | for(i++,i2=0;;i2++,i++){
|
---|
| 79 | if(IsCommandDelimitation(buffer[i])){
|
---|
| 80 | temp2[i2]=0;
|
---|
| 81 | break;
|
---|
| 82 | }
|
---|
| 83 | temp2[i2]=buffer[i];
|
---|
| 84 | }
|
---|
| 85 | NextValue=atoi(temp2);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | //メンバを追加
|
---|
| 89 | ppobj_EnumMember=(CEnumMember **)HeapReAlloc(hHeap,0,ppobj_EnumMember,(iEnumMemberNum+1)*sizeof(CEnumMember *));
|
---|
| 90 | ppobj_EnumMember[iEnumMemberNum]=new CEnumMember(temporary,NextValue);
|
---|
| 91 | iEnumMemberNum++;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | CEnumParent::~CEnumParent(){
|
---|
| 95 | HeapDefaultFree(TypeName);
|
---|
| 96 |
|
---|
| 97 | int i;
|
---|
| 98 | for(i=0;i<iEnumMemberNum;i++){
|
---|
| 99 | delete ppobj_EnumMember[i];
|
---|
| 100 | }
|
---|
| 101 | HeapDefaultFree(ppobj_EnumMember);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | void CEnumParent::InitEnum(void){
|
---|
| 107 | ppobj_EnumParent=(CEnumParent **)HeapAlloc(hHeap,0,1);
|
---|
| 108 | iEnumParentNum=0;
|
---|
| 109 |
|
---|
| 110 | extern char *basbuf;
|
---|
| 111 | int i;
|
---|
| 112 | for(i=0;;i++){
|
---|
| 113 | if(basbuf[i]=='\0') break;
|
---|
| 114 |
|
---|
| 115 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENUM){
|
---|
| 116 | if(i>=2){
|
---|
| 117 | if(basbuf[i-2]==1&&basbuf[i-1]==ESC_CONST) continue;
|
---|
| 118 | }
|
---|
| 119 | ppobj_EnumParent=(CEnumParent **)HeapReAlloc(hHeap,0,ppobj_EnumParent,(iEnumParentNum+1)*sizeof(CEnumParent *));
|
---|
| 120 | ppobj_EnumParent[iEnumParentNum]=new CEnumParent(basbuf+i,i);
|
---|
| 121 | iEnumParentNum++;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | void CEnumParent::DestroyEnum(void){
|
---|
| 126 | int i;
|
---|
| 127 | for(i=0;i<iEnumParentNum;i++){
|
---|
| 128 | delete ppobj_EnumParent[i];
|
---|
| 129 | }
|
---|
| 130 | HeapDefaultFree(ppobj_EnumParent);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | char *CEnumParent::GenerateCodes(void){
|
---|
| 134 | int i,i2;
|
---|
| 135 |
|
---|
| 136 | char *buffer;
|
---|
| 137 | int MaxSize,length;
|
---|
| 138 | MaxSize=65535;
|
---|
| 139 | buffer=(char *)HeapAlloc(hHeap,0,MaxSize+65535);
|
---|
| 140 | length=0;
|
---|
| 141 |
|
---|
| 142 | buffer[0]=0;
|
---|
| 143 |
|
---|
| 144 | for(i=0;i<iEnumParentNum;i++){
|
---|
| 145 | CEnumParent *parent;
|
---|
| 146 | parent=ppobj_EnumParent[i];
|
---|
| 147 |
|
---|
| 148 | sprintf(buffer+length,"Class %s\n",parent->TypeName);
|
---|
| 149 | length+=lstrlen(buffer+length);
|
---|
| 150 | lstrcpy(buffer+length,"\tInherits EnumBase\n");
|
---|
| 151 | length+=lstrlen(buffer+length);
|
---|
| 152 | lstrcpy(buffer+length,"Public\n");
|
---|
| 153 | length+=lstrlen(buffer+length);
|
---|
| 154 | sprintf(buffer+length,"\tSub %s()\n",parent->TypeName);
|
---|
| 155 | length+=lstrlen(buffer+length);
|
---|
| 156 | if(parent->iEnumMemberNum){
|
---|
| 157 | sprintf(buffer+length,"\t\tEnumBase(%d)\n",
|
---|
| 158 | parent->ppobj_EnumMember[0]->m_value);
|
---|
| 159 | length+=lstrlen(buffer+length);
|
---|
| 160 | }
|
---|
| 161 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 162 | length+=lstrlen(buffer+length);
|
---|
[47] | 163 | sprintf(buffer+length,"\tSub %s(ByRef e As %s)\n",parent->TypeName,parent->TypeName);
|
---|
| 164 | length+=lstrlen(buffer+length);
|
---|
| 165 | lstrcpy(buffer+length,"\t\tEnumBase(e.m_Value)\n");
|
---|
| 166 | length+=lstrlen(buffer+length);
|
---|
| 167 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 168 | length+=lstrlen(buffer+length);
|
---|
[4] | 169 | sprintf(buffer+length,"\tSub %s(value As Long)\n",parent->TypeName);
|
---|
| 170 | length+=lstrlen(buffer+length);
|
---|
| 171 | lstrcpy(buffer+length,"\t\tEnumBase(value)\n");
|
---|
| 172 | length+=lstrlen(buffer+length);
|
---|
| 173 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 174 | length+=lstrlen(buffer+length);
|
---|
| 175 | sprintf(buffer+length,"\tSub ~%s()\n",parent->TypeName);
|
---|
| 176 | length+=lstrlen(buffer+length);
|
---|
| 177 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 178 | length+=lstrlen(buffer+length);
|
---|
| 179 |
|
---|
| 180 | for(i2=0;i2<parent->iEnumMemberNum;i2++){
|
---|
| 181 | CEnumMember *member;
|
---|
| 182 | member=parent->ppobj_EnumMember[i2];
|
---|
| 183 |
|
---|
| 184 | sprintf(buffer+length,"\tStatic %s As %s(%d)\n",
|
---|
| 185 | member->m_name,
|
---|
| 186 | parent->TypeName,
|
---|
| 187 | member->m_value);
|
---|
| 188 | length+=lstrlen(buffer+length);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[29] | 191 | sprintf(buffer+length,"\tOverride Function ToString() As String\n",parent->TypeName);
|
---|
[4] | 192 | length+=lstrlen(buffer+length);
|
---|
| 193 | lstrcpy(buffer+length,"\t\tSelect Case m_Value\n");
|
---|
| 194 | length+=lstrlen(buffer+length);
|
---|
| 195 | for(i2=0;i2<parent->iEnumMemberNum;i2++){
|
---|
| 196 | CEnumMember *member;
|
---|
| 197 | member=parent->ppobj_EnumMember[i2];
|
---|
| 198 |
|
---|
| 199 | sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);
|
---|
| 200 | length+=lstrlen(buffer+length);
|
---|
| 201 | sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name);
|
---|
| 202 | length+=lstrlen(buffer+length);
|
---|
| 203 | }
|
---|
| 204 | lstrcpy(buffer+length,"\t\tEnd Select\n");
|
---|
| 205 | length+=lstrlen(buffer+length);
|
---|
| 206 | lstrcpy(buffer+length,"\tEnd Function\n");
|
---|
| 207 | length+=lstrlen(buffer+length);
|
---|
| 208 |
|
---|
| 209 | sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName);
|
---|
| 210 | length+=lstrlen(buffer+length);
|
---|
| 211 | lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");
|
---|
| 212 | length+=lstrlen(buffer+length);
|
---|
| 213 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 214 | length+=lstrlen(buffer+length);
|
---|
| 215 |
|
---|
| 216 | /*sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName);
|
---|
| 217 | length+=lstrlen(buffer+length);
|
---|
| 218 | lstrcpy(buffer+length,"\t\tSelect Case value\n");
|
---|
| 219 | length+=lstrlen(buffer+length);
|
---|
| 220 | for(i2=0;i2<parent->iEnumMemberNum;i2++){
|
---|
| 221 | CEnumMember *member;
|
---|
| 222 | member=parent->ppobj_EnumMember[i2];
|
---|
| 223 |
|
---|
| 224 | sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);
|
---|
| 225 | length+=lstrlen(buffer+length);
|
---|
| 226 | sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name);
|
---|
| 227 | length+=lstrlen(buffer+length);
|
---|
| 228 | }
|
---|
| 229 | lstrcpy(buffer+length,"\t\tEnd Select\n");
|
---|
| 230 | length+=lstrlen(buffer+length);
|
---|
| 231 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 232 | length+=lstrlen(buffer+length);*/
|
---|
| 233 |
|
---|
| 234 | sprintf(buffer+length,"\tSub Operator= (value As Long)\n",parent->TypeName);
|
---|
| 235 | length+=lstrlen(buffer+length);
|
---|
| 236 | lstrcpy(buffer+length,"\t\tm_Value=value\n");
|
---|
| 237 | length+=lstrlen(buffer+length);
|
---|
| 238 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 239 | length+=lstrlen(buffer+length);
|
---|
| 240 |
|
---|
[47] | 241 | sprintf(buffer+length,"\tFunction Operator== (ByRef e As %s) As Boolean\n",parent->TypeName);
|
---|
| 242 | length+=lstrlen(buffer+length);
|
---|
| 243 | lstrcpy(buffer+length,"\t\tReturn ( e.m_Value = m_Value )\n");
|
---|
| 244 | length+=lstrlen(buffer+length);
|
---|
| 245 | lstrcpy(buffer+length,"\tEnd Function\n");
|
---|
| 246 | length+=lstrlen(buffer+length);
|
---|
| 247 |
|
---|
[4] | 248 | lstrcpy(buffer+length,"End Class\n");
|
---|
| 249 | length+=lstrlen(buffer+length);
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 | //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
| 253 | if(length>MaxSize){
|
---|
| 254 | MaxSize+=65535;
|
---|
| 255 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,MaxSize+65535);
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | return buffer;
|
---|
| 260 | }
|
---|