Index: /trunk/ab5.0/abdev/BasicCompiler_Common/BreakPoint.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/BreakPoint.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/BreakPoint.cpp	(revision 636)
@@ -42,7 +42,9 @@
 	const IncludedFilesRelation *pIncludedFilesRelation = NULL;
 	const BasicSource *pNowSource = NULL;
-	BOOST_FOREACH( const BasicSource &source, compiler.GetObjectModule().GetSources() )
+	BOOST_FOREACH( const ObjectModule *pObjectModule, compiler.staticLibraries )
 	{
-		pIncludedFilesRelation = &source.GetIncludedFilesRelation();
+		const BasicSource *pSource = &pObjectModule->GetSource();
+
+		pIncludedFilesRelation = &pSource->GetIncludedFilesRelation();
 
 		for(FileNum=0;FileNum<pIncludedFilesRelation->GetFileCounts();FileNum++)
@@ -50,5 +52,5 @@
 			if(lstrcmpi(pIncludedFilesRelation->GetFilePathFromFileNumber(FileNum).c_str(),lpszFileName)==0)
 			{
-				pNowSource = &source;
+				pNowSource = pSource;
 				break;
 			}
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/CDebugThreadInfo.cpp	(revision 636)
@@ -37,5 +37,5 @@
 	lplpSpBase=(ULONG_PTR *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(ULONG_PTR));
 	lpdwCp=(DWORD *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(DWORD));
-	lpdwSourceIndex=(DWORD *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(DWORD));
+	this->relationalObjectModuleIndexes.resize( iProcLevel + 1 );
 
 	//lplpObp
@@ -108,5 +108,5 @@
 		HeapDefaultFree(lplpSpBase);
 		HeapDefaultFree(lpdwCp);
-		HeapDefaultFree(lpdwSourceIndex);
+		relationalObjectModuleIndexes.clear();
 	}
 
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/Compile.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/Compile.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/Compile.cpp	(revision 636)
@@ -18,4 +18,7 @@
 //デバッグ用行番号情報
 SourceLines oldSourceLines;
+
+// オブジェクトモジュールリストに類似したソースコードリスト
+BasicSources sourcesLinkRelationalObjectModule;
 
 
@@ -744,5 +747,5 @@
 			}
 
-			compiler.codeGenerator.NextSourceLine( compiler.GetObjectModule().GetCurrentSourceIndex() );
+			compiler.codeGenerator.NextSourceLine( compiler.GetCurrentRelationalObjectModuleIndexForSource() );
 
 			if(Command[0]==1){
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/Debug.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/Debug.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/Debug.cpp	(revision 636)
@@ -58,7 +58,9 @@
 	const IncludedFilesRelation *pIncludedFilesRelation = NULL;
 	const BasicSource *pNowSource = NULL;
-	BOOST_FOREACH( const BasicSource &source, compiler.GetObjectModule().GetSources() )
+	BOOST_FOREACH( const ObjectModule *pObjectModule, compiler.staticLibraries )
 	{
-		pIncludedFilesRelation = &source.GetIncludedFilesRelation();
+		const BasicSource *pSource = &pObjectModule->GetSource();
+
+		pIncludedFilesRelation = &pSource->GetIncludedFilesRelation();
 
 		for(FileNum=0;FileNum<pIncludedFilesRelation->GetFileCounts();FileNum++)
@@ -66,5 +68,5 @@
 			if(lstrcmpi(pIncludedFilesRelation->GetFilePathFromFileNumber(FileNum).c_str(),szFilePath)==0)
 			{
-				pNowSource = &source;
+				pNowSource = pSource;
 				break;
 			}
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/DebugMiddleFile.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/DebugMiddleFile.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/DebugMiddleFile.cpp	(revision 636)
@@ -99,4 +99,36 @@
 	}
 
+	// オブジェクトモジュールリストに類似したソースコードリスト
+	{
+		// オブジェクトモジュールリストに類似したソースコードリストを作成
+		BasicSources sources;
+		BOOST_FOREACH( const ObjectModule *pObjectModule, compiler.staticLibraries )
+		{
+			sources.push_back( pObjectModule->GetSource() );
+		}
+
+		// テキストデータにシリアライズ
+		std::string textString;
+		sources.WriteBinaryString( textString );
+
+		// サイズ
+		*(long *)(buffer+i2) = (long)textString.size();
+		i2+=sizeof(long);
+
+		//バッファが足りない場合は再確保
+		if(BufferSize<i2+(int)textString.size()+32768){
+			while( BufferSize<i2+(int)textString.size()+32768 )
+			{
+				BufferSize+=32768;
+			}
+
+			buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);
+		}
+
+		// バッファ
+		memcpy( buffer+i2, textString.c_str(), textString.size() );
+		i2 += (int)textString.size();
+	}
+
 
 	////////////////////////
