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