Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h	(revision 813)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h	(revision 814)
@@ -29,5 +29,5 @@
 
 	// TypeDefを収集する
-	static void AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const std::string &expression, int nowLine );
+	static void AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const boost::iterator_range<char const*> &expression, int nowLine );
 	static void CollectTypeDefs( const char *source, TypeDefCollection &typeDefs );
 
@@ -35,5 +35,11 @@
 	static void AddConstEnum( Consts &consts, const NamespaceScopes &namespaceScopes, const char *buffer );
 	static void CollectConsts( const char *source, Consts &consts, ConstMacros &constMacros );
-	static bool ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest );
+	static bool ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, std::string& dest );
+	static bool ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest, std::size_t destSize );
+	template<std::size_t N>
+	static bool ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char (&dest)[N] )
+	{
+		return ConstMacroToExpression(constMacro, parameterStr, dest, N);
+	}
 
 	// クラスを収集する
Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp	(revision 813)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp	(revision 814)
@@ -3,9 +3,8 @@
 using namespace ActiveBasic::Compiler;
 
-bool LexicalAnalyzer::CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection )
+using boost::numeric_cast;
+
+bool LexicalAnalyzer::CollectNamespaces(char const* source, NamespaceScopesCollection &namespaceScopesCollection)
 {
-	int i, i2;
-	char temporary[1024];
-
 	bool isSuccessful = true;
 
@@ -13,16 +12,16 @@
 	NamespaceScopes namespaceScopes;
 
-	for(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];
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
 			}
-			namespaceScopes.push_back( temporary );
+			namespaceScopes.push_back(std::string(p, &source[i]));
 
 			if( !namespaceScopesCollection.IsExist( namespaceScopes ) ){
@@ -46,5 +45,5 @@
 	}
 
-	if( namespaceScopes.size() > 0 ){
+	if( !namespaceScopes.empty() ){
 		compiler.errorMessenger.Output( 63, NULL, cp );
 		isSuccessful = false;
Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp	(revision 813)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp	(revision 814)
@@ -15,5 +15,5 @@
 void LexicalAnalyzer::CollectClassesForNameOnly( const char *source, Classes &classes )
 {
-	int i, i2;
+	int i2;
 	char temporary[VN_SIZE];
 
@@ -25,16 +25,15 @@
 	compiler.GetNamespaceSupporter().ClearImportedNamespaces();
 
-	for(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;
@@ -52,14 +51,14 @@
 		}
 		else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-			if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
-			{
-				compiler.errorMessenger.Output(64,temporary,i );
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
+			}
+			std::string s(p, &source[i]);
+			if (!compiler.GetNamespaceSupporter().ImportsNamespace(s))
+			{
+				compiler.errorMessenger.Output(64, s.c_str(), i);
 			}
 
@@ -1518,5 +1517,5 @@
 		else
 		{
-			for( int i=0; i<pInterface->GetDynamicMethods().size(); i++ )
+			for( std::size_t i=0; i<pInterface->GetDynamicMethods().size(); i++ )
 			{
 				if( pInterface->GetDynamicMethods()[i]->IsAbstract() != pExpandedInterface->GetDynamicMethods()[i]->IsAbstract() )
Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp	(revision 813)
+++ /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;
 }
Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Delegate.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Delegate.cpp	(revision 813)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Delegate.cpp	(revision 814)
@@ -5,7 +5,4 @@
 void LexicalAnalyzer::CollectDelegates( const char *source, Delegates &delegates )
 {
-	int i2;
-	char temporary[VN_SIZE];
-
 	// 名前空間管理
 	NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
@@ -15,16 +12,14 @@
 	compiler.GetNamespaceSupporter().ClearImportedNamespaces();
 
-	int length = lstrlen( source );
-	for( int i=0; i<length; i++ )
+	for (int i=0; source[i] != '\0'; i++)
 	{
 		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;
@@ -42,14 +37,14 @@
 		}
 		else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-			if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
-			{
-				compiler.errorMessenger.Output(64,temporary,i );
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
+			}
+			std::string s(p, &source[i]);
+			if (!compiler.GetNamespaceSupporter().ImportsNamespace(s))
+			{
+				compiler.errorMessenger.Output(64, s.c_str(), i);
 			}
 
@@ -112,5 +107,5 @@
 				{
 					compiler.errorMessenger.Output(-104,name,nowLine);
-					lstrcpy( returnTypeName, "Double" );
+					strcpy( returnTypeName, "Double" );
 				}
 			}
Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp	(revision 813)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp	(revision 814)
@@ -913,12 +913,11 @@
 
 		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;
@@ -936,14 +935,14 @@
 		}
 		else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-			if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
-			{
-				compiler.errorMessenger.Output(64,temporary,cp );
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
+			}
+			std::string s(p, &source[i]);
+			if (!compiler.GetNamespaceSupporter().ImportsNamespace(s))
+			{
+				compiler.errorMessenger.Output(64, s.c_str(), i);
 			}
 
Index: /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp
===================================================================
--- /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp	(revision 813)
+++ /branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp	(revision 814)
@@ -4,35 +4,25 @@
 #include "Compiler.h"
 #include "StrOperation.h"
+#include <boost/algorithm/string/predicate.hpp>
 
 using namespace ActiveBasic::Compiler;
 
-void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const std::string &expression, int nowLine )
+void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const boost::iterator_range<char const*> &expression, int nowLine )
 {
-	int i;
-	char temporary[VN_SIZE];
+	auto name = boost::find<boost::return_begin_found>(expression, '=');
 
-	for(i=0;;i++){
-		if(expression[i]=='='||expression[i]=='\0'){
-			temporary[i]=0;
-			break;
-		}
-		temporary[i]=expression[i];
-	}
-
-	if(expression[i]!='='){
-		compiler.errorMessenger.Output(10,"TypeDef",nowLine);
+	if (boost::end(name) == boost::end(expression))
+	{
+		compiler.errorMessenger.Output(10, "TypeDef", nowLine);
 		return;
 	}
 
-	const char *pTemp=expression.c_str()+i+1;
+	const char *pTemp = expression.begin() + boost::size(name) + 1;
 
 	//識別文字のエラーチェック（新しい型）
-	i=0;
-	for(;;i++){
-		if(temporary[i]=='\0') break;
-		if( !( IsVariableChar( temporary[i], true) ) ){
-			compiler.errorMessenger.Output(10,"TypeDef",nowLine);
-			return;
-		}
+	if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);}))
+	{
+		compiler.errorMessenger.Output(10, "TypeDef", nowLine);
+		return;
 	}
 
