Index: trunk/abdev/BasicCompiler_Common/src/Procedure.cpp
===================================================================
--- trunk/abdev/BasicCompiler_Common/src/Procedure.cpp	(revision 400)
+++ trunk/abdev/BasicCompiler_Common/src/Procedure.cpp	(revision 402)
@@ -3,5 +3,4 @@
 #include <jenga/include/smoothie/Smoothie.h>
 #include <jenga/include/smoothie/SmoothieException.h>
-#include <jenga/include/smoothie/LexicalAnalysis.h>
 
 #include <Compiler.h>
@@ -100,34 +99,64 @@
 	if(sourceOfParams[i]!='('){
 		SetError(1,NULL,nowLine);
-		return 0;
-	}
-	i++;
-	if(sourceOfParams[i]!=')'&& this->pParentClass ){
+		return false;
+	}
+	if(sourceOfParams[i + 1]!=')'&& this->pParentClass ){
 		//クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす
 		if(this->GetName()[0]=='~'){
-			SmoothieException::Throw(114,NULL,nowLine);
-			i=JumpStringInPare(sourceOfParams,i);
-		}
-	}
-
-	/*
-	GetStringInPare( temporary, sourceOfParams + i );
-	RemoveStringPare( temporary );
-	*/
-
-	while(1){
-		if(sourceOfParams[i]==')') break;
-
-		//ByRef
-		bool isRef;
-		if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
-			isRef = false;
-			i+=2;
-		}
-		else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
-			isRef = true;
-			i+=2;
-		}
-		else isRef = false;
+			SetError(114,NULL,nowLine);
+			return false;
+		}
+	}
+
+	// カッコ内のパラメータ文字列を取得
+	char parametersStr1[8192];
+	char parametersStr2[8192] = "";
+	i += GetStringInPare( parametersStr1, sourceOfParams + i, true );
+	if( sourceOfParams[i] == '(' )
+	{
+		i += GetStringInPare( parametersStr2, sourceOfParams + i, true );
+	}
+
+	// 戻り値文字列を取得
+	char returnTypeStr[VN_SIZE] = "";
+	if( sourceOfParams[i] )
+	{
+		if( sourceOfParams[i] == 1 && sourceOfParams[i+1] == ESC_AS )
+		{
+			if( !this->IsFunction() ){
+				// Sub/Macroの場合
+				SetError(38,this->GetName(),nowLine);
+			}
+
+			lstrcpy( returnTypeStr, sourceOfParams + i + 2 );
+		}
+		else
+		{
+			SetError(1,NULL,nowLine);
+			return false;
+		}
+	}
+
+	// パラメータを分割
+	Jenga::Common::Strings parameters;
+	SplitParameter( parametersStr1, parameters );
+	BOOST_FOREACH( const std::string &paramStr, parameters )
+	{
+		int i = 0;
+
+		bool isRef = false;
+		if( paramStr[i] == 1 )
+		{
+			if( paramStr[i+1] == ESC_BYVAL )
+			{
+				isRef = false;
+				i += 2;
+			}
+			else if( paramStr[i+1] == ESC_BYREF )
+			{
+				isRef = true;
+				i += 2;
+			}
+		}
 
 		//パラメータ名
@@ -137,29 +166,32 @@
 		sw=0;
 		for(i2=0;;i++,i2++){
-			if(sourceOfParams[i]=='('){
+			if(paramStr[i]=='('){
 				if(!sw) sw=1;
 
-				i3=GetStringInPare(name+i2,sourceOfParams+i);
+				i3=GetStringInPare(name+i2,paramStr.c_str()+i);
 				i2+=i3-1;
 				i+=i3-1;
 				continue;
 			}
-			if(sourceOfParams[i]=='['){
+			if(paramStr[i]=='['){
 				if(!sw) sw=1;
 
-				i3=GetStringInBracket(name+i2,sourceOfParams+i);
+				i3=GetStringInBracket(name+i2,paramStr.c_str()+i);
 				i2+=i3-1;
 				i+=i3-1;
 				continue;
 			}
-			if(!IsVariableChar(sourceOfParams[i])){
+			if(!IsVariableChar(paramStr[i])){
 				name[i2]=0;
 				break;
 			}
-			name[i2]=sourceOfParams[i];
+			name[i2]=paramStr[i];
 		}
 		if(sw){
 			//配列パラメータ
-			if( isRef == false ) SmoothieException::Throw(29,NULL,nowLine);
+			if( isRef == false )
+			{
+				SetError(29,NULL,nowLine);
+			}
 			isArray = true;
 
@@ -181,8 +213,8 @@
 		Type type( DEF_NON );
 		char initValue[8192] = "";
-		if( sourceOfParams[i] == '=' ){
+		if( paramStr[i] == '=' ){
 			i++;
-			i = GetOneParameter( sourceOfParams, i, initValue );
-			if( sourceOfParams[i-1] == ',' )
+			i = GetOneParameter( paramStr.c_str(), i, initValue );
+			if( paramStr[i-1] == ',' )
 			{
 				i--;
@@ -199,19 +231,19 @@
 			}
 		}
-		else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
+		else if(paramStr[i]==1&&paramStr[i+1]==ESC_AS){
 			// As指定
 			i+=2;
 
 			i2=0;
-			while(sourceOfParams[i]=='*'){
-				temporary[i2]=sourceOfParams[i];
+			while(paramStr[i]=='*'){
+				temporary[i2]=paramStr[i];
 				i++;
 				i2++;
 			}
 			for(;;i++,i2++){
-				if(!IsVariableChar(sourceOfParams[i])){
-					if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
-						temporary[i2++]=sourceOfParams[i++];
-						temporary[i2]=sourceOfParams[i];
+				if(!IsVariableChar(paramStr[i])){
+					if(paramStr[i]==1&&(paramStr[i+1]==ESC_FUNCTION||paramStr[i+1]==ESC_SUB)){
+						temporary[i2++]=paramStr[i++];
+						temporary[i2]=paramStr[i];
 						continue;
 					}
@@ -219,5 +251,5 @@
 					break;
 				}
-				temporary[i2]=sourceOfParams[i];
+				temporary[i2]=paramStr[i];
 			}
 
@@ -248,140 +280,148 @@
 		//パラメータを追加
 		this->params.push_back( pParam );
-
-		if(sourceOfParams[i]==','){
+	}
+
+	this->secondParmNum = (int)this->params.size();
+
+	SplitParameter( parametersStr2, parameters );
+	BOOST_FOREACH( const std::string &paramStr, parameters )
+	{
+		int i = 0;
+
+		bool isRef = false;
+		if( paramStr[i] == 1 )
+		{
+			if( paramStr[i+1] == ESC_BYVAL )
+			{
+				isRef = true;
+				i += 2;
+			}
+			else if( paramStr[i+1] == ESC_BYREF )
+			{
+				isRef = false;
+				i += 2;
+			}
+		}
+
+		//パラメータ名
+		bool isArray = false;
+		Subscripts subscripts;
+		char name[VN_SIZE];
+		sw=0;
+		for(i2=0;;i++,i2++){
+			if(paramStr[i]=='('){
+				if(!sw) sw=1;
+
+				i3=GetStringInPare(name+i2,paramStr.c_str()+i);
+				i2+=i3-1;
+				i+=i3-1;
+				continue;
+			}
+			if(paramStr[i]=='['){
+				if(!sw) sw=1;
+
+				i3=GetStringInBracket(name+i2,paramStr.c_str()+i);
+				i2+=i3-1;
+				i+=i3-1;
+				continue;
+			}
+			if(!IsVariableChar(paramStr[i])){
+				name[i2]=0;
+				break;
+			}
+			name[i2]=paramStr[i];
+		}
+		if(sw){
+			//配列パラメータ
+			if( isRef == false ) SmoothieException::Throw(29,NULL,nowLine);
+			isArray = true;
+
+			if((name[i2-2]=='('&&name[i2-1]==')')||
+				(name[i2-2]=='['&&name[i2-1]==']'))
+			{
+				subscripts.push_back( LONG_MAX );
+
+				name[i2-2]=0;
+			}
+			else{
+				GetArrange(name,temp2,subscripts);
+				lstrcpy(name,temp2);
+			}
+
+			i2=lstrlen(name);
+		}
+
+		Type type( DEF_NON );
+		char initValue[8192] = "";
+		if( paramStr[i] == '=' ){
 			i++;
-			continue;
-		}
-		else if(sourceOfParams[i]==')') continue;
-		else{
-			SetError(1,NULL,nowLine);
-			break;
-		}
-	}
-	this->secondParmNum = (int)this->params.size();
-	i++;
-	if(sourceOfParams[i]=='('){
-		i++;
-		while(1){
-			if(sourceOfParams[i]==')') break;
-
-			//ByRef
-			bool isRef;
-			if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
-				isRef = false;
-				i+=2;
-			}
-			else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
-				isRef = true;
-				i+=2;
-			}
-			else isRef = false;
-
-			//パラメータ名
-			bool isArray = false;
-			Subscripts subscripts;
-			char name[VN_SIZE];
-			sw=0;
-			for(i2=0;;i++,i2++){
-				if(sourceOfParams[i]=='('){
-					if(!sw) sw=1;
-
-					i3=GetStringInPare(name+i2,sourceOfParams+i);
-					i2+=i3-1;
-					i+=i3-1;
-					continue;
-				}
-				if(sourceOfParams[i]=='['){
-					if(!sw) sw=1;
-
-					i3=GetStringInBracket(name+i2,sourceOfParams+i);
-					i2+=i3-1;
-					i+=i3-1;
-					continue;
-				}
-				if(!IsVariableChar(sourceOfParams[i])){
-					name[i2]=0;
+			i = GetOneParameter( paramStr.c_str(), i, initValue );
+			if( paramStr[i-1] == ',' )
+			{
+				i--;
+			}
+
+			// TODO: エラー用 fix me!!!
+			//cp = nowLine;
+
+			NumOpe_GetType( initValue, GetStringTypeInfo(), type );
+			
+			if( IS_LITERAL(type.GetIndex()) )
+			{
+				type.SetIndex( -1 );
+			}
+		}
+		else if(paramStr[i]==1&&paramStr[i+1]==ESC_AS){
+			// As指定
+			i+=2;
+
+			i2=0;
+			while(paramStr[i]=='*'){
+				temporary[i2]=paramStr[i];
+				i++;
+				i2++;
+			}
+			for(;;i++,i2++){
+				if(!IsVariableChar(paramStr[i])){
+					if(paramStr[i]==1&&(paramStr[i+1]==ESC_FUNCTION||paramStr[i+1]==ESC_SUB)){
+						temporary[i2++]=paramStr[i++];
+						temporary[i2]=paramStr[i];
+						continue;
+					}
+					temporary[i2]=0;
 					break;
 				}
-				name[i2]=sourceOfParams[i];
-			}
-			if(sw){
-				//配列パラメータ
-				if( isRef == false ) SmoothieException::Throw(29,NULL,nowLine);
-				isArray = true;
-
-				if((name[i2-2]=='('&&name[i2-1]==')')||
-					(name[i2-2]=='['&&name[i2-1]==']'))
-				{
-					subscripts.push_back( LONG_MAX );
-
-					name[i2-2]=0;
+				temporary[i2]=paramStr[i];
+			}
+
+			compiler.StringToType( temporary, type );
+
+			if( type.IsNull() ){
+				SmoothieException::Throw(3,temporary,nowLine);
+				type.SetBasicType( DEF_PTR_VOID );
+			}
+
+			if( type.IsObject() ){
+				if( type.GetClass().IsBlittableType() ){
+					// Blittable型のときは基本型として扱う
+					type = type.GetClass().GetBlittableType();
 				}
-				else{
-					GetArrange(name,temp2,subscripts);
-					lstrcpy(name,temp2);
-				}
-
-				i2=lstrlen(name);
-			}
-
-			//型
-			Type type( DEF_NON );
-			if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
-				i+=2;
-
-				i2=0;
-				while(sourceOfParams[i]=='*'){
-					temporary[i2]=sourceOfParams[i];
-					i++;
-					i2++;
-				}
-				for(;;i++,i2++){
-					if(!IsVariableChar(sourceOfParams[i])){
-						if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
-							temporary[i2++]=sourceOfParams[i++];
-							temporary[i2]=sourceOfParams[i];
-							continue;
-						}
-						temporary[i2]=0;
-						break;
-					}
-					temporary[i2]=sourceOfParams[i];
-				}
-
-				compiler.StringToType( temporary, type );
-
-				if( type.IsNull() ){
-					SmoothieException::Throw(3,temporary,nowLine);
-					type.SetBasicType( DEF_PTR_VOID );
-				}
-			}
-			else{
-				type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
-				SmoothieException::Throw(-103,temporary,nowLine);
-			}
-
-			Parameter *pParam = new Parameter( name, type, isRef );
-			if( isArray ){
-				pParam->SetArray( subscripts );
-			}
-
-			//パラメータを追加
-			this->params.push_back( pParam );
-
-			if(sourceOfParams[i]==','){
-				i++;
-				continue;
-			}
-			else if(sourceOfParams[i]==')') continue;
-			else{
-				SetError(1,NULL,nowLine);
-				break;
-			}
-		}
-		i++;
-	}
-
-	if(sourceOfParams[i]){
+			}
+		}
+		else{
+			type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
+			SmoothieException::Throw(-103,temporary,nowLine);
+		}
+
+		Parameter *pParam = new Parameter( name, type, isRef, initValue );
+		if( isArray ){
+			pParam->SetArray( subscripts );
+		}
+
+		//パラメータを追加
+		this->params.push_back( pParam );
+	}
+
+	if(returnTypeStr[0]){
 		///////////////////
 		// 戻り値を取得
@@ -390,5 +430,5 @@
 		if( !this->IsFunction() ){
 			// Sub/Macroの場合
-			SmoothieException::Throw(38,this->GetName(),nowLine);
+			SetError(38,this->GetName(),nowLine);
 		}
 
@@ -397,44 +437,27 @@
 				this->GetName()[0]=='~'){
 				//クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす
-				SmoothieException::Throw(115,NULL,nowLine);
-			}
-		}
-
-
-		i2=lstrlen(sourceOfParams)-2;
-
-		int sw_as=0;
-		for(;i2>0;i2--){
-			if(sourceOfParams[i2]==')') break;
-
-			if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){
-				i2+=2;
-				i3=0;
-				while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];
-				for(;;i2++,i3++){
-					if( IsCommandDelimitation( sourceOfParams[i2] ) )
-					{
-						temporary[i3]=0;
-						break;
-					}
-					temporary[i3]=sourceOfParams[i2];
-				}
-				compiler.StringToType( temporary, this->returnType );
-				if( this->returnType.IsNull() ) SmoothieException::Throw(3,temporary,nowLine);
-
-				sw_as=1;
-				break;
-			}
-		}
-
-		if(!sw_as){
-			SmoothieException::Throw(-104,this->GetName().c_str(),nowLine);
+				SetError(115,NULL,nowLine);
+			}
+		}
+
+		compiler.StringToType( returnTypeStr, this->returnType );
+		if( this->returnType.IsNull() )
+		{
+			SetError(3,returnTypeStr,nowLine);
+		}
+	}
+	else{
+		if( this->IsFunction() )
+		{
+			// Function定義なのに、戻り値の型がセットされていない
+			SetError(-104,this->GetName().c_str(),nowLine);
 
 			this->returnType.SetBasicType( DEF_DOUBLE );
 		}
-	}
-	else{
-		//戻り値なしのSub定義
-		this->returnType.SetNull();
+		else
+		{
+			//戻り値なしのSub定義
+			this->returnType.SetNull();
+		}
 	}
 
