void throw_invalid_object_type(const Variant& p) { auto tv = p.asCell(); switch (tv->m_type) { case KindOfNull: case KindOfUninit: throw_null_pointer_exception(); case KindOfObject: throw_invalid_object_type(tv->m_data.pobj->getClassName().c_str()); case KindOfResource: throw_invalid_object_type(tv->m_data.pres->o_getClassName().c_str()); default: throw_invalid_object_type(tname(tv->m_type).c_str()); } }
static void unserializeProp(VariableUnserializer *uns, ObjectData *obj, const String& key, Class* ctx, const String& realKey, int nProp) { // Do a two-step look up bool visible, accessible, unset; auto t = &tvAsVariant(obj->getProp(ctx, key.get(), visible, accessible, unset)); assert(!unset); if (!t || !accessible) { // Dynamic property. If this is the first, and we're using MixedArray, // we need to pre-allocate space in the array to ensure the elements // dont move during unserialization. // // TODO(#2881866): this assumption means we can't do reallocations // when promoting kPackedKind -> kMixedKind. t = &obj->reserveProperties(nProp).lvalAt(realKey, AccessFlags::Key); } t->unserialize(uns); if (!RuntimeOption::EvalCheckRepoAuthDeserialize) return; if (!RuntimeOption::RepoAuthoritative) return; if (!Repo::get().global().HardPrivatePropInference) return; /* * We assume for performance reasons in repo authoriative mode that * we can see all the sets to private properties in a class. * * It's a hole in this if we don't check unserialization doesn't * violate what we've seen, which we handle by throwing if the repo * was built with this option. */ auto const cls = obj->getVMClass(); auto const slot = cls->lookupDeclProp(key.get()); if (UNLIKELY(slot == kInvalidSlot)) return; auto const repoTy = obj->getVMClass()->declPropRepoAuthType(slot); if (LIKELY(tvMatchesRepoAuthType(*t->asTypedValue(), repoTy))) { return; } auto msg = folly::format( "Property {} for class {} was deserialized with type ({}) that " "didn't match what we inferred in static analysis", key.data(), obj->getVMClass()->name()->data(), tname(t->asTypedValue()->m_type) ).str(); throw Exception(msg); }
//----------------------------------------------------------------------------- // setVisualParamWeight() //----------------------------------------------------------------------------- BOOL LLCharacter::setVisualParamWeight(const char* param_name, F32 weight, BOOL upload_bake) { std::string tname(param_name); LLStringUtil::toLower(tname); char *tableptr = sVisualParamNames.checkString(tname); visual_param_name_map_t::iterator name_iter = mVisualParamNameMap.find(tableptr); if (name_iter != mVisualParamNameMap.end()) { name_iter->second->setWeight(weight, upload_bake); return TRUE; } llwarns << "LLCharacter::setVisualParamWeight() Invalid visual parameter: " << param_name << llendl; return FALSE; }
inline void SkyLinesTracking::Client::OnUserNameReceived(const UserNameResponsePacket &packet, size_t length) { if (length != sizeof(packet) + packet.name_length) return; /* the name follows the UserNameResponsePacket object */ const char *_name = (const char *)(&packet + 1); const std::string name(_name, packet.name_length); if (!ValidateUTF8(name.c_str())) return; UTF8ToWideConverter tname(name.c_str()); handler->OnUserName(FromBE32(packet.user_id), tname); }
/* v - точка prefXXX X X XXX \ / ^ ^^^\ PID + TID | \------/ | +---------- [0A-Z] */ string& FarMkTempEx(string &strDest, const wchar_t *Prefix, BOOL WithTempPath, const wchar_t *UserTempPath) { static UINT s_shift = 0; if (!(Prefix && *Prefix)) Prefix=L"F3T"; string strPath = L"."; if (WithTempPath) { apiGetTempPath(strPath); } else if(UserTempPath) { strPath=UserTempPath; } AddEndSlash(strPath); wchar_t *lpwszDest = strDest.GetBuffer(StrLength(Prefix)+strPath.GetLength()+13); UINT uniq = 23*GetCurrentProcessId() + s_shift, uniq0 = uniq ? uniq : 1; s_shift = (s_shift + 1) % 23; for (;;) { if (!uniq) ++uniq; if (GetTempFileName(strPath, Prefix, uniq, lpwszDest)) { string tname(lpwszDest); FindFile f(tname,false); FAR_FIND_DATA_EX ffdata; if (!f.Get(ffdata)) break; } if ((++uniq & 0xffff) == (uniq0 & 0xffff)) { *lpwszDest = 0; break; } } strDest.ReleaseBuffer(); return strDest; }
Team * Server::getWeakestTeam() { unsigned maxTeams=4; DOPE_ASSERT(maxTeams>=4); unsigned numTeams=m_game.numTeams(); unsigned maxPlayers=4; const std::vector<Team> &teams(m_game.getTeams()); bool createTeam=false; // try to fill the first two teams first if (numTeams<2) createTeam=true; else { // hmm std::min did not work unsigned p0=teams[0].playerIDs.size(); unsigned p1=teams[1].playerIDs.size(); unsigned minp=(p0<=p1) ? p0 : p1; if (minp==maxPlayers) // team 0 and 1 are full - if team 2 does not exist create it if it is full create team 3 (if possible) if ((numTeams<3)||((numTeams==3)&&(teams[2].playerIDs.size()==maxPlayers))) createTeam=true; } if (createTeam) { // create team std::string tname("Team"); tname+=anyToString(numTeams+1); return m_game.addTeam(tname,numTeams); } // find team with fewest players unsigned minp=~0U; unsigned i=0; for (;i<numTeams;++i) { // std::min does not work minp=std::min(teams[i].playerIDs.size(),minp); unsigned tp=teams[i].playerIDs.size(); minp=(tp<minp) ? tp : minp; } if (minp>=maxPlayers) return NULL; for (i=0;i<numTeams;++i) if (teams[i].playerIDs.size()==minp) break; if (i>=numTeams) return NULL; return m_game.getTeam(i); }
void logSerDes(const char* format, const char* op, const String& serialized, const Variant& value) { StructuredLogEntry sample; sample.setStr("format", format); sample.setStr("operation", op); DataType t = value.getType(); sample.setStr("type", tname(t)); if (isArrayType(t)) { sample.setInt("array_len", value.toCArrRef().length()); } if (auto sd = serialized.get()) { sample.setInt("length_ser", sd->size()); sample.setInt("hash_ser", sd->hash()); } StackTrace st; sample.setStackTrace("stack", st); StructuredLog::log("hhvm_serdes", sample); }
INT_PTR FacebookProto::CancelFriendship(WPARAM wParam, LPARAM lParam) { if (wParam == NULL || isOffline()) return 1; bool deleting = (lParam == 1); MCONTACT hContact = MCONTACT(wParam); // Ignore groupchats and, if deleting, also not-friends if (isChatRoom(hContact) || (deleting && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE) != CONTACT_FRIEND)) return 0; ptrT tname(getTStringA(hContact, FACEBOOK_KEY_NICK)); if (tname == NULL) tname = getTStringA(hContact, FACEBOOK_KEY_ID); if (tname == NULL) return 1; TCHAR tstr[256]; mir_sntprintf(tstr, TranslateT("Do you want to cancel your friendship with '%s'?"), tname); if (MessageBox(0, tstr, m_tszUserName, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES) { ptrA id(getStringA(hContact, FACEBOOK_KEY_ID)); if (id == NULL) return 1; std::string *val = new std::string(id); if (deleting) { facebook_user *fbu = facy.buddies.find(*val); if (fbu != NULL) fbu->handle = NULL; } ForkThread(&FacebookProto::DeleteContactFromServer, val); } return 0; }
File* D2Data::loadImageByName(char const* name) { if (!name[0]) return NULL; File* invfile = loadImage(String::format("data\\global\\items\\%s.dc6", name)); if (invfile) return invfile; int index = -1; D2BaseItem* base = baseItems.getptr(name); if (!base) { String tname(name); if (!s_isdigit(tname[tname.length() - 1])) return NULL; index = (tname[tname.length() - 1] - '1'); tname.resize(tname.length() - 1); base = baseItems.getptr(tname); } if (!base) return NULL; if (index >= 0 && base->type && index < base->type->invgfx.length()) invfile = loadImage(String::format("data\\global\\items\\%s.dc6", base->type->invgfx[index])); if (!invfile) invfile = loadImage(String::format("data\\global\\items\\%s.dc6", base->invfile)); return invfile; }
void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMString& defaultFile) { if (Proto_IsAccountEnabled(acc) && acc->szProtoName && IsSmileyProto(acc->szModuleName)) { CMString displayName(acc->tszAccountName ? acc->tszAccountName : A2T_SM(acc->szModuleName)); CMString PhysProtoName, paths; DBVARIANT dbv; if (db_get_ts(NULL, acc->szModuleName, "AM_BaseProto", &dbv) == 0) { PhysProtoName = _T("AllProto"); PhysProtoName += dbv.ptszVal; db_free(&dbv); } if (!PhysProtoName.IsEmpty()) paths = g_SmileyCategories.GetSmileyCategory(PhysProtoName) ? g_SmileyCategories.GetSmileyCategory(PhysProtoName)->GetFilename() : _T(""); if (paths.IsEmpty()) { const char* packnam = acc->szProtoName; if (mir_strcmp(packnam, "JABBER") == 0) packnam = "JGMail"; else if (strstr(packnam, "SIP") != NULL) packnam = "MSN"; char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); paths = A2T_SM(path); CMString patha; pathToAbsolute(paths, patha); if (_taccess(patha.c_str(), 0) != 0) paths = defaultFile; } CMString tname(A2T_SM(acc->szModuleName)); AddCategory(tname, displayName, acc->bIsVirtual ? smcVirtualProto : smcProto, paths); } }
int CMaxMesh::GetSubmeshMaterialThreadId(int submeshId) { // check if the submesh id is valid if((submeshId < 0) || (submeshId >= (int)m_vectorStdMat.size())) { theExporter.SetLastError("Invalid handle.", __FILE__, __LINE__); return -1; } // get the material of the submesh StdMat *pStdMat; pStdMat = m_vectorStdMat[submeshId]; // get name of the material std::tstring tname(pStdMat->GetName()); std::string strName(tname.begin(), tname.end()); // get positions of the material thread id std::string::size_type openPos; openPos = strName.find_last_of("["); std::string::size_type closePos; closePos = strName.find_last_of("]"); if((openPos == std::string::npos) || (closePos == std::string::npos) || (++openPos >= closePos)) { theExporter.SetLastError("Invalid material thread id in material.", __FILE__, __LINE__); return -1; } // extract material thread id from material name std::string strMaterialThreadId; strMaterialThreadId = strName.substr(openPos, closePos - openPos); int materialThreadId; materialThreadId = atoi(strMaterialThreadId.c_str()); return materialThreadId; }
int jdip::context_parser::handle_scope(definition_scope *scope, token_t& token, unsigned inherited_flags) { definition* decl; token = read_next_token(scope); for (;;) { switch (token.type) { case TT_TYPENAME: case TT_DECFLAG: case TT_DECLTYPE: case TT_DECLARATOR: case_TT_DECLARATOR: case TT_CLASS: case TT_STRUCT: case TT_ENUM: case TT_UNION: case TT_TILDE: decl = NULL; handle_declarator_block: if (handle_declarators(scope, token, inherited_flags, decl)) { FATAL_RETURN(1); while (token.type != TT_ENDOFCODE and token.type != TT_SEMICOLON and token.type != TT_LEFTBRACE and token.type != TT_RIGHTBRACE) token = read_next_token(scope); } handled_declarator_block: if (token.type != TT_SEMICOLON) { if (token.type == TT_LEFTBRACE || token.type == TT_ASM) { if (!(decl and decl->flags & DEF_FUNCTION)) { token.report_error(herr, "Unexpected opening brace here; declaration is not a function"); FATAL_RETURN(1); handle_function_implementation(lex,token,scope,herr); } else ((definition_function*)decl)->implementation = handle_function_implementation(lex,token,scope,herr); if (token.type != TT_RIGHTBRACE && token.type != TT_SEMICOLON) { token.report_error(herr, "Expected closing symbol to function"); continue; } } else { token.report_errorf(herr, "Expected semicolon before %s following declaration"); #if FATAL_ERRORS return 1; #else semicolon_bail: while (token.type != TT_SEMICOLON && token.type != TT_LEFTBRACE && token.type != TT_RIGHTBRACE && token.type != TT_ENDOFCODE) token = read_next_token(scope); if (token.type == TT_LEFTBRACE) { size_t depth = 1; while (token.type != TT_ENDOFCODE) { token = read_next_token(scope); if (token.type == TT_LEFTBRACE) ++depth; else if (token.type == TT_RIGHTBRACE) if (!--depth) break; } } #endif } } break; case TT_EXTERN: token = read_next_token(scope); if (token.type == TT_STRINGLITERAL) { token = read_next_token(scope); if (token.type == TT_LEFTBRACE) { FATAL_RETURN_IF(handle_scope(scope, token, inherited_flags), 1); if (token.type != TT_RIGHTBRACE) { token.report_error(herr, "Expected closing brace to extern block"); FATAL_RETURN(1); } break; } } else if (token.type == TT_TEMPLATE) { token = read_next_token(scope); if (token.type != TT_CLASS and token.type != TT_STRUCT and token.type != TT_DECLARATOR and token.type != TT_DEFINITION) { token.report_errorf(herr, "Expected template specialization following `extern template' directive; %s unhandled"); FATAL_RETURN(1); } } goto handle_declarator_block; case TT_COMMA: token.report_error(herr, "Unexpected comma at this point."); return 1; case TT_SEMICOLON: /* Printing a warning here is advisable but unnecessary. */ break; case TT_NAMESPACE: if (handle_namespace(scope,token)) return 1; break; case TT_LEFTPARENTH: { token.report_error(herr, "Stray opening parenthesis."); #if FATAL_ERRORS return 1; #else int bc = 1; while (bc) { token = read_next_token(scope); bc += token.type == TT_LEFTPARENTH; bc -= token.type == TT_RIGHTPARENTH; } #endif } break; case TT_RIGHTPARENTH: token.report_error(herr, "Stray closing parenthesis."); return 1; case TT_LEFTBRACKET: token.report_error(herr, "Stray opening bracket."); return 1; case TT_RIGHTBRACKET: token.report_error(herr, "Stray closing bracket."); return 1; case TT_RIGHTBRACE: return 0; case TT_LEFTBRACE: { token.report_error(herr, "Expected scope declaration before opening brace."); #if FATAL_ERRORS return 1; #else int bc = 1; while (bc) { token = read_next_token(scope); if (token.type == TT_ENDOFCODE) { token.report_error(herr, "Expected closing brace before end of code."); return 1; } bc += token.type == TT_LEFTBRACE; bc -= token.type == TT_RIGHTBRACE; } #endif } break; case TT_TYPEDEF: token = read_next_token(scope); if (handle_declarators(scope,token,inherited_flags | DEF_TYPENAME)) FATAL_RETURN(1); break; case TT_PUBLIC: if (scope->flags & DEF_CLASS) { inherited_flags &= ~(DEF_PRIVATE | DEF_PROTECTED); } else token.report_error(herr, "Unexpected `public' token outside class scope."); if ((token = read_next_token(scope)).type != TT_COLON) token.report_error(herr, "Colon expected following `public' token"); break; case TT_PRIVATE: if (scope->flags & DEF_CLASS) { inherited_flags &= ~(DEF_PRIVATE | DEF_PROTECTED); inherited_flags |= DEF_PRIVATE; } else token.report_error(herr, "Unexpected `private' token outside class scope."); if ((token = read_next_token(scope)).type != TT_COLON) token.report_error(herr, "Colon expected following `private' token"); break; case TT_PROTECTED: if (scope->flags & DEF_CLASS) { inherited_flags &= ~(DEF_PRIVATE | DEF_PROTECTED); inherited_flags |= DEF_PROTECTED; } else token.report_error(herr, "Unexpected `protected' token outside class scope."); if ((token = read_next_token(scope)).type != TT_COLON) token.report_error(herr, "Colon expected following `protected' token"); break; case TT_USING: token = read_next_token(scope); if (token.type == TT_NAMESPACE) { token = lex->get_token(herr); if (token.type == TT_IDENTIFIER) { definition* d = scope->look_up(token.content.toString()); if (!d) { token.report_errorf(herr, "Expected id to use before %s"); FATAL_RETURN(1); } else { if (d->flags & DEF_NAMESPACE) scope->use_namespace((definition_scope*)d); else token.report_error(herr, "Expected namespace name following `namespace' token"); } token = read_next_token(scope); } else token.report_error(herr, "Expected namespace name following `namespace' token"); } else { definition *usedef = read_qualified_definition(lex, scope, token, this, herr); if (usedef) scope->use_general(usedef->name, usedef); else { token.report_errorf(herr, "Using directive does not specify an object"); FATAL_RETURN(1); } if (token.type != TT_SEMICOLON) { token.report_errorf(herr, "Expected semicolon before %s to terminate using directive"); FATAL_RETURN(1); } } break; case TT_SCOPE: token = read_next_token(global); continue; case TT_DEFINITION: { if (token.def->flags & DEF_NAMESPACE) { definition_scope* dscope = (definition_scope*)token.def; token = read_next_token(scope); if (token.type == TT_SCOPE) { token = read_next_token(dscope); continue; } token.report_errorf(herr, "Expected `::' here to access namespace members"); FATAL_RETURN(1); break; } if (token.def->flags & DEF_TEMPLATE) goto case_TT_DECLARATOR; } case TT_IDENTIFIER: { string tname(token.content.toString()); if (tname == scope->name and (scope->flags & DEF_CLASS)) { token = read_next_token(scope); if (token.type != TT_LEFTPARENTH) { token.report_errorf(herr, "Expected constructor parmeters before %s"); break; } full_type ft; ft.def = scope; token = read_next_token(scope); read_function_params(ft.refs, lex, token, scope, this, herr); if (handle_declarators(scope,token,ft,inherited_flags | DEF_TYPENAME,decl)) FATAL_RETURN(1); goto handled_declarator_block; } token.report_error(herr, "Unexpected identifier in this scope; `" + tname + "' does not name a type"); } break; case TT_TEMPLATE: if (handle_template(scope, token, inherited_flags)) { FATAL_RETURN(1); goto semicolon_bail; } break; case TT_OPERATORKW: token = read_next_token(scope); if (token.type != TT_DECLARATOR and token.type != TT_DECFLAG and token.type != TT_DECLTYPE) { token.report_errorf(herr, "Expected cast type to overload before %s"); FATAL_RETURN(1); } else { lex_buffer lb(lex); while (token.type != TT_LEFTPARENTH and token.type != TT_LEFTBRACE and token.type != TT_SEMICOLON and token.type != TT_ENDOFCODE) lb.push(token), token = read_next_token(scope); if (token.type != TT_LEFTPARENTH) { token.report_error(herr, "Expected function parmeters before %s"); FATAL_RETURN(1); break; } token.type = TT_ENDOFCODE; lb.push(token); token.type = TT_LEFTPARENTH; lb.reset(); token_t kick = lb.get_token(herr); full_type ft = read_fulltype(&lb, kick, scope, this, herr); string opname; { ref_stack my_func_refs; read_referencers_post(my_func_refs, lex, token, scope, this, herr); if (my_func_refs.empty() or my_func_refs.top().type != ref_stack::RT_FUNCTION) { token.report_error(herr, "Expected function parameters for operator overload"); return 1; } opname = "operator " + ft.toString(); ft.refs.append_c(my_func_refs); } definition_function *const df = new definition_function(opname, scope, ft.def, ft.refs, ft.flags, inherited_flags); decl = df; decpair ins = scope->declare(decl->name, decl); if (!ins.inserted) { arg_key k(df->referencers); decl = ((definition_function*)ins.def)->overload(k, df, herr); } goto handled_declarator_block; } break; case TT_ASM: case TT_SIZEOF: case TT_ISEMPTY: case TT_OPERATOR: case TT_ELLIPSIS: case TT_LESSTHAN: case TT_GREATERTHAN: case TT_COLON: case TT_DECLITERAL: case TT_HEXLITERAL: case TT_OCTLITERAL: case TT_STRINGLITERAL: case TT_CHARLITERAL: case TT_NEW: case TT_DELETE: case TTM_CONCAT: case TTM_TOSTRING: case TT_INVALID: #include <User/token_cases.h> default: token.report_errorf(herr, "Unexpected %s in this scope"); break; case TT_ENDOFCODE: return 0; } token = read_next_token(scope); } }
int jdip::context_parser::handle_scope(definition_scope *scope, token_t& token, unsigned inherited_flags) { definition* decl; token = read_next_token(scope); for (;;) { switch (token.type) { case TT_TYPENAME: case TT_DECFLAG: case TT_DECLTYPE: case TT_DECLARATOR: case_TT_DECLARATOR: case TT_CLASS: case TT_STRUCT: case TT_ENUM: case TT_UNION: case TT_TILDE: decl = NULL; handle_declarator_block: if (handle_declarators(scope, token, inherited_flags, decl)) { FATAL_RETURN(1); while (token.type != TT_ENDOFCODE and token.type != TT_SEMICOLON and token.type != TT_LEFTBRACE and token.type != TT_RIGHTBRACE) token = read_next_token(scope); } handled_declarator_block: if (token.type != TT_SEMICOLON) { if (token.type == TT_LEFTBRACE || token.type == TT_ASM) { if (!(decl and decl->flags & DEF_OVERLOAD)) { token.report_error(herr, "Unexpected opening brace here; declaration is not a function"); FATAL_RETURN(1); handle_function_implementation(lex,token,scope,herr); } else { definition_overload *ovr = ((definition_overload*)decl); if (ovr->implementation != NULL) { token.report_error(herr, "Multiple implementations of function" FATAL_TERNARY("", "; old implementation discarded")); delete_function_implementation(ovr->implementation); } ovr->implementation = handle_function_implementation(lex,token,scope,herr); } if (token.type != TT_RIGHTBRACE && token.type != TT_SEMICOLON) { token.report_error(herr, "Expected closing symbol to function"); continue; } } else { token.report_errorf(herr, "Expected semicolon before %s following declaration"); #if FATAL_ERRORS return 1; #else semicolon_bail: while (token.type != TT_SEMICOLON && token.type != TT_LEFTBRACE && token.type != TT_RIGHTBRACE && token.type != TT_ENDOFCODE) token = read_next_token(scope); if (token.type == TT_LEFTBRACE) { size_t depth = 1; while (token.type != TT_ENDOFCODE) { token = read_next_token(scope); if (token.type == TT_LEFTBRACE) ++depth; else if (token.type == TT_RIGHTBRACE) if (!--depth) break; } } #endif } } break; case TT_EXTERN: token = read_next_token(scope); if (token.type == TT_STRINGLITERAL) { token = read_next_token(scope); if (token.type == TT_LEFTBRACE) { FATAL_RETURN_IF(handle_scope(scope, token, inherited_flags), 1); if (token.type != TT_RIGHTBRACE) { token.report_error(herr, "Expected closing brace to extern block"); FATAL_RETURN(1); } break; } } else if (token.type == TT_TEMPLATE) { token = read_next_token(scope); if (token.type != TT_CLASS and token.type != TT_STRUCT and token.type != TT_DECLARATOR and token.type != TT_DECFLAG and token.type != TT_DEFINITION) { token.report_errorf(herr, "Expected template specialization following `extern template' directive; %s unhandled"); FATAL_RETURN(1); } if (handle_template_extern(scope, token, inherited_flags)) FATAL_RETURN(1); break; } goto handle_declarator_block; case TT_COMMA: token.report_error(herr, "Unexpected comma at this point."); return 1; case TT_SEMICOLON: /* Printing a warning here is advisable but unnecessary. */ break; case TT_NAMESPACE: if (handle_namespace(scope,token)) return 1; break; case TT_LEFTPARENTH: { token.report_error(herr, "Stray opening parenthesis."); #if FATAL_ERRORS return 1; #else int bc = 1; while (bc) { token = read_next_token(scope); bc += token.type == TT_LEFTPARENTH; bc -= token.type == TT_RIGHTPARENTH; } #endif } break; case TT_RIGHTPARENTH: token.report_error(herr, "Stray closing parenthesis."); return 1; case TT_LEFTBRACKET: token.report_error(herr, "Stray opening bracket."); return 1; case TT_RIGHTBRACKET: token.report_error(herr, "Stray closing bracket."); return 1; case TT_RIGHTBRACE: return 0; case TT_LEFTBRACE: { token.report_error(herr, "Expected scope declaration before opening brace."); #if FATAL_ERRORS return 1; #else int bc = 1; while (bc) { token = read_next_token(scope); if (token.type == TT_ENDOFCODE) { token.report_error(herr, "Expected closing brace before end of code."); return 1; } bc += token.type == TT_LEFTBRACE; bc -= token.type == TT_RIGHTBRACE; } #endif } break; case TT_TYPEDEF: token = read_next_token(scope); if (handle_declarators(scope,token,inherited_flags | DEF_TYPENAME)) FATAL_RETURN(1); break; case TT_PUBLIC: if (scope->flags & DEF_CLASS) { inherited_flags &= ~(DEF_PRIVATE | DEF_PROTECTED); } else token.report_error(herr, "Unexpected `public' token outside class scope."); if ((token = read_next_token(scope)).type != TT_COLON) token.report_error(herr, "Colon expected following `public' token"); break; case TT_PRIVATE: if (scope->flags & DEF_CLASS) { inherited_flags &= ~(DEF_PRIVATE | DEF_PROTECTED); inherited_flags |= DEF_PRIVATE; } else token.report_error(herr, "Unexpected `private' token outside class scope."); if ((token = read_next_token(scope)).type != TT_COLON) token.report_error(herr, "Colon expected following `private' token"); break; case TT_PROTECTED: if (scope->flags & DEF_CLASS) { inherited_flags &= ~(DEF_PRIVATE | DEF_PROTECTED); inherited_flags |= DEF_PROTECTED; } else token.report_error(herr, "Unexpected `protected' token outside class scope."); if ((token = read_next_token(scope)).type != TT_COLON) token.report_error(herr, "Colon expected following `protected' token"); break; case TT_FRIEND: if (!(scope->flags & DEF_CLASS)) { token.report_error(herr, "`friend' statement may only appear in a class or structure"); FATAL_RETURN(1); while ((token = read_next_token(scope)).type != TT_SEMICOLON && token.type != TT_RIGHTBRACE && token.type != TT_ENDOFCODE); } else { if (handle_friend(scope, token, (definition_class*)scope)) FATAL_RETURN(1); if (token.type == TT_SEMICOLON) token = read_next_token(scope); else { token.report_errorf(herr, "Expected semicolon before %s"); FATAL_RETURN(1); } } continue; case TT_USING: token = read_next_token(scope); if (token.type == TT_NAMESPACE) { token = lex->get_token_in_scope(scope, herr); if (token.type == TT_DEFINITION) { definition *d = read_qualified_definition(token, scope); if (!d) { token.report_errorf(herr, "Expected namespace-name following `namespace' token"); FATAL_RETURN(1); } else { if (d->flags & DEF_NAMESPACE) scope->use_namespace((definition_scope*)d); else token.report_error(herr, "Expected namespace-name following `namespace' token"); } if (token.type == TT_SEMICOLON) token = read_next_token(scope); else { token.report_errorf(herr, "Expected semicolon before %s"); FATAL_RETURN(1); } } else { token.report_errorf(herr, "Expected namespace to use before %s"); FATAL_RETURN(1); } } else { definition *usedef = read_qualified_definition(token, scope); if (usedef) scope->use_general(usedef->name, usedef); else { token.report_errorf(herr, "Using directive does not specify an object"); FATAL_RETURN(1); } if (token.type != TT_SEMICOLON) { token.report_errorf(herr, "Expected semicolon before %s to terminate using directive"); FATAL_RETURN(1); } } continue; case TT_SCOPE: token = read_next_token(ctex->get_global()); continue; case TT_MEMBEROF: token.report_error(herr, "Unexpected (scope::*) reference"); return 1; case TT_STATIC_ASSERT: token.report_error(herr, "Unimplemented: static assert"); break; case TT_AUTO: token.report_error(herr, "Unimplemented: `auto' type inference"); break; case TT_CONSTEXPR: token.report_error(herr, "Unimplemented: const expressions outside enum"); break; case TT_DEFINITION: { if (token.def->flags & DEF_NAMESPACE) { definition_scope* dscope = (definition_scope*)token.def; token = read_next_token(scope); if (token.type == TT_SCOPE) { token = read_next_token(dscope); continue; } token.report_errorf(herr, "Expected `::' here to access namespace members"); FATAL_RETURN(1); break; } if (token.def->flags & DEF_TEMPLATE) goto case_TT_DECLARATOR; } case TT_IDENTIFIER: { string tname(token.content.toString()); if (tname == scope->name and (scope->flags & DEF_CLASS)) { token = read_next_token(scope); if (token.type != TT_LEFTPARENTH) { token.report_errorf(herr, "Expected constructor parmeters before %s"); break; } full_type ft; ft.def = scope; token = read_next_token(scope); read_function_params(ft.refs, token, scope); if (handle_declarators(scope,token,ft,inherited_flags | DEF_TYPENAME,decl)) FATAL_RETURN(1); goto handled_declarator_block; } token.report_error(herr, "Unexpected identifier in this scope (" + scope->name + "); `" + tname + "' does not name a type"); } break; case TT_TEMPLATE: if (handle_template(scope, token, inherited_flags)) { FATAL_RETURN(1); goto semicolon_bail; } break; case TT_OPERATORKW: { full_type ft = read_operatorkw_cast_type(token, scope); if (!ft.def) return 1; if (!(decl = scope->overload_function("(cast)", ft, inherited_flags, token, herr))) return 1; goto handled_declarator_block; } break; case TT_ASM: case TT_SIZEOF: case TT_ISEMPTY: case TT_ALIGNOF: case TT_ALIGNAS: case TT_OPERATOR: case TT_ELLIPSIS: case TT_LESSTHAN: case TT_GREATERTHAN: case TT_COLON: case TT_DECLITERAL: case TT_HEXLITERAL: case TT_OCTLITERAL: case TT_STRINGLITERAL: case TT_CHARLITERAL: case TT_NEW: case TT_DELETE: case TTM_CONCAT: case TTM_TOSTRING: case TT_INVALID: case TT_CONST_CAST: case TT_STATIC_CAST: case TT_DYNAMIC_CAST: case TT_REINTERPRET_CAST: case TT_NOEXCEPT: case TT_TYPEID: #include <User/token_cases.h> default: token.report_errorf(herr, "Unexpected %s in this scope"); break; case TT_ENDOFCODE: return 0; } token = read_next_token(scope); } }
// ============================================================================ // pxpByteCode // ============================================================================ pxpByteCode::pxpByteCode( pkgDecompiler* decompiler ) : Decompiler(decompiler) , CToken(NULL) , CTokenTree(NULL) , CTokenGroup(NULL) , CTokenGroupTree(NULL) , CTokenItem(NULL) , CTokenItemTree(NULL) , CTokenGroupCnd(NULL) , CTokenGroupCndTree(NULL) , unXmlParser() { // temp tree nodes unXmlParseTree bytecode ( wxT("bytecode") ); unXmlParseTree bgroup ( wxT("group") ); unXmlParseTree gname ( wxT("name") ); unXmlParseTree gmemo ( wxT("memo") ); unXmlParseTree gtoken ( wxT("token") ); unXmlParseTree tcode ( wxT("code") ); unXmlParseTree tname ( wxT("name") ); unXmlParseTree tdesc ( wxT("desc") ); unXmlParseTree tdata ( wxT("data") ); unXmlParseTree titem ( wxT("item") ); unXmlParseTree itype ( wxT("type") ); unXmlParseTree iname ( wxT("name") ); unXmlParseTree ttext ( wxT("text") ); unXmlParseTree gcond ( wxT("gcond") ); unXmlParseTree cif ( wxT("if") ); unXmlParseTree ceq ( wxT("eq") ); unXmlParseTree cthen ( wxT("then") ); unXmlParseTree cleft ( wxT("left") ); unXmlParseTree cright ( wxT("right") ); unXmlParseTree ctstream ( wxT("tstream") ); unXmlParseTree cnum ( wxT("num") ); unXmlParseTree nfunc ( wxT("nativefunctions") ); unXmlParseTree ffirst ( wxT("first") ); unXmlParseTree fextended ( wxT("extended") ); // token group - pre bgroup.AddCommand( new_xpObjCreate<pkgTokenGroup>(txpParseTree) ); bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroup, txpTokenGroupObject ) ); bgroup.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupTree, txpParseTree ) ); gname.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::SetName, txpNodeName(txpParseTree) ) ); gname.AddPostCommand( new_xpFunc1( Decompiler, &pkgDecompiler::AddTokenGroup, txpTokenGroup ) ); // token group - post bgroup.AddPostCommand( new_xpObjClear(txpParseTree) ); bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroup ) ); bgroup.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupTree ) ); // gcond = pre gcond.AddCommand( new_xpObjCreate<pkgTokenCondition>(txpParseTree) ); gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCnd, txpTokenGroupCndObject ) ); gcond.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenGroupCndTree, txpParseTree ) ); // gcond = post gcond.AddPostCommand( new_xpObjClear(txpParseTree) ); gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCnd ) ); gcond.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenGroupCndTree ) ); // token - pre gtoken.AddCommand( new_xpObjCreate<dtToken>(txpParseTree) ); gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetToken, txpTokenObject ) ); gtoken.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenTree, txpParseTree ) ); tcode.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenData, txpNodeData(txpParseTree) ) ); tname.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetTokenName, txpNodeName(txpParseTree) ) ); tdesc.AddCommand( new_xpFunc1( txpTokenTreeObject, &dtToken::SetDesc, txpNodeName(txpParseTree) ) ); tdesc.AddCommand( new_xpFunc1( txpTokenGroup, &pkgTokenGroup::AddToken, txpToken ) ); tdesc.AddCommand( new_xpFunc2( Decompiler, &pkgDecompiler::AddToken, txpToken, txpTokenGroupCnd ) ); // token - post gtoken.AddPostCommand( new_xpFunc0( txpToken, &dtToken::DumpInfo ) ); gtoken.AddPostCommand( new_xpObjClear(txpParseTree) ); gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearToken ) ); gtoken.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenTree ) ); // titem - pre titem.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItemTree, txpParseTree ) ); itype.AddCommand( new_xpObjFactory( txpTokenItemTree, &GDataTypeFactory, &pkgDataTypeFactory::Create, txpNodeName(txpParseTree) ) ); itype.AddCommand( new_xpFunc1( this, &pxpByteCode::SetTokenItem, txpTokenItemTreeObject ) ); iname.AddCommand( new_xpFunc1( txpTokenItem, &pkgDataType::SetDesc, txpNodeName(txpParseTree) ) ); // titem - post titem.AddPostCommand( new_xpFunc1( txpToken, &dtToken::AddItem, txpTokenItem ) ); titem.AddPostCommand( new_xpObjClear(txpParseTree) ); titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItem ) ); titem.AddPostCommand( new_xpFunc0( this, &pxpByteCode::ClearTokenItemTree ) ); ffirst.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdFirst, txpNodeData(txpParseTree) ) ); fextended.AddCommand( new_xpFunc1( Decompiler, &pkgDecompiler::SetFunctionIdExtended, txpNodeData(txpParseTree) ) ); // construct tree starting from leaves // ie: node on right side *cannot* appear anywhere below on left side // token gtoken.AddChild( tcode, pl::one ); gtoken.AddChild( tname, pl::one ); gtoken.AddChild( tdesc, pl::one ); titem.AddChild( itype, pl::one ); titem.AddChild( iname, pl::one ); tdata.AddChild( titem, pl::minone ); tdata.AddChild( ttext, pl::maxone ); gtoken.AddChild( tdata, pl::maxone ); // if cleft.AddChild( ctstream, pl::maxone ); cleft.AddChild( cnum, pl::maxone ); cright.AddChild( ctstream, pl::maxone ); cright.AddChild( cnum, pl::maxone ); ceq.AddChild( cleft, pl::one ); ceq.AddChild( cright, pl::one ); cif.AddChild( ceq, pl::one ); // then cthen.AddChild( gtoken, pl::any ); // group bgroup.AddChild( gname, pl::one ); bgroup.AddChild( gmemo, pl::any ); gcond.AddChild( cif, pl::one ); gcond.AddChild( cthen, pl::one ); bgroup.AddChild( gcond, pl::maxone ); bgroup.AddChild( gtoken, pl::any ); // native functions nfunc.AddChild( fextended, pl::one ); nfunc.AddChild( ffirst, pl::one ); // bytecode bytecode.AddChild( bgroup, pl::minone ); bytecode.AddChild( nfunc, pl::maxone ); ParseTree = new unXmlParseTree( bytecode ); }
void CLowDiskSpaceTest::FillDiskL() { _LIT(KFillDiskTitle, "Fill the disk"); test.Next(_L("Fill the disk")); TVolumeInfo tv; User::LeaveIfError( iFileSession.Volume(tv) ); TInt frees = 0; iManyFiles = tv.iFree / KMaxTInt; if ( iManyFiles > 0) { TPtrC tname( KFileName ); TInt i = 0; for( ; i < iManyFiles; ++i ) { HBufC *fval=HBufC::NewLC( tname.Length()+4 );//assume #files < 10000 TPtr fptr = fval->Des() ; fptr.Append( tname ); fptr.AppendNum( i ); User::LeaveIfError( iFile->Replace( iFileSession, fptr, EFileWrite ) ); User::LeaveIfError( iFile->SetSize( KMaxTInt ) ); iFile->Close(); CleanupStack::PopAndDestroy( fval ); } User::LeaveIfError( iFileSession.Volume(tv) ); frees = tv.iFree - KMinusFull ; if( frees <= 0 ) { frees = tv.iFree; } User::LeaveIfError( iFile->Replace( iFileSession, KFileName, EFileWrite ) ); #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ TInt err = KErrDiskFull; while(err == KErrDiskFull) { err = iFile->SetSize(frees); frees -= 100; if(frees <= 0) { break; } } #else User::LeaveIfError( iFile->SetSize( frees ) ); #endif iFile->Close(); } else { frees = tv.iFree - KMinusFull ; if( frees <= 0 ) { frees = tv.iFree; } User::LeaveIfError( iFile->Replace( iFileSession, KFileName, EFileWrite ) ); #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ TInt err = KErrDiskFull; while(err == KErrDiskFull) { err = iFile->SetSize(frees); frees -= 100; if(frees <= 0) { break; } } #else User::LeaveIfError( iFile->SetSize( frees ) ); #endif iFile->Close(); } }
void CStreamInfo2::paint_signal_fe_box(int _x, int _y, int w, int h) { int y1; int xd = w/4; std::string tname(g_Locale->getText(LOCALE_STREAMINFO_SIGNAL)); tname += ": "; if (mp) tname += g_Locale->getText(LOCALE_WEBTV_HEAD); else tname += to_string(1 + frontend->getNumber()) + ": " + frontend->getName(); #if 0 int tuner = 1 + frontend->getNumber(); char tname[255]; snprintf(tname, sizeof(tname), "%s: %d: %s", g_Locale->getText(LOCALE_STREAMINFO_SIGNAL), tuner, frontend->getName()); #endif g_Font[font_small]->RenderString(_x, _y+iheight+15, width-_x-10, tname /*tuner_name.c_str()*/, COL_INFOBAR_TEXT); sigBox_x = _x; sigBox_y = _y+iheight+15; sigBox_w = w; sigBox_h = h-iheight*3; frameBuffer->paintBoxRel(sigBox_x,sigBox_y,sigBox_w+2,sigBox_h, COL_BLACK); sig_text_y = sigBox_y + sigBox_h; y1 = sig_text_y + sheight+4; int fw = g_Font[font_small]->getWidth(); if (!mp) { frameBuffer->paintBoxRel(_x+xd*0,y1- 12,16,2, COL_RED); //red g_Font[font_small]->RenderString(_x+20+xd*0, y1, fw*4, "BER", COL_INFOBAR_TEXT); frameBuffer->paintBoxRel(_x+xd*1,y1- 12,16,2,COL_BLUE); //blue g_Font[font_small]->RenderString(_x+20+xd*1, y1, fw*4, "SNR", COL_INFOBAR_TEXT); frameBuffer->paintBoxRel(_x+8+xd*2,y1- 12,16,2, COL_GREEN); //green g_Font[font_small]->RenderString(_x+28+xd*2, y1, fw*4, "SIG", COL_INFOBAR_TEXT); } frameBuffer->paintBoxRel(_x+xd*3,y1- 12,16,2,COL_YELLOW); // near yellow g_Font[font_small]->RenderString(_x+20+xd*3, y1, fw*5, "Bitrate", COL_INFOBAR_TEXT); sig_text_ber_x = _x + xd * 0; sig_text_snr_x = _x + 5 + xd * 1; sig_text_sig_x = _x + 5 + xd * 2; sig_text_rate_x = _x + 10 + xd * 3; int maxmin_x; // x-position of min and max int fontW = g_Font[font_small]->getWidth(); if (paint_mode == 0) maxmin_x = sig_text_ber_x-(fontW*4); else maxmin_x = _x + 40 + xd * 3 + (fontW*4); g_Font[font_small]->RenderString(maxmin_x, y1 + sheight + 5, fw*3, "max", COL_INFOBAR_TEXT); g_Font[font_small]->RenderString(maxmin_x, y1 + (sheight * 2) +5, fw*3, "now", COL_INFOBAR_TEXT); g_Font[font_small]->RenderString(maxmin_x, y1 + (sheight * 3) +5, fw*3, "min", COL_INFOBAR_TEXT); sigBox_pos = 0; signal.old_sig = 1; signal.old_snr = 1; signal.old_ber = 1; }
void D2Item::parse(D2Data* data) { int underscore = title.indexOf('_'); if (underscore >= 0 && title.substr(0, underscore).isDigits()) title.cut(0, underscore + 1); String desc = description; String gidInfo; int gidSep = desc.lastIndexOf('$'); if (gidSep >= 0) { gidInfo = desc.substring(gidSep + 1); gid = atoi(gidInfo); desc.resize(gidSep); } Array<String> lines; desc.split(lines, "\\n"); if (!lines.length()) return; int ilvlSep = lines[0].lastIndexOf('('); if (ilvlSep >= 0) { itemLevel = atoi(lines[0].c_str() + ilvlSep + 1); lines[0].resize(ilvlSep); lines[0].trim(); } while (!strncmp(lines[0], "\\xffc", 5)) { colorCode = (lines[0][5] - '0'); lines[0].cut(0, 6); } re::Prog remover("\\\\xffc[0-9:;<]"); for (int i = 0; i < lines.length(); i++) lines[i] = remover.replace(lines[i], ""); if (desc.find(data->getLocalizedString(5203)) >= 0) flags |= D2Item::fEthereal; if (desc.find(data->getLocalizedString(3455)) >= 0) flags |= D2Item::fUnidentified; if (!(flags & D2Item::fUnidentified) && (colorCode == 2 || colorCode == 4 || colorCode == 1)) unique = data->getUniqueItem(lines[0]); if (!base && lines.length() > 1 && colorCode != 0 && colorCode != 3 && colorCode != 5) base = data->getBaseItem(lines[1]); if (!base && unique) base = unique->base; if (!base) base = data->getBaseItem(lines[0], true); if (!base) return; if (!unique && (flags & D2Item::fUnidentified)) { unique = data->getUniqueByBase(base, colorCode); if (unique) title = String::format("[%s] %s", unique->name, base->name); } D2ItemType* info = base->type->getInfo(); if (info) { type = info->type; subType = info->subType; quality = info->quality; } static int colorToQuality[] = {qNormal, qNormal, qSet, qMagic, qUnique, qNormal, 0, 0, qCrafted, qRare, 0, 0, 0}; static int qualityToType[] = {tMisc, tWhite, tWhite, tWhite, tMagic, tSet, tRare, tUnique, tCrafted}; if (quality < 0) { if (unique) quality = (unique->type == 6 ? qUnique : colorToQuality[unique->type]); else quality = colorToQuality[colorCode]; } if (type == tAuto) { if (unique && unique->type == 6) type = tRuneword; else type = qualityToType[quality]; } if (colorCode == 1) { if (unique) colorCode = (unique->type == 2 ? 2 : 4); // more broken detection? } if (!title.length()) { title = lines[0]; if (quality == D2Item::qSet || quality == D2Item::qRare || quality == D2Item::qCrafted || quality == D2Item::qUnique) title = String::format("%s %s", lines[0], base->name); } if (!base || base->type->isType("rune") || base->type->isType("gem")) return; if (sockets.length()) { Array<String> jewDesc; gidInfo.split(jewDesc, "\n\n"); int curJew = 1; for (int sox = 0; sox < sockets.length(); sox++) { D2BaseItem* soxBase = data->getBaseByCode(sockets[sox]); if (!soxBase) { String tname(sockets[sox]); if (s_isdigit(tname[tname.length() - 1])) { tname.resize(tname.length() - 1); soxBase = data->getBaseByCode(tname); } } if (!soxBase) socketItems.push(NULL); else { D2Item* sock = new D2Item; sock->socketParent = this; sock->image = sockets[sox]; sock->base = soxBase; if (soxBase->type->isType("jewl") && curJew < jewDesc.length()) sock->description = jewDesc[curJew++]; else { sock->title = soxBase->name; sock->description = soxBase->gemDesc; } sock->header = String::format("%s (Socketed)", header); sock->parse(data); socketItems.push(sock); } } } D2StatData* statData = data->getStatData(); for (int i = 0; i < lines.length(); i++) statData->parse(stats, lines[i]); statText = statData->process(this); }
void GamesXmlParser::getGaussianCenters(vector<xmlNodePtr>& bPtrList) { //if(bPtrList.size() != aPtrList.size()) gBound.push_back(0); int offset=0; double zeta,c; SizeOfBasisSet=0; for(int i=0; i<bPtrList.size(); i++) { string p; int ng_tot=0,ng; xmlNodePtr cur=bPtrList[i]->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "PSHELL") { ng_tot++; xmlNodePtr cur1=cur->children; int gshellType=1; while(cur1!= NULL) { string tname((const char*)cur1->name); if(tname == "PTYPE") { putContent(p,cur1); if(p == "S") { gshellType=1; SizeOfBasisSet+=1; } else if(p == "P") { gshellType=3; SizeOfBasisSet+=3; } else if(p == "D") { gshellType=4; SizeOfBasisSet+=5; } gShell.push_back(gshellType); } else if(tname == "PNGAUSS") { putContent(ng,cur1); gNumber.push_back(ng); // ng_tot+=ng; } else if(tname == "PGAUSSIAN") { xmlNodePtr cur2=cur1->children; while(cur2 != NULL) { string cname2((const char*)cur2->name); if(cname2 == "PZETA") { putContent(zeta,cur2); gExp.push_back(zeta); } else if(cname2 == "PCONE") { putContent(c,cur2); gC0.push_back(c); } cur2=cur2->next; } cout << "zeta,c " << zeta << " " << c << endl; } cur1=cur1->next; } } cur=cur->next; } offset+=ng_tot; gBound.push_back(offset); } cout << "Bound of gauassians " << endl; std::copy(gBound.begin(), gBound.end(),ostream_iterator<int>(cout, " ")); cout << endl; cout << "Number of shell type " << endl; std::copy(gShell.begin(), gShell.end(),ostream_iterator<int>(cout, " ")); cout << endl; cout << "Number of gaussians per shell " << endl; std::copy(gNumber.begin(), gNumber.end(),ostream_iterator<int>(cout, " ")); cout << endl; gC1.resize(gC0.size(),0.0); }
Pname name.normalize(Pbase b, Pblock bl, bit cast) /* if (bl) : a function definition (check that it really is a type if (cast) : no name string for each name on the name list invert the declarator list(s) and attatch basetype watch out for class object initializers convert struct s { int a; } a; into struct s { int a; }; struct s a; */ { Pname n; Pname nn; TOK stc = b->b_sto; bit tpdf = b->b_typedef; bit inli = b->b_inline; bit virt = b->b_virtual; Pfct f; Pname nx; if (b == 0) error('i',"%d->N.normalize(0)",this); if (this == 0) error('i',"0->N.normalize(%k)",base); if (inli && stc==EXTERN) { error("both extern and inline"); inli = 0; } //fprintf(stderr,"name.norm(%d %s) tp (%d %d)\n",this,string,tp,tp->base); if (stc==FRIEND && tp==0) { /* friend x; must be handled during syntax analysis to cope with class x { friend y; y* p; }; "y" is not local to "x": class x { friend y; ... }; y* p; is legal */ if (b->base) error(0,"T specified for friend"); if (n_list) { error("L of friends"); n_list = 0; } Pname nx = tname(CLASS); modified_tn = modified_tn->l; /* global */ n_sto = FRIEND; tp = nx->tp; return this; } if (tp && n_oper==TNAME && tp->base==FCT) { /* HORRIBLE FUDGE: fix the bad grammar */ Pfct f = (Pfct)tp; Pfct f2 = (Pfct)f->returns; if (f2 && f2->base==FCT) { Pexpr e = f2->argtype; //error('d',"%s: mis-analyzedP toF",string); if (e->base == ELIST) { // get the real name, fix its type if (e->e2 || e->e1->base!=DEREF) goto zse1; Pname rn = (Pname)e->e1->e1; if (rn->base!=NAME) goto zse1; f->returns = new ptr(PTR,0); b = new basetype(TYPE,ktbl->look(string,0)); n_oper = 0; string = rn->string; base = NAME; //error('d',"realN %n b==%t",rn,b); } } } zse1: if (cast) string = ""; b = b->check(this); switch (b->base) { // separate class definitions // from object and function type declarations case COBJ: nn = b->b_name; //fprintf(stderr,"COBJ (%d %s) -> (%d %d body=%d)\n",nn,nn->string,nn->tp,nn->tp->base,Pclass(nn->tp)->c_body); if (Pclass(nn->tp)->c_body==2) { /* first occurrence */ if (tp && tp->base==FCT) { error('s',&this->where,"%k%n defined as returnT for%n (did you forget a ';' after '}' ?)",Pclass(nn->tp)->csu,nn,this); nn = this; break; } nn->n_list = this; Pclass(nn->tp)->c_body = 1; /* other occurences */ } else nn = this; break; case EOBJ: nn = b->b_name; if (Penum(nn->tp)->e_body==2) { if (tp && tp->base==FCT) { error('s',"enum%n defined as returnT for%n (did you forget a ';'?)",nn,this); nn = this; break; } nn->n_list = this; Penum(nn->tp)->e_body = 1; } else nn = this; break; default: nn = this; } for (n=this; n; n=nx) { Ptype t = n->tp; nx = n->n_list; n->n_sto = stc; /* if (t && n_oper==TNAME && t->base==FCT) { // HORRIBLE FUDGE: fix the bad grammar Pfct f = (Pfct)t; Pfct f2 = (Pfct)f->returns; if (f2 && f2->base==FCT) { Pexpr e = f2->argtype; if (e->base == ELIST) { // get the real name, fix its type if (e->e2 || e->e1->base!=DEREF) goto zse; Pname rn = (Pname)e->e1->e1; if (rn->base!=NAME) goto zse; f->returns = new ptr(PTR,0); b = new basetype(TYPE,ktbl->look(n->string,0)); n->n_oper = 0; n->string = rn->string; n->base = NAME; } } } zse: */ if (n->base == TNAME) error('i',"redefinition ofTN%n",n); if (t == 0) { if (bl == 0) n->tp = t = b; else { error("body of nonF%n",n); t = new fct(defa_type,0,0); } } switch (t->base) { case PTR: case RPTR: n->tp = Pptr(t)->normalize(b); break; case VEC: n->tp = Pvec(t)->normalize(b); break; case FCT: n->tp = Pfct(t)->normalize(b); break; case FIELD: if (n->string == 0) n->string = make_name('F'); n->tp = t; Pbase tb = b; flatten: //error('d',"flatten %d %d %d",tb->base,b->b_unsigned,b->b_const); switch (tb->base) { case TYPE: /* chase typedefs */ tb = (Pbase)tb->b_name->tp; goto flatten; case INT: Pbase(t)->b_fieldtype = (b->b_unsigned) ? uint_type : int_type; goto iii; case CHAR: Pbase(t)->b_fieldtype = (b->b_unsigned) ? uchar_type : char_type; goto iii; case SHORT: Pbase(t)->b_fieldtype = (b->b_unsigned) ? ushort_type : short_type; goto iii; iii: Pbase(t)->b_unsigned = b->b_unsigned; Pbase(t)->b_const = b->b_const; break; default: error("non-int field"); n->tp = defa_type; } break; } f = (Pfct) n->tp; if (f->base != FCT) { if (bl) { error("body for nonF%n",n); n->tp = f = new fct(defa_type,0,0); continue; } if (inli) error("inline nonF%n",n); if (virt) error("virtual nonF%n",n); if (tpdf) { if (n->n_initializer) { error("Ir for typedefN%n",n); n->n_initializer = 0; } n->tdef(); } continue; } f->f_inline = inli; f->f_virtual = virt; if (tpdf) { if (f->body = bl) error("typedef%n { ... }",n); n->tdef(); continue; } if (f->body = bl) continue; /* Check function declarations. Look for class object instansiations The real ambiguity: ; class x fo(); is interpreted as an extern function declaration NOT a class object with an empty initializer */ { Pname cn = f->returns->is_cl_obj(); bit clob = (cn || cl_obj_vec); //error('d',"%n: fr%t cn%n",n,f->returns,cn); if (f->argtype) { /* check argument/initializer list */ Pname nn; for (nn=f->argtype; nn; nn=nn->n_list) { if (nn->base != NAME) { if (!clob) { error("ATX for%n",n); goto zzz; } goto is_obj; } /* if (nn->string) { error("AN%n inD of%n",nn,n); nn->string = 0; } */ if (nn->tp) goto ok; } if (!clob) { error("FALX"); goto zzz; } is_obj: //fprintf(stderr,"is_obj: %d %s tp = %d %d\n",this,string,f->returns,f->returns->base); fflush(stderr); /* it was an initializer: expand to constructor */ n->tp = f->returns; if (f->argtype->base != ELIST) f->argtype = (Pname)new expr(ELIST,(Pexpr)f->argtype,0); n->n_initializer = new texpr(VALUE,cn->tp,(Pexpr)f->argtype); goto ok; zzz: if (f->argtype) { DEL(f->argtype); f->argtype = 0; f->nargs = 0; f->nargs_known = !fct_void; } } else { /* T a(); => function declaration */ /* if (clob) { DEL(n->tp); n->tp = f->returns; } */ } ok: ; } } return nn; }
item *game::inv_map_for_liquid(const item &liquid, const std::string title) { std::vector <item> &here = m.i_at(g->u.posx, g->u.posy); typedef std::vector< std::list<item> > pseudo_inventory; pseudo_inventory grounditems; indexed_invslice grounditems_slice; std::vector<item *> ground_containers; LIQUID_FILL_ERROR error; std::set<std::string> dups; for( auto item_iter = here.begin(); item_iter != here.end(); ++item_iter ) { if( item_iter->get_remaining_capacity_for_liquid(liquid, error) > 0 ) { if( dups.count( item_iter->tname()) == 0 ) { grounditems.push_back( std::list<item>(1, *item_iter) ); if( grounditems.size() <= 10 ) { grounditems.back().front().invlet = '0' + grounditems.size() - 1; } else { grounditems.back().front().invlet = ' '; } dups.insert( item_iter->tname() ); ground_containers.push_back( &*item_iter ); } } } for (size_t a = 0; a < grounditems.size(); a++) { // avoid INT_MIN, as it can be confused with "no item at all" grounditems_slice.push_back(indexed_invslice::value_type(&grounditems[a], INT_MIN + a + 1)); } static const item_category category_on_ground( "GROUND:", _("GROUND:"), -1000 ); u.inv.restack(&u); u.inv.sort(); const indexed_invslice stacks = u.inv.slice_filter_by_capacity_for_liquid(liquid); inventory_selector inv_s(false, true, title); inv_s.make_item_list(grounditems_slice, &category_on_ground); inv_s.make_item_list(stacks); inv_s.prepare_paging(); inventory_selector::drop_map prev_droppings; while (true) { inv_s.display(); const std::string action = inv_s.ctxt.handle_input(); const long ch = inv_s.ctxt.get_raw_input().get_first_input(); const int item_pos = g->u.invlet_to_position(static_cast<char>(ch)); if (item_pos != INT_MIN) { inv_s.set_to_drop(item_pos, 0); return inv_s.first_item; } else if (ch >= '0' && ch <= '9' && (size_t)(ch - '0') < grounditems_slice.size()) { const int ip = ch - '0'; return ground_containers[ip]; } else if (inv_s.handle_movement(action)) { // continue with comparison below } else if (action == "QUIT") { return NULL; } else if (action == "RIGHT" || action == "CONFIRM") { inv_s.set_selected_to_drop(0); for( size_t i = 0; i < grounditems_slice.size(); i++) { if( &grounditems_slice[i].first->front() == inv_s.first_item ) { return ground_containers[i]; } } return inv_s.first_item; } } }
std::string TypedValue::pretty() const { char buf[20]; sprintf(buf, "0x%lx", long(m_data.num)); return Trace::prettyNode(tname(m_type).c_str(), std::string(buf)); }
/* * Get a file data block, perhaps allocating it on demand * if mkit. The file must be r/wlocked and melted if mkit. * * Adds disk refs for dir entries copied during melts and * considers that /archive is always melted. * * Read-ahead is not considered here. The file only records * the last accessed block number, to help the caller do RA. * */ static Memblk* dfblk(Memblk *f, ulong bno, int mkit) { ulong prev, nblks; int i, idx, nindir, type, isdir, chg; Memblk *b, *pb; daddrt *addrp; if(mkit) ismelted(f); isdir = (f->d.mode&DMDIR); if(bno != f->mf->lastbno){ f->mf->sequential = (!mkit && bno == f->mf->lastbno + 1); f->mf->lastbno = bno; } /* * bno: block # relative to the the block we are looking at. * prev: # of blocks before the current one. */ prev = 0; chg = 0; /* * Direct block? */ if(bno < nelem(f->d.dptr)){ if(mkit) b = getmelted(isdir, DBdata, &f->d.dptr[bno], &chg); else b = dbget(DBdata, f->d.dptr[bno]); if(chg) changed(f); return b; } bno -= nelem(f->d.dptr); prev += nelem(f->d.dptr); /* * Indirect block * nblks: # of data blocks addressed by the block we look at. */ nblks = Dptrperblk; for(i = 0; i < nelem(f->d.iptr); i++){ if(bno < nblks) break; bno -= nblks; prev += nblks; nblks *= Dptrperblk; } if(i == nelem(f->d.iptr)) error("offset exceeds file capacity"); ainc(&fs->nindirs[i]); type = DBptr0+i; dFprint("dfblk: indirect %s nblks %uld (ppb %ud) bno %uld\n", tname(type), nblks, Dptrperblk, bno); addrp = &f->d.iptr[i]; if(mkit) b = getmelted(isdir, type, addrp, &chg); else b = dbget(type, *addrp); if(chg) changed(f); pb = b; if(catcherror()){ mbput(pb); error(nil); } /* at the loop header: * pb: parent of b * b: DBptr block we are looking at. * addrp: ptr to b within fb. * nblks: # of data blocks addressed by b */ for(nindir = i+1; nindir >= 0; nindir--){ chg = 0; dFprint("indir %s d%#ullx nblks %uld ptrperblk %d bno %uld\n\n", tname(DBdata+nindir), *addrp, nblks, Dptrperblk, bno); idx = 0; if(nindir > 0){ nblks /= Dptrperblk; idx = bno/nblks; } if(*addrp == 0 && !mkit){ /* hole */ fprint(2, "HOLE\n"); b = nil; }else{ assert(type >= DBdata); if(mkit) b = getmelted(isdir, type, addrp, &chg); else b = dbget(type, *addrp); if(chg) changed(pb); addrp = &b->d.ptr[idx]; } mbput(pb); pb = b; USED(&b); /* force to memory in case of error */ USED(&pb); /* force to memory in case of error */ bno -= idx * nblks; prev += idx * nblks; type--; } noerror(); return b; }