@@ -115,5 +147,5 @@
 		i2+=sizeof(long);
 
-		*(long *)(buffer+i2) = sourceLine.GetSourceIndex();
+		*(long *)(buffer+i2) = sourceLine.GetRelationalObjectModuleIndex();
 		i2+=sizeof(long);
 
@@ -192,7 +224,20 @@
 		this->objectModule.ReadString( textString );
 
-		compiler.SelectObjectModule( this->objectModule );
-	}
-
+		compiler.SelectObjectModule( &this->objectModule );
+	}
+
+	// オブジェクトモジュールリストに類似したソースコードリスト
+	{
+		// サイズ
+		int size = *(long *)(buffer+i2);
+		i2 += sizeof(long);
+
+		// バッファ
+		const std::string textString( (const char *)(buffer + i2), size );
+		i2 += size;
+
+		// テキストデータからシリアライズ
+		this->_sourcesLinkRelationalObjectModule.ReadBinaryString( textString );
+	}
 
 	//コードと行番号の関係
@@ -246,5 +291,5 @@
 	//ソースコード
 	extern char *basbuf;
-	basbuf = const_cast<char *>(compiler.GetObjectModule().GetSource(0).GetBuffer());
+	basbuf = const_cast<char *>(compiler.GetObjectModule().GetSource().GetBuffer());
 
 
@@ -252,4 +297,8 @@
 	// ブレークポイントを適用
 	/////////////////////////////
+
+	// オブジェクトモジュールリストに類似したソースコードリスト
+	extern BasicSources sourcesLinkRelationalObjectModule;
+	sourcesLinkRelationalObjectModule = this->_sourcesLinkRelationalObjectModule;
 
 	//コードと行番号の関係
@@ -364,5 +413,5 @@
 
 	// オブジェクトモジュール
-	compiler.SelectObjectModule( this->objectModule );
+	compiler.SelectObjectModule( &this->objectModule );
 
 	//コードと行番号の関係
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/DebugSection.h
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/DebugSection.h	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/DebugSection.h	(revision 636)
@@ -24,4 +24,7 @@
 	// オブジェクトモジュール
 	ObjectModule objectModule;
+
+	// オブジェクトモジュールリストに類似したソースコードリスト
+	BasicSources _sourcesLinkRelationalObjectModule;
 
 	//コードと行番号の関係
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/MakeExe.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/MakeExe.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/MakeExe.cpp	(revision 636)
@@ -34,5 +34,5 @@
 
 	//最後尾に貼り付け
-	compiler.GetObjectModule().GetCurrentSource().Addition( temp );
+	compiler.GetObjectModule().GetSource().Addition( temp );
 
 	HeapDefaultFree(temp);
@@ -64,8 +64,9 @@
 	TypeOfSubSystem=IMAGE_SUBSYSTEM_WINDOWS_GUI;
 
+	// オブジェクトモジュール名をセットする
+	compiler.GetObjectModule().SetName( program.GetOutputFileName() );
+
 	//プログラムをファイルから読み込む
