#include "stdafx.h" #include #include #include #include #include #include "../BasicCompiler_Common/common.h" #ifdef _AMD64_ #include "../BasicCompiler64/opcode.h" #else #include "../BasicCompiler32/opcode.h" #endif int GetCallProcName(char *buffer,char *name){ int i2,i3,IsStr=0; for(i2=0;;i2++){ if(buffer[i2]=='\"') IsStr^=1; if(IsDBCSLeadByte(buffer[i2])){ name[i2]=buffer[i2]; i2++; name[i2]=buffer[i2]; continue; } if(buffer[i2]=='['&&IsStr==0){ i3=GetStringInBracket(name+i2,buffer+i2); i2+=i3-1; continue; } if(buffer[i2]=='('&&IsStr==0){ name[i2]=0; break; } if(buffer[i2]=='='&&IsStr==0){ name[i2]=0; break; } name[i2]=buffer[i2]; if(buffer[i2]=='\0') break; } return i2; } int GetProc(char *name,void **ppInfo){ //ユーザー定義関数 *ppInfo=(void *)GetSubHash(name); if(*ppInfo) return PROC_DEFAULT; //DLL関数 *ppInfo=(void *)GetDeclareHash(name); if(*ppInfo) return PROC_DLL; //コンパイラ埋め込み型 *ppInfo=(void *)(_int64)GetFunctionFromName(name); if(*ppInfo) return PROC_BUILTIN; //関数ポインタ Type type; if( !GetVarType( name, type, false ) ){ return 0; } if( type.IsProcPtr() ){ return PROC_PTR; } return 0; } void SplitObjectName(const char *name,char *ObjectName,int *pRefType){ int i4; for(i4=lstrlen(name)-1;i4>=0;i4--){ if(name[i4]=='.'||(name[i4]==1&&name[i4+1]==ESC_PSMEM)) break; } if(i4==-1) ObjectName[0]=0; else{ //参照タイプを判別 if(name[i4]=='.') *pRefType=DEF_OBJECT; else *pRefType=DEF_PTR_OBJECT; if(i4==0) GetWithName(ObjectName); else{ memcpy(ObjectName,name,i4); ObjectName[i4]=0; } } } bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn ){ //GetSubHash内でエラー提示が行われた場合 if(pProc==(Procedure *)-1){ return false; } if(kind==PROC_DEFAULT){ ///////////////////// // ユーザー定義関数 ///////////////////// const UserProc *pUserProc = (const UserProc *)pProc; //オブジェクト名を取得 char ObjectName[VN_SIZE]; int RefType; SplitObjectName(fullCallName,ObjectName,&RefType); //////////////////////// // オーバーロードを解決 //////////////////////// std::vector subs; GetOverloadSubHash(fullCallName,subs); if(subs.size()){ //オーバーロードを解決 pUserProc=OverloadSolutionWithStrParam(fullCallName,subs,lpszParms,ObjectName); if(!pUserProc){ return false; } } resultType = pUserProc->ReturnType(); if( isCallOn ){ if( !Opcode_CallProc(lpszParms,pUserProc,0,ObjectName,RefType) ){ return false; } } } else if(kind==PROC_DLL){ ///////////////////////// // DLL関数 ///////////////////////// DllProc *pDllProc = (DllProc *)pProc; resultType = pDllProc->ReturnType(); if( isCallOn ){ if( !Opcode_CallDllProc(lpszParms,pDllProc) ){ return false; } } } else if(kind==PROC_BUILTIN){ ///////////////////////// // 組み込み関数 ///////////////////////// int FuncId = (int)(_int64)pProc; if( !Opcode_CallFunc( lpszParms, FuncId, resultType, isCallOn ) ){ return false; } } else if(kind==PROC_PTR){ ///////////////// // 関数ポインタ ///////////////// Type type; GetVarType(fullCallName,type,false); ProcPointer *pProcPtr = compiler.GetObjectModule().meta.GetProcPointers()[type.GetIndex()]; resultType = pProcPtr->ReturnType(); if( isCallOn ){ if( !Opcode_CallProcPtr(fullCallName,lpszParms,pProcPtr) ){ return false; } } } else{ return false; } return true; } bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType){ //プロパティ用のメソッドを呼び出す //配列要素を取得 char VarName[VN_SIZE],ArrayElements[VN_SIZE]; GetArrayElement(variable,VarName,ArrayElements); //オブジェクト名を取得 char ObjectName[VN_SIZE]; int RefType; SplitObjectName(VarName,ObjectName,&RefType); //オーバーロード用の関数リストを作成 std::vector subs; GetOverloadSubHash(VarName,subs); if(subs.size()==0){ return false; } //パラメータを整備 char *Parameter; Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32); lstrcpy(Parameter,ArrayElements); if(rightSide){ if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,","); lstrcat(Parameter,rightSide); } //オーバーロードを解決 const UserProc *pUserProc = OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); if(pUserProc){ //呼び出し Opcode_CallProc(Parameter,pUserProc,0,ObjectName,RefType); resultType = pUserProc->ReturnType(); } HeapDefaultFree(Parameter); return true; } bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType ){ //プロパティ用のメソッドを呼び出す //配列要素を取得 char VarName[VN_SIZE],ArrayElements[VN_SIZE]; GetArrayElement(variable,VarName,ArrayElements); //オブジェクト名を取得 char ObjectName[VN_SIZE]; int RefType; SplitObjectName(VarName,ObjectName,&RefType); //オーバーロード用の関数リストを作成 std::vector subs; GetOverloadSubHash(VarName,subs); if(subs.size()==0){ return 0; } //パラメータを整備 char *Parameter; Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32); lstrcpy(Parameter,ArrayElements); if(rightSide){ if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,","); lstrcat(Parameter,rightSide); } //オーバーロードを解決 const UserProc *pUserProc = OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName); if(pUserProc){ resultType = pUserProc->ReturnType(); } return 1; } //インデクサ(getter)の戻り値を取得 bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType ){ vector subs; objClass.GetMethods().Enum( CALC_ARRAY_GET, subs ); if( subs.size() == 0 ){ return false; } resultType = subs[0]->ReturnType(); return true; } void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs ) { extern HANDLE hHeap; int i,i2,i3; char temporary[8192]; // 名前空間管理 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(); namespaceScopes.clear(); // Importsされた名前空間の管理 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces(); importedNamespaces.clear(); i=-1; while(1){ i++; if(source[i]==1&&(source[i+1]==ESC_CLASS||source[i+1]==ESC_INTERFACE)){ /* Class 〜 End Class Interface 〜 End Interface を飛び越す */ i3=GetEndXXXCommand(source[i+1]); for(i+=2,i2=0;;i++,i2++){ if(source[i]=='\0') break; if(source[i]==1&&source[i+1]==(char)i3){ i++; break; } } if(source[i]=='\0') break; continue; } if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ for(i+=2,i2=0;;i2++,i++){ if( IsCommandDelimitation( source[i] ) ){ temporary[i2]=0; break; } temporary[i2]=source[i]; } namespaceScopes.push_back( temporary ); continue; } else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){ if( namespaceScopes.size() <= 0 ){ SetError(12, "End Namespace", i ); } else{ namespaceScopes.pop_back(); } i += 2; continue; } else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){ for(i+=2,i2=0;;i2++,i++){ if( IsCommandDelimitation( source[i] ) ){ temporary[i2]=0; break; } temporary[i2]=source[i]; } if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) { SetError(64,temporary,cp ); } continue; } else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){ importedNamespaces.clear(); continue; } if(source[i]==1&&source[i+1]==ESC_DECLARE){ for(i+=2,i2=0;;i2++,i++){ if(source[i]=='\n'){ temporary[i2]=0; break; } temporary[i2]=source[i]; if(source[i]=='\0') break; } dllProcs.Add(namespaceScopes,temporary,i); continue; } if(source[i]==1&&(source[i+1]==ESC_SUB||source[i+1]==ESC_FUNCTION||source[i+1]==ESC_MACRO)){ char statementChar = source[i+1]; for(i2=0;;i2++,i++){ if(IsCommandDelimitation(source[i])){ temporary[i2]=0; break; } temporary[i2]=source[i]; if(source[i]=='\0') break; } userProcs.Add(namespaceScopes, importedNamespaces, temporary,i,false,NULL,false); /* Sub 〜 End Sub Function 〜 End Function Macro 〜 End Macro を飛び越す */ char endStatementChar = GetEndXXXCommand( statementChar ); for(i2=0;;i++,i2++){ if( source[i] == '\0' ) break; if( source[i] == 1 && source[i+1] == endStatementChar ){ i++; break; } } if(source[i]=='\0') break; continue; } //次の行 for(;;i++){ if(IsCommandDelimitation(source[i])) break; } if(source[i]=='\0') break; } } bool IsNeedProcCompile(){ compiler.GetObjectModule().meta.GetUserProcs().Iterator_Reset(); while( compiler.GetObjectModule().meta.GetUserProcs().Iterator_HasNext() ) { UserProc *pUserProc = compiler.GetObjectModule().meta.GetUserProcs().Iterator_GetNext(); if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){ return true; } } return false; }