Index: trunk/abdev/BasicCompiler_Common/include/Procedure.h
===================================================================
--- trunk/abdev/BasicCompiler_Common/include/ProcedureImpl.h	(revision 193)
+++ trunk/abdev/BasicCompiler_Common/include/Procedure.h	(revision 206)
@@ -1,75 +1,537 @@
 #pragma once
 
-#include <jenga/include/smoothie/Procedure.h>
-
-
-class UserProcImpl : public UserProc
+#include <jenga/include/common/Hashmap.h>
+#include <jenga/include/smoothie/Source.h>
+#include <jenga/include/smoothie/LexicalAnalysis.h>
+
+#include <option.h>
+#include <Program.h>
+#include <Class.h>
+#include <Method.h>
+#include <Procedure.h>
+#include <Parameter.h>
+#include <Variable.h>
+
+class CClass;
+class CMethod;
+
+class Procedure
 {
 public:
-	UserProcImpl( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport )
-		: UserProc( name, kind, isMacro, isCdecl, isExport )
-	{
-	}
-	virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
+	// 種類
+	enum Kind{
+		Sub,
+		Function,
+	};
+
+private:
+	string name;						// プロシージャ名
+
+	Kind kind;
+
+	bool isCdecl;
+	mutable bool isUsing;
+
+protected:
+
+	// パラメータ
+	Parameters params;
+
+	// 戻り値の型
+	Type returnType;
+
+	// ソースコードの位置
+	int codePos;
+
+	// XMLシリアライズ用
+private:
+private:
+	friend class boost::serialization::access;
+	BOOST_SERIALIZATION_SPLIT_MEMBER();
+	template<class Archive> void load(Archive& ar, const unsigned int version)
+	{
+		trace_for_serialize( "serializing - Procedure" );
+
+		std::string _name;
+		ar & BOOST_SERIALIZATION_NVP( _name );
+		this->name = Operator_NaturalStringToCalcMarkString( _name );
+
+		ar & BOOST_SERIALIZATION_NVP( kind );
+		ar & BOOST_SERIALIZATION_NVP( isCdecl );
+		ar & BOOST_SERIALIZATION_NVP( isUsing );
+		ar & BOOST_SERIALIZATION_NVP( params );
+		ar & BOOST_SERIALIZATION_NVP( returnType );
+		ar & BOOST_SERIALIZATION_NVP( codePos );
+	}
+	template<class Archive> void save(Archive& ar, const unsigned int version) const
+	{
+		trace_for_serialize( "serializing - Procedure" );
+
+		std::string _name = Operator_CalcMarkStringToNaturalString( name );
+		ar & BOOST_SERIALIZATION_NVP( _name );
+
+		ar & BOOST_SERIALIZATION_NVP( kind );
+		ar & BOOST_SERIALIZATION_NVP( isCdecl );
+		ar & BOOST_SERIALIZATION_NVP( isUsing );
+		ar & BOOST_SERIALIZATION_NVP( params );
+		ar & BOOST_SERIALIZATION_NVP( returnType );
+		ar & BOOST_SERIALIZATION_NVP( codePos );
+	}
+
+public:
+	Procedure( const string &name, Kind kind, bool isCdecl )
+		: name( name )
+		, kind( kind )
+		, isCdecl( isCdecl )
+		, isUsing( false )
+		, codePos( -1 )
+	{
+	}
+	Procedure()
+	{
+	}
+	~Procedure(){
+		BOOST_FOREACH( Parameter *pParam, params ){
+			delete pParam;
+		}
+	}
+
+	const string &GetName() const
+	{
+		return name;
+	}
+
+	bool IsSub() const
+	{
+		return ( kind == Sub );
+	}
+	bool IsFunction() const
+	{
+		return ( kind == Function );
+	}
+
+	bool IsCdecl() const
+	{
+		return isCdecl;
+	}
+	void Using() const
+	{
+		isUsing = true;
+	}
+	bool IsUsing() const
+	{
+		return isUsing;
+	}
+
+	int GetCodePos() const
+	{
+		return codePos;
+	}
+
+	const Parameters &Params() const
+	{
+		return params;
+	}
+	const Type &ReturnType() const
+	{
+		return returnType;
+	}
 };
 