-	compiler.GetObjectModule().SetCurrentSourceIndex( (int)compiler.GetObjectModule().GetSources().size() );
-	compiler.GetObjectModule().GetSources().push_back( BasicSource() );
-	bool result = compiler.GetObjectModule().GetCurrentSource().ReadFile(
+	bool result = compiler.GetObjectModule().GetSource().ReadFile(
 		program.GetSourceFilePath(),
 		compiler.IsDebug(),
@@ -80,10 +81,10 @@
 		goto EndCompile;
 	}
-	if( !compiler.GetObjectModule().GetCurrentSource().cannotIncludePath.empty() )
+	if( !compiler.GetCurrentSource().cannotIncludePath.empty() )
 	{
 		compiler.errorMessenger.Output(
 			35,
-			compiler.GetObjectModule().GetCurrentSource().cannotIncludePath,
-			compiler.GetObjectModule().GetCurrentSource().cannotIncludeSourcePos
+			compiler.GetCurrentSource().cannotIncludePath,
+			compiler.GetCurrentSource().cannotIncludeSourcePos
 		);
 		goto EndCompile;
@@ -145,5 +146,5 @@
 
 	ChangeCommandToCode(basbuf);
-	compiler.GetObjectModule().GetSources()[0]._ResetLength();
+	compiler.GetObjectModule().GetSource()._ResetLength();
 
 	if( compiler.errorMessenger.HasError() || bStopCompile )
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/VarList.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/VarList.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/VarList.cpp	(revision 636)
@@ -621,5 +621,5 @@
 		{
 			pobj_dti->lpdwCp[i3]=oldSourceLines[i2].GetSourceCodePos();
-			pobj_dti->lpdwSourceIndex[i3]=oldSourceLines[i2].GetSourceIndex();
+			pobj_dti->relationalObjectModuleIndexes[i3]=oldSourceLines[i2].GetRelationalObjectModuleIndex();
 		}
 	}
@@ -631,5 +631,5 @@
 				pobj_dti->lplpSpBase[i2]=pobj_dti->lplpSpBase[i2+1];
 				pobj_dti->lpdwCp[i2]=pobj_dti->lpdwCp[i2+1];
-				pobj_dti->lpdwSourceIndex[i2]=pobj_dti->lpdwSourceIndex[i2+1];
+				pobj_dti->relationalObjectModuleIndexes[i2]=pobj_dti->relationalObjectModuleIndexes[i2+1];
 			}
 			i3--;
@@ -639,5 +639,6 @@
 
 	std::string dummyStr;
