Index: trunk/ab5.0/abdev/BasicCompiler_Common/Compile.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/Compile.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/Compile.cpp	(revision 632)
@@ -758,5 +758,8 @@
 			}
 
-			ChangeOpcode(Command);
+			if( Command[0] )
+			{
+				ChangeOpcode(Command);
+			}
 
 
Index: trunk/ab5.0/abdev/BasicCompiler_Common/NumOpe_GetType.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/NumOpe_GetType.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/NumOpe_GetType.cpp	(revision 632)
@@ -829,11 +829,13 @@
 						isNothing_stack[sp] = true;
 
-						type_stack[sp] = DEF_OBJECT;
 						if( baseType.IsObject() ){
+							type_stack[sp] = DEF_OBJECT;
 							index_stack[sp] = baseType.GetIndex();
 						}
 						else{
-							index_stack[sp] = (LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
+							type_stack[sp] = baseType.GetBasicType();
+							index_stack[sp] = baseType.GetIndex();
 						}
+
 						*pIsLiteralCalculation = false;
 						sp++;
Index: trunk/ab5.0/abdev/BasicCompiler_Common/StrOperation.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/StrOperation.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/StrOperation.cpp	(revision 632)
@@ -365,4 +365,7 @@
 			lstrcpy(name,"End Enum");
 			break;
+		case ESC_OPERATOR:
+			lstrcpy( name, "Operator" );
+			break;
 	}
 }
@@ -378,6 +381,7 @@
 		if( temporary[i] == 1 )
 		{
+			int esc = temporary[i+1];
 			char temp2[255];
-			GetDefaultNameFromES( temporary[i+1], temp2 );
+			GetDefaultNameFromES( esc, temp2 );
 			if( i>0 )
 			{
@@ -391,6 +395,19 @@
 			}
 
+			int slide = 2;
+
+			if( esc == ESC_OPERATOR )
+			{
+				extern char *calcNames[256];
+				char calcId = temporary[i+2];
+				if( calcNames[calcId] )
+				{
+					lstrcat( temp2, calcNames[calcId] );
+				}
+				slide = 3;
+			}
+
 			int length = lstrlen( temp2 );
-			SlideString( temporary + i+2, length-2 );
+			SlideString( temporary + i+slide, length-slide );
 			memcpy( temporary + i, temp2, length );
 			maxLength = lstrlen( temporary );
Index: trunk/ab5.0/abdev/BasicCompiler_Common/VariableOpe.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/VariableOpe.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/VariableOpe.cpp	(revision 632)
@@ -633,8 +633,9 @@
 		}
 
-		int typeDefIndex = compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( LexicalAnalyzer::FullNameToSymbol( VarName ) );
-		if( typeDefIndex != -1 ){
+		const TypeDef *pTypeDef = compiler.GetObjectModule().meta.GetTypeDefs().Find( LexicalAnalyzer::FullNameToSymbol( VarName ) );
+		if( pTypeDef )
+		{
 			// TypeDef後の型名だったとき
-			lstrcpy( VarName, compiler.GetObjectModule().meta.GetTypeDefs()[typeDefIndex].GetBaseName().c_str() );
+			lstrcpy( VarName, pTypeDef->GetBaseName().c_str() );
 		}
 
Index: trunk/ab5.0/abdev/BasicCompiler_Common/include/Compiler.h
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/include/Compiler.h	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/include/Compiler.h	(revision 632)
@@ -184,4 +184,7 @@
 
 
+private:
+	ActiveBasic::Compiler::Error::StringToTypeErrorCode::EnumType StringToGenericTypeEx( const std::string &typeName, Type &type );
+public:
 	ActiveBasic::Compiler::Error::StringToTypeErrorCode::EnumType StringToTypeEx( const std::string &typeName, Type &type, bool isResolveGenerics = false );
 	bool StringToType( const std::string &typeName, Type &type );
Index: trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h	(revision 632)
@@ -43,4 +43,8 @@
 	static void CollectClasses( const char *source, Classes &classes );
 
+	// テンプレート展開
+	static void TemplateExpand_ResolveMethod( const CMethod *pBaseMethod, const Types &actualTypes, CClass *pNewClass );
+	static const CClass *TemplateExpand( CClass &_class, const Types &actualTypes );
+
 	// グローバルプロシージャを収集する
 	static bool AnalyzeParameter( Parameters &params, const Jenga::Common::Strings &parameterStrings, int nowLine );
Index: trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp	(revision 632)
@@ -14,62 +14,106 @@
 }
 
