/* 添加常量到符号表中 */ Symbol AddConstant (Type ty, union value val) { unsigned h = (unsigned)val.i[0] & SYM_HASH_MASK; Symbol p; /* 去掉修饰符 */ ty = Unqual (ty); if (IsIntegType (ty)) { ty = T (INT); } else if (IsPtrType (ty)) { ty = T (POINTER); } else if (LONGDOUBLE == ty->categ) { ty = T (DOUBLE); } /* 如果已经添加直接返回 */ for (p = Constants.buckets[h]; p; p = p->link) { if (p->ty == ty && p->val.i[0] == val.i[0] && p->val.i[1] == val.i[1]) return p; } /* 将常量添加到符号表中 */ CALLOC (p); p->kind = SK_Constant; switch (ty->categ) { case INT: p->name = FormatName ("%d", val.i[0]); break; case POINTER: p->name = (val.i[0] ? FormatName ("0x%x", val.i[0]) : "0"); break; case FLOAT: /* %g可以省略浮点多余的0 */ p->name = FormatName ("%g", val.f); break; case DOUBLE: p->name = FormatName ("%g", val.d); break; default: assert (0); } p->ty = ty; p->sclass = TK_STATIC; p->val = val; p->link = Constants.buckets[h]; Constants.buckets[h] = p; if (FLOAT == ty->categ || DOUBLE == ty->categ) { *FloatTail = p; FloatTail = &p->next; } return p; }
bool CChat::CreateChannel(LPCTSTR pszName, LPCTSTR pszPassword, CChatMember *pMember) { ADDTOCALLSTACK("CChat::CreateChannel"); if ( pMember ) { CClient *pClient = pMember->GetClient(); if ( pClient && !pClient->IsPriv(PRIV_GM) && !(g_Cfg.m_iChatFlags & CHATF_CHANNELCREATION) ) { CGString sName; FormatName(sName, NULL, true); pMember->SendChatMsg(CHATMSG_PlayerMessage, sName, " Channel creation is disabled."); return false; } } if ( !IsValidName(pszName, false) ) { if ( pMember ) pMember->SendChatMsg(CHATMSG_InvalidConferenceName); return false; } else if ( FindChannel(pszName) ) { if ( pMember ) pMember->SendChatMsg(CHATMSG_DuplicatedConferenceName); return false; } CChatChannel *pChannel = new CChatChannel(pszName, pszPassword, !pMember); m_Channels.InsertTail(pChannel); BroadcastAddChannel(pChannel); if ( pMember && (g_Cfg.m_iChatFlags & CHATF_CHANNELMODERATION) ) pChannel->SetModerator(pMember->GetChatName()); return true; }
/* 给基本块创建名字 */ Symbol CreateLabel (void) { Symbol p; CALLOC (p); p->kind = SK_Label; p->name = FormatName ("BB%d", LabelNum++); return p; }
NameType::NameType(const char *rhs) { const char *ptr = rhs; for (unsigned int j = 0; j < NameSize_-1; j++) { c_array_[j] = *ptr; if (*ptr=='\0') break; ++ptr; } FormatName(); }
void DefineFloatConstant(Symbol p) { int align = p->ty->align; p->aname = FormatName(".flt%d", FloatNum++); Align(p); Print("%s:\t", p->aname); DefineValue(p->ty, p->val); }
std::string UPKReader::FormatNames(bool verbose) { std::ostringstream ss; ss << "NameTable:" << std::endl; for (unsigned i = 0; i < NameTable.size(); ++i) { ss << FormatName(i, verbose); } return ss.str(); }
NameType::NameType(std::string const& str) { unsigned int ns1 = NameSize_ - 1; unsigned int strend = (unsigned int)str.size(); if (strend > ns1) strend = ns1; for (unsigned int j = 0; j < strend; j++) c_array_[j] = str[j]; c_array_[strend] = '\0'; FormatName(); }
static char* GetAccessName(Symbol p) { if (p->aname != NULL) return p->aname; switch (p->kind) { case SK_Constant: p->aname = FormatName("$%s", p->name); break; case SK_String: case SK_Label: p->aname = FormatName(".%s", p->name); break; case SK_Variable: case SK_Temp: if (p->level == 0) { p->aname = p->name; } else if (p->sclass == TK_STATIC) { p->aname = FormatName("%s.%d", p->name, TempNum++); } else { p->aname = FormatName("%d(%%ebp)", AsVar(p)->offset); } break; case SK_Function: p->aname = p->name; break; case SK_Offset: { Symbol base = p->link; int n = AsVar(p)->offset; if (base->level == 0 || base->sclass == TK_STATIC) { p->aname = FormatName("%s%s%d", GetAccessName(base), n >= 0 ? "+" : "", n); } else { n += AsVar(base)->offset; p->aname = FormatName("%d(%%ebp)", n); } } break; default: assert(0); } return p->aname; }
// This is used if we don't have any other activity to get network status from void ImapActivityFactory::BuildConnect(ActivityBuilder& ab, const MojObject& accountId, MojUInt64 uniqueId) { MojString name; MojErr err = name.format("%s - %lld", CONNECT_NAME, uniqueId); ErrorToException(err); ab.SetName( FormatName(name.data(), accountId) ); ab.SetDescription("Activity for connecting to server"); ab.SetExplicit(false); ab.SetPersist(false); ab.SetForeground(true); ab.SetRequiresInternet(false); }
void CChat::JoinChannel(LPCTSTR pszName, LPCTSTR pszPassword, CChatMember *pMember) { ADDTOCALLSTACK("CChat::JoinChannel"); ASSERT(pMember); CClient *pMemberClient = pMember->GetClient(); ASSERT(pMemberClient); CChatChannel *pNewChannel = FindChannel(pszName); if ( !pNewChannel ) { pMemberClient->addChatSystemMessage(CHATMSG_NoConference, pszName); return; } pszName = pNewChannel->m_sName; // fix case-sensitive mismatch CChatChannel *pCurrentChannel = pMember->GetChannel(); if ( pCurrentChannel && (pCurrentChannel == pNewChannel) ) { pMember->SendChatMsg(CHATMSG_AlreadyInConference, pszName); return; } else if ( !pNewChannel->m_sPassword.IsEmpty() && (!pszPassword || (strcmp(static_cast<LPCTSTR>(pNewChannel->m_sPassword), pszPassword) != 0)) ) { if ( pMemberClient->m_UseNewChatSystem ) { CGString sName; FormatName(sName, NULL, true); pMember->SendChatMsg(CHATMSG_PlayerMessage, sName, " Your client version can't join channels with password."); } else pMemberClient->addChatSystemMessage(CHATMSG_IncorrectPassword); return; } /*else if ( pNewChannel->m_Members.GetCount() >= UCHAR_MAX ) { pMemberClient->addChatSystemMessage(CHATMSG_ConferenceIsFull, pszName); return; }*/ // Leave current channel if ( pCurrentChannel ) pCurrentChannel->RemoveMember(pMember); // Join the new channel pNewChannel->AddMember(pMember); pNewChannel->SendMember(pMember); // send this member to all others clients pMemberClient->addChatSystemMessage(CHATCMD_JoinedChannel, pszName); if ( !pMemberClient->m_UseNewChatSystem ) pNewChannel->FillMembersList(pMember); // fill the members list on this client }
void CChat::Broadcast(CChatMember *pFrom, LPCTSTR pszText, CLanguageID lang, bool bOverride) { ADDTOCALLSTACK("CChat::Broadcast"); CGString sName; FormatName(sName, pFrom, bOverride); ClientIterator it; for ( CClient *pClient = it.next(); pClient != NULL; pClient = it.next() ) { if ( !pClient->m_bChatActive ) continue; if ( bOverride || pClient->m_bReceiving ) pClient->SendChatMsg(CHATMSG_PlayerMessage, sName, pszText, lang); } }
/* 创建函数内部的临时变量 */ Symbol CreateTemp (Type ty) { VariableSymbol p; CALLOC (p); p->kind = SK_Temp; p->name = FormatName ("t%d", TempNum++); p->ty = ty; p->level = 1; /* 添加到函数符号表中 */ *FSYM->lastv = (Symbol)p; FSYM->lastv = &p->next; return (Symbol)p; }
/* 添加字符串到字符串符号表中 */ Symbol AddString (Type ty, String str) { Symbol p; CALLOC (p); /* 设置p的属性 */ p->kind = SK_String; p->name = FormatName ("str%d", StringNum++); p->ty = ty; p->sclass = TK_STATIC; p->val.p = str; /* 添加到字符串符号表中 */ *StringTail = p; StringTail = &p->next; return p; }
/* 创建偏移符号 */ Symbol CreateOffset (Type ty, Symbol base, int coff) { VariableSymbol p; if (0 == coff) return base; CALLOC (p); if (SK_Offset == base->kind) { coff += AsVar(base)->offset; base = base->link; } p->addressed = 1; p->kind = SK_Offset; p->ty = ty; p->link = base; p->offset = coff; p->name = FormatName ("%s[%d]", base->name, coff); base->ref++; return (Symbol)p; }
wxString PHPSetterGetterEntry::GetSetter(eSettersGettersFlags flags) const { wxString nameNoDollar = m_entry->Cast<PHPEntityVariable>()->GetNameNoDollar(); wxString nameWithDollar = m_entry->GetShortName(); // Remove user prefixes wxString functionName = nameNoDollar; FormatName(functionName); wxString prefix = (flags & kSG_StartWithUpperCase) ? "Set" : "set"; functionName.Prepend(prefix); if(flags & kSG_NameOnly) { return functionName; } wxString body; body << "/**\n" << " * @param " << m_entry->Cast<PHPEntityVariable>()->GetTypeHint() << " " << m_entry->GetShortName() << "\n" << " */\n" << "public function " << functionName << "(" << nameWithDollar << ") {\n" << " $this->" << nameNoDollar << " = " << nameWithDollar << ";\n" << "}"; return body; }
SkPDFName::SkPDFName(const SkString& name) : fValue(FormatName(name)) {}
MojString ImapActivityFactory::GetPreferencesWatchName(const MojObject& accountId) { return FormatName(PREFS_WATCH_NAME, accountId); }
MojString ImapActivityFactory::GetOutboxWatchName(const MojObject& accountId, const MojObject& folderId) { return FormatName(OUTBOX_WATCH_NAME, accountId, folderId); }
SkPDFName::SkPDFName(const char name[]) : fValue(FormatName(SkString(name))) {}
MojString ImapActivityFactory::GetStartIdleName(const MojObject& accountId, const MojObject& folderId) { return FormatName(MAINTAIN_IDLE_NAME, accountId, folderId); }
MojString ImapActivityFactory::GetDraftsWatchName(const MojObject& accountId, const MojObject& folderId) { return FormatName(DRAFTS_WATCH_NAME, accountId, folderId); }
MojString ImapActivityFactory::GetScheduledSyncName(const MojObject& accountId, const MojObject& folderId) { return FormatName(SCHEDULED_SYNC_NAME, accountId, folderId); }
MojString ImapActivityFactory::GetIdleWakeupName(const MojObject& accountId, const MojObject& folderId) { return FormatName(IDLE_WAKEUP_NAME, accountId, folderId); }
MojString ImapActivityFactory::GetSyncRetryName(const MojObject& accountId, const MojObject& folderId) { return FormatName(SYNC_RETRY_NAME, accountId, folderId); }
/** * Get a symbol's name in assembly */ static char* GetAccessName(Symbol p) { if (p->aname != NULL) return p->aname; switch (p->kind) { case SK_Constant: if (p->name[0] == '0' && p->name[1] == 'x') p->aname = FormatName("0%sH", &p->name[2]); else p->aname = p->name; break; case SK_String: case SK_IRegister: case SK_Label: p->aname = p->name; break; case SK_Variable: case SK_Temp: if (p->level == 0) { p->aname = FormatName("_%s", p->name); } else if (p->sclass == TK_STATIC) { p->aname = FormatName("%s%d", p->name, TempNum++); } else { p->aname = FormatName("(%d)[ebp]", AsVar(p)->offset); } break; case SK_Function: p->aname = FormatName("_%s", p->name); break; case SK_Offset: { Symbol base = p->link; int n = AsVar(p)->offset; if (base->level == 0 || base->sclass == TK_STATIC) { p->aname = FormatName("%s%s%d", GetAccessName(base), n >= 0 ? "+" : "", n); } else { n += AsVar(base)->offset; p->aname = FormatName("(%d)[ebp]", n); } } break; default: assert(0); } return p->aname; }
SYMBOL FormatMsg( VBUF *pbuf, char *fmt, va_list arg ) /****************************************************/ // this function assumes that pbuf is initialized // all information is concatenated to the end of pbuf { VBUF prefix, suffix; char cfmt; char local_buf[ 1 + sizeof( int ) * 2 + 1 ]; unsigned len; SYMBOL retn_symbol; retn_symbol = NULL; cfmt = *fmt; while( cfmt ) { if( cfmt == '%' ) { fmt++; cfmt = *fmt; switch( cfmt ) { case '1': /* %01d */ case '2': /* %02d */ case '3': /* %03d */ case '4': /* %04d */ case '5': /* %05d */ case '6': /* %06d */ case '7': /* %07d */ case '8': /* %08d */ case '9': /* %09d */ len = sticpy( local_buf, va_arg( arg, int ) ) - local_buf; leading( pbuf, '0', ( cfmt - '0' ) - len ); VbufConcStr( pbuf, local_buf ); break; case 'c': /* %c */ VbufConcChr( pbuf, va_arg( arg, int ) ); break; case 's': /* %s */ VbufConcStr( pbuf, va_arg( arg, char * ) ); break; case 'u': /* %u */ VbufConcDecimal( pbuf, va_arg( arg, unsigned int ) ); break; case 'd': /* %d */ VbufConcInteger( pbuf, va_arg( arg, int ) ); break; case 'L': /* token location */ { TOKEN_LOCN *locn; locn = va_arg( arg, TOKEN_LOCN * ); if( locn == NULL ) { VbufConcStr( pbuf, "by compiler" ); } else { char *src_file = SrcFileName( locn->src_file ); if( src_file == NULL ) { VbufConcStr( pbuf, "on the command line" ); } else { if( ( CompFlags.ew_switch_used ) &&( locn->src_file == SrcFileTraceBackFile() ) ) { VbufConcStr( pbuf, "at: " ); } else { VbufConcStr( pbuf, "in: " ); VbufConcStr( pbuf, SrcFileName( locn->src_file ) ); } VbufConcChr( pbuf, '(' ); VbufConcInteger( pbuf, locn->line ); if( locn->column ) { if( CompFlags.ew_switch_used ) { VbufConcChr( pbuf, ',' ); VbufConcInteger( pbuf, locn->column ); } else { VbufConcStr( pbuf, ") (col " ); VbufConcInteger( pbuf, locn->column ); } } VbufConcChr( pbuf, ')' ); } } } break; case 'N': /* name */ FormatName( va_arg( arg, NAME ), &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); break; case 'F': /* symbol name (decorated) */ { SYMBOL sym; sym = va_arg( arg, SYMBOL ); FormatSym( sym, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; case 'S': /* symbol name (abbreviated) */ { SYMBOL sym; SYMBOL_NAME sn; NAME name; sym = va_arg( arg, SYMBOL ); if( sym == NULL ) { VbufConcStr( pbuf, "module data" ); } else { if( formatClassForSym( sym, pbuf ) ) { VbufConcStr( pbuf, "::" ); } if( SymIsCtor( sym ) ) { formatClassForSym( sym, pbuf ); } else if( SymIsDtor( sym ) ) { VbufConcChr( pbuf, '~' ); formatClassForSym( sym, pbuf ); } else { sn = sym->name; #ifndef NDEBUG if( sn == NULL ) { CFatal( "FormatMsg -- %S symbol has NULL SYMBOL_NAME" ); } #endif name = sn->name; #ifndef NDEBUG if( name == NULL ) { CFatal( "FormatMsg -- %S SYMBOL_NAME has NULL name" ); } #endif if( name == CppConversionName() ) { VbufConcStr( pbuf, "operator " ); FormatType( SymFuncReturnType( sym ) , &prefix , &suffix ); VbufFree( &suffix ); } else { FormatName( name, &prefix ); } VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } if( sym->flag2 & SF2_TOKEN_LOCN ) { DbgVerify( retn_symbol == NULL, "too many symbols" ); retn_symbol = sym; } } } break; case 'T': /* type name */ { TYPE type = va_arg( arg, TYPE ); TYPE refed = TypeReference( type ); if( NULL != refed ) { type = refed; } FormatType( type, &prefix, &suffix ); VbufConcVbuf( pbuf, &prefix ); VbufConcVbuf( pbuf, &suffix ); VbufFree( &prefix ); VbufFree( &suffix ); VbufTruncWhite( pbuf ); if( NULL != refed ) { VbufConcStr( pbuf, " (lvalue)" ); } } break; case 'P': /* PTREE list */ { const PTREE p = va_arg( arg, PTREE ); FormatPTreeList( p, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; case 'I': /* PTREE id */ { const PTREE p = va_arg( arg, PTREE ); FormatPTreeId( p, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; case 'M': /* template info */ { TEMPLATE_INFO * const tinfo = va_arg( arg, TEMPLATE_INFO * ); const SYMBOL sym = tinfo->sym; FormatTemplateInfo( tinfo, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); if( sym->flag2 & SF2_TOKEN_LOCN ) { DbgVerify( retn_symbol == NULL, "too many symbols" ); retn_symbol = sym; } } break; case 'C': /* template specialisation */ { TEMPLATE_SPECIALIZATION * const tspec = va_arg( arg, TEMPLATE_SPECIALIZATION * ); FormatTemplateSpecialization( tspec, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; default: VbufConcChr( pbuf, cfmt ); } } else {
/* * Translate symbol table data particularly for sorting. * Input is the symbol table data structure, number of symbols, * opened ELF file, and the string table link offset. */ static SYM * readsyms(Elf_Data * data, GElf_Sxword num, Elf *elf, unsigned int link, unsigned int symscnndx) { SYM *s, *buf; GElf_Sym sym; Elf32_Word *symshndx = 0; unsigned int nosymshndx = 0; int i; if ((buf = calloc(num, sizeof (SYM))) == NULL) { (void) fprintf(stderr, gettext("%s: cannot allocate memory\n"), prog_name); return (NULL); } s = buf; /* save pointer to head of array */ for (i = 1; i < num; i++, buf++) { (void) gelf_getsym(data, i, &sym); buf->indx = i; /* allow to work on machines where NULL-derefs dump core */ if (sym.st_name == 0) buf->name = ""; else if (C_flag) { const char *dn; char *name = (char *)elf_strptr(elf, link, sym.st_name); dn = conv_demangle_name(name); if (strcmp(dn, name) == 0) { /* Not demangled */ if (exotic(name)) { name = FormatName(name, d_buf); } } else { /* name demangled */ name = FormatName(name, dn); } buf->name = name; } else buf->name = (char *)elf_strptr(elf, link, sym.st_name); buf->value = sym.st_value; buf->size = sym.st_size; buf->type = GELF_ST_TYPE(sym.st_info); buf->bind = GELF_ST_BIND(sym.st_info); buf->other = sym.st_other; if ((sym.st_shndx == SHN_XINDEX) && (symshndx == 0) && (nosymshndx == 0)) { Elf_Scn *_scn; GElf_Shdr _shdr; _scn = 0; while ((_scn = elf_nextscn(elf, _scn)) != 0) { if (gelf_getshdr(_scn, &_shdr) == 0) break; if ((_shdr.sh_type == SHT_SYMTAB_SHNDX) && (_shdr.sh_link == symscnndx)) { Elf_Data *_data; if ((_data = elf_getdata(_scn, 0)) != 0) { symshndx = (Elf32_Word *)_data->d_buf; break; } } } nosymshndx = 1; } if ((symshndx) && (sym.st_shndx == SHN_XINDEX)) { buf->shndx = symshndx[i]; } else { buf->shndx = sym.st_shndx; if (sym.st_shndx >= SHN_LORESERVE) buf->flags |= FLG_SYM_SPECSEC; } } /* end for loop */ return (s); }
MojString ImapActivityFactory::GetFolderWatchName(const MojObject& accountId, const MojObject& folderId) { return FormatName(FOLDER_WATCH_NAME, accountId, folderId); }