Index: trunk/ab5.0/abdev/ab_common/src/Environment.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Environment.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Environment.cpp	(revision 637)
@@ -2,4 +2,5 @@
 
 std::string ActiveBasic::Common::Environment::rootPath;
+bool ActiveBasic::Common::Environment::isRemoveExternal = false;
 
 using namespace ActiveBasic::Common;
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Class.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Class.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Class.cpp	(revision 637)
@@ -2,6 +2,6 @@
 
 
-CClass::CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const std::string &name )
-	: ClassPrototype( namespaceScopes, name )
+CClass::CClass( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces )
+	: ClassPrototype( symbol )
 	, importedNamespaces( importedNamespaces )
 	, classType( Class )
@@ -21,7 +21,7 @@
 }
 
-CClass::CClass( const NamespaceScopes &namespaceScopes,
+CClass::CClass(
+	const Symbol &symbol,
 	const NamespaceScopesCollection &importedNamespaces,
-	const std::string &name,
 	ClassType classType,
 	const GenericTypes &formalGenericTypes,
@@ -31,5 +31,5 @@
 	int vtblNum,
 	int fixedAlignment )
-	: ClassPrototype( namespaceScopes, name )
+	: ClassPrototype( symbol )
 	, importedNamespaces( importedNamespaces )
 	, classType( classType )
@@ -868,2 +868,8 @@
 	}
 }
+
+bool CClass::Resolve()
+{
+	// TODO: Resolve
+	return true;
+}
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Const.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Const.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Const.cpp	(revision 637)
@@ -7,13 +7,19 @@
 }
 
-void Consts::Add( const NamespaceScopes &namespaceScopes, const std::string &name, _int64 i64data, const Type &type )
+bool CConst::Resolve()
 {
-	CConst *newconst = new CConst(namespaceScopes, name, type, i64data);
+	// TODO: Resolve
+	return true;
+}
+
+void Consts::Add( const Symbol &symbol, _int64 i64data, const Type &type )
+{
+	CConst *newconst = new CConst( symbol, type, i64data );
 
 	//ハッシュリストに追加
 	Put( newconst );
 }
-void Consts::Add(const NamespaceScopes &namespaceScopes, const std::string &name, int value){
-	CConst *newconst = new CConst( namespaceScopes, name, value);
+void Consts::Add(const Symbol &symbol, int value){
+	CConst *newconst = new CConst( symbol, value);
 
 	//ハッシュリストに追加
@@ -72,6 +78,12 @@
 }
 
+bool ConstMacro::Resolve()
+{
+	// TODO: Resolve
+	return true;
+}
+
 // マクロ定数を追加するための関数
-bool ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr )
+bool ConstMacros::Add( const Symbol &symbol, const char *parameterStr )
 {
 	std::vector<std::string> parameters;
@@ -113,5 +125,5 @@
 	lstrcpy(temporary,parameterStr+i+1);
 
-	this->Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) );
+	this->Put( new ConstMacro( symbol, parameters, temporary ) );
 
 	return true;
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/DataTable.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/DataTable.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/DataTable.cpp	(revision 637)
@@ -77,2 +77,7 @@
 	}
 }
+
+void DataTable::Resolve()
+{
+	// TODO: Resolve
+}
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Delegate.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Delegate.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Delegate.cpp	(revision 637)
@@ -18,2 +18,8 @@
 	return false;
 }
