Index: BasicCompiler_Common/TypeDef.cpp
===================================================================
--- BasicCompiler_Common/TypeDef.cpp	(revision 46)
+++ BasicCompiler_Common/TypeDef.cpp	(revision 78)
@@ -1,41 +1,29 @@
-#include "../BasicCompiler_Common/common.h"
+#include "common.h"
 
 
-CDBTypeDef *pobj_DBTypeDef;
-
-
-CTypeDef::CTypeDef(const char *name,char *base){
-	lpszName=(char *)malloc(lstrlen(name)+1);
-	lstrcpy(lpszName,name);
-	lpszBaseName=(char *)malloc(lstrlen(base)+1);
-	lstrcpy(lpszBaseName,base);
+TypeDef::TypeDef( const string &newName, const string &baseName ):
+	newName( newName ),
+	baseName( baseName )
+{
+	if( !Type::StringToType( baseName, baseType ) ){
+		SetError(3, baseName, cp );
+		return;
+	}
 }
-CTypeDef::~CTypeDef(){
-	free(lpszName);
-	free(lpszBaseName);
+TypeDef::~TypeDef(){
 }
 
 
-CDBTypeDef::CDBTypeDef(){
-	ppobj_TypeDef=(CTypeDef **)malloc(1);
-	iNum=0;
+TypeDefCollection::TypeDefCollection(){
 }
-CDBTypeDef::~CDBTypeDef(){
-	init();
-	free(ppobj_TypeDef);
+TypeDefCollection::~TypeDefCollection(){
 }
-void CDBTypeDef::init(){
-	int i;
-	for(i=0;i<iNum;i++){
-		delete ppobj_TypeDef[i];
-	}
-	iNum=0;
-}
-void CDBTypeDef::add(const char *name,char *base){
-	ppobj_TypeDef=(CTypeDef **)realloc(ppobj_TypeDef,(iNum+1)*sizeof(CTypeDef *));
-	ppobj_TypeDef[iNum]=new CTypeDef(name,base);
-	iNum++;
+void TypeDefCollection::Add( const string &newName, const string &baseName ){
+	TypeDef typeDef( newName, baseName );
+	this->push_back( typeDef );
 
 
+	/*
+	TODO: 消す1
 	////////////////////////
 	// 循環参照をチェック
@@ -43,12 +31,11 @@
 
 	int i;
-	char temporary[1024];
-	lstrcpy(temporary,base);
+	string tempName = newName;
 
 	while(1){
-		i=check(temporary);
+		i=GetIndex( tempName );
 		if(i==-1) break;
 
-		if(lstrcmp(base,ppobj_TypeDef[i]->lpszBaseName)==0){
+		if( (*this)[i].baseName == newName ){
 			//循環エラー
 			extern int cp;
@@ -56,17 +43,16 @@
 
 			//不明な型として、Long型を指定しておく
-			ppobj_TypeDef[i]->lpszBaseName=(char *)realloc(ppobj_TypeDef[i]->lpszBaseName,5);
-			lstrcpy(ppobj_TypeDef[i]->lpszBaseName,"Long");
+			(*this)[i].baseName = "Long";
 
 			break;
 		}
 
-		lstrcpy(temporary,ppobj_TypeDef[i]->lpszBaseName);
-	}
+		tempName = (*this)[i].baseName;
+	}*/
 }
-int CDBTypeDef::check(const char *name){
-	int i;
-	for(i=0;i<iNum;i++){
-		if(lstrcmp(ppobj_TypeDef[i]->lpszName,name)==0){
+int TypeDefCollection::GetIndex( const string &typeName ) const{
+	int max = (*this).size();
+	for( int i=0; i<max; i++ ){
+		if( (*this)[i].newName == typeName ){
 			return i;
 		}
@@ -75,25 +61,22 @@
 }
 
-
-
-void AddTypeDefData(char *Command){
-	extern int cp;
+void TypeDefCollection::Add( const string &expression, int nowLine ){
 	int i;
-	char temporary[VN_SIZE],*pTemp;
+	char temporary[VN_SIZE];
 
 	for(i=0;;i++){
-		if(Command[i]=='='||Command[i]=='\0'){
+		if(expression[i]=='='||expression[i]=='\0'){
 			temporary[i]=0;
 			break;
 		}
-		temporary[i]=Command[i];
+		temporary[i]=expression[i];
 	}
 
-	if(Command[i]!='='){
-		SetError(10,"TypeDef",cp);
+	if(expression[i]!='='){
+		SetError(10,"TypeDef",nowLine);
 		return;
 	}
 
-	pTemp=Command+i+1;
+	const char *pTemp=expression.c_str()+i+1;
 
 	//識別文字のエラーチェック（新しい型）
@@ -102,5 +85,5 @@
 		if(temporary[i]=='\0') break;
 		if(!IsVariableChar(temporary[i])){
-			SetError(10,"TypeDef",cp);
+			SetError(10,"TypeDef",nowLine);
 			return;
 		}
@@ -111,5 +94,5 @@
 		//関数ポインタ
 		if(pTemp[3]!='('){
-			SetError(10,"TypeDef",cp);
+			SetError(10,"TypeDef",nowLine);
 			return;
 		}
@@ -121,5 +104,5 @@
 			if(pTemp[i]=='\0') break;
 			if(!IsVariableChar(pTemp[i])){
-				SetError(10,"TypeDef",cp);
+				SetError(10,"TypeDef",nowLine);
 				return;
 			}
@@ -129,5 +112,5 @@
 	//識別子が重複している場合はエラーにする
 	if(lstrcmp(temporary,pTemp)==0){
-		SetError(1,NULL,cp);
+		SetError(1,NULL,nowLine);
 		return;
 	}
@@ -138,4 +121,56 @@
 	// TypeDef情報を追加
 	//////////////////////////
-	pobj_DBTypeDef->add(temporary,pTemp);
+
+	//エラー用
+	extern int cp;
+	cp = nowLine;
+
+	House::typeDefs.Add(temporary,pTemp);
 }
+
+void TypeDefCollection::Init(){
+	// 初期化
+	clear();
+
+	int i=-1;
+	while(1){
+		i++;
+
+		extern char *basbuf;
+		if( basbuf[i]==1 ){
+			char temporary[VN_SIZE];
+			if(basbuf[i+1]==ESC_TYPEDEF){
+				int i2 = 0;
+				for(i+=2;;i2++,i++){
+					if(basbuf[i]=='\n'){
+						temporary[i2]=0;
+						break;
+					}
+					temporary[i2]=basbuf[i];
+					if(basbuf[i]=='\0') break;
+				}
+				Add(temporary,i);
+
+				continue;
+			}
+			else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
+				int i2 = 0;
+				for(i+=4;;i2++,i++){
+					if(!IsVariableChar(basbuf[i])){
+						temporary[i2]=0;
+						break;
+					}
+					temporary[i2]=basbuf[i];
+					if(basbuf[i]=='\0') break;
+				}
+				House::typeDefs.Add(temporary,"Long");
+			}
+		}
+
+		//次の行
+		for(;;i++){
+			if(IsCommandDelimitation(basbuf[i])) break;
+		}
+		if(basbuf[i]=='\0') break;
+	}
+}