-	if(!compiler.GetObjectModule().GetSource( pobj_dti->lpdwSourceIndex[pobj_dti->iProcLevel] ).GetLineInfo( pobj_dti->lpdwCp[pobj_dti->iProcLevel], i2, dummyStr )){
+	extern BasicSources sourcesLinkRelationalObjectModule;
+	if(!sourcesLinkRelationalObjectModule[pobj_dti->relationalObjectModuleIndexes[pobj_dti->iProcLevel]].GetLineInfo( pobj_dti->lpdwCp[pobj_dti->iProcLevel], i2, dummyStr )){
 		extern HWND hMainDlg;
 		//"デバッグ情報の取得に失敗"
@@ -721,5 +722,6 @@
 
 				std::string dummyStr;
-				compiler.GetObjectModule().GetSource( pobj_dti->lpdwSourceIndex[pobj_dti->iProcLevel] ).GetLineInfo( pobj_dti->lpdwCp[pobj_dti->iProcLevel-i2], i3, dummyStr );
+				extern BasicSources sourcesLinkRelationalObjectModule;
+				sourcesLinkRelationalObjectModule[pobj_dti->relationalObjectModuleIndexes[pobj_dti->iProcLevel]].GetLineInfo( pobj_dti->lpdwCp[pobj_dti->iProcLevel-i2], i3, dummyStr );
 				ShowErrorLine(i3,dummyStr.c_str());
 
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/debug.h
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/debug.h	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/debug.h	(revision 636)
@@ -4,5 +4,5 @@
 	//ソースコードポインタ
 	DWORD *lpdwCp;
-	DWORD *lpdwSourceIndex;
+	std::vector<int> relationalObjectModuleIndexes;
 
 	//ネイティブコードポインタ
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/include/Compiler.h
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/include/Compiler.h	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/include/Compiler.h	(revision 636)
@@ -25,35 +25,18 @@
 	const CClass *pCompilingClass;
 
-	// オブジェクトモジュール
-	ObjectModule *pObjectModule;
-	ObjectModule *pNowObjectModule;
+	// 現在参照したいソースコードのオブジェクト モジュール インデックス
+	int currentRelationalObjectModuleIndexForSource;
+
+
 
 public:
 
-	Compiler()
-		: isBuildSuccessful( false )
-		, pObjectModule( new ObjectModule )
-		, targetModuleType( ActiveBasic::Common::TargetModuleType::Exe )
-		, isDebug( false )
-		, isUnicode( false )
-		, isCore( false )
-	{
-		SelectObjectModule( *pObjectModule );
-		Symbol::RegistNamespaceSupporter( &namespaceSupporter );
-	}
-	~Compiler()
-	{
-		delete pObjectModule;
-		Clear();
-	}
-	void Clear()
-	{
-		BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries )
-		{
-			delete pStaticLibrary;
-		}
-		staticLibraries.clear();
-	}
-
+	Compiler();
+	~Compiler();
+
+	// 静的リンクの準備を行う（オブジェクトモジュール同士の名前リストの結合など、前処理を行う）
+	void PreStaticLink( const ObjectModules &staticLibraries );
+
+	// 静的リンクを行う
 	void StaticLink( ObjectModules &staticLibraries );
 
@@ -103,14 +86,31 @@
 	ObjectModules staticLibraries;
 
+	ObjectModule *pSelectedObjectModule;
+
 	// オブジェクトモジュール
 	ObjectModule &GetObjectModule()
 	{
-		return *pNowObjectModule;
-	}
-	void SelectObjectModule( ObjectModule &objectModule )
-	{
-		pNowObjectModule = &objectModule;
-
-		namespaceSupporter.RegistAllNamespaceScopesCollection( &GetObjectModule().meta.GetNamespaces() );
+		return *pSelectedObjectModule;
+	}
+
+	void SelectObjectModule( ObjectModule *pObjectModule )
+	{
+		this->pSelectedObjectModule = pObjectModule;
+	}
+
+	// 現在参照すべきソースコード
+	const BasicSource &GetCurrentSource()
+	{
+		return staticLibraries[currentRelationalObjectModuleIndexForSource]->GetSource();
+	}
+
+	// 現在参照すべきソースコードを格納するオブジェクトモジュールのインデックス
+	int GetCurrentRelationalObjectModuleIndexForSource() const
+	{
+		return currentRelationalObjectModuleIndexForSource;
+	}
+	void SetCurrentRelationalObjectModuleIndexForSource( int currentRelationalObjectModuleIndexForSource )
+	{
+		this->currentRelationalObjectModuleIndexForSource = currentRelationalObjectModuleIndexForSource;
 	}
 
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/include/Program.h
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/include/Program.h	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/include/Program.h	(revision 636)
@@ -42,4 +42,9 @@
 	{
 		return outputFilePath;
+	}
+	const std::string GetOutputFileName() const
+	{
+		Jenga::Common::Path path( outputFilePath );
+		return path.GetFileName() + path.GetExt();
 	}
 	void SetOutputFilePath( const std::string &outputFilePath )
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/src/BoostSerializationSupport.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/src/BoostSerializationSupport.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/src/BoostSerializationSupport.cpp	(revision 636)
@@ -496,5 +496,7 @@
 #include <logger.h>
 #include <Configuration.h>
+#include <abdev/ab_common/include/Lexical/Source.h>
 
 template class Jenga::Common::BoostSerializationSupport<LoggerSetting>;
 template class Jenga::Common::BoostSerializationSupport<Configuration>;
+template class Jenga::Common::BoostSerializationSupport<BasicSources>;
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/src/Compiler.cpp	(revision 636)
@@ -5,10 +5,50 @@
 Compiler compiler;
 
+Compiler::Compiler()
+	: isBuildSuccessful( false )
+	, targetModuleType( ActiveBasic::Common::TargetModuleType::Exe )
+	, isDebug( false )
+	, isUnicode( false )
+	, isCore( false )
+	, currentRelationalObjectModuleIndexForSource( 0 )
+{
+	// 生成先のオブジェクトモジュールを登録
+	ObjectModule *pObjectModule = new ObjectModule();
+	staticLibraries.push_back( pObjectModule );
+	SelectObjectModule( pObjectModule );
+
+	namespaceSupporter.RegistAllNamespaceScopesCollection( &GetObjectModule().meta.GetNamespaces() );
+
+	Symbol::RegistNamespaceSupporter( &namespaceSupporter );
+}
+Compiler::~Compiler()
+{
+	BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries )
+	{
+		delete pStaticLibrary;
+	}
+	staticLibraries.clear();
+}
+
+void Compiler::PreStaticLink( const ObjectModules &staticLibraries )
+{
+	BOOST_FOREACH( const ObjectModule *pStaticLibrary, staticLibraries )
+	{
+		// 関連オブジェクトモジュールの名前リスト
+		this->GetObjectModule().relationalObjectModuleNames.push_back( pStaticLibrary->GetName() );
+	}
+}
 void Compiler::StaticLink( ObjectModules &staticLibraries )
 {
 	BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries )
 	{
+		if( &this->GetObjectModule() == pStaticLibrary )
+		{
+			// 自分自身の場合はリンクしない
+			continue;
+		}
+
 		// メタ情報
-		pNowObjectModule->StaticLink( *pStaticLibrary );
+		this->GetObjectModule().StaticLink( *pStaticLibrary );
 	}
 }