-ActiveBasic::Compiler::Error::StringToTypeErrorCode::EnumType Compiler::StringToTypeEx( const std::string &typeName, Type &type, bool isResolveGenerics )
-{
-	type.SetIndex( -1 );
-
-
-	/////////////////////////////////////////////////////////
-	// ☆★☆ ジェネリクスサポート ☆★☆
-
-	if( strstr( typeName.c_str(), "<" ) )
-	{
-		// ジェネリッククラスをインスタンス化した型の場合
-		int i = 0;
-		char className[VN_SIZE];
-		GetIdentifierToken( className, typeName.c_str(), i );
-
-		// ジェネリクスクラスを取得
-		const CClass *pGenericClass = this->GetObjectModule().meta.FindClassSupportedTypeDef( 
-			LexicalAnalyzer::FullNameToSymbol( className )
-		);
-
-		if( !pGenericClass )
-		{
-			return ActiveBasic::Compiler::Error::StringToTypeErrorCode::NotfoundGenericClass;
-		}
-
-		if( typeName[i] != '<' )
-		{
-			Jenga::Throw( "StringToType内でジェネリクス構文の解析に失敗" );
-		}
-
-		GenericTypes genericTypes;
-		while( true )
-		{
-			i++;
-
-			char typeParameter[VN_SIZE];
-			GetIdentifierToken( typeParameter, typeName.c_str(), i );
-
-			// 型パラメータの型情報を取得
-			Type baseType;
-			StringToType( typeParameter, baseType );
-
-			genericTypes.push_back( GenericType( "(non support)", baseType ) );
-
-			if( typeName[i] != ',' )
-			{
-				break;
-			}
-		}
-
-		// 基本型をセット
-		type.SetBasicType( DEF_OBJECT );
+ActiveBasic::Compiler::Error::StringToTypeErrorCode::EnumType Compiler::StringToGenericTypeEx( const std::string &typeName, Type &type )
+{
+	// ジェネリッククラスをインスタンス化した型の場合
+	int i = 0;
+	char className[VN_SIZE];
+	GetIdentifierToken( className, typeName.c_str(), i );
+
+	// ジェネリクスクラスを取得
+	const CClass *pGenericClass = this->GetObjectModule().meta.FindClassSupportedTypeDef( 
+		LexicalAnalyzer::FullNameToSymbol( className )
+	);
+
+	if( !pGenericClass )
+	{
+		return ActiveBasic::Compiler::Error::StringToTypeErrorCode::NotfoundGenericClass;
+	}
+
+	if( typeName[i] != '<' )
+	{
+		Jenga::Throw( "StringToType内でジェネリクス構文の解析に失敗" );
+	}
+
+	GenericTypes genericTypes;
+	bool isValueType = false;
+	while( true )
+	{
+		i++;
+
+		char typeParameterStr[VN_SIZE];
+		GetIdentifierToken( typeParameterStr, typeName.c_str(), i );
+
+		// 型パラメータの型情報を取得
+		Type typeParameterType;
+		StringToType( typeParameterStr, typeParameterType );
+
+		genericTypes.push_back( GenericType( "(non support)", typeParameterType ) );
+
+		if( typeParameterType.IsValueType() )
+		{
+			// 値型の場合
+			isValueType = true;
+		}
+
+		if( typeName[i] != ',' )
+		{
+			break;
+		}
+	}
+
+	// 基本型をセット
+	type.SetBasicType( DEF_OBJECT );
+
+	if( isValueType )
+	{
+		// 型パラメータに値型が指定された場合
+
+		// 仮型パラメータを実型パラメータに変換
+		Types actualTypes;
+		BOOST_FOREACH( const GenericType &genericType, genericTypes )
+		{
+			actualTypes.push_back( genericType.GetType() );
+		}
+
+		// テンプレートとしてクラスを展開する
+		const CClass *pExpandedClass = LexicalAnalyzer::TemplateExpand( *const_cast<CClass *>(pGenericClass), actualTypes );
+
+		if( pExpandedClass )
+		{
+			// 拡張情報をセット
+			type.SetClassPtr( pExpandedClass );
+		}
+		else
+		{
+			// TODO: 消す
+			goto Generic;
+		}
+	}
+	else
+	{
+Generic:
+		// 型パラメータにクラス型が指定された場合
+
+		// ジェネリック クラスとして利用する
 
 		// 拡張情報をセット
 		type.SetClassPtr( pGenericClass );
 		type.SetActualGenericTypes( genericTypes );
-
-		return ActiveBasic::Compiler::Error::StringToTypeErrorCode::Successful;
+	}
+
+	return ActiveBasic::Compiler::Error::StringToTypeErrorCode::Successful;
+}
+ActiveBasic::Compiler::Error::StringToTypeErrorCode::EnumType Compiler::StringToTypeEx( const std::string &typeName, Type &type, bool isResolveGenerics )
+{
+	type.SetIndex( -1 );
+
+
+	/////////////////////////////////////////////////////////
+	// ☆★☆ ジェネリクスサポート ☆★☆
+
+	if( strstr( typeName.c_str(), "<" ) )
+	{
+		return StringToGenericTypeEx( typeName, type );
 	}
 
@@ -147,13 +191,24 @@
 	// TypeDefされた型
 	////////////////////
-	int i=this->GetObjectModule().meta.GetTypeDefs().GetIndex( LexicalAnalyzer::FullNameToSymbol( typeName ) );
-	if(i!=-1)
-	{
-		type = this->GetObjectModule().meta.GetTypeDefs()[i].GetBaseType();
+	const TypeDef *pTypeDef = this->GetObjectModule().meta.GetTypeDefs().Find( LexicalAnalyzer::FullNameToSymbol( typeName ) );
+	if( pTypeDef )
+	{
+		type = pTypeDef->GetBaseType();
+
+		if( type.IsObject() )
+		{
+			if( isResolveGenerics && !type.HasActualGenericType() )
+			{
+				// ジェネリッククラスの場合
+				trace( "型解決されていない" );
+				return ActiveBasic::Compiler::Error::StringToTypeErrorCode::FailedResolveGenericType;
+			}
+		}
+
 		return ActiveBasic::Compiler::Error::StringToTypeErrorCode::Successful;
 	}
 
 	//クラス
-	const CClass *pobj_c = this->GetObjectModule().meta.GetClasses().FindEx( LexicalAnalyzer::FullNameToSymbol( typeName ) );
+	const CClass *pobj_c = this->GetObjectModule().meta.FindClassSupportedTypeDef( LexicalAnalyzer::FullNameToSymbol( typeName ) );
 	if(pobj_c)
 	{
Index: trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp	(revision 632)
@@ -287,5 +287,8 @@
 	Subscripts subscripts;
 	Type type;
-	GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter);
+	if( !GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter) )
+	{
+		return NULL;
+	}
 
 	//重複チェック
@@ -1217,36 +1220,37 @@
 				extern int cp;
 				if(i3==0){
-					if(bStatic){
-						//静的メンバを追加
-						cp=i;	//エラー用
-						pobj_c->AddStaticMember(
-							LexicalAnalyzer::CreateMember( *pobj_c, accessibility, isConst, false, temporary, i )
-						);
-					}
-					else{
-						//メンバを追加
-						cp=i;	//エラー用
-						pobj_c->AddDynamicMember(
-							LexicalAnalyzer::CreateMember( *pobj_c, accessibility, isConst, false, temporary, i )
-						);
-
-
-						if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
-							if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
-								//参照先が読み取られていないとき
-								GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes );
+					cp=i;	//エラー用
+					Member *pMember = LexicalAnalyzer::CreateMember( *pobj_c, accessibility, isConst, false, temporary, i );
+					if( pMember )
+					{
+						if(bStatic)
+						{
+							//静的メンバを追加
+							pobj_c->AddStaticMember( pMember );
+						}
+						else
+						{
+							//メンバを追加
+							pobj_c->AddDynamicMember( pMember );
+
+
+							if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
+								if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
+									//参照先が読み取られていないとき
+									GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes );
+								}
 							}
-						}
-
-
-						if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
-							//循環参照のチェック
-							pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
-							if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
-								//エラー回避
-								Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
-								type.SetBasicType( DEF_PTR_VOID );
+
+
+							if(pobj_c->GetDynamicMembers().back()->GetType().IsStruct()){
+								//循環参照のチェック
+								pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
+								if(!MemberVar_LoopRefCheck(pobj_c->GetDynamicMembers().back()->GetType().GetClass())){
+									//エラー回避
+									Type &type = const_cast<Type &>(pobj_c->GetDynamicMembers().back()->GetType());
+									type.SetBasicType( DEF_PTR_VOID );
+								}
+								pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
 							}
-							pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
 						}
 					}
