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