Changeset 103 in dev for BasicCompiler_Common/Enum.cpp
- Timestamp:
- May 2, 2007, 4:08:58 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Enum.cpp
r92 r103 15 15 16 16 17 CEnumParent::CEnumParent(const char *buffer,int nowLine){ 17 CEnumParent::CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine) 18 : namespaceScopes( namespaceScopes ) 19 { 18 20 ppobj_EnumMember=(CEnumMember **)HeapAlloc(hHeap,0,1); 19 21 iEnumMemberNum=0; … … 38 40 } 39 41 40 TypeName=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 41 lstrcpy(TypeName,temporary); 42 name = temporary; 42 43 43 44 if(buffer[i]=='\0'){ … … 93 94 } 94 95 CEnumParent::~CEnumParent(){ 95 HeapDefaultFree(TypeName);96 97 96 int i; 98 97 for(i=0;i<iEnumMemberNum;i++){ … … 110 109 const char *source = Smoothie::Lexical::source.GetBuffer(); 111 110 112 int i; 113 for(i=0;;i++){ 111 // 名前空間管理 112 NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes; 113 namespaceScopes.clear(); 114 115 int i2; 116 char temporary[VN_SIZE]; 117 for(int i=0;;i++){ 114 118 if(source[i]=='\0') break; 119 120 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 121 for(i+=2,i2=0;;i2++,i++){ 122 if( IsCommandDelimitation( source[i] ) ){ 123 temporary[i2]=0; 124 break; 125 } 126 temporary[i2]=source[i]; 127 } 128 namespaceScopes.push_back( temporary ); 129 130 continue; 131 } 132 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){ 133 if( namespaceScopes.size() <= 0 ){ 134 SetError(12, "End Namespace", i ); 135 } 136 else{ 137 namespaceScopes.pop_back(); 138 } 139 140 i += 2; 141 continue; 142 } 115 143 116 144 if(source[i]==1&&source[i+1]==ESC_ENUM){ … … 119 147 } 120 148 ppobj_EnumParent=(CEnumParent **)HeapReAlloc(hHeap,0,ppobj_EnumParent,(iEnumParentNum+1)*sizeof(CEnumParent *)); 121 ppobj_EnumParent[iEnumParentNum]=new CEnumParent( source+i,i);149 ppobj_EnumParent[iEnumParentNum]=new CEnumParent( namespaceScopes, source+i,i); 122 150 iEnumParentNum++; 123 151 } … … 133 161 134 162 char *CEnumParent::GenerateCodes(void){ 135 int i,i2;136 137 163 char *buffer; 138 164 int MaxSize,length; … … 143 169 buffer[0]=0; 144 170 145 for(i =0;i<iEnumParentNum;i++){171 for(int i=0;i<iEnumParentNum;i++){ 146 172 CEnumParent *parent; 147 173 parent=ppobj_EnumParent[i]; 148 174 149 sprintf(buffer+length,"Class Enum %s\n",parent->TypeName); 175 BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){ 176 sprintf(buffer+length,"Namespace %s\n",namespaceStr.c_str()); 177 length+=lstrlen(buffer+length); 178 } 179 180 sprintf(buffer+length,"Class Enum %s\n",parent->GetName().c_str()); 150 181 length+=lstrlen(buffer+length); 151 182 lstrcpy(buffer+length,"\tInherits EnumBase\n"); 152 183 length+=lstrlen(buffer+length); 153 sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",parent-> TypeName);184 sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",parent->GetName().c_str()); 154 185 length+=lstrlen(buffer+length); 155 186 lstrcpy(buffer+length,"\t\tEnumBase(value,lpszName)\n"); … … 159 190 lstrcpy(buffer+length,"Public\n"); 160 191 length+=lstrlen(buffer+length); 161 sprintf(buffer+length,"\tSub %s()\n",parent-> TypeName);192 sprintf(buffer+length,"\tSub %s()\n",parent->GetName().c_str()); 162 193 length+=lstrlen(buffer+length); 163 194 if(parent->iEnumMemberNum){ … … 169 200 lstrcpy(buffer+length,"\tEnd Sub\n"); 170 201 length+=lstrlen(buffer+length); 171 sprintf(buffer+length,"\tSub ~%s()\n",parent->TypeName); 172 length+=lstrlen(buffer+length); 173 lstrcpy(buffer+length,"\tEnd Sub\n"); 174 length+=lstrlen(buffer+length); 175 202 sprintf(buffer+length,"\tSub ~%s()\n",parent->GetName().c_str()); 203 length+=lstrlen(buffer+length); 204 lstrcpy(buffer+length,"\tEnd Sub\n"); 205 length+=lstrlen(buffer+length); 206 207 for(int i2=0;i2<parent->iEnumMemberNum;i2++){ 208 CEnumMember *member; 209 member=parent->ppobj_EnumMember[i2]; 210 211 sprintf(buffer+length,"\tStatic %s As %s(%d,\"%s\")\n", 212 member->m_name, 213 parent->GetName().c_str(), 214 member->m_value, 215 member->m_name); 216 length+=lstrlen(buffer+length); 217 } 218 219 /* 220 sprintf(buffer+length,"\tOverride Function ToString() As String\n",parent->TypeName); 221 length+=lstrlen(buffer+length); 222 lstrcpy(buffer+length,"\t\tSelect Case value\n"); 223 length+=lstrlen(buffer+length); 176 224 for(i2=0;i2<parent->iEnumMemberNum;i2++){ 177 225 CEnumMember *member; 178 226 member=parent->ppobj_EnumMember[i2]; 179 227 180 sprintf(buffer+length,"\tStatic %s As %s(%d,\"%s\")\n", 181 member->m_name, 182 parent->TypeName, 183 member->m_value, 184 member->m_name); 185 length+=lstrlen(buffer+length); 186 } 187 188 /* 189 sprintf(buffer+length,"\tOverride Function ToString() As String\n",parent->TypeName); 228 sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value); 229 length+=lstrlen(buffer+length); 230 sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name); 231 length+=lstrlen(buffer+length); 232 } 233 lstrcpy(buffer+length,"\t\tEnd Select\n"); 234 length+=lstrlen(buffer+length); 235 lstrcpy(buffer+length,"\tEnd Function\n"); 236 length+=lstrlen(buffer+length); 237 238 239 sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName); 240 length+=lstrlen(buffer+length); 241 lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n"); 242 length+=lstrlen(buffer+length); 243 lstrcpy(buffer+length,"\tEnd Sub\n"); 244 length+=lstrlen(buffer+length); 245 246 sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName); 190 247 length+=lstrlen(buffer+length); 191 248 lstrcpy(buffer+length,"\t\tSelect Case value\n"); … … 195 252 member=parent->ppobj_EnumMember[i2]; 196 253 197 sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);198 length+=lstrlen(buffer+length); 199 sprintf(buffer+length,"\t\t\t\t Return \"%s\"\n",member->m_name);254 sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name); 255 length+=lstrlen(buffer+length); 256 sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name); 200 257 length+=lstrlen(buffer+length); 201 258 } 202 259 lstrcpy(buffer+length,"\t\tEnd Select\n"); 203 260 length+=lstrlen(buffer+length); 204 lstrcpy(buffer+length,"\tEnd Function\n");205 length+=lstrlen(buffer+length);206 207 208 sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName);209 length+=lstrlen(buffer+length);210 lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");211 length+=lstrlen(buffer+length);212 lstrcpy(buffer+length,"\tEnd Sub\n");213 length+=lstrlen(buffer+length);214 215 sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName);216 length+=lstrlen(buffer+length);217 lstrcpy(buffer+length,"\t\tSelect Case value\n");218 length+=lstrlen(buffer+length);219 for(i2=0;i2<parent->iEnumMemberNum;i2++){220 CEnumMember *member;221 member=parent->ppobj_EnumMember[i2];222 223 sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);224 length+=lstrlen(buffer+length);225 sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name);226 length+=lstrlen(buffer+length);227 }228 lstrcpy(buffer+length,"\t\tEnd Select\n");229 length+=lstrlen(buffer+length);230 261 lstrcpy(buffer+length,"\tEnd Sub\n"); 231 262 length+=lstrlen(buffer+length); … … 240 271 lstrcpy(buffer+length,"End Class\n"); 241 272 length+=lstrlen(buffer+length); 273 274 BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){ 275 lstrcpy( buffer+length, "End Namespace\n" ); 276 length+=lstrlen(buffer+length); 277 } 242 278 243 279
Note:
See TracChangeset
for help on using the changeset viewer.