Index: /trunk/ab5.0/abdev/BasicCompiler_Common/src/Messenger.cpp
===================================================================
--- /trunk/ab5.0/abdev/BasicCompiler_Common/src/Messenger.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/BasicCompiler_Common/src/Messenger.cpp	(revision 636)
@@ -42,5 +42,5 @@
 	if( sourceIndex != -1 )
 	{
-		compiler.GetObjectModule().GetCurrentSource().GetLineInfo( sourceIndex, sourceLineNum, sourceFilePath );
+		compiler.GetCurrentSource().GetLineInfo( sourceIndex, sourceLineNum, sourceFilePath );
 	}
 
Index: /trunk/ab5.0/abdev/ab_common/include/Lexical/Interface.h
===================================================================
--- /trunk/ab5.0/abdev/ab_common/include/Lexical/Interface.h	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/include/Lexical/Interface.h	(revision 636)
@@ -72,5 +72,6 @@
 	}
 
-	const CClass &GetClass() const{
+	const CClass &GetClass() const
+	{
 		return *pInterfaceClass;
 	}
Index: /trunk/ab5.0/abdev/ab_common/include/Lexical/Meta.h
===================================================================
--- /trunk/ab5.0/abdev/ab_common/include/Lexical/Meta.h	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/include/Lexical/Meta.h	(revision 636)
@@ -69,5 +69,5 @@
 
 	// 静的リンク
-	void StaticLink( Meta &meta, long dataSectionBaseOffset, int sourceIndexBase );
+	void StaticLink( Meta &meta, long dataSectionBaseOffset, const std::vector<int> &relationTable );
 
 	const NamespaceScopesCollection &GetNamespaces() const
Index: /trunk/ab5.0/abdev/ab_common/include/Lexical/NativeCode.h
===================================================================
--- /trunk/ab5.0/abdev/ab_common/include/Lexical/NativeCode.h	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/include/Lexical/NativeCode.h	(revision 636)
@@ -125,5 +125,5 @@
 	int lineNum;
 	long nativeCodePos;
-	int sourceIndex;
+	int relationalObjectModuleIndex;
 	long sourceCodePos;
 	DWORD codeType;
@@ -138,5 +138,5 @@
 		ar & BOOST_SERIALIZATION_NVP( lineNum );
 		ar & BOOST_SERIALIZATION_NVP( nativeCodePos );
-		ar & BOOST_SERIALIZATION_NVP( sourceIndex );
+		ar & BOOST_SERIALIZATION_NVP( relationalObjectModuleIndex );
 		ar & BOOST_SERIALIZATION_NVP( sourceCodePos );
 		ar & BOOST_SERIALIZATION_NVP( codeType );
@@ -144,8 +144,8 @@
 
 public:
-	SourceLine( int lineNum, int nativeCodePos, int sourceIndex, int sourceCodePos, DWORD codeType )
+	SourceLine( int lineNum, int nativeCodePos, int relationalObjectModuleIndex, int sourceCodePos, DWORD codeType )
 		: lineNum( lineNum )
 		, nativeCodePos( nativeCodePos )
-		, sourceIndex( sourceIndex )
+		, relationalObjectModuleIndex( relationalObjectModuleIndex )
 		, sourceCodePos( sourceCodePos )
 		, codeType( codeType )
@@ -164,11 +164,11 @@
 		return nativeCodePos;
 	}
-	int GetSourceIndex() const
-	{
-		return sourceIndex;
-	}
-	void SetSourceIndex( int sourceIndex )
-	{
-		this->sourceIndex = sourceIndex;
+	int GetRelationalObjectModuleIndex() const
+	{
+		return relationalObjectModuleIndex;
+	}
+	void SetRelationalObjectModuleIndex( int relationalObjectModuleIndex )
+	{
+		this->relationalObjectModuleIndex = relationalObjectModuleIndex;
 	}
 	long GetSourceCodePos() const
@@ -259,4 +259,4 @@
 
 	void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
-	void ResetSourceIndexes( long sourceIndexBase );
+	void ResetSourceIndexes( const std::vector<int> &relationTable );
 };
Index: /trunk/ab5.0/abdev/ab_common/include/Lexical/ObjectModule.h
===================================================================
--- /trunk/ab5.0/abdev/ab_common/include/Lexical/ObjectModule.h	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/include/Lexical/ObjectModule.h	(revision 636)
@@ -6,4 +6,7 @@
 	// オブジェクトモジュール名
 	std::string name;
