/// <summary>Read the full method from the supplied buffer.</summary> void Method::ReadMethod(IMAGE_COR_ILMETHOD* pMethod) { BYTE* pCode; auto fatImage = static_cast<COR_ILMETHOD_FAT*>(&pMethod->Fat); if (!fatImage->IsFat()) { #ifdef TRACE_ENABLED ATLTRACE(_T("TINY")); #endif auto tinyImage = static_cast<COR_ILMETHOD_TINY*>(&pMethod->Tiny); m_header.CodeSize = tinyImage->GetCodeSize(); pCode = tinyImage->GetCode(); #ifdef TRACE_ENABLED ATLTRACE(_T("TINY(%X) => (%d + 1) : %d"), m_header.CodeSize, m_header.CodeSize, m_header.MaxStack); #endif } else { memcpy(&m_header, pMethod, fatImage->Size * sizeof(DWORD)); pCode = fatImage->GetCode(); #ifdef TRACE_ENABLED ATLTRACE(_T("FAT(%X) => (%d + 12) : %d"), m_header.CodeSize, m_header.CodeSize, m_header.MaxStack); #endif } SetBuffer(pCode); ReadBody(); }
int FtpClient::Login() { try { char buffer[2048]; int code; strcpy ( buffer, "USER " ); strcat ( buffer, this->userName ); if(!SendMessage ( buffer )) { perror("Can't send message\n"); return 1; } strcpy ( buffer, ReceiveMessage() ); //receiving confirmation code = GetCode ( buffer ); if ( code != 331 ) //if the FTP server sent a code that it's not 331, than we've got problems return code; strcpy ( buffer, "PASS " ); strcat ( buffer, password ); SendMessage ( buffer ); //now we have to send the password strcpy ( buffer, ReceiveMessage() ); code = GetCode ( buffer ); Sock = _Socket; if ( code != 230 ) //if something went wrong, then we send the code back to the calling function return code; } catch ( Exception ex ) { cout << ex.Message; } return 0; //this means that we are logged in }
void CppCodeGenerator::GenClassDeclaration(shared_ptr<ObjectBase> class_obj, bool use_enum) { shared_ptr<Property> propName = class_obj->GetProperty( wxT("name") ); if ( !propName ) { wxLogError(wxT("Missing \"name\" property on \"%s\" class. Review your XML object description"), class_obj->GetClassName().c_str()); return; } wxString class_name = propName->GetValue(); if ( class_name.empty() ) { wxLogError( wxT("Object name can not be null") ); return; } m_header->WriteLn( wxT("/**") ); m_header->WriteLn( wxT(" * Class ") + class_name); m_header->WriteLn( wxT(" */") ); m_header->WriteLn( wxT("class ") + class_name + wxT(" : ") + GetCode( class_obj, wxT("base") ) ); m_header->WriteLn( wxT("{") ); m_header->Indent(); // private m_header->WriteLn( wxT("private:") ); m_header->Indent(); GenAttributeDeclaration(class_obj,P_PRIVATE); m_header->Unindent(); m_header->WriteLn( wxT("") ); // protected m_header->WriteLn( wxT("protected:") ); m_header->Indent(); if (use_enum) GenEnumIds(class_obj); GenAttributeDeclaration(class_obj,P_PROTECTED); m_header->Unindent(); m_header->WriteLn( wxT("") ); // public m_header->WriteLn( wxT("public:") ); m_header->Indent(); GenAttributeDeclaration(class_obj,P_PUBLIC); // The constructor is also included within public m_header->WriteLn( GetCode( class_obj, wxT("cons_decl") ) ); m_header->Unindent(); m_header->WriteLn( wxT("") ); m_header->Unindent(); m_header->WriteLn( wxT("};") ); m_header->WriteLn( wxT("") ); }
void LL1Parsing::LL1() { OpenFile(); Production(); FisrtInit(); //FIRST集合初始化 //l.PrintVariFst(); GetVariFst(); //求FIRST集 //l.PrintVariFst(); GetVariFol(); //求FOLLOW集 //l.PrintVariFol(); GetProFst(); //求产生式的FIRST集合 //l.PrintProFst(); GetFAATable(); //构造预测分析表 //l.PrintFAATable(); stack<int> s; enum tokenType token; s.push(99); s.push(50); int top; token = GetNewToken(); do{ top = s.top(); if (top < t_len || top == 99){ if (top != 99 && top == GetCode(token)){ cout << "pop " << top << endl; s.pop(); token = GetNewToken(); } else { cerr << "error" << endl; } } else{ if (faaTable[top - 50][GetCode(token)].size()>0){ long long int code = faaTable[top - 50][GetCode(token)][0]; cout << top << "-->" << code << endl; s.pop(); if (code > 0){ for (size_t j = (int)((GetLength(code) + 1) / 2); j > 0; --j){ s.push(Get2Code(code, j)); } } } else { cerr << "error" << endl; } } } while (s.top() != 99 && !s.empty()); }
void PHPCodeGenerator::GenConstructor( PObjectBase class_obj, const EventVector &events ) { m_source->WriteLn(); // generate function definition m_source->WriteLn( GetCode( class_obj, wxT("cons_def") ) ); m_source->Indent(); m_source->WriteLn( GetCode( class_obj, wxT("cons_call") ) ); m_source->WriteLn(); wxString settings = GetCode( class_obj, wxT("settings") ); if ( !settings.IsEmpty() ) { m_source->WriteLn( settings ); } for ( unsigned int i = 0; i < class_obj->GetChildCount(); i++ ) { GenConstruction( class_obj->GetChild( i ), true ); } wxString afterAddChild = GetCode( class_obj, wxT("after_addchild") ); if ( !afterAddChild.IsEmpty() ) { m_source->WriteLn( afterAddChild ); } GenEvents( class_obj, events ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); m_source->WriteLn( wxT("") ); if ( class_obj->GetObjectTypeName() == wxT("wizard") && class_obj->GetChildCount() > 0 ) { m_source->WriteLn( wxT("function AddPage($page){") ); m_source->Indent(); m_source->WriteLn( wxT("if(count($this->m_pages) > 0){") ); m_source->Indent(); m_source->WriteLn( wxT("$previous_page = $this->m_pages[count($this->m_pages)-1];") ); m_source->WriteLn( wxT("$page->SetPrev($previous_page);") ); m_source->WriteLn( wxT("$previous_page->SetNext($page);") ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); m_source->WriteLn( wxT("$this->m_pages[] = $page;") ); m_source->Unindent(); m_source->WriteLn( wxT("}") ); } }
TEST_FIXTURE_END_TEST_CASES_BEGIN // Verify that the sole owner of an indirect storage will reuse the // base register for the direct register after dereferencing. TEST_F(ExpressionTree, BaseRegisterReuse) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); // Create indirect storage to reference an integer. struct Test { int m_dummy; }; Test testStruct; auto & structNode = e.Immediate(&testStruct); auto & indirectNode = e.Deref(e.FieldPointer(structNode, &Test::m_dummy)); indirectNode.IncrementParentCount(); structNode.CodeGenCache(e); indirectNode.CodeGenCache(e); auto storage = indirectNode.CodeGen(e); auto baseRegister = storage.GetBaseRegister(); ASSERT_TRUE(storage.ConvertToDirect(false).IsSameHardwareRegister(baseRegister)); }
void CParmChValueDlg::OnChangeCode() { if (!m_bInit) return; UpdateData(); m_CharStr = CSymbolDlg::CodeToChar(GetCode()); UpdateData(FALSE); }
//--------------------------------------------------------------------------- string_type Value::AsciiDump() const { stringstream_type ss; ss << g_sCmdCode[ GetCode() ]; ss << _T(" [addr=0x") << std::hex << this << std::dec; ss << _T("; pos=") << GetExprPos(); ss << _T("; type=\"") << GetType() << _T("\""); ss << _T("; val="); switch(m_cType) { case 'i': ss << (int_type)m_val.real(); break; case 'f': ss << m_val.real(); break; case 'm': ss << _T("(matrix)"); break; case 's': assert(m_psVal!=nullptr); ss << _T("\"") << m_psVal << _T("\""); break; } ss << ((IsFlagSet(IToken::flVOLATILE)) ? _T("; ") : _T("; not ")) << _T("vol"); ss << _T("]"); return ss.str(); }
TEST_F(ExpressionTree, TakeSoleOwnershipOfDirect) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); auto s = e.Direct<int>(eax); ASSERT_TRUE(s.IsSoleDataOwner()); ASSERT_EQ(s.GetStorageClass(), StorageClass::Direct); ASSERT_EQ(s.GetDirectRegister(), eax); auto s2 = s; ASSERT_FALSE(s.IsSoleDataOwner()); ASSERT_FALSE(s2.IsSoleDataOwner()); ASSERT_EQ(s2.GetStorageClass(), StorageClass::Direct); ASSERT_EQ(s2.GetDirectRegister(), eax); s.TakeSoleOwnershipOfDirect(); ASSERT_TRUE(s.IsSoleDataOwner()); ASSERT_EQ(s.GetStorageClass(), StorageClass::Direct); ASSERT_EQ(s.GetDirectRegister(), eax); ASSERT_TRUE(s2.IsSoleDataOwner()); ASSERT_EQ(s2.GetStorageClass(), StorageClass::Direct); // ASSERT_NE(s2.GetDirectRegister(), eax); Doesn't compile! ASSERT_FALSE((s2.GetDirectRegister() == eax)); }
void pgaStep::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { if (!expandedKids) { expandedKids = true; } if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("ID"), GetRecId()); properties->AppendYesNoItem(_("Enabled"), GetEnabled()); properties->AppendItem(_("Kind"), GetKind()); if (GetConnStr().IsEmpty()) properties->AppendItem(_("Database"), GetDbname()); else properties->AppendItem(_("Connection String"), GetConnStr()); properties->AppendItem(_("Code"), GetCode()); properties->AppendItem(_("On error"), GetOnError()); properties->AppendItem(_("Comment"), firstLineOnly(GetComment())); } }
TEST_F(ExpressionTree, SoleDataOwner) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); Storage<int> empty; ASSERT_TRUE(empty.IsSoleDataOwner()); auto s = e.Direct<int>(); ASSERT_TRUE(s.IsSoleDataOwner()); auto s2 = s; ASSERT_FALSE(s.IsSoleDataOwner()); ASSERT_FALSE(s2.IsSoleDataOwner()); s2.Reset(); ASSERT_TRUE(s.IsSoleDataOwner()); ASSERT_TRUE(s2.IsSoleDataOwner()); // Different indirects that refer to stack are sole owners of their storage. auto stack1 = e.Temporary<int>(); ASSERT_TRUE(stack1.IsSoleDataOwner()); auto stack2 = e.Temporary<int>(); ASSERT_TRUE(stack2.IsSoleDataOwner()); }
char *FtpClient::GetCurrentDirectory() { try { char buffer[2048]; bzero ( buffer, 2048 ); SendMessage ( "PWD" ); strcpy ( buffer, ReceiveMessage() ); int code = GetCode ( buffer ); if ( code == 257 ) { int i = 0; for ( i = 0; i < strlen ( buffer ) && buffer[i] != '\"'; i++ ); char dir[2048]; bzero ( dir, 2048 ); strcpy ( dir, buffer + ( i + 1 ) ); for ( i = 0; i < strlen ( dir ) && dir[i] != '\"'; i++ ); dir[i] = '\0'; return dir; } else return "error"; } catch ( Exception ex ) { cout << ex.Message; return ex.Message; } }
TEST_F(Conditional, If) { auto setup = GetSetup(); Function<uint64_t, bool, uint64_t, uint64_t> e(setup->GetAllocator(), setup->GetCode()); auto & test = e.If(e.GetP1(), e.GetP2(), e.GetP3()); auto function = e.Compile(test); bool p1 = true; uint64_t p2 = 0xFFFFFFFFFFFFFFFF; uint64_t p3 = 0; auto expected = p1 ? p2 : p3; auto observed = function(p1, p2, p3); ASSERT_EQ(expected, observed); p1 = false; expected = p1 ? p2 : p3; observed = function(p1, p2, p3); ASSERT_EQ(expected, observed); }
//----------------------------------------------------------------------------------------------- string_type Variable::AsciiDump() const { stringstream_type ss; ss << g_sCmdCode[ GetCode() ]; ss << _T(" [addr=0x") << std::hex << this << std::dec; ss << _T("; id=\"") << GetIdent() << _T("\""); ss << _T("; type=\"") << GetType() << _T("\""); ss << _T("; val="); switch(GetType()) { case 'i': ss << (int_type)GetFloat(); break; case 'f': ss << GetFloat(); break; case 'm': ss << _T("(array)"); break; case 's': ss << _T("\"") << GetString() << _T("\""); break; } ss << ((IsFlagSet(IToken::flVOLATILE)) ? _T("; ") : _T("; not ")) << _T("volatile"); ss << _T("]"); return ss.str(); }
void KeyboardEvent::GetInitDict(KeyboardEventInit& aParam) { GetKey(aParam.mKey); GetCode(aParam.mCode); aParam.mLocation = Location(); aParam.mRepeat = Repeat(); aParam.mIsComposing = IsComposing(); // legacy attributes aParam.mKeyCode = KeyCode(); aParam.mCharCode = CharCode(); aParam.mWhich = Which(); // modifiers from EventModifierInit aParam.mCtrlKey = CtrlKey(); aParam.mShiftKey = ShiftKey(); aParam.mAltKey = AltKey(); aParam.mMetaKey = MetaKey(); WidgetKeyboardEvent* internalEvent = mEvent->AsKeyboardEvent(); aParam.mModifierAltGraph = internalEvent->IsAltGraph(); aParam.mModifierCapsLock = internalEvent->IsCapsLocked(); aParam.mModifierFn = internalEvent->IsFn(); aParam.mModifierFnLock = internalEvent->IsFnLocked(); aParam.mModifierNumLock = internalEvent->IsNumLocked(); aParam.mModifierOS = internalEvent->IsOS(); aParam.mModifierScrollLock = internalEvent->IsScrollLocked(); aParam.mModifierSymbol = internalEvent->IsSymbol(); aParam.mModifierSymbolLock = internalEvent->IsSymbolLocked(); // EventInit aParam.mBubbles = internalEvent->mFlags.mBubbles; aParam.mCancelable = internalEvent->mFlags.mCancelable; }
BOOL CUIKeyEvent::IsInverse(const CUIEvent &cOther) const { return (ClassName() == ((const CUIKeyEvent *)&cOther)->ClassName()) && (GetCode() == ((const CUIKeyEvent *)&cOther)->GetCode()) && (((GetType() == UIEVENT_KEYDOWN) && (cOther.GetType() == UIEVENT_KEYUP)) || ((GetType() == UIEVENT_KEYUP) && (cOther.GetType() == UIEVENT_KEYDOWN))); }
const TCHAR * NOAAStore::GetCodeT(unsigned index) { #ifdef _UNICODE const char *code = GetCode(index); int length = strlen(code); TCHAR *code2 = new TCHAR[length + 1]; length = MultiByteToWideChar(CP_UTF8, 0, code, length, code2, length); code2[length] = _T('\0'); return code2; #else return GetCode(index); #endif }
int GetRCCodeNW() { int b_key=-1,i=-1,debounce=200; i=GetCode(); if(i!=-1) { if(i==b_key) { usleep(debounce*1000); while((i=GetCode())!=-1); } b_key=i; } return i; }
TEST_F(ExpressionTree, RegisterSpillingInteger) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); std::vector<Storage<int>> storages; const unsigned totalRegisterCount = RegisterBase::c_maxIntegerRegisterID + 1; // Try to obtain totalRegisterCount direct registers. for (unsigned i = 0; i < totalRegisterCount; ++i) { storages.push_back(e.Direct<int>()); ASSERT_EQ(storages.back().GetStorageClass(), StorageClass::Direct); } // There won't be enough registers for all storages to stay // direct since reserved base pointers can't be obtained. Thus, // some of the storages should have their registers spilled. // Three reserved registers are RBP, RSP and RIP. Note: this // assumes that RBP is a base register - if RSP is used instead // of RBP, the test will need to be adjusted. // Alternatively, ExpressionTree::IsAnyBaseRegister could be // made accessible and used to count the reserved registers. const unsigned reservedRegisterCount = 3; unsigned directCount = 0; unsigned indirectCount = 0; unsigned indexOfFirstDirect = 0; for (unsigned i = 0; i < storages.size(); ++i) { if (storages[i].GetStorageClass() == StorageClass::Direct) { directCount++; if (directCount == 1) { indexOfFirstDirect = i; } } else { indirectCount++; } } // Most storages should be direct, some corresponding to the // reserved registers should not. ASSERT_EQ(totalRegisterCount - reservedRegisterCount, directCount); ASSERT_EQ(reservedRegisterCount, indirectCount); // A new direct storage should cause the oldest reserved register // to be spilled (note: this assumes current allocation strategy). ASSERT_EQ(storages[indexOfFirstDirect].GetStorageClass(), StorageClass::Direct); Storage<int> spillTrigger = e.Direct<int>(); ASSERT_EQ(spillTrigger.GetStorageClass(), StorageClass::Direct); ASSERT_EQ(storages[indexOfFirstDirect].GetStorageClass(), StorageClass::Indirect); }
void CParmChValueDlg::OnSymbol() { UpdateData(); CSymbolDlg dlg; dlg.m_Code = GetCode(); if (dlg.DoModal() != IDOK) return; SetCodeStr(dlg.m_Code); SetCharStr(dlg.m_Code); UpdateData(FALSE); }
TEST_F(ExpressionTree, NoBaseRegisterReuseRIPRelative) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); auto storage = e.RIPRelative<int>(16); ASSERT_TRUE(storage.GetBaseRegister().IsRIP()); ASSERT_FALSE(storage.ConvertToDirect(false).IsRIP()); }
TEST_F(ExpressionTree, NoBaseRegisterReuseBasePointer) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); auto storage = e.Temporary<int>(); auto baseRegister = storage.GetBaseRegister(); ASSERT_FALSE(storage.ConvertToDirect(false).IsSameHardwareRegister(baseRegister)); }
void CppCodeGenerator::GenClassDeclaration(PObjectBase class_obj) { string class_name = class_obj->GetProperty("name")->GetValue(); m_header->WriteLn("/**"); m_header->WriteLn(" * Class " + class_name); m_header->WriteLn(" */"); m_header->WriteLn("class " + class_name + " : " + GetCode(class_obj,"base")); m_header->WriteLn("{"); m_header->Indent(); // private m_header->WriteLn("private:"); m_header->Indent(); GenAttributeDeclaration(class_obj,P_PRIVATE); m_header->Unindent(); m_header->WriteLn(""); // protected m_header->WriteLn("protected:"); m_header->Indent(); GenAttributeDeclaration(class_obj,P_PROTECTED); m_header->Unindent(); m_header->WriteLn(""); // public m_header->WriteLn("public:"); m_header->Indent(); GenAttributeDeclaration(class_obj,P_PUBLIC); m_header->WriteLn(""); // dentro de public también incluimos el constructor m_header->WriteLn(GetCode(class_obj,"cons_decl")); m_header->Unindent(); m_header->WriteLn(""); m_header->Unindent(); m_header->WriteLn("};"); m_header->WriteLn(""); }
//--------------------------------------------------------------------------- string_type TokenNewline::AsciiDump() const { stringstream_type ss; ss << g_sCmdCode[ GetCode() ]; ss << _T(" [addr=0x") << std::hex << this << std::dec; ss << _T("; pos=") << GetExprPos(); ss << _T("; offset=") << m_nOffset; ss << _T("]"); return ss.str(); }
TEST_F(ExpressionTree, MultipleReferencesToBasePointer) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); auto temp1 = e.Temporary<int>(); auto temp2 = e.Temporary<int>(); ASSERT_EQ(temp1.GetBaseRegister(), temp2.GetBaseRegister()); ASSERT_NE(temp1.GetOffset(), temp2.GetOffset()); }
TEST_F(ExpressionTree, MultipleReferencesToRIP) { auto setup = GetSetup(); ExpressionNodeFactory e(setup->GetAllocator(), setup->GetCode()); auto temp1 = e.RIPRelative<int>(0); auto temp2 = e.RIPRelative<int>(16); ASSERT_TRUE(temp1.GetBaseRegister().IsRIP()); ASSERT_EQ(temp1.GetBaseRegister(), temp2.GetBaseRegister()); }
//------------------------------------------------------------------------------ string_type IOprtIndex::AsciiDump() const { stringstream_type ss; ss << g_sCmdCode[ GetCode() ]; ss << _T(" [addr=0x") << std::hex << this << std::dec; ss << _T("; ident=\"") << GetIdent() << _T("\""); ss << _T("; argc=") << GetArgc(); ss << _T("]"); return ss.str(); }
void CppCodeGenerator::GenConstructor(shared_ptr<ObjectBase> class_obj) { m_source->WriteLn( wxT("") ); m_source->WriteLn( GetCode( class_obj, wxT("cons_def") ) ); m_source->WriteLn( wxT("{") ); m_source->Indent(); wxString settings = GetCode( class_obj, wxT("settings") ); if ( !settings.empty() ) { m_source->WriteLn( settings ); } for ( unsigned int i = 0; i < class_obj->GetChildCount(); i++ ) { GenConstruction( class_obj->GetChild( i ), true ); } m_source->Unindent(); m_source->WriteLn( wxT("}") ); }
//------------------------------------------------------------------------------ string_type ICallback::AsciiDump() const { stringstream_type ss; ss << g_sCmdCode[ GetCode() ]; ss << _T(" [addr=0x") << std::hex << this << std::dec; ss << _T("; ident=\"") << GetIdent() << "\""; ss << _T("; argc=") << GetArgc() << " (present: " << m_nArgsPresent << ")"; ss << _T("]"); return ss.str(); }
/* static */ unsigned ES_NativeStackFrame::GetDepth(ES_NativeStackFrame *stack_frame) { unsigned depth = 0; do { stack_frame = GetNextFrame(stack_frame); ++depth; } while (GetCode(stack_frame)); return depth; }