void CObjectIStreamJson::ReadBitString(CBitString& obj) { #if BITSTRING_AS_VECTOR ThrowError(fNotImplemented, "Not Implemented"); #else if (TopFrame().HasMemberId() && TopFrame().GetMemberId().IsCompressed()) { ThrowError(fNotImplemented, "Not Implemented"); return; } Expect('\"'); obj.clear(); obj.resize(0); CBitString::size_type len = 0; for ( ;; ++len) { char c = GetChar(); if (c == '1') { obj.resize(len+1); obj.set_bit(len); } else if (c != '0') { if ( c != 'B' ) { ThrowError(fFormatError, "invalid char in bit string"); } break; } } obj.resize(len); Expect('\"'); #endif }
size_t CObjectIStreamJson::ReadBytes( ByteBlock& block, char* dst, size_t length) { if (m_BinaryFormat != CObjectIStreamJson::eDefault) { return ReadCustomBytes(block,dst,length); } if (TopFrame().HasMemberId() && TopFrame().GetMemberId().IsCompressed()) { return ReadBase64Bytes( block, dst, length ); } return ReadHexBytes( block, dst, length ); }
void CObjectOStreamXml::x_EndTypeNamespace(void) { if (m_UseSchemaRef) { if (TopFrame().HasTypeInfo()) { TTypeInfo type = TopFrame().GetTypeInfo(); if (type->HasNamespaceName()) { x_EndNamespace(type->GetNamespaceName()); } } } }
TMemberIndex CObjectIStreamJson::BeginClassMember(const CClassTypeInfo* classType, TMemberIndex pos) { TMemberIndex first = classType->GetMembers().FirstIndex(); TMemberIndex last = classType->GetMembers().LastIndex(); if (m_RejectedTag.empty()) { if (pos == first) { if (classType->GetMemberInfo(first)->GetId().IsAttlist()) { TopFrame().SetNotag(); return first; } } } if ( !NextElement() ) { if (pos == last && classType->GetMemberInfo(pos)->GetId().HasNotag() && classType->GetMemberInfo(pos)->GetTypeInfo()->GetTypeFamily() == eTypeFamilyPrimitive) { TopFrame().SetNotag(); return pos; } return kInvalidMember; } char c = PeekChar(); if (m_RejectedTag.empty() && (c == '[' || c == '{')) { for (TMemberIndex i = pos; i <= last; ++i) { if (classType->GetMemberInfo(i)->GetId().HasNotag()) { TopFrame().SetNotag(); return i; } } } string tagName = ReadKey(); if (tagName[0] == '#') { tagName = tagName.substr(1); TopFrame().SetNotag(); } bool deep = false; TMemberIndex ind = FindDeep(classType->GetMembers(), tagName, deep); if (deep) { if (ind != kInvalidMember) { TopFrame().SetNotag(); } UndoClassMember(); } else if (ind != kInvalidMember) { if (classType->GetMembers().GetItemInfo(ind)->GetId().HasAnyContent()) { UndoClassMember(); } } return ind; }
string CObjectIStreamJson::ReadFileHeader(void) { StartBlock('{'); string str( ReadKey()); if (TopFrame().HasTypeInfo()) { const string& tname = TopFrame().GetTypeInfo()->GetName(); if (tname.empty()) { UndoClassMember(); } if (str != tname) { if (str == NStr::Replace(tname,"-","_")) { return tname; } } } return str; }
TMemberIndex CObjectIStreamJson::BeginClassMember(const CClassTypeInfo* classType) { if ( !NextElement() ) return kInvalidMember; string tagName = ReadKey(); bool deep = false; TMemberIndex ind = FindDeep(classType->GetMembers(), tagName, deep); if (deep) { if (ind != kInvalidMember) { TopFrame().SetNotag(); } UndoClassMember(); } return ind; }
int VMFrameStack::Call(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults, VMException **trap) { bool allocated = false; try { if (func->Native) { return static_cast<VMNativeFunction *>(func)->NativeCall(this, params, numparams, results, numresults); } else { AllocFrame(static_cast<VMScriptFunction *>(func)); allocated = true; VMFillParams(params, TopFrame(), numparams); int numret = VMExec(this, static_cast<VMScriptFunction *>(func)->Code, results, numresults); PopFrame(); return numret; } } catch (VMException *exception) { if (allocated) { PopFrame(); } if (trap != NULL) { *trap = exception; return -1; } throw; } catch (...) { if (allocated) { PopFrame(); } throw; } }
TMemberIndex CObjectIStreamJson::BeginChoiceVariant(const CChoiceTypeInfo* choiceType) { if ( !NextElement() ) return kInvalidMember; string tagName = ReadKey(); bool deep = false; TMemberIndex ind = FindDeep(choiceType->GetVariants(), tagName, deep); if (deep) { if (ind == kInvalidMember) { const CItemsInfo& items = choiceType->GetItems(); TMemberIndex first = items.FirstIndex(); if (items.GetItemInfo(first)->GetId().IsAttlist()) { ind = first; } } if (ind != kInvalidMember) { TopFrame().SetNotag(); } UndoClassMember(); } return ind; }
void CObjectIStreamJson::EndChoiceVariant(void) { TopFrame().SetNotag(false); }
void CObjectIStreamJson::EndClassMember(void) { TopFrame().SetNotag(false); }
int VMFrameStack::Call(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults, VMException **trap) { bool allocated = false; try { if (func->Native) { return static_cast<VMNativeFunction *>(func)->NativeCall(this, params, numparams, results, numresults); } else { AllocFrame(static_cast<VMScriptFunction *>(func)); allocated = true; VMFillParams(params, TopFrame(), numparams); int numret = VMExec(this, static_cast<VMScriptFunction *>(func)->Code, results, numresults); PopFrame(); return numret; } } catch (VMException *exception) { if (allocated) { PopFrame(); } if (trap != NULL) { *trap = exception; return -1; } throw; } catch (EVMAbortException exception) { if (allocated) { PopFrame(); } if (trap != nullptr) { *trap = nullptr; } Printf("VM execution aborted: "); switch (exception) { case X_READ_NIL: Printf("tried to read from address zero."); break; case X_WRITE_NIL: Printf("tried to write to address zero."); break; case X_TOO_MANY_TRIES: Printf("too many try-catch blocks."); break; case X_ARRAY_OUT_OF_BOUNDS: Printf("array access out of bounds."); break; case X_DIVISION_BY_ZERO: Printf("division by zero."); break; case X_BAD_SELF: Printf("invalid self pointer."); break; } Printf("\n"); return -1; } catch (...) { if (allocated) { PopFrame(); } throw; } }