+
+	// 関連オブジェクトモジュールの名前リスト
+	Jenga::Common::Strings relationalObjectModuleNames;
 
 	// メタ情報
@@ -18,6 +21,5 @@
 private:
 	// ソースコード
-	int currentSourceIndex;
-	BasicSources sources;
+	BasicSource source;
 
 	// XMLシリアライズ用
@@ -33,9 +35,9 @@
 
 		ar & BOOST_SERIALIZATION_NVP( name );
+		ar & BOOST_SERIALIZATION_NVP( relationalObjectModuleNames );
 		ar & BOOST_SERIALIZATION_NVP( meta );
 		ar & BOOST_SERIALIZATION_NVP( globalNativeCode );
 		ar & BOOST_SERIALIZATION_NVP( dataTable );
-		ar & BOOST_SERIALIZATION_NVP( currentSourceIndex );
-		ar & BOOST_SERIALIZATION_NVP( sources );
+		ar & BOOST_SERIALIZATION_NVP( source );
 	}
 
@@ -51,28 +53,16 @@
 		this->name = name;
 	}
-	int GetCurrentSourceIndex() const
+	const BasicSource &GetSource() const
 	{
-		return currentSourceIndex;
+		return source;
 	}
-	const BasicSource &GetCurrentSource() const
+	BasicSource &GetSource()
 	{
-		return sources[currentSourceIndex];
+		return source;
 	}
-	BasicSource &GetCurrentSource()
-	{
-		return sources[currentSourceIndex];
-	}
-	void SetCurrentSourceIndex( int currentSourceIndex )
-	{
-		this->currentSourceIndex = currentSourceIndex;
-	}
-	const BasicSource &GetSource( int sourceIndex ) const
-	{
-		return sources[sourceIndex];
-	}
-	BasicSources &GetSources()
-	{
-		return sources;
-	}
+
+	// 下記の関連になるようなテーブルを取得する
+	// 要素 = 古いインデックス、値 = 新しいインデックス
+	const std::vector<int> GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModule );
 
 	bool Read( const std::string &filePath );
Index: /trunk/ab5.0/abdev/ab_common/include/Lexical/Source.h
===================================================================
--- /trunk/ab5.0/abdev/ab_common/include/Lexical/Source.h	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/include/Lexical/Source.h	(revision 636)
@@ -11,6 +11,4 @@
 	template<class Archive> void serialize(Archive& ar, const unsigned int version)
 	{
-		trace_for_serialize( "serializing - IncludedFilesRelation" );
-
 		ar & BOOST_SERIALIZATION_NVP( filePaths );
 		ar & BOOST_SERIALIZATION_NVP( lineFileNumbers );
@@ -119,6 +117,4 @@
 	template<class Archive> void load(Archive& ar, const unsigned int version)
 	{
-		trace_for_serialize( "serializing(load) - BasicSource" );
-
 		std::string _buffer;
 		ar & BOOST_SERIALIZATION_NVP( _buffer );
@@ -139,6 +135,4 @@
 	template<class Archive> void save(Archive& ar, const unsigned int version) const
 	{
-		trace_for_serialize( "serializing(save) - BasicSource" );
-
 		// 保存準備
 		char *tempCode = (char *)calloc( (length+1) * 3, 1 );
@@ -252,5 +246,20 @@
 	int cannotIncludeSourcePos;
 };
-typedef std::vector<BasicSource> BasicSources;
+class BasicSources
+	: public std::vector<BasicSource>
+	, public Jenga::Common::BoostSerializationSupport<BasicSources>
+{
+	// XMLシリアライズ用
+private:
+	virtual const char *RootTagName() const
+	{
+		return "basicSources";
+	}
+	friend class boost::serialization::access;
+	template<class Archive> void serialize(Archive& ar, const unsigned int version)
+	{
+		ar & boost::serialization::make_nvp("vector_BasicSource", boost::serialization::base_object<std::vector<BasicSource>>(*this));
+	}
+};
 
 class SourceCodePosition
Index: /trunk/ab5.0/abdev/ab_common/src/Lexical/Class.cpp
===================================================================
--- /trunk/ab5.0/abdev/ab_common/src/Lexical/Class.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/src/Lexical/Class.cpp	(revision 636)
@@ -677,4 +677,5 @@
 	}
 
+	_ASSERT( false );
 	throw;
 }
@@ -693,4 +694,5 @@
 	}
 
+	_ASSERT( false );
 	throw;
 }