+
+bool Delegate::Resolve()
+{
+	// TODO: Resolve
+	return true;
+}
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp	(revision 637)
@@ -50,8 +50,13 @@
 	{
 		UserProc *pUserProc = meta.GetUserProcs().Iterator_GetNext();
-		pUserProc->isTargetObjectModule = false;
+		if( pUserProc->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pUserProc->ResetRelationalObjectModuleIndex( relationTable );
 
 		pUserProc->GetNativeCode().ResetDataSectionBaseOffset( dataSectionBaseOffset );
-		pUserProc->GetNativeCode().ResetSourceIndexes( relationTable );
 
 		this->userProcs.Put( pUserProc );
@@ -64,5 +69,11 @@
 	{
 		DllProc *pDllProc = meta.GetDllProcs().Iterator_GetNext();
-		pDllProc->isTargetObjectModule = false;
+		if( pDllProc->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pDllProc->ResetRelationalObjectModuleIndex( relationTable );
 		this->dllProcs.Put( pDllProc );
 	}
@@ -74,5 +85,11 @@
 	{
 		CClass *pClass = meta.GetClasses().Iterator_GetNext();
-		pClass->isTargetObjectModule = false;
+		if( pClass->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pClass->ResetRelationalObjectModuleIndex( relationTable );
 		pClass->Readed();
 		this->GetClasses().Put( pClass );
@@ -84,4 +101,10 @@
 	BOOST_FOREACH( Variable *pVar, meta.globalVars )
 	{
+		if( pVar->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
 		// 基底スコープレベルのグローバル変数の生存値をオンにする
 		if( pVar->GetScopeLevel() == 0 )
@@ -99,5 +122,5 @@
 		}
 
-		pVar->isTargetObjectModule = false;
+		pVar->ResetRelationalObjectModuleIndex( relationTable );
 		this->globalVars.Add( pVar, isResetOffsetAddress );
 	}
@@ -113,5 +136,11 @@
 	{
 		CConst *pConst = meta.GetGlobalConsts().Iterator_GetNext();
-		pConst->isTargetObjectModule = false;
+		if( pConst->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pConst->ResetRelationalObjectModuleIndex( relationTable );
 		this->GetGlobalConsts().Put( pConst );
 	}
@@ -123,5 +152,11 @@
 	{
 		ConstMacro *pConstMacro = meta.GetGlobalConstMacros().Iterator_GetNext();
-		pConstMacro->isTargetObjectModule = false;
+		if( pConstMacro->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pConstMacro->ResetRelationalObjectModuleIndex( relationTable );
 		this->GetGlobalConstMacros().Put( pConstMacro );
 	}
@@ -131,5 +166,5 @@
 	BOOST_FOREACH( BlittableType &blittableType, meta.blittableTypes )
 	{
-		blittableType.isTargetObjectModule = false;
+		// TODO: coreモジュール以外でもBlittable型用のクラスモジュールを定義できるようにすべき
 		this->blittableTypes.push_back( blittableType );
 	}
@@ -139,5 +174,11 @@
 	BOOST_FOREACH( TypeDef &typeDef, meta.typeDefs )
 	{
-		typeDef.isTargetObjectModule = false;
+		if( typeDef.IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		typeDef.ResetRelationalObjectModuleIndex( relationTable );
 		this->typeDefs.push_back( typeDef );
 	}
@@ -147,5 +188,11 @@
 	BOOST_FOREACH( ProcPointer *pProcPointer, meta.procPointers )
 	{
-		pProcPointer->isTargetObjectModule = false;
+		if( pProcPointer->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pProcPointer->ResetRelationalObjectModuleIndex( relationTable );
 		this->procPointers.push_back( pProcPointer );
 	}
@@ -157,5 +204,11 @@
 	{
 		Delegate *pDelegate = meta.GetDelegates().Iterator_GetNext();
-		pDelegate->isTargetObjectModule = false;
+		if( pDelegate->IsExternal() )
+		{
+			// 外部参照の場合は取り込まない
+			continue;
+		}
+
+		pDelegate->ResetRelationalObjectModuleIndex( relationTable );
 		this->GetDelegates().Put( pDelegate );
 	}
@@ -199,2 +252,77 @@
 	return NULL;
 }
+
+void Meta::Resolve()
+{
+	// 関数・メソッド
+	this->GetUserProcs().Iterator_Init();
+	this->GetUserProcs().Iterator_Reset();
+	while( this->GetUserProcs().Iterator_HasNext() )
+	{
+		UserProc *pUserProc = this->GetUserProcs().Iterator_GetNext();
+		pUserProc->Resolve();
+	}
+
+	// DLL関数
+	this->GetDllProcs().Iterator_Init();
+	this->GetDllProcs().Iterator_Reset();
+	while( this->GetDllProcs().Iterator_HasNext() )
+	{
+		DllProc *pDllProc = this->GetDllProcs().Iterator_GetNext();
+		pDllProc->Resolve();
+	}
+
+	// クラス
+	this->GetClasses().Iterator_Init();
+	this->GetClasses().Iterator_Reset();
+	while( this->GetClasses().Iterator_HasNext() )
+	{
+		CClass *pClass = this->GetClasses().Iterator_GetNext();
+		pClass->Resolve();
+	}
+
+	// グローバル変数
+	BOOST_FOREACH( Variable *pVar, globalVars )
+	{
+		pVar->Resolve();
+	}
+
+	// グローバル定数
+	this->GetGlobalConsts().Iterator_Init();
+	this->GetGlobalConsts().Iterator_Reset();
+	while( this->GetGlobalConsts().Iterator_HasNext() )
+	{
+		CConst *pConst = this->GetGlobalConsts().Iterator_GetNext();
+		pConst->Resolve();
+	}
+
+	// グローバル定数マクロ
+	this->GetGlobalConstMacros().Iterator_Init();
+	this->GetGlobalConstMacros().Iterator_Reset();
+	while( this->GetGlobalConstMacros().Iterator_HasNext() )
+	{
+		ConstMacro *pConstMacro = this->GetGlobalConstMacros().Iterator_GetNext();
+		pConstMacro->Resolve();
+	}
+
+	// TypeDef
+	BOOST_FOREACH( TypeDef &typeDef, typeDefs )
+	{
+		typeDef.Resolve();
+	}
+
+	// 関数ポインタ
+	BOOST_FOREACH( ProcPointer *pProcPointer, procPointers )
+	{
+		pProcPointer->Resolve();
+	}
+
+	// デリゲート
+	this->GetDelegates().Iterator_Init();
+	this->GetDelegates().Iterator_Reset();
+	while( this->GetDelegates().Iterator_HasNext() )
+	{
+		Delegate *pDelegate = this->GetDelegates().Iterator_GetNext();
+		pDelegate->Resolve();
+	}
+}
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp	(revision 637)
@@ -43,9 +43,7 @@
 		this->sourceLines.push_back(
 			SourceLine(
-				sourceLine.GetLineNum(),
 				baseOffset + sourceLine.GetNativeCodePos(),
-				sourceLine.GetRelationalObjectModuleIndex(),	// TODO: 複数libの取り込みを想定できていない（ソースコード行番号とネイティブコード位置の対応情報の追加は静的リンクが完了した後に行うべき）
-				sourceLine.GetSourceCodePos(),
-				sourceLine.GetCodeType()
+				sourceLine.GetCodeType(),
+				sourceLine.GetSourceCodePosition()
 			)
 		);
@@ -106,5 +104,5 @@
 }
 
-void NativeCode::NextSourceLine( int currentSourceIndex, int nowLine )
+void NativeCode::NextSourceLine( const SourceCodePosition &sourceCodePosition )
 {
 	if( sourceLines.size() )
@@ -112,5 +110,5 @@
 		if( sourceLines.back().GetNativeCodePos() == GetSize() )
 		{
-			sourceLines.back().SetSourceCodePos( nowLine );
+			sourceLines.back().SetSourceCodePosition( sourceCodePosition );
 			return;
 		}
@@ -130,9 +128,7 @@
 	sourceLines.push_back(
 		SourceLine(
-			(long)sourceLines.size(),
 			GetSize(),
-			currentSourceIndex,
-			nowLine,
-			sourceLineType
+			sourceLineType,
+			sourceCodePosition
 		)
 	);
@@ -152,9 +148,16 @@
 	}
 }
-void NativeCode::ResetSourceIndexes( const std::vector<int> &relationTable )
+void NativeCode::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
 {
 	BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
 	{
-		sourceLine.SetRelationalObjectModuleIndex( relationTable[sourceLine.GetRelationalObjectModuleIndex()] );
+		sourceLine.GetSourceCodePosition().SetRelationalObjectModuleIndex(
+			relationTable[sourceLine.GetSourceCodePosition().GetRelationalObjectModuleIndex()]
+		);
 	}
 }
+
+void NativeCode::Resolve()
+{
+	// TODO: Resolve
+}
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp	(revision 637)
@@ -56,5 +56,5 @@
 
 
-void ObjectModule::StaticLink( ObjectModule &objectModule )
+void ObjectModule::StaticLink( ObjectModule &objectModule, bool isSll )
 {
 	const std::vector<int> relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames );
@@ -65,16 +65,33 @@
 	meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable );
 
-	// グローバル ネイティブコードを結合
-	objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
-	objectModule.globalNativeCode.ResetSourceIndexes( relationTable );
-	globalNativeCode.PutEx( objectModule.globalNativeCode );
-
-	// データテーブルを結合
-	objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
-	dataTable.Add( objectModule.dataTable );
+	if( !isSll )
+	{
+		// グローバル ネイティブコードを結合
+		objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
+		objectModule.globalNativeCode.ResetRelationalObjectModuleIndex( relationTable );
+		globalNativeCode.PutEx( objectModule.globalNativeCode );
+
+		// データテーブルを結合
+		objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
+		dataTable.Add( objectModule.dataTable );
+	}
+
+	// 依存関係を解決
+	this->Resolve();
 
 	// TODO: basbufがいらなくなったら消す
 	extern char *basbuf;
 	basbuf = this->source.GetBuffer();
+}
+
+void ObjectModule::Resolve()
+{
+	this->meta.Resolve();
+
+	// グローバルネイティブコードを解決（スケジュールを解決する）
+	this->globalNativeCode.Resolve();
+
+	// データテーブルを解決（スケジュールを解決する）
+	this->dataTable.Resolve();
 }
 
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Procedure.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Procedure.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Procedure.cpp	(revision 637)
@@ -1,8 +1,26 @@
 #include "stdafx.h"
 
+
+void Procedure::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
+{
+	RelationalObjectModuleItem::ResetRelationalObjectModuleIndex( relationTable );
+
+	if( !this->sourceCodePosition.IsNothing() )
+	{
+		this->sourceCodePosition.SetRelationalObjectModuleIndex( relationTable[this->sourceCodePosition.GetRelationalObjectModuleIndex()] );
+	}
+}
+
+void UserProc::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
+{
+	Procedure::ResetRelationalObjectModuleIndex( relationTable );
+
+	this->GetNativeCode().ResetRelationalObjectModuleIndex( relationTable );
+}
+
 int id_base = 0;
 
-UserProc::UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const std::string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport )
-	: Procedure( namespaceScopes, name, kind, isCdecl )
+UserProc::UserProc( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces, Kind kind, bool isMacro, bool isCdecl, bool isExport )
+	: Procedure( symbol, kind, isCdecl )
 	, importedNamespaces( importedNamespaces )
 	, pParentClass( NULL )
@@ -139,4 +157,10 @@
 }
 
+bool UserProc::Resolve()
+{
+	// TODO: Resolve
+	return true;
+}
+
 const UserProc *UserProc::pGlobalProc = NULL;
 
@@ -161,4 +185,16 @@
 }
 
+bool DllProc::Resolve()
+{
+	// TODO: Resolve
+	return true;
+}
+
+bool ProcPointer::Resolve()
+{
+	// TODO: Resolve
+	return true;
+}
+
 void ProcPointers::Clear()
 {
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Source.cpp	(revision 637)
@@ -941,2 +941,28 @@
 	return 1;
 }
+
+int SourceCodePosition::GetRelationalObjectModuleIndex() const
+{
+	if( this->IsNothing() )
+	{
+		_ASSERTE( false );
+		throw;
+	}
+
+	return relationalObjectModuleIndex;
+}
+bool SourceCodePosition::IsNothing() const
+{
+	if( this->relationalObjectModuleIndex == -1 && this->pos == -1 )
+	{
+		return true;
+	}
+
+	if( this->relationalObjectModuleIndex == -1 || this->pos == -1 )
+	{
+		_ASSERTE( false );
+		throw;
+	}
+
+	return false;
+}
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/TypeDef.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/TypeDef.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/TypeDef.cpp	(revision 637)
@@ -1,9 +1,15 @@
 #include "stdafx.h"
 
-TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const std::string &name, const std::string &baseName, const Type &baseType )
-	: Symbol( namespaceScopes, name )
+TypeDef::TypeDef( const Symbol &symbol, const std::string &baseName, const Type &baseType )
+	: RelationalObjectModuleItem( symbol )
 	, baseName( baseName )
 	, baseType( baseType )
 {
+}
+
+bool TypeDef::Resolve()
+{
+	// TODO: Resolve
+	return true;
 }
 
