gsmfunc.cc
来自「Gambit 是一个游戏库理论软件」· CC 代码 · 共 1,808 行 · 第 1/4 页
CC
1,808 行
// increment counter, and while it is a list, keep incrementing. listNum++; ch=s[index++]; // move ch past left parenthesis // Word gets the word, which is the type of variable. word = ch; ch=s[index++]; while (isalpha(ch)) { word += ch; ch = s[index++]; } } } // Check to see if it is a list (should prolly only do if req.) if (word == "NLIST") { // set listnum to be NLIST listNum = NLIST; ch=s[index++]; // move ch past left parenthesis // Word gets the word, which is the type of variable. word = ch; ch=s[index++]; while (isalpha(ch)) { word += ch; ch = s[index++]; } } // See if it is modified by a star if (ch == '*') { word += ch; ch=s[index++]; } specList.Append(word); listList.Append(listNum); // Move ch past the right parentheses (and braces), if applicable while (ch == ')') { ch=s[index++]; } /*while (ch == '}') { ch=s[index++]; }*/ if (ch == ',') // If there will be another variable { // Move ch to the first letter of the next variable name index++; ch=s[index++]; } else done = true; } // if not done (didn't hit ], and we found a ',') } // while not done // Move ch to point to first char of return type while (ch != ':' && index<=length) ch=s[index++]; index++; ch=s[index++]; // Word gets the word, which is the type of variable. gText word = ch; ch=s[index++]; while (isalpha(ch)) { word += ch; ch = s[index++]; } int listNum = 0; // Check to see if it is a list if (word == "LIST") { while (word == "LIST") { // increment counter, and while it is a list, keep incrementing. listNum++; ch=s[index++]; // move ch past left parenthesis // Word gets the word, which is the type of variable. word = ch; ch=s[index++]; while (isalpha(ch)) { word += ch; ch = s[index++]; } } } // Check to see if it is a list (should prolly only do if req.) if (word == "NLIST") { // set listnum to be NLIST listNum = NLIST; ch=s[index++]; // move ch past left parenthesis // Word gets the word, which is the type of variable. word = ch; ch=s[index++]; while (isalpha(ch)) { word += ch; ch = s[index++]; } } // Bunch of prints for debugging purposes. /*_gsm->OutputStream() << "\nReturn Type: " << word << "\n";*/ /*_gsm->OutputStream() << "Return listNum: " << listNum << "\n";*/ /*_gsm->OutputStream() << "SpecList: \n";*/ /*specList.Dump(_gsm->OutputStream());*/ /*_gsm->OutputStream() << "NameList: \n";*/ /*nameList.Dump(_gsm->OutputStream());*/ /*_gsm->OutputStream() << "ListList: \n";*/ /*listList.Dump(_gsm->OutputStream());*/ /*_gsm->OutputStream() << "RefList: \n";*/ /*refList.Dump(_gsm->OutputStream());*/ /*int rl = reqList.Length();*/ /*_gsm->OutputStream() << "ReqL Length: " << rl << "\n";*/ /*_gsm->OutputStream() << "NumArgs: " << numArgs << "\n";*/ /*_gsm->OutputStream() << "\n\n";*/ gclParameter *PIT = new gclParameter[numArgs]; for (int i=1;i<=numArgs;i++) { PIT[i-1] = gclParameter(nameList[i], ToSpec(specList[i], listList[i]), reqList[i], refList[i]); } SetFuncInfo(funcindex, gclSignature(funcptr, ToSpec(word, listNum), numArgs, PIT, FFT));} // Replaces strings with their enumerated types.PortionSpec ToSpec(gText &str, int num /* =0 */){ /*_gsm->OutputStream() << "ToSpec called with " << str << " and " << num << ".\n";*/ if (str == "BOOLEAN") return PortionSpec(porBOOLEAN, num); else if (str == "INTEGER") return PortionSpec(porINTEGER, num); else if (str == "NUMBER") return PortionSpec(porNUMBER, num); else if (str == "TEXT") return PortionSpec(porTEXT, num); else if (str == "EFG") return PortionSpec(porEFG, num); else if (str == "EFPLAYER") return PortionSpec(porEFPLAYER, num); else if (str == "EFOUTCOME") return PortionSpec(porEFOUTCOME, num); else if (str == "NODE") return PortionSpec(porNODE, num); else if (str == "INFOSET") return PortionSpec(porINFOSET, num); else if (str == "BEHAV") return PortionSpec(porBEHAV, num); else if (str == "NFG") return PortionSpec(porNFG, num); else if (str == "NFPLAYER") return PortionSpec(porNFPLAYER, num); else if (str == "NFOUTCOME") return PortionSpec(porNFOUTCOME, num); else if (str == "MIXED") return PortionSpec(porMIXED, num); else if (str == "STRATEGY") return PortionSpec(porSTRATEGY, num); else if (str == "ACTION") return PortionSpec(porACTION, num); else if (str == "ANYTYPE") return PortionSpec(porANYTYPE, num); else if (str == "EFSUPPORT") return PortionSpec(porEFSUPPORT, num); else if (str == "EFBASIS") return PortionSpec(porEFBASIS, num); else if (str == "NFSUPPORT") return PortionSpec(porNFSUPPORT, num); else if (str == "INPUT") return PortionSpec(porINPUT, num); else if (str == "OUTPUT") return PortionSpec(porOUTPUT, num); else if (str == "BOOLEAN*") return PortionSpec(porBOOLEAN, num, porNULLSPEC); else if (str == "INTEGER*") return PortionSpec(porINTEGER, num, porNULLSPEC); else if (str == "NUMBER*") return PortionSpec(porNUMBER, num, porNULLSPEC); else if (str == "TEXT*") return PortionSpec(porTEXT, num, porNULLSPEC); else if (str == "EFG*") return PortionSpec(porEFG, num, porNULLSPEC); else if (str == "EFPLAYER*") return PortionSpec(porEFPLAYER, num, porNULLSPEC); else if (str == "EFOUTCOME*") return PortionSpec(porEFOUTCOME, num, porNULLSPEC); else if (str == "NODE*") return PortionSpec(porNODE, num, porNULLSPEC); else if (str == "INFOSET*") return PortionSpec(porINFOSET, num, porNULLSPEC); else if (str == "BEHAV*") return PortionSpec(porBEHAV, num, porNULLSPEC); else if (str == "NFG*") return PortionSpec(porNFG, num, porNULLSPEC); else if (str == "NFPLAYER*") return PortionSpec(porNFPLAYER, num, porNULLSPEC); else if (str == "NFOUTCOME*") return PortionSpec(porNFOUTCOME, num, porNULLSPEC); else if (str == "MIXED*") return PortionSpec(porMIXED, num, porNULLSPEC); else if (str == "STRATEGY*") return PortionSpec(porSTRATEGY, num, porNULLSPEC); else if (str == "ACTION*") return PortionSpec(porACTION, num, porNULLSPEC); else if (str == "ANYTYPE*") return PortionSpec(porANYTYPE, num, porNULLSPEC); else if (str == "EFSUPPORT*") return PortionSpec(porEFSUPPORT, num, porNULLSPEC); else if (str == "EFBASIS*") return PortionSpec(porEFBASIS, num, porNULLSPEC); else if (str == "NFSUPPORT*") return PortionSpec(porNFSUPPORT, num, porNULLSPEC); else if (str == "INPUT*") return PortionSpec(porINPUT, num, porNULLSPEC); else if (str == "OUTPUT*") return PortionSpec(porOUTPUT, num, porNULLSPEC); else throw gclRuntimeError("ERROR: incorrect type, " + str + ", in function definition");}void gclFunction::SetParamInfo(int funcindex, int index, const gclParameter param){ if ((funcindex < 0) || (funcindex >= _NumFuncs)) throw gclRuntimeError("Internal GCL error"); if ((index < 0) || (index >= _FuncInfo[funcindex].NumParams)) throw gclRuntimeError("Internal GCL error"); _FuncInfo[funcindex].ParamInfo[index] = param;}void gclFunction::SetParamInfo(int funcindex, const gclParameter params[]){ if ((funcindex < 0) || (funcindex >= _NumFuncs)) throw gclRuntimeError("Internal GCL error"); for (int i = 0; i < _FuncInfo[funcindex].NumParams; i++) _FuncInfo[funcindex].ParamInfo[i] = params[i];}bool gclFunction::Combine(gclFunction* newfunc){ bool finalresult = true; bool same_params; int i; int j; int f_index; int index; gStack<int> delete_stack; for (i = 0; i < newfunc->_NumFuncs; i++) { bool result = true; for(f_index = 0; f_index < _NumFuncs; f_index++) { same_params = true; for(index = 0; (index < _FuncInfo[f_index].NumParams) && (index < newfunc->_FuncInfo[i].NumParams); index++) { if((_FuncInfo[f_index].ParamInfo[index].Name == newfunc->_FuncInfo[i].ParamInfo[index].Name) && (_FuncInfo[f_index].ParamInfo[index].Spec.Type == newfunc->_FuncInfo[i].ParamInfo[index].Spec.Type) && (_FuncInfo[f_index].ParamInfo[index].Spec.ListDepth == newfunc->_FuncInfo[i].ParamInfo[index].Spec.ListDepth)) { same_params = same_params & true; } else { same_params = false; break; } } if(same_params) { if(_FuncInfo[f_index].NumParams < newfunc->_FuncInfo[i].NumParams) { for(index = _FuncInfo[f_index].NumParams; index < newfunc->_FuncInfo[i].NumParams; index++) { if(newfunc->_FuncInfo[i].ParamInfo[index].DefaultValue==0) { same_params = false; break; } } } else if(_FuncInfo[f_index].NumParams > newfunc->_FuncInfo[i].NumParams) { for(index = newfunc->_FuncInfo[i].NumParams; index < _FuncInfo[f_index].NumParams; index++) { if(_FuncInfo[f_index].ParamInfo[index].DefaultValue==0) { same_params = false; break; } } } } if (same_params) { if (!_FuncInfo[f_index].UserDefined) { m_environment.ErrorStream() << "Function ambiguous with " << FuncList()[f_index+1] <<'\n'; result = false; } else { delete_stack.Push(f_index); } } } if (result) { while(delete_stack.Depth() > 0) { int delete_index = delete_stack.Pop(); m_environment.ErrorStream() << "Replacing " << FuncList()[delete_index+1] << '\n'; Delete(delete_index); } gclSignature* NewFuncInfo = new gclSignature[_NumFuncs+1]; for(j=0; j<_NumFuncs; j++) NewFuncInfo[j] = _FuncInfo[j]; delete[] _FuncInfo; _FuncInfo = NewFuncInfo; _NumFuncs++; if(newfunc->_FuncInfo[i].UserDefined) SetFuncInfo(_NumFuncs-1, newfunc->_FuncInfo[i]); else SetFuncInfo(_NumFuncs-1, newfunc->_FuncInfo[i]); for(j = 0; j < newfunc->_FuncInfo[i].NumParams; j++) { SetParamInfo(_NumFuncs-1, j, newfunc->_FuncInfo[i].ParamInfo[j]); newfunc->_FuncInfo[i].ParamInfo[j].DefaultValue = 0; } } finalresult = finalresult & result; } delete newfunc; return finalresult;}bool gclFunction::Delete(gclFunction* newfunc){ bool finalresult = true; bool same_params; int i; int f_index; int delete_index = 0; int index; for (i = 0; i < newfunc->_NumFuncs; i++) { bool result = false; for(f_index = 0; f_index < _NumFuncs; f_index++) { if(_FuncInfo[f_index].NumParams == newfunc->_FuncInfo[i].NumParams) { same_params = true; for(index = 0; index < _FuncInfo[f_index].NumParams; index++) { if((_FuncInfo[f_index].ParamInfo[index].DefaultValue == 0 && newfunc->_FuncInfo[i].ParamInfo[index].DefaultValue == 0) && (_FuncInfo[f_index].ParamInfo[index].Name == newfunc->_FuncInfo[i].ParamInfo[index].Name) && (_FuncInfo[f_index].ParamInfo[index].Spec == newfunc->_FuncInfo[i].ParamInfo[index].Spec)) { same_params = same_params & true; } else { same_params = false; break; } } if(same_params) { delete_index = f_index; result = true; break; } } } if(result) Delete(delete_index); finalresult = finalresult & result; } delete newfunc; return finalresult;}void gclFunction::Delete(int delete_index){ gclSignature* NewFuncInfo = new gclSignature[_NumFuncs-1]; int j; for(j=0; j<delete_index; j++) NewFuncInfo[j] = _FuncInfo[j]; for(j=delete_index+1; j<_NumFuncs; j++) NewFuncInfo[j-1] = _FuncInfo[j]; delete[] _FuncInfo; _FuncInfo = NewFuncInfo; _NumFuncs--;}gText gclFunction::FuncName(void) const{ return _FuncName; }bool gclFunction::UDF(void) const{ for (int i = 0; i < _NumFuncs; i++) { if (_FuncInfo[i].UserDefined) return true; } return false;}bool gclFunction::BIF(void) const{ for (int i = 0; i < _NumFuncs; i++) { if( !_FuncInfo[i].UserDefined ) return true; } return false;}gList<gText> gclFunction::FuncList( bool udf, bool bif, bool getdesc ) const{ gList<gText> list;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?