@@ -699,4 +701,5 @@
 	if( vtblMasterListOffset == -1 )
 	{
+		_ASSERT( false );
 		throw;
 	}
Index: /trunk/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp
===================================================================
--- /trunk/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp	(revision 636)
@@ -34,5 +34,5 @@
 }
 
-void Meta::StaticLink( Meta &meta, long dataSectionBaseOffset, int sourceIndexBase )
+void Meta::StaticLink( Meta &meta, long dataSectionBaseOffset, const std::vector<int> &relationTable )
 {
 	// 名前空間
@@ -53,5 +53,5 @@
 
 		pUserProc->GetNativeCode().ResetDataSectionBaseOffset( dataSectionBaseOffset );
-		pUserProc->GetNativeCode().ResetSourceIndexes( sourceIndexBase );
+		pUserProc->GetNativeCode().ResetSourceIndexes( relationTable );
 
 		this->userProcs.Put( pUserProc );
@@ -75,4 +75,5 @@
 		CClass *pClass = meta.GetClasses().Iterator_GetNext();
 		pClass->isTargetObjectModule = false;
+		pClass->Readed();
 		this->GetClasses().Put( pClass );
 	}
Index: /trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp
===================================================================
--- /trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp	(revision 636)
@@ -45,5 +45,5 @@
 				sourceLine.GetLineNum(),
 				baseOffset + sourceLine.GetNativeCodePos(),
-				sourceLine.GetSourceIndex(),
+				sourceLine.GetRelationalObjectModuleIndex(),	// TODO: 複数libの取り込みを想定できていない（ソースコード行番号とネイティブコード位置の対応情報の追加は静的リンクが完了した後に行うべき）
 				sourceLine.GetSourceCodePos(),
 				sourceLine.GetCodeType()
@@ -152,9 +152,9 @@
 	}
 }
-void NativeCode::ResetSourceIndexes( long sourceIndexBase )
+void NativeCode::ResetSourceIndexes( const std::vector<int> &relationTable )
 {
 	BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
 	{
-		sourceLine.SetSourceIndex( sourceLine.GetSourceIndex() + sourceIndexBase );
+		sourceLine.SetRelationalObjectModuleIndex( relationTable[sourceLine.GetRelationalObjectModuleIndex()] );
 	}
 }
Index: /trunk/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp
===================================================================
--- /trunk/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp	(revision 636)
@@ -58,13 +58,14 @@
 void ObjectModule::StaticLink( ObjectModule &objectModule )
 {
+	const std::vector<int> relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames );
+
 	long dataSectionBaseOffset = dataTable.GetSize();
-	int sourceIndexBase = (int)sources.size();
 
 	// メタ情報を結合
-	meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
+	meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable );
 
 	// グローバル ネイティブコードを結合
 	objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
-	objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
+	objectModule.globalNativeCode.ResetSourceIndexes( relationTable );
 	globalNativeCode.PutEx( objectModule.globalNativeCode );
 
@@ -73,13 +74,36 @@
 	dataTable.Add( objectModule.dataTable );
 
-	// ソースコードを結合
-	BOOST_FOREACH( const BasicSource &source, objectModule.sources )
-	{
-		this->sources.push_back( source );
-	}
-
 	// TODO: basbufがいらなくなったら消す
 	extern char *basbuf;
-	basbuf = this->sources[0].GetBuffer();
+	basbuf = this->source.GetBuffer();
+}
+
+const std::vector<int> ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames )
+{
+	// 要素 = 古いインデックス、値 = 新しいインデックス
+	std::vector<int> relationTable;
+
+	// リレーションテーブルを構築
+	BOOST_FOREACH( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames )
+	{
+		bool isMatch = false;
+		for( int i=0; i<static_cast<int>(this->relationalObjectModuleNames.size()); i++ )
+		{
+			if( oldRelationalObjectModuleName == this->relationalObjectModuleNames[i] )
+			{
+				isMatch = true;
+				relationTable.push_back( i );
+				break;
+			}
+		}
+
+		if( !isMatch )
+		{
+			// エラー
+			_ASSERT( false );
+		}
+	}
+
+	return relationTable;
 }
 
Index: /trunk/ab5.0/abdev/compiler_x86/Compile_ProcOp.cpp
===================================================================
--- /trunk/ab5.0/abdev/compiler_x86/Compile_ProcOp.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/compiler_x86/Compile_ProcOp.cpp	(revision 636)
@@ -328,6 +328,24 @@
 	}
 
