Index: trunk/abdev/BasicCompiler_Common/Enum.cpp
===================================================================
--- trunk/abdev/BasicCompiler_Common/Enum.cpp	(revision 402)
+++ trunk/abdev/BasicCompiler_Common/Enum.cpp	(revision 406)
@@ -8,25 +8,9 @@
 #include "common.h"
 
-CEnumParent **ppobj_EnumParent;
-int iEnumParentNum;
-
-CEnumMember::CEnumMember(char *name,int value){
-	m_name=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1);
-	lstrcpy(m_name,name);
-
-	m_value=value;
-}
-CEnumMember::~CEnumMember(){
-	if(m_name) HeapDefaultFree(m_name);
-}
-
-
-CEnumParent::CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine)
-	: namespaceScopes( namespaceScopes )
+void EnumInfo::Collect( const char *buffer,int nowLine)
 {
-	ppobj_EnumMember=(CEnumMember **)HeapAlloc(hHeap,0,1);
-	iEnumMemberNum=0;
-
-	int i=0,i2;
+	this->members.clear();
+
+	int i=nowLine,i2;
 
 	if(!(buffer[i]==1&&buffer[i+1]==ESC_ENUM)) return;
@@ -47,6 +31,4 @@
 	}
 
-	name = temporary;
-
 	if(buffer[i]=='\0'){
 		SetError(22,"Enum",nowLine);
@@ -54,5 +36,9 @@
 	}
 
-	int NextValue=0;
+	int currentValue = 0;
+	bool isUseCurrentValue = true;
+	std::string currentValueStr;
+	std::string lastMemberName;
+	char temp2[VN_SIZE];
 	while(1){
 		i++;
@@ -79,38 +65,51 @@
 		}
 
-		if(buffer[i]!='='){
-			NextValue++;
-		}
-		else{
-			char temp2[VN_SIZE];
-			for(i++,i2=0;;i2++,i++){
-				if(IsCommandDelimitation(buffer[i])){
-					temp2[i2]=0;
-					break;
-				}
-				temp2[i2]=buffer[i];
-			}
-			NextValue=atoi(temp2);
+		if( buffer[i] != '=' )
+		{
+			if( isUseCurrentValue )
+			{
+				currentValue++;
+
+				sprintf( temp2, "%d", currentValue );
+				currentValueStr = temp2;
+			}
+			else
+			{
+				currentValueStr = lastMemberName + "+1";
+			}
+		}
+		else
+		{
+			i++;
+			GetCommandToken( temp2, buffer, i );
+
+			_int64 i64data;
+			if( StaticCalculation( false, temp2, 0, &i64data, Type() ) )
+			{
+				currentValue = static_cast<int>(i64data);
+
+				sprintf( temp2, "%d", currentValue );
+				currentValueStr = temp2;
+			}
+			else
+			{
+				// 取得できなかった（なんらかの識別子を含む可能性あり）
+				isUseCurrentValue = false;
+
+				currentValueStr = temp2;
+			}
 		}
 
 		//メンバを追加
-		ppobj_EnumMember=(CEnumMember **)HeapReAlloc(hHeap,0,ppobj_EnumMember,(iEnumMemberNum+1)*sizeof(CEnumMember *));
-		ppobj_EnumMember[iEnumMemberNum]=new CEnumMember(temporary,NextValue);
-		iEnumMemberNum++;
+		this->members.push_back( EnumMember( temporary, currentValueStr, i ) );
+
+		lastMemberName = temporary;
 	}
 }
-CEnumParent::~CEnumParent(){
-	int i;
-	for(i=0;i<iEnumMemberNum;i++){
-		delete ppobj_EnumMember[i];
-	}
-	HeapDefaultFree(ppobj_EnumMember);
-}
-
-
-
-void CEnumParent::InitEnum(void){
-	ppobj_EnumParent=(CEnumParent **)HeapAlloc(hHeap,0,1);
-	iEnumParentNum=0;
+
+
+void EnumInfoCollection::InitEnum(void)
+{
+	this->clear();
 
 	const char *source = compiler.GetObjectModule().GetCurrentSource().GetBuffer();
@@ -153,19 +152,18 @@
 				if(source[i-2]==1&&source[i-1]==ESC_CONST) continue;
 			}
-			ppobj_EnumParent=(CEnumParent **)HeapReAlloc(hHeap,0,ppobj_EnumParent,(iEnumParentNum+1)*sizeof(CEnumParent *));
-			ppobj_EnumParent[iEnumParentNum]=new CEnumParent( namespaceScopes, source+i,i);
-			iEnumParentNum++;
+
+			i2 = i + 2;
+			GetCommandToken( temporary, source, i2 );
+
+			// 追加
+			this->push_back( EnumInfo( namespaceScopes, temporary ) );
+
+			// 収集
+			this->back().Collect( source, i );
 		}
 	}
 }
