Index: trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Delegate.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Delegate.cpp	(revision 526)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Delegate.cpp	(revision 526)
@@ -0,0 +1,222 @@
+#include "stdafx.h"
+
+using namespace ActiveBasic::Compiler;
+
+void LexicalAnalyzer::CollectDelegates( const BasicSource &source, Delegates &delegates )
+{
+	int i2;
+	char temporary[VN_SIZE];
+
+	// 名前空間管理
+	NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
+	namespaceScopes.clear();
+
+	// Importsされた名前空間の管理
+	NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
+	importedNamespaces.clear();
+
+	for( int i=0; i<source.GetLength(); 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 );
+
+			continue;
+		}
+		else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
+			if( namespaceScopes.size() <= 0 ){
+				compiler.errorMessenger.Output(12, "End Namespace", i );
+			}
+			else{
+				namespaceScopes.pop_back();
+			}
+
+			i += 2;
+			continue;
+		}
+		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 );
+			}
+
+			continue;
+		}
+		else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
+			importedNamespaces.clear();
+			continue;
+		}
+
+		else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
+		{
+			int nowLine = i;
+
+			i += 2;
+			if( !( source[i] == 1 && ( source[i+1] == ESC_SUB || source[i+1] == ESC_FUNCTION ) ) )
+			{
+				compiler.errorMessenger.Output(1,NULL,i);
+				continue;
+			}
+
+			Procedure::Kind procKind = Procedure::Sub;
+			if( source[i+1] == ESC_FUNCTION )
+			{
+				procKind = Procedure::Function;
+			}
+			i += 2;
+
+			// 名前
+			char name[VN_SIZE];
+			GetIdentifierToken( name, source.GetBuffer(), i );
+
+			if( source[i] != '(' )
+			{
+				compiler.errorMessenger.Output(1,NULL,nowLine);
+				continue;
+			}
+
+			// パラメータ文字列
+			char paramStr[8192];
+			i += GetStringInPare( paramStr, source.GetBuffer() + i, true );
+
+			// 戻り値の型の文字列
+			char returnTypeName[VN_SIZE] = "";
+			if( source[i] == 1 && source[i+1] == ESC_AS )
+			{
+				i += 2;
+				GetCommandToken( returnTypeName, source.GetBuffer(), i );
+
+				if( procKind != Procedure::Function )
+				{
+					compiler.errorMessenger.Output(38,name,nowLine);
+				}
+			}
+			else
+			{
+				if( procKind == Procedure::Function )
+				{
+					compiler.errorMessenger.Output(-104,name,nowLine);
+					lstrcpy( returnTypeName, "Double" );
+				}
+			}
+
+			delegates.Put( new Delegate( namespaceScopes, importedNamespaces, name, procKind, paramStr, returnTypeName, nowLine ) );
+		}
+	}
+}
+
+std::string LexicalAnalyzer::GenerateDelegatesSourceCode( const Delegates &delegates )
+{
+	std::string destSource = "";
+
+	SourceTemplate sourceTemplate( ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\templates\\delegate_class.tab" );
+
+	delegates.Iterator_Reset();
+	while( delegates.Iterator_HasNext() )
+	{
+		const Delegate &dg = *delegates.Iterator_GetNext();
+
+		if( !dg.isTargetObjectModule )
+		{
+			// 静的リンクライブラリの場合は飛ばす（既にインスタンスが定義済みであるため）
+			continue;
+		}
+
+		std::map<std::string,std::string> values;
+
+		if( dg.GetNamespaceScopes().size() )
+		{
+			std::string namespaceScopesCommandStr = "";
+			std::string endNamespaceScopesCommandStr = "";
+			BOOST_FOREACH( const std::string &namespaceStr, dg.GetNamespaceScopes() )
+			{
+				if( namespaceScopesCommandStr.size() )
+				{
+					namespaceScopesCommandStr += ":";
+					endNamespaceScopesCommandStr += ":";
+				}
+				namespaceScopesCommandStr += "Namespace " + namespaceStr;
+				endNamespaceScopesCommandStr += "End Namespace";
+			}
+
+			values.insert( std::map<std::string,std::string>::value_type(
+				"#namespace_begin#",
+				namespaceScopesCommandStr
+			) );
+			values.insert( std::map<std::string,std::string>::value_type(
+				"#namespace_end#",
+				endNamespaceScopesCommandStr
+			) );
+		}
+		else
+		{
+			values.insert( std::map<std::string,std::string>::value_type( "#namespace_begin#", "" ) );
+			values.insert( std::map<std::string,std::string>::value_type( "#namespace_end#", "" ) );
+		}
+
+		values.insert( std::map<std::string,std::string>::value_type( "#name#", dg.GetName() ) );
+
+		if( dg.IsFunction() )
+		{
+			values.insert( std::map<std::string,std::string>::value_type(
+				"#call_method_begin#",
+				(std::string)"Function Call(" + dg.GetParamStr() + ") As " + dg.GetReturnTypeName()
+			) );
+
+			values.insert( std::map<std::string,std::string>::value_type(
+				"#call_method_end#",
+				"End Function"
+			) );
+
+			values.insert( std::map<std::string,std::string>::value_type( "#result#", "Call=" ) );
+		}
+		else
+		{
+			values.insert( std::map<std::string,std::string>::value_type(
+				"#call_method_begin#",
+				(std::string)"Sub Call(" + dg.GetParamStr() + ")"
+			) );
+
+			values.insert( std::map<std::string,std::string>::value_type(
+				"#call_method_end#",
+				"End Sub"
+			) );
+
+			values.insert( std::map<std::string,std::string>::value_type( "#result#", "" ) );
+		}
+
+		values.insert( std::map<std::string,std::string>::value_type( "#params#", dg.GetParamStr() ) );
+
+		destSource += sourceTemplate.GetResult( values );
+	}
+/*
+	std::ofstream ofs( ( Jenga::Common::Environment::GetAppDir() + "\\generated_delegate_code.log" ).c_str() );
+	ofs << destSource;
+	ofs.close();
+	*/
+
+	return destSource;
+}
+
+void LexicalAnalyzer::RefleshDelegatesParameterAndReturnType( Delegates &delegates )
+{
+	delegates.Iterator_Reset();
+	while( delegates.Iterator_HasNext() )
+	{
+		Delegate &dg = *delegates.Iterator_GetNext();
+		dg.RefleshParameterAndReturnType();
+	}
+}
Index: trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj
===================================================================
--- trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj	(revision 525)
+++ trunk/ab5.0/abdev/compiler_x86/compiler_x86.vcproj	(revision 526)
@@ -1276,4 +1276,8 @@
 					>
 					<File
+						RelativePath="..\BasicCompiler_Common\src\Class.cpp"
+						>
+					</File>
+					<File
 						RelativePath="..\BasicCompiler_Common\src\Const.cpp"
 						>
@@ -1308,4 +1312,8 @@
 					</File>
 					<File
+						RelativePath="..\BasicCompiler_Common\src\Method.cpp"
+						>
+					</File>
+					<File
 						RelativePath="..\BasicCompiler_Common\src\NativeCode.cpp"
 						>
@@ -1341,4 +1349,8 @@
 					<File
 						RelativePath="..\BasicCompiler_Common\src\Source.cpp"
+						>
+					</File>
+					<File
+						RelativePath="..\BasicCompiler_Common\src\Type.cpp"
 						>
 					</File>
@@ -1469,4 +1481,8 @@
 					>
 					<File
+						RelativePath="..\BasicCompiler_Common\include\Class.h"
+						>
+					</File>
+					<File
 						RelativePath="..\BasicCompiler_Common\include\Const.h"
 						>
@@ -1497,8 +1513,16 @@
 					</File>
 					<File
+						RelativePath="..\BasicCompiler_Common\include\Member.h"
+						>
+					</File>
+					<File
 						RelativePath="..\BasicCompiler_Common\include\Meta.h"
 						>
 					</File>
 					<File
+						RelativePath="..\BasicCompiler_Common\include\Method.h"
+						>
+					</File>
+					<File
 						RelativePath="..\BasicCompiler_Common\include\NativeCode.h"
 						>
@@ -1518,4 +1542,8 @@
 					<File
 						RelativePath="..\BasicCompiler_Common\include\Source.h"
+						>
+					</File>
+					<File
+						RelativePath="..\BasicCompiler_Common\include\Type.h"
 						>
 					</File>
