Index: BasicCompiler_Common/Variable.h
===================================================================
--- BasicCompiler_Common/Variable.h	(revision 64)
+++ BasicCompiler_Common/Variable.h	(revision 75)
@@ -1,31 +1,188 @@
+
+class Variable : public Type
+{
+	string name;
+	bool isConst;
+	bool isRef;
+	bool isArray;
+	int subScripts[MAX_ARRAYDIM];
+
+	bool isParameter;
+
+public:
+	Variable( const string &name, const Type &type, bool isConst = false, bool isRef = false ):
+		Type( type ),
+		name( name ),
+		isConst( isConst ),
+		isRef( isRef ),
+		isArray( false ),
+		isParameter( false)
+	{
+		subScripts[0] = -1;
+	}
+	Variable( const Variable &var ):
+		Type( var ),
+		name( var.name ),
+		isConst( var.isConst ),
+		isRef( var.isRef ),
+		isArray( false ),
+		isParameter( false )
+	{
+		subScripts[0] = -1;
+		if( var.isArray ){
+			SetArray( var.subScripts );
+		}
+	}
+	~Variable(){}
+
+	void SetArray( const int *pSubScripts ){
+		isArray = true;
+		memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM );
+	}
+
+	const string &GetName() const
+	{
+		return name;
+	}
+
+	void ConstOff(){
+		isConst = false;
+	}
+	void ConstOn(){
+		isConst = true;
+	}
+	bool IsConst() const
+	{
+		return isConst;
+	}
+	bool IsRef() const
+	{
+		return isRef;
+	}
+	bool IsArray()const
+	{
+		return isArray;
+	}
+	const int *GetSubScriptsPtr() const
+	{
+		return subScripts;
+	}
+
+	void ThisIsParameter(){
+		isParameter = true;
+	}
+	bool IsParameter() const
+	{
+		return isParameter;
+	}
 
 
-BOOL IsVariableTopChar(char c);
-BOOL IsVariableChar(char c);
-BOOL IsPtrType(int type);
-BOOL IsSignedType(int type);
-BOOL IsNaturalWholeNumberType(int type);
-BOOL IsWholeNumberType(int type);
-BOOL IsRealNumberType(int type);
-BOOL Is64Type(int type);
-int GetSignedType(int type);
-int GetUnsignedType(int type);
-int GetTypeSize(int type,LONG_PTR lpIndex);
-int GetPtrType(int type,LONG_PTR lpIndex);
-int GetTypeFixed(const char *TypeName,LONG_PTR *lpNum);
-void GetOriginalTypeName(char *buffer);
-BOOL GetTypeName(int type,LONG_PTR lpIndex,char *name);
-bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member );
-BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember, CClass::RefType &refType );
-void GetArrayElement(char *buffer,char *variable,char *array_element);
-BOOL CheckVarNameError(char *name,int NowLine);
-int JumpSubScripts(int *ss);
-void GetArrange(char *variable,char *variAnswer,int *SubScripts);
-int GetTypeFromSimpleName(char *variable);
-int GetVarType(const char *NameBuffer,LONG_PTR *plpIndex,BOOL bError);
-BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
-BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
-BOOL GetDimentionFormat(const char *buffer, const bool isRef, char *VarName,int *SubScripts,TYPEINFO *pTypeInfo,char *InitBuf,char *ConstractParameter);
-BOOL GetNowStaticVarFullName(char *VarName,char *FullName);
-void AddGlobalVariable(bool isRef, char *name,int *SubScripts,TYPEINFO *pTypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlag);
+	int GetMemorySize() const
+	{
+		if( isRef || isParameter ){
+			return PTR_SIZE;
+		}
 
+		int size = Type::GetSize();
+
+		if( isArray ){
+			int num = 1;
+			for( int i=0; i<MAX_ARRAYDIM; i++){
+				if(subScripts[i]==-1) break;
+				num *= subScripts[i]+1;
+			}
+			size *= num;
+		}
+
+		if( size % PTR_SIZE ){
+			size += PTR_SIZE-(size%PTR_SIZE);
+		}
+
+		return size;
+	}
+
+
+	/* --- オフセット ---
+
+		※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、
+		初期バッファの有無が識別される。
+		（その後、スケジュール実行により、実際の配置に並び替えられる）*/
+	int offset;
+
+	//コンストラクタ用パラメータ
+	string paramStrForConstructor;
+
+	//レキシカルスコープ用
+	int ScopeStartAddress;
+	int ScopeEndAddress;
+	int ScopeLevel;
+	BOOL bLiving;
+
+
+	int source_code_address;
+};
+
+class Variables : public vector<Variable *>
+{
+public:
+	Variables(){}
+	~Variables(){
+		clear();
+	}
+
+	void clear(){
+		for( int i=0; i<(int)this->size(); i++ ){
+			delete (*this)[i];
+		}
+
+		vector<Variable *>::clear();
+	}
+
+	bool DuplicateCheck( const string &varName ) const
+	{
+		//レキシカルスコープを考慮して重複判定
+		for( int i=(int)this->size()-1; i>=0 ; i-- ){
+			Variable &var = *(*this)[i];
+			if( var.bLiving											//現在のスコープで有効なもの
+				&& var.ScopeLevel == obj_LexScopes.GetNowLevel()	//現在のスコープと同一レベル
+				){
+					if( var.GetName() == varName ){
+						return true;
+					}
+			}
+		}
+		return false;
+	}
+
+	const Variable *BackSearch( const string &varName ) const
+	{
+		//レキシカルスコープを考慮してバックサーチ
+		for( int i=(int)this->size()-1; i>=0 ; i-- ){
+			Variable &var = *(*this)[i];
+			if( var.bLiving											//現在のスコープで有効なもの
+				&& var.ScopeLevel <= obj_LexScopes.GetNowLevel()	//現在のスコープレベルを超さないもの（Returnによる解放処理中を考慮）
+				){
+					if( var.GetName() == varName ){
+						return &var;
+					}
+			}
+		}
+		return NULL;
+	}
+
+	const Variable *Find( const string &varName )const
+	{
+		int max = (int)this->size();
+		for( int i=0; i<max; i++ ){
+			Variable *pVar = (*this)[i];
+			if( pVar->GetName() == varName ){
+				return pVar;
+			}
+		}
+		return NULL;
+	}
+};
+
+extern Variables globalVars;
+
+