+	char *backupBasbuf = NULL;
+	int backupCurrentRelationalObjectModuleIndexForSource = compiler.GetCurrentRelationalObjectModuleIndexForSource();
+
 	if( !pUserProc->IsAutoGeneration() )
 	{
+		// テンプレート展開がされている場合、対象のソースコードが現在のオブジェクトモジュールではない場合がある
+		if( compiler.staticLibraries[compiler.GetCurrentRelationalObjectModuleIndexForSource()]->GetName() != pUserProc->GetSourceCodePosition().GetObjectModuleName() )
+		{
+			for( int i=0; i<static_cast<int>(compiler.staticLibraries.size()); i++ )
+			{
+				const ObjectModule *pObjectModule = compiler.staticLibraries[i];
+
+				if( pObjectModule->GetName() == pUserProc->GetSourceCodePosition().GetObjectModuleName() )
+				{
+					compiler.SetCurrentRelationalObjectModuleIndexForSource( i );
+					basbuf = const_cast<char *>(compiler.GetCurrentSource().GetBuffer());
+				}
+			}
+		}
+
 		cp=pUserProc->GetSourceCodePosition().GetPos();
 		for(;;cp++){
Index: /trunk/ab5.0/abdev/compiler_x86/MakePeHdr.cpp
===================================================================
--- /trunk/ab5.0/abdev/compiler_x86/MakePeHdr.cpp	(revision 635)
+++ /trunk/ab5.0/abdev/compiler_x86/MakePeHdr.cpp	(revision 636)
@@ -120,4 +120,5 @@
 
 	// 静的リンク
+	compiler.PreStaticLink( compiler.staticLibraries );
 	compiler.StaticLink( compiler.staticLibraries );
 
@@ -144,5 +145,5 @@
 	{
 		ActiveBasic::Compiler::LexicalAnalyzer::CollectEnums(
-			compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+			compiler.GetCurrentSource().GetBuffer(),
 			compiler.enumInfoCollection
 		);
@@ -157,5 +158,5 @@
 	// 名前空間情報を取得
 	ActiveBasic::Compiler::LexicalAnalyzer::CollectNamespaces(
-		compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+		compiler.GetCurrentSource().GetBuffer(),
 		compiler.GetObjectModule().meta.GetNamespaces()
 	);
@@ -164,5 +165,5 @@
 	{
 		ActiveBasic::Compiler::LexicalAnalyzer::CollectDelegates(
-			compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+			compiler.GetCurrentSource().GetBuffer(),
 			compiler.GetObjectModule().meta.GetDelegates()
 		);
@@ -180,5 +181,5 @@
 	//     ※オブジェクトの内容までは取得しない
 	ActiveBasic::Compiler::LexicalAnalyzer::CollectClassesForNameOnly(
-		compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+		compiler.GetCurrentSource().GetBuffer(),
 		compiler.GetObjectModule().meta.GetClasses()
 	);
@@ -186,5 +187,5 @@
 	//TypeDef情報を収集
 	ActiveBasic::Compiler::LexicalAnalyzer::CollectTypeDefs(
-		compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+		compiler.GetCurrentSource().GetBuffer(),
 		compiler.GetObjectModule().meta.GetTypeDefs()
 	);
@@ -201,5 +202,5 @@
 	//定数情報を取得
 	ActiveBasic::Compiler::LexicalAnalyzer::CollectConsts(
-		compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+		compiler.GetCurrentSource().GetBuffer(),
 		compiler.GetObjectModule().meta.GetGlobalConsts(),
 		compiler.GetObjectModule().meta.GetGlobalConstMacros()
@@ -209,5 +210,5 @@
 	compiler.SetCompilingClass( NULL );
 	ActiveBasic::Compiler::LexicalAnalyzer::CollectProcedures(
-		compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+		compiler.GetCurrentSource().GetBuffer(),
 		compiler.GetObjectModule().meta.GetUserProcs(),
 		compiler.GetObjectModule().meta.GetDllProcs()
@@ -216,5 +217,5 @@
 	// クラス情報を取得（※注 - CollectProceduresの後に呼び出す）
 	ActiveBasic::Compiler::LexicalAnalyzer::CollectClasses(
-		compiler.GetObjectModule().GetCurrentSource().GetBuffer(),
+		compiler.GetCurrentSource().GetBuffer(),
 		compiler.GetObjectModule().meta.GetClasses()
 	);