@@ -12,6 +18,6 @@
 TypeDefCollection::~TypeDefCollection(){
 }
-void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const std::string &baseName, int nowLine ){
-	TypeDef typeDef( namespaceScopes, name, baseName, nowLine );
+void TypeDefCollection::Add( const Symbol &symbol, const std::string &baseName, int nowLine ){
+	TypeDef typeDef( symbol, baseName, nowLine );
 	this->push_back( typeDef );
 }
Index: trunk/ab5.0/abdev/ab_common/src/Lexical/Variable.cpp
===================================================================
--- trunk/ab5.0/abdev/ab_common/src/Lexical/Variable.cpp	(revision 636)
+++ trunk/ab5.0/abdev/ab_common/src/Lexical/Variable.cpp	(revision 637)
@@ -2,16 +2,5 @@
 
 Variable::Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string &paramStrForConstructor, bool hasInitData )
-	: Symbol( symbol )
-	, type( type )
-	, isConst( isConst )
-	, isRef( isRef )
-	, isArray( false )
-	, isParameter( false)
-	, paramStrForConstructor( paramStrForConstructor )
-	, hasInitData( hasInitData )
-{
-}
-Variable::Variable( const NamespaceScopes &namespaceScopes, const std::string &name, const Type &type, bool isConst, bool isRef, const std::string &paramStrForConstructor, bool hasInitData )
-	: Symbol( namespaceScopes, name )
+	: RelationalObjectModuleItem( symbol )
 	, type( type )
 	, isConst( isConst )
@@ -24,5 +13,5 @@
 }
 Variable::Variable( const Variable &var )
-	: Symbol( var )
+	: RelationalObjectModuleItem( var )
 	, type( var.type )
 	, isConst( var.isConst )
@@ -37,4 +26,10 @@
 Variable::Variable()
 {
+}
+
+bool Variable::Resolve()
+{
+	// TODO: Resolve
+	return true;
 }
 