@@ -1355,2 +1359,148 @@
 	classes.Iterator_Init();
 }
+
+void LexicalAnalyzer::TemplateExpand_ResolveMethod( const CMethod *pBaseMethod, const Types &actualTypes, CClass *pNewClass )
+{
+	UserProc *pUserProc = new UserProc(
+		pBaseMethod->GetUserProc(),
+		pNewClass
+	);
+	pUserProc->Using();
+	pUserProc->GetParameters().clear();
+	pUserProc->RealParams().clear();
+
+	// パラメータのジェネリック型を解決
+	BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().Params() )
+	{
+		Type type = pParam->IsTypeParameter()
+			? actualTypes[pParam->GetFormalTypeIndex()]
+			: *pParam;
+		type.SetPtrLevel( pParam->PtrLevel() );
+
+		pUserProc->GetParameters().push_back( new Parameter( *pParam, type ) );
+	}
+	BOOST_FOREACH( const Parameter *pParam, pBaseMethod->GetUserProc().RealParams() )
+	{
+		Type type = pParam->IsTypeParameter()
+			? actualTypes[pParam->GetFormalTypeIndex()]
+			: *pParam;
+		type.SetPtrLevel( pParam->PtrLevel() );
+
+		pUserProc->RealParams().push_back( new Parameter( *pParam, type ) );
+	}
+
+	// 戻り値のジェネリック型を解決
+	if( pUserProc->ReturnType().IsTypeParameter() )
+	{
+		Type type = actualTypes[pUserProc->ReturnType().GetFormalTypeIndex()];
+		type.SetPtrLevel( pUserProc->ReturnType().PtrLevel() );
+		pUserProc->SetReturnType( type );
+	}
+
+	compiler.GetObjectModule().meta.GetUserProcs().Put( pUserProc );
+	compiler.GetObjectModule().meta.GetUserProcs().Iterator_Init();
+
+	LexicalAnalyzer::AddMethod(
+		pNewClass,
+		pUserProc,
+		pBaseMethod->GetAccessibility(),
+		pBaseMethod->IsStatic(),
+		pBaseMethod->IsConst(),
+		pBaseMethod->IsAbstract(),
+		pBaseMethod->IsVirtual(),
+		false,
+		"",
+		false,
+		-1
+	);
+}
+
+const CClass *LexicalAnalyzer::TemplateExpand( CClass &_class, const Types &actualTypes )
+{
+	// 展開済みのクラスがあればそれを返す
+	BOOST_FOREACH( const ExpandedTemplateClass *pExpandedTemplateClass, _class.expandedTemplateClasses )
+	{
+		if( pExpandedTemplateClass->GetActualTypes().IsEquals( actualTypes ) )
+		{
+			return &pExpandedTemplateClass->GetClass();
+		}
+	}
+
+
+	/////////////////////////////////////////////////////////////////
+	// 未展開の場合は新たに展開する
+	/////////////////////////////////////////////////////////////////
+
+	// クラスをコピー
+	CClass *pNewClass = new CClass(
+		_class.GetNamespaceScopes(),
+		_class.GetImportedNamespaces(),
+		_class.GetName(),
+		_class.GetClassType(),
+		_class.GetFormalGenericTypes(),
+		actualTypes,
+		_class.GetConstructorMemberSubIndex(),
+		_class.GetDestructorMemberSubIndex(),
+		0,
+		_class.GetFixedAlignment()
+	);
+
+	// 基底クラス
+	pNewClass->SetSuperClass( &_class.GetSuperClass() );
+
+	// インターフェイスのジェネリック型を解決
+	BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
+	{
+		pNewClass->AddInterface( new ::Interface( &pInterface->GetClass(), actualTypes ) );
+	}
+
+	// メンバのジェネリック型を解決
+	BOOST_FOREACH( const Member *pMember, _class.GetDynamicMembers() )
+	{
+		Type type = pMember->GetType();
+		if( type.IsTypeParameter() )
+		{
+			// ジェネリック型だったときは値型に変換
+			type = actualTypes[type.GetFormalTypeIndex()];
+			type.SetPtrLevel( pMember->GetType().PtrLevel() );
+		}
+
+		pNewClass->GetDynamicMembers().push_back(
+			new Member( *pMember, type )
+		);
+	}
+
+	// クラス メソッドのジェネリック型を解決
+	BOOST_FOREACH( const CMethod *pMethod, _class.GetDynamicMethods() )
+	{
+		if( pMethod->GetUserProc().GetParentClassPtr() == &_class )
+		{
+			// ターゲットクラス内で実装されるメソッドの場合
+
+			TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
+		}
+		else
+		{
+			DynamicMethod *pNewDynamicMethod = new DynamicMethod( *pMethod );
+			pNewClass->GetDynamicMethods().push_back( pNewDynamicMethod );
+		}
+	}
+
+	// インターフェイス メソッドのジェネリック型を解決
+	BOOST_FOREACH( const ::Interface *pInterface, _class.GetInterfaces() )
+	{
+		BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() )
+		{
+			TemplateExpand_ResolveMethod( pMethod, actualTypes, pNewClass );
+		}
+	}
+
+	pNewClass->SetVtblNum( _class.GetVtblNum() );
+
+	// 展開済みクラスとして登録
+	_class.expandedTemplateClasses.push_back( new ExpandedTemplateClass( pNewClass, actualTypes ) );
+
+	pNewClass->Readed();
+
+	return pNewClass;
+}
Index: trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp	(revision 632)
@@ -156,5 +156,5 @@
 
 	//ソースコードの位置