-void CEnumParent::DestroyEnum(void){
-	int i;
-	for(i=0;i<iEnumParentNum;i++){
-		delete ppobj_EnumParent[i];
-	}
-	HeapDefaultFree(ppobj_EnumParent);
-}
-
-char *CEnumParent::GenerateSourceCode(void){
+
+char *EnumInfoCollection::GenerateSourceCode(void){
 	char *buffer;
 	int MaxSize,length;
@@ -176,18 +174,17 @@
 	buffer[0]=0;
 
-	for(int i=0;i<iEnumParentNum;i++){
-		CEnumParent *parent;
-		parent=ppobj_EnumParent[i];
-
-		BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){
+	const EnumInfoCollection &thisEnumInfoCollection = *this;
+	BOOST_FOREACH( const EnumInfo &enumInfo, thisEnumInfoCollection )
+	{
+		BOOST_FOREACH( const string &namespaceStr, enumInfo.GetNamespaceScopes() ){
 			sprintf(buffer+length,"Namespace %s\n",namespaceStr.c_str());
 			length+=lstrlen(buffer+length);
 		}
 
-		sprintf(buffer+length,"Class Enum %s\n",parent->GetName().c_str());
+		sprintf(buffer+length,"Class Enum %s\n",enumInfo.GetName().c_str());
 		length+=lstrlen(buffer+length);
 		lstrcpy(buffer+length,"\tInherits EnumBase\n");
 		length+=lstrlen(buffer+length);
-		sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",parent->GetName().c_str());
+		sprintf(buffer+length,"\tSub %s(value As Long,lpszName As LPSTR)\n",enumInfo.GetName().c_str());
 		length+=lstrlen(buffer+length);
 		lstrcpy(buffer+length,"\t\tEnumBase(value,lpszName)\n");
@@ -197,91 +194,88 @@
 		lstrcpy(buffer+length,"Public\n");
 		length+=lstrlen(buffer+length);
-		sprintf(buffer+length,"\tSub %s()\n",parent->GetName().c_str());
-		length+=lstrlen(buffer+length);
-		if(parent->iEnumMemberNum){
-			sprintf(buffer+length,"\t\tEnumBase(%d,\"%s\")\n",
-				parent->ppobj_EnumMember[0]->m_value,
-				parent->ppobj_EnumMember[0]->m_name);
-			length+=lstrlen(buffer+length);
-		}
-		lstrcpy(buffer+length,"\tEnd Sub\n");
-		length+=lstrlen(buffer+length);
-		sprintf(buffer+length,"\tSub ~%s()\n",parent->GetName().c_str());
-		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\tEnd Sub\n");
-		length+=lstrlen(buffer+length);
-
-		for(int i2=0;i2<parent->iEnumMemberNum;i2++){
+		sprintf(buffer+length,"\tSub %s()\n",enumInfo.GetName().c_str());
+		length+=lstrlen(buffer+length);
+		if( enumInfo.GetMembers().size()){
+			sprintf(buffer+length,"\t\tEnumBase(%s)\n",
+				enumInfo.GetMembers().begin()->GetName().c_str() );
+			length+=lstrlen(buffer+length);
+		}
+		lstrcpy(buffer+length,"\tEnd Sub\n");
+		length+=lstrlen(buffer+length);
+		sprintf(buffer+length,"\tSub ~%s()\n",enumInfo.GetName().c_str());
+		length+=lstrlen(buffer+length);
+		lstrcpy(buffer+length,"\tEnd Sub\n");
+		length+=lstrlen(buffer+length);
+
+		BOOST_FOREACH( const EnumMember &member, enumInfo.GetMembers() )
+		{
+			sprintf(buffer+length,"\tStatic %s As %s((%s) As Long,\"%s\")\n",
+				member.GetName().c_str(),
+				enumInfo.GetName().c_str(),
+				member.GetValueStr().c_str(),
+				member.GetName().c_str());
+			length+=lstrlen(buffer+length);
+		}
+
+		sprintf(buffer+length,"\tFunction Operator or (enumBase As %s) As %s\n",enumInfo.GetName().c_str(),enumInfo.GetName().c_str());
+		length+=lstrlen(buffer+length);
+		sprintf(buffer+length,"\t\tReturn New %s(This.value or enumBase.value, \"custom\")\n",enumInfo.GetName().c_str());
+		length+=lstrlen(buffer+length);
+		lstrcpy(buffer+length,"\tEnd Function\n");
+		length+=lstrlen(buffer+length);
+
+		sprintf(buffer+length,"\tFunction Operator and (enumBase As %s) As %s\n",enumInfo.GetName().c_str(),enumInfo.GetName().c_str());
+		length+=lstrlen(buffer+length);
+		sprintf(buffer+length,"\t\tReturn New %s(This.value and enumBase.value, \"custom\")\n",enumInfo.GetName().c_str());
+		length+=lstrlen(buffer+length);
+		lstrcpy(buffer+length,"\tEnd Function\n");
+		length+=lstrlen(buffer+length);
+
+		/*
+		sprintf(buffer+length,"\tOverride Function ToString() As String\n",enumInfo.TypeName);
+		length+=lstrlen(buffer+length);
+		lstrcpy(buffer+length,"\t\tSelect Case value\n");
+		length+=lstrlen(buffer+length);
+		for(i2=0;i2<enumInfo.iEnumMemberNum;i2++){
 			CEnumMember *member;
-			member=parent->ppobj_EnumMember[i2];
-
-			sprintf(buffer+length,"\tStatic %s As %s(%d,\"%s\")\n",
-				member->m_name,
-				parent->GetName().c_str(),
-				member->m_value,
-				member->m_name);
-			length+=lstrlen(buffer+length);
-		}
-
-		sprintf(buffer+length,"\tFunction Operator or (enumBase As %s) As %s\n",parent->GetName().c_str(),parent->GetName().c_str());
-		length+=lstrlen(buffer+length);
-		sprintf(buffer+length,"\t\tReturn New %s(This.value or enumBase.value, \"custom\")\n",parent->GetName().c_str());
+			member=enumInfo.ppobj_EnumMember[i2];
+
+			sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);
+			length+=lstrlen(buffer+length);
+			sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name);
+			length+=lstrlen(buffer+length);
+		}
+		lstrcpy(buffer+length,"\t\tEnd Select\n");
 		length+=lstrlen(buffer+length);
 		lstrcpy(buffer+length,"\tEnd Function\n");
 		length+=lstrlen(buffer+length);
 
-		sprintf(buffer+length,"\tFunction Operator and (enumBase As %s) As %s\n",parent->GetName().c_str(),parent->GetName().c_str());
-		length+=lstrlen(buffer+length);
-		sprintf(buffer+length,"\t\tReturn New %s(This.value and enumBase.value, \"custom\")\n",parent->GetName().c_str());
-		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\tEnd Function\n");
-		length+=lstrlen(buffer+length);
-
-		/*
-		sprintf(buffer+length,"\tOverride Function ToString() As String\n",parent->TypeName);
+		
+		sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",enumInfo.TypeName);
+		length+=lstrlen(buffer+length);
+		lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");
+		length+=lstrlen(buffer+length);
+		lstrcpy(buffer+length,"\tEnd Sub\n");
+		length+=lstrlen(buffer+length);
+
+		sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",enumInfo.TypeName);
 		length+=lstrlen(buffer+length);
 		lstrcpy(buffer+length,"\t\tSelect Case value\n");
 		length+=lstrlen(buffer+length);
-		for(i2=0;i2<parent->iEnumMemberNum;i2++){
+		for(i2=0;i2<enumInfo.iEnumMemberNum;i2++){
 			CEnumMember *member;
-			member=parent->ppobj_EnumMember[i2];
-
-			sprintf(buffer+length,"\t\t\tCase %d\n",member->m_value);
-			length+=lstrlen(buffer+length);
-			sprintf(buffer+length,"\t\t\t\tReturn \"%s\"\n",member->m_name);
+			member=enumInfo.ppobj_EnumMember[i2];
+
+			sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);
+			length+=lstrlen(buffer+length);
+			sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",enumInfo.TypeName,member->m_name);
 			length+=lstrlen(buffer+length);
 		}
 		lstrcpy(buffer+length,"\t\tEnd Select\n");
 		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\tEnd Function\n");
-		length+=lstrlen(buffer+length);
-
-		
-		sprintf(buffer+length,"\tSub Operator= (ByRef value As %s)\n",parent->TypeName);
-		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\t\tThis.Copy(ByVal VarPtr(value))\n");
-		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\tEnd Sub\n");
-		length+=lstrlen(buffer+length);
-
-		sprintf(buffer+length,"\tSub Operator= (ByRef value As String)\n",parent->TypeName);
-		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\t\tSelect Case value\n");
-		length+=lstrlen(buffer+length);
-		for(i2=0;i2<parent->iEnumMemberNum;i2++){
-			CEnumMember *member;
-			member=parent->ppobj_EnumMember[i2];
-
-			sprintf(buffer+length,"\t\t\tCase \"%s\"\n",member->m_name);
-			length+=lstrlen(buffer+length);
-			sprintf(buffer+length,"\t\t\t\tThis=%s.%s\n",parent->TypeName,member->m_name);
-			length+=lstrlen(buffer+length);
-		}
-		lstrcpy(buffer+length,"\t\tEnd Select\n");
-		length+=lstrlen(buffer+length);
-		lstrcpy(buffer+length,"\tEnd Sub\n");
-		length+=lstrlen(buffer+length);
-
-		sprintf(buffer+length,"\tSub Operator= (value As Long)\n",parent->TypeName);
+		lstrcpy(buffer+length,"\tEnd Sub\n");
+		length+=lstrlen(buffer+length);
+
+		sprintf(buffer+length,"\tSub Operator= (value As Long)\n",enumInfo.TypeName);
 		length+=lstrlen(buffer+length);
 		lstrcpy(buffer+length,"\t\tm_Value=value\n");
@@ -293,5 +287,5 @@
 		length+=lstrlen(buffer+length);
 
-		BOOST_FOREACH( const string &namespaceStr, parent->GetNamespaceScopes() ){
+		BOOST_FOREACH( const string &namespaceStr, enumInfo.GetNamespaceScopes() ){
 			lstrcpy( buffer+length, "End Namespace\n" );
 			length+=lstrlen(buffer+length);