@@ -45,19 +35,20 @@
 		}
 	}
-	else{
-		i=0;
+	else
+	{
+		int i=0;
 		while(pTemp[i]=='*') i++;
-		for(;;i++){
-			if(pTemp[i]=='\0') break;
-			if( !( IsVariableChar( pTemp[i], true) ) )
-			{
-				compiler.errorMessenger.Output(10,"TypeDef",nowLine);
-				return;
-			}
+		if (!boost::algorithm::all(name, [](char c) {return IsVariableChar(c, true);}))
+		{
+			compiler.errorMessenger.Output(10,"TypeDef",nowLine);
+			return;
 		}
 	}
 
+	std::string baseName(pTemp, expression.end());
+
 	//識別子が重複している場合はエラーにする
-	if(lstrcmp(temporary,pTemp)==0){
+	if (boost::algorithm::equals(name, baseName))
+	{
 		compiler.errorMessenger.Output(1,NULL,nowLine);
 		return;
@@ -71,7 +62,7 @@
 
 	Type baseType;
-	if( !compiler.StringToType( pTemp, baseType ) )
+	if( !compiler.StringToType( baseName, baseType ) )
 	{
-		compiler.errorMessenger.Output(3, pTemp, nowLine );
+		compiler.errorMessenger.Output(3, baseName, nowLine );
 		return;
 	}
@@ -79,6 +70,6 @@
 	typeDefs.push_back(
 		TypeDef(
-			Symbol( namespaceScopes, temporary ),
-			pTemp,
+			Symbol(namespaceScopes, boost::copy_range<std::string>(name)),
+			baseName,
 			baseType
 		)
@@ -94,19 +85,14 @@
 	compiler.GetNamespaceSupporter().ClearImportedNamespaces();
 
-	int i=-1, i2;
-	char temporary[VN_SIZE];
-	while(1){
-
-		i++;
-
+	for (int i = 0; ; ++i)
+	{
 		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];
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
 			}
-			namespaceScopes.push_back( temporary );
+			namespaceScopes.push_back(std::string(p, &source[i]));
 
 			continue;
@@ -124,14 +110,14 @@
 		}
 		else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
+			i+=2;
+			char const* p = &source[i];
+			while (!IsCommandDelimitation(source[i]))
+			{
+				++i;
 			}
-			if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
+			std::string s(p, &source[i]);
+			if (!compiler.GetNamespaceSupporter().ImportsNamespace(s))
 			{
-				compiler.errorMessenger.Output(64,temporary,i );
+				compiler.errorMessenger.Output(64, s.c_str(), i);
 			}
 
@@ -148,15 +134,11 @@
 			char temporary[VN_SIZE];
 			if(source[i+1]==ESC_TYPEDEF){
-				int i2 = 0;
-				for(i+=2;;i2++,i++){
-					if(source[i]=='\n'){
-						temporary[i2]=0;
-						break;
-					}
-					temporary[i2]=source[i];
-					if(source[i]=='\0') break;
+				i+=2;
+				char const* p = &source[i];
+				while (!IsCommandDelimitation(source[i]))
+				{
+					++i;
 				}
-				AddTypeDef( typeDefs, namespaceScopes, temporary, i );
-
+				AddTypeDef(typeDefs, namespaceScopes, boost::make_iterator_range(p, &source[i]), i);
 				continue;
 			}
@@ -172,15 +154,9 @@
 				}
 
-				Type baseType;
-				if( !compiler.StringToType( "Long", baseType ) )
-				{
-					throw;
-				}
-
 				typeDefs.push_back(
 					TypeDef(
 						Symbol( namespaceScopes, temporary ),
 						"Long",
-						baseType
+						Type(DEF_LONG)
 					)
 				);
