[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 |
|
---|
| 17 | CEnumParent::CEnumParent(char *buffer,int NowLine){
|
---|
| 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'){
|
---|
| 44 | SetError(22,"Enum",NowLine);
|
---|
| 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'){
|
---|
| 67 | SetError(22,"Enum",NowLine);
|
---|
| 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);
|
---|
| 163 | sprintf(buffer+length,"\tSub %s(value As Long)\n",parent->TypeName);
|
---|
| 164 | length+=lstrlen(buffer+length);
|
---|
| 165 | lstrcpy(buffer+length,"\t\tEnumBase(value)\n");
|
---|
| 166 | length+=lstrlen(buffer+length);
|
---|
| 167 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 168 | length+=lstrlen(buffer+length);
|
---|
| 169 | sprintf(buffer+length,"\tSub ~%s()\n",parent->TypeName);
|
---|
| 170 | length+=lstrlen(buffer+length);
|
---|
| 171 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 172 | length+=lstrlen(buffer+length);
|
---|
| 173 |
|
---|
| 174 | for(i2=0;i2<parent->iEnumMemberNum;i2++){
|
---|
| 175 | CEnumMember *member;
|
---|
| 176 | member=parent->ppobj_EnumMember[i2];
|
---|
| 177 |
|
---|
| 178 | sprintf(buffer+length,"\tStatic %s As %s(%d)\n",
|
---|
| 179 | member->m_name,
|
---|
| 180 | parent->TypeName,
|
---|
| 181 | member->m_value);
|
---|
| 182 | length+=lstrlen(buffer+length);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | sprintf(buffer+length,"\tFunction ToString() As String\n",parent->TypeName);
|
---|
| 186 | length+=lstrlen(buffer+length);
|
---|
| 187 | lstrcpy(buffer+length,"\t\tSelect Case m_Value\n");
|
---|
| 188 | length+=lstrlen(buffer+length);
|
---|
| 189 | for(i2=0;i2<parent->iEnumMemberNum;i2++){
|
---|
| 190 | CEnumMember *member;
|
---|
| 191 | member=parent->ppobj_EnumMember[i2];
|
---|
| 192 |
|
---|
| 193 | sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);
|
---|
| 194 | length+=lstrlen(buffer+length);
|
---|
| 195 | sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name);
|
---|
| 196 | length+=lstrlen(buffer+length);
|
---|
| 197 | }
|
---|
| 198 | lstrcpy(buffer+length,"\t\tEnd Select\n");
|
---|
| 199 | length+=lstrlen(buffer+length);
|
---|
| 200 | lstrcpy(buffer+length,"\tEnd Function\n");
|
---|
| 201 | length+=lstrlen(buffer+length);
|
---|
| 202 |
|
---|
| 203 | sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName);
|
---|
| 204 | length+=lstrlen(buffer+length);
|
---|
| 205 | lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");
|
---|
| 206 | length+=lstrlen(buffer+length);
|
---|
| 207 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 208 | length+=lstrlen(buffer+length);
|
---|
| 209 |
|
---|
| 210 | /*sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName);
|
---|
| 211 | length+=lstrlen(buffer+length);
|
---|
| 212 | lstrcpy(buffer+length,"\t\tSelect Case value\n");
|
---|
| 213 | length+=lstrlen(buffer+length);
|
---|
| 214 | for(i2=0;i2<parent->iEnumMemberNum;i2++){
|
---|
| 215 | CEnumMember *member;
|
---|
| 216 | member=parent->ppobj_EnumMember[i2];
|
---|
| 217 |
|
---|
| 218 | sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);
|
---|
| 219 | length+=lstrlen(buffer+length);
|
---|
| 220 | sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name);
|
---|
| 221 | length+=lstrlen(buffer+length);
|
---|
| 222 | }
|
---|
| 223 | lstrcpy(buffer+length,"\t\tEnd Select\n");
|
---|
| 224 | length+=lstrlen(buffer+length);
|
---|
| 225 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 226 | length+=lstrlen(buffer+length);*/
|
---|
| 227 |
|
---|
| 228 | sprintf(buffer+length,"\tSub Operator= (value As Long)\n",parent->TypeName);
|
---|
| 229 | length+=lstrlen(buffer+length);
|
---|
| 230 | lstrcpy(buffer+length,"\t\tm_Value=value\n");
|
---|
| 231 | length+=lstrlen(buffer+length);
|
---|
| 232 | lstrcpy(buffer+length,"\tEnd Sub\n");
|
---|
| 233 | length+=lstrlen(buffer+length);
|
---|
| 234 |
|
---|
| 235 | lstrcpy(buffer+length,"End Class\n");
|
---|
| 236 | length+=lstrlen(buffer+length);
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
| 240 | if(length>MaxSize){
|
---|
| 241 | MaxSize+=65535;
|
---|
| 242 | buffer=(char *)HeapReAlloc(hHeap,0,buffer,MaxSize+65535);
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | return buffer;
|
---|
| 247 | }
|
---|