-class GlobalProc : public UserProcImpl
+class UserProc : public Procedure, public Jenga::Common::ObjectInHashmap<UserProc>
 {
-	const NamespaceScopes namespaceScopes;
-	const NamespaceScopesCollection importedNamespaces;
+public:
+	string _paramStr;
+
+private:
+	NamespaceScopes namespaceScopes;
+	NamespaceScopesCollection importedNamespaces;
+
+	// 親クラスと対応するメソッド
+	const CClass *pParentClass;
+	CMethod *pMethod;
+
+	bool isMacro;
+
+	// パラメータの追加情報
+	int secondParmNum;
+	Parameters realParams;
+	int realSecondParmNum;
+
+	// 各種フラグ
+	bool isExport;
+	mutable bool isSystem;
+	mutable bool isAutoGeneration;
+	mutable bool isCompiled;
+
+	mutable DWORD beginOpAddress;
+	mutable DWORD endOpAddress;
+
+	// ローカル変数
+	mutable Variables localVars;
+
+	// 識別ID
+	int id;
+
+	// XMLシリアライズ用
+private:
+	friend class boost::serialization::access;
+	template<class Archive> void serialize(Archive& ar, const unsigned int version)
+	{
+		trace_for_serialize( "serializing - UserProc" );
+
+		ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
+		ar & BOOST_SERIALIZATION_NVP( _paramStr );
+		ar & BOOST_SERIALIZATION_NVP( namespaceScopes );
+		ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
+		ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
+		ar & BOOST_SERIALIZATION_NVP( pMethod );
+		ar & BOOST_SERIALIZATION_NVP( isMacro );
+		ar & BOOST_SERIALIZATION_NVP( secondParmNum );
+		ar & BOOST_SERIALIZATION_NVP( realParams );
+		ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
+		ar & BOOST_SERIALIZATION_NVP( isExport );
+		ar & BOOST_SERIALIZATION_NVP( isSystem );
+		ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
+		ar & BOOST_SERIALIZATION_NVP( isCompiled );
+		ar & BOOST_SERIALIZATION_NVP( beginOpAddress );
+		ar & BOOST_SERIALIZATION_NVP( endOpAddress );
+		ar & BOOST_SERIALIZATION_NVP( localVars );
+		ar & BOOST_SERIALIZATION_NVP( id );
+	}
+
+public:
+
+	UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport, int id )
+		: Procedure( name, kind, isCdecl )
+		, namespaceScopes( namespaceScopes )
+		, importedNamespaces( importedNamespaces )
+		, pParentClass( NULL )
+		, pMethod( NULL )
+		, isMacro( isMacro )
+		, isExport( isExport )
+		, isSystem( false )
+		, isAutoGeneration( false )
+		, isCompiled( false )
+		, beginOpAddress( 0 )
+		, endOpAddress( 0 )
+		, id( id )
+	{
+	}
+	UserProc()
+	{
+	}
+	~UserProc()
+	{
+		BOOST_FOREACH( Parameter *pParam, realParams ){
+			delete pParam;
+		}
+	}
+
+	virtual const std::string &GetKeyName() const
+	{
+		return GetName();
+	}
+
+	bool IsMacro() const
+	{
+		return isMacro;
+	}
+
+	int GetSecondParmNum() const
+	{
+		return secondParmNum;
+	}
+	const Parameters &RealParams() const
+	{
+		return realParams;
+	}
+	int GetRealSecondParmNum() const
+	{
+		return realSecondParmNum;
+	}
+
+	void ExportOff(){
+		isExport = false;
+	}
+	bool IsExport() const
+	{
+		return isExport;
+	}
+	void ThisIsSystemProc() const
+	{
+		isSystem = true;
+	}
+	bool IsSystem() const
+	{
+		return isSystem;
+	}
+	void ThisIsAutoGenerationProc() const
+	{
+		isAutoGeneration = true;
+	}
+	bool IsAutoGeneration() const
+	{
+		return isAutoGeneration;
+	}
+	void CompleteCompile() const
+	{
+		isCompiled = true;
+	}
+	void KillCompileStatus() const
+	{
+		isCompiled = false;
+	}
+	bool IsCompiled() const
+	{
+		return isCompiled;
+	}
+	bool IsDestructor() const
+	{
+		return ( GetName()[0] == '~' );
+	}
+
+	// バイナリコード位置とサイズ
+	DWORD GetBeginOpAddress() const
+	{
+		return beginOpAddress;
+	}
+	void SetBeginOpAddress( DWORD beginOpAddress ) const
+	{
+		this->beginOpAddress = beginOpAddress;
+	}
+	DWORD GetEndOpAddress() const
+	{
+		return endOpAddress;
+	}
+	void SetEndOpAddress( DWORD endOpAddress ) const
+	{
+		this->endOpAddress = endOpAddress;
+	}
+	int GetCodeSize() const
+	{
+		return endOpAddress - beginOpAddress;
+	}
+
+	const NamespaceScopes &GetNamespaceScopes() const;
+	const NamespaceScopesCollection &GetImportedNamespaces() const;
+
+	Variables &GetLocalVars() const
+	{
+		return localVars;
+	}
+
+	int GetId() const
+	{
+		return id;
+	}
+
+	std::string GetFullName() const;
+
+	virtual bool IsDuplication( const UserProc *pUserProc ) const
+	{
+		if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr()
+			&& pUserProc->IsEqualSymbol( *this )
+			&& this->Params().Equals( pUserProc->Params() ) )
+		{
+			return true;
+		}
+		return false;
+	}
+
+	bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
+	bool IsEqualSymbol( const UserProc &globalProc ) const;
+	bool IsEqualSymbol( const string &name ) const;
+
+	bool IsVirtual() const;
+
+	void SetParentClass( const CClass *pParentClass ){
+		this->pParentClass = pParentClass;
+	}
+	const CClass *GetParentClassPtr() const
+	{
+		return pParentClass;
+	}
+	const CClass &GetParentClass() const
+	{
+		return *pParentClass;
+	}
+	bool HasParentClass() const
+	{
+		return ( pParentClass != NULL );
+	}
+	void SetMethod( CMethod *pMethod ){
+		this->pMethod = pMethod;
+	}
+
+	bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
+
+
+
+	/////////////////////////////////////////////////////////////////
+	// コンパイル中の関数を管理
+	/////////////////////////////////////////////////////////////////
+private:
+	static const UserProc *pCompilingUserProc;
+public:
+	static void CompileStartForGlobalArea(){
+		pCompilingUserProc = NULL;
+	}
+	static void CompileStartForUserProc( const UserProc *pUserProc ){
+		pCompilingUserProc = pUserProc;
+	}
+	static bool IsGlobalAreaCompiling(){
+		return ( pCompilingUserProc == NULL );
+	}
+	static bool IsLocalAreaCompiling(){
+		return ( pCompilingUserProc != NULL );
+	}
+	static const UserProc &CompilingUserProc(){
+		return *pCompilingUserProc;
+	}
+};
+
+class UserProcs : public Jenga::Common::Hashmap<UserProc>
+{
+	std::vector<std::string> macroNames;
+
+	// XMLシリアライズ用
+private:
+	friend class boost::serialization::access;
+	template<class Archive> void serialize(Archive& ar, const unsigned int version)
+	{
+		trace_for_serialize( "serializing - UserProcs" );
+
+		ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
+			boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
+		ar & BOOST_SERIALIZATION_NVP( macroNames );
+	}
+
+
+public:
+	UserProcs()
+	{
+	}
+	~UserProcs()
+	{
+	}
+
+	bool Insert( UserProc *pUserProc, int nowLine );
+
+	UserProc *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic);
+
+	void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
+
+	static void CollectUserProcs( const BasicSource &source, UserProcs &userProcs );
+};
+
+class DllProc : public Procedure
+{
+	NamespaceScopes namespaceScopes;
+
+	string dllFileName;
+	string alias;
+	int lookupAddress;
+
+	// XMLシリアライズ用
+private:
+	friend class boost::serialization::access;
+	template<class Archive> void serialize(Archive& ar, const unsigned int version)
+	{
+		trace_for_serialize( "serializing - DllProc" );
+
+		ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
+		ar & BOOST_SERIALIZATION_NVP( namespaceScopes );
+		ar & BOOST_SERIALIZATION_NVP( dllFileName );
+		ar & BOOST_SERIALIZATION_NVP( alias );
+		ar & BOOST_SERIALIZATION_NVP( lookupAddress );
+	}
+
 public:
 	// ハッシュリスト用
-	GlobalProc *pNextData;
-
-	GlobalProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
-	  UserProcImpl( name, kind, isMacro, isCdecl, isExport ),
+	DllProc *pNextData;
+
+	DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
+	  Procedure( name, kind, isCdecl ),
 	  namespaceScopes( namespaceScopes ),
-	  importedNamespaces( importedNamespaces ),
+	  dllFileName( dllFileName ),
+	  alias( alias ),
+	  lookupAddress( 0 ),
 	  pNextData( NULL )
-	{}
-	~GlobalProc(){}
-
-	virtual const NamespaceScopes &GetNamespaceScopes() const;
-	virtual const NamespaceScopesCollection &GetImportedNamespaces() const
-	{
-		return importedNamespaces;
-	}
+	{
+	}
+	~DllProc(){}
 
 	virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
-	virtual bool IsEqualSymbol( const GlobalProc &globalProc ) const;
-	virtual bool IsEqualSymbol( const string &name ) const;
+	bool IsEqualSymbol( const string &name ) const;
+
+	const NamespaceScopes &GetNamespaceScopes() const
+	{
+		return namespaceScopes;
+	}
+
+	const string &GetDllFileName() const
+	{
+		return dllFileName;
+	}
+	const string &GetAlias() const
+	{
+		return alias;
+	}
+
+	void SetLookupAddress( int lookupAddress ){
+		this->lookupAddress = lookupAddress;
+	}
+	int GetLookupAddress() const
+	{
+		return lookupAddress;
+	}
+
+	bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
 };
 