-	userProc.SetCodePos( nowLine );
+	userProc.SetSourceCodePosition( SourceCodePosition( compiler.GetObjectModule().GetName(), nowLine ) );
 
 	//パラメータ
@@ -286,5 +286,5 @@
 
 	//ソースコードの位置
-	pProc->SetCodePos( nowLine );
+	pProc->SetSourceCodePosition( SourceCodePosition( compiler.GetObjectModule().GetName(), nowLine ) );
 
 	//パラメータ
Index: trunk/ab5.0/abdev/BasicCompiler_Common/src/VtblGenerator.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/src/VtblGenerator.cpp	(revision 628)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/src/VtblGenerator.cpp	(revision 632)
@@ -96,5 +96,18 @@
 	while( classes.Iterator_HasNext() )
 	{
-		GenerateFullVTables( *classes.Iterator_GetNext() );
+		CClass *pClass = classes.Iterator_GetNext();
+		GenerateFullVTables( *pClass );
+
+		// テンプレート展開されたクラスも
+		BOOST_FOREACH( ActiveBasic::Common::Lexical::ExpandedTemplateClass *pExpandedTemplateClass, pClass->expandedTemplateClasses )
+		{
+			if( !pExpandedTemplateClass->GetClass().expandedTemplateClasses.empty() )
+			{
+				// テンプレート展開後のクラスが更にテンプレート展開されていることはありえない
+				throw;
+			}
+
+			GenerateFullVTables( pExpandedTemplateClass->GetClass() );
+		}
 	}
 }
@@ -167,5 +180,18 @@
 	while( classes.Iterator_HasNext() )
 	{
-		ActionVtblSchedule( *classes.Iterator_GetNext(), ImageBase, MemPos_CodeSection, MemPos_DataSection );
+		CClass *pClass = classes.Iterator_GetNext();
+		ActionVtblSchedule( *pClass, ImageBase, MemPos_CodeSection, MemPos_DataSection );
+
+		// テンプレート展開されたクラスも
+		BOOST_FOREACH( ActiveBasic::Common::Lexical::ExpandedTemplateClass *pExpandedTemplateClass, pClass->expandedTemplateClasses )
+		{
+			if( !pExpandedTemplateClass->GetClass().expandedTemplateClasses.empty() )
+			{
+				// テンプレート展開後のクラスが更にテンプレート展開されていることはありえない
+				throw;
+			}
+
+			ActionVtblSchedule( pExpandedTemplateClass->GetClass(), ImageBase, MemPos_CodeSection, MemPos_DataSection );
+		}
 	}
 }
