Index: branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp
===================================================================
--- branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp	(revision 803)
+++ branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp	(revision 814)
@@ -85,5 +85,4 @@
 
 	int i2;
-	char temporary[1024];
 
 	// 名前空間管理
@@ -91,16 +90,16 @@
 	namespaceScopes.clear();
 
-	for(int i=0;;i++){
+	for (int i = 0; ; ++i)
+	{
 		if( source[i] == '\0' ) break;
 
 		if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-			namespaceScopes.push_back( temporary );
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
+			}
+			namespaceScopes.push_back(std::string(p, &source[i]));
 
 			continue;
@@ -131,9 +130,10 @@
 				}
 
+				char const* beginTemp = &source[i];
+				char const* endTemp = &source[i];
+
 				for(i2=0;;i++,i2++){
 					if(source[i]=='\"'){
-						temporary[i2]=source[i];
 						for(i++,i2++;;i++,i2++){
-							temporary[i2]=source[i];
 							if(source[i]=='\"') break;
 						}
@@ -141,23 +141,22 @@
 					}
 					if(IsCommandDelimitation(source[i])){
-						temporary[i2]=0;
+						endTemp = beginTemp + i2;
 						break;
 					}
-					temporary[i2]=source[i];
 				}
 
 				//名前を取得
-				char name[VN_SIZE];
+				char const* nameEnd;
 				for(i2=0;;i2++){
-					if(temporary[i2]=='\0'){
+					if(beginTemp[i2]=='\0'){
 						compiler.errorMessenger.Output(10,"Const",cp);
 						return;
 					}
-					if(temporary[i2]=='='||temporary[i2]=='('){
-						name[i2]=0;
+					if(beginTemp[i2]=='='||beginTemp[i2]=='('){
+						nameEnd = beginTemp + i2;
 						break;
 					}
-					name[i2]=temporary[i2];
-				}
+				}
+				std::string name(beginTemp, nameEnd);
 
 				//重複チェック
@@ -165,16 +164,16 @@
 					|| compiler.GetObjectModule().meta.GetGlobalConsts().IsExistDuplicationKeyName( name ) )
 				{
-					compiler.errorMessenger.Output(15,name,cp);
+					compiler.errorMessenger.Output(15, name, cp);
 					return;
 				}
 
-				if( temporary[i2] == '=' )
+				if( beginTemp[i2] == '=' )
 				{
 					// 定数
-					const char *expression = temporary + i2 + 1;
+					std::string expression(beginTemp + i2 + 1, endTemp);
 
 					_int64 i64data;
 					Type resultType;
-					if( StaticCalculation(false, expression, 0, &i64data, resultType) )
+					if( StaticCalculation(false, expression.c_str(), 0, &i64data, resultType) )
 					{
 						consts.Add( Symbol( namespaceScopes, name ), i64data, resultType );
@@ -184,6 +183,6 @@
 				{
 					// 定数マクロ
-					const char *params = temporary + i2;
-					if( !constMacros.Add( Symbol( namespaceScopes, name ), params ) )
+					std::string params(beginTemp + i2, endTemp);
+					if( !constMacros.Add( Symbol( namespaceScopes, name ), params.c_str() ) )
 					{
 						compiler.errorMessenger.Output( 1, NULL, i );
@@ -208,31 +207,34 @@
 }
 
-bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest )
-{
-	extern HANDLE hHeap;
-	int i2,i3,i4,num;
+bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest, std::size_t destSize )
+{
+	std::string s;
+	auto ret = ConstMacroToExpression(constMacro, parameterStr, s);
+	strcpy_s(dest, destSize, s.c_str());
+	return ret;
+}
+
+bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, std::string& dest )
+{
+	int i2,i3;
 	char temporary[VN_SIZE];
-	char *pParms[MAX_PARMS];
-	num=0;
+	std::vector<std::string> Parms;
+	dest.reserve(8192);
 	i2=0;
 	while(1){
 		i2=GetOneParameter(parameterStr,i2,temporary);
 
-		pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
-		lstrcpy(pParms[num],temporary);
-
-		num++;
+		Parms.push_back(temporary);
+
 		if(parameterStr[i2]=='\0') break;
 	}
-	if( num != constMacro.GetParameters().size() ){
+	if( Parms.size() != constMacro.GetParameters().size() ){
 		extern int cp;
-		for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
 		compiler.errorMessenger.Output(10,constMacro.GetName().c_str(),cp);
-		lstrcpy(dest,"0");
+		dest = '0';
 		return true;
 	}
 
 	i2=0;
-	i4=0;
 	while(1){
 
@@ -253,22 +255,20 @@
 		if( i3 == (int)constMacro.GetParameters().size() ){
 			//パラメータでないとき
-			lstrcpy(dest+i4,temporary);
-			i4+=lstrlen(temporary);
+			dest += temporary;
 		}
 		else{
 			//パラメータのとき
-			lstrcpy(dest+i4,pParms[i3]);
-			i4+=lstrlen(pParms[i3]);
+			dest += Parms[i3];
 		}
 
 		//演算子をコピー
-		for(;;i2++,i4++){
+		for(;;i2++){
 			if( constMacro.GetExpression()[i2] == 1 ){
-				dest[i4++] = constMacro.GetExpression()[i2++];
-				dest[i4] = constMacro.GetExpression()[i2];
+				dest += constMacro.GetExpression()[i2++];
+				dest += constMacro.GetExpression()[i2];
 				continue;
 			}
 			if(IsVariableTopChar( constMacro.GetExpression()[i2] )) break;
-			dest[i4] = constMacro.GetExpression()[i2];
+			dest += constMacro.GetExpression()[i2];
 			if( constMacro.GetExpression()[i2] == '\0' ) break;
 		}
@@ -277,6 +277,4 @@
 	}
 
-	for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
-
 	return true;
 }
