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