inline bool TypeCheckRec(const hapi::MpsExp &Theta, const hapi::MpsMsgEnv &Gamma, const hapi::MpsProcEnv &Omega, const std::set<std::pair<std::string,int> > &pureStack, const std::string &curPure, MpsTerm::PureState pureState, bool checkPure, hapi::MpsTerm &term, const std::string &session) // Using new rule unfold (or eq) {{{ { hapi::MpsMsgEnv::const_iterator it=Gamma.find(session); if (it==Gamma.end()) return PrintTypeError((std::string)"Unfolding closed session: " + session,term,Theta,Gamma,Omega); const hapi::MpsDelegateMsgType *delType = dynamic_cast<const hapi::MpsDelegateMsgType*>(it->second); const hapi::MpsLocalRecType *type = dynamic_cast<const hapi::MpsLocalRecType*>(delType->GetLocalType()); if (type==NULL) return PrintTypeError((std::string)"Unfolding non-rec type: " + it->second->ToString(),term,Theta,Gamma,Omega); hapi::MpsMsgEnv newGamma = Gamma; // Create type for substitution std::vector<hapi::TypeArg> args; std::vector<std::string> argnames; for (std::vector<hapi::TypeArg>::const_iterator arg=type->GetArgs().begin(); arg!=type->GetArgs().end(); ++arg) { hapi::MpsExp *newValue = new hapi::MpsVarExp(arg->myName, hapi::MpsMsgNoType()); hapi::TypeArg newArg(arg->myName, *arg->myType, *newValue); delete newValue; args.push_back(newArg); argnames.push_back(newArg.myName); } hapi::MpsLocalType *substType=new hapi::MpsLocalRecType(type->GetName(), *type->GetSucc(), args); hapi::MpsLocalType *newType = type->GetSucc()->LSubst(type->GetName(),*substType,argnames); delete substType; for (std::vector<hapi::TypeArg>::const_iterator arg=type->GetArgs().begin(); arg!=type->GetArgs().end(); ++arg) { hapi::MpsLocalType *tmpType = newType->ESubst(arg->myName,*arg->myValue); delete newType; newType=tmpType; } hapi::MpsDelegateLocalMsgType *newMsgType=new hapi::MpsDelegateLocalMsgType(*newType,delType->GetPid(),delType->GetParticipants()); newGamma[session] = newMsgType; bool result = false; if (dynamic_cast<hapi::MpsLocalRecType*>(newType)==NULL) result = term.TypeCheck(Theta,newGamma,Omega,pureStack,curPure,pureState,checkPure); else result = PrintTypeError((std::string)"Using non-contractive type: " + it->second->ToString(),term,Theta,Gamma,Omega); delete newType; delete newMsgType; return result; } // }}}
void DebugFormat::loadPdbFunctions() { auto* pdbFunctions = _pdbFile->get_functions(); if (pdbFunctions == nullptr) return; for (auto& f : *pdbFunctions) { if (f.second == nullptr) continue; pdbparser::PDBFunction *pfnc = f.second; retdec_config::Function fnc(pfnc->getNameWithOverloadIndex()); fnc.setStart(pfnc->address); fnc.setEnd(pfnc->address + pfnc->length); fnc.setSourceFileName(_pdbFile->get_module_name(pfnc->module_index)); auto* sym = _inFile->getFileFormat()->getSymbol(pfnc->address + 1); fnc.setIsThumb(sym && sym->isThumbSymbol()); fnc.setIsVariadic(pfnc->type_def->func_is_variadic); if (!pfnc->lines.empty()) { fnc.setStartLine(pfnc->lines.front().line); fnc.setEndLine(pfnc->lines.back().line); } if (pfnc->type_def != nullptr) { fnc.returnType = loadPdbType(pfnc->type_def->func_rettype_def); } unsigned argCntr = 0; for (auto& a : pfnc->arguments) { retdec_config::Storage storage; if (a.location == pdbparser::PDBLVLOC_REGISTER) // in register { storage = retdec_config::Storage::inRegister(a.register_num); } else // in register-relative stack { auto num = a.location == pdbparser::PDBLVLOC_BPREL32 ? 22 /*CV_REG_EBP*/ : a.register_num; storage = retdec_config::Storage::onStack(a.offset, num); } std::string n = a.name; std::string name = n.empty() ? std::string("arg") + std::to_string(argCntr) : n; retdec_config::Object newArg(name, storage); newArg.type = loadPdbType(a.type_def); fnc.parameters.insert(newArg); ++argCntr; } for (auto& lv : pfnc->loc_variables) { std::string name = lv.name; if (name.empty()) { continue; } retdec_config::Storage storage; if (lv.location == pdbparser::PDBLVLOC_REGISTER) // in register { storage = retdec_config::Storage::inRegister(lv.register_num); } else // in register-relative stack { auto num = lv.location == pdbparser::PDBLVLOC_BPREL32 ? 22 /*CV_REG_EBP*/ : lv.register_num; storage = retdec_config::Storage::onStack(lv.offset, num); } retdec_config::Object newLocalVar(name, storage); newLocalVar.type = loadPdbType(lv.type_def); fnc.locals.insert(newLocalVar); } fnc.setIsFromDebug(true); functions.insert( {fnc.getStart(), fnc} ); } }