-class DllProcImpl : public DllProc
+class ProcPointer : public Procedure
 {
-public:
-	DllProcImpl( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias )
-		: DllProc( namespaceScopes, name, kind, isCdecl, dllFileName, alias )
-	{
-	}
-
-	virtual bool IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const;
+	// XMLシリアライズ用
+private:
+	friend class boost::serialization::access;
+	template<class Archive> void serialize(Archive& ar, const unsigned int version)
+	{
+		trace_for_serialize( "serializing - ProcPointer" );
+
+		ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
+	}
+
+public:
+	ProcPointer( Kind kind )
+		: Procedure( "", kind, false )
+	{
+	}
+	ProcPointer()
+	{
+	}
+	~ProcPointer(){}
 
 	virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
 };
 
-class ProcPointerImpl : public ProcPointer
+class ProcPointers : public vector<ProcPointer *>
 {
-public:
-	ProcPointerImpl( Kind kind ):
-	  ProcPointer( kind )
-	{
-	}
-
-	virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
-};
-
-class ProcPointersImpl : public ProcPointers
-{
-public:
-	ProcPointersImpl()
-	{
-	}
-	~ProcPointersImpl()
+	// XMLシリアライズ用
+private:
+	friend class boost::serialization::access;
+	template<class Archive> void serialize(Archive& ar, const unsigned int version)
+	{
+		trace_for_serialize( "serializing - ProcPointers" );
+
+		ar & boost::serialization::make_nvp("vector_ProcPointer",
+			boost::serialization::base_object<vector<ProcPointer *>>(*this));
+	}
+
+public:
+	ProcPointers()
+	{
+	}
+	~ProcPointers()
 	{
 		Clear();
