static void MEMArrayPtrTest() { short i, element; scMemArray *ptrArr; ptrArr = SCNEW scMemArray( sizeof(short) ); for ( i = 0; i < 100; i++ ) ptrArr->AppendData( (ElementPtr)&i ); for ( i = 0; i < ptrArr->GetNumItems(); i++ ) { ptrArr->GetDataAt( i, (ElementPtr)&element ); scAssert( i == element ); } ptrArr->RemoveDataAt( 0 ); for ( i = 0; i < ptrArr->GetNumItems(); i++ ) { ptrArr->GetDataAt( i, (ElementPtr)&element ); scAssert( i+1 == element ); } ptrArr->RemoveAll(); delete ptrArr; }
static void MEMArrayHndTest() { short i, element; scHandleArray ptrArr( sizeof(short) ); for ( i = 0; i < 100; i++ ) ptrArr.AppendData( (ElementPtr)&i ); for ( i = 0; i < ptrArr.GetNumItems(); i++ ) { ptrArr.GetDataAt( i, (ElementPtr)&element ); scAssert( i == element ); } ptrArr.RemoveDataAt( 0 ); for ( i = 0; i < ptrArr.GetNumItems(); i++ ) { ptrArr.GetDataAt( i, (ElementPtr)&element ); scAssert( i+1 == element ); } ptrArr.RemoveAll(); }
void scContUnit::scAssertValid( Bool recurse ) const { scTBObj::scAssertValid(); scAssert( !Marked( scRETABULATE ) ); scAssert( !Marked( scREBREAK ) ); if ( fFirstline ) { fFirstline->scAssertValid( false ); scAssert( fFirstline->GetStartOffset() == 0 ); scAssert( fFirstline->GetEndOffset() <= fCharArray.GetContentSize() ); } }
void scTBObj::Insert( scTBObj* next ) { scTBObj* prev; scAssert( this && next ); scAssert( Prev() == 0 && Next() == 0 ); if ( ( prev = next->Prev() ) != 0 ) { SetPrev( prev ); prev->SetNext( this ); } next->SetPrev( this ); SetNext( next ); }
/////////////////////////////////////////////////////////////////////////// ////sctypGoDeeper////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // Changes type of val to next in unary * operator void sctypGoDeeper(scType * typ) { if (sctypIsFunction(typ)) { return; //don't change with functions } /* if ((!val->type.params)||!(val->type.params[0]))//end of type string {//go deeper, if possible if (((val->type.flags&typTYPE)!=typUSERDEFINED))//its standard or struct type:-( serr3(scErr_Operand, invalid_operand_to,"","unary `*' or `->'"); // val->sym=((scSymbol *)val->sym->add->main); // val->where=val->sym->add->queue; *typ=type->main->type; sctypGoDeeper(typ); } else*/ sctypSimplifyType(typ); if (*(typ->params) == '*') (typ->params)++; else if (*(typ->params) == '&') (typ->params)++; else if (*(typ->params) == '[') { while (typ->params && *typ->params != ']') (typ->params)++; scAssert(scvalGoDeeper, *typ->params == ']'); (typ->params)++; } else serr3(scErr_Operand, invalid_operand_to, "", "unary `*' (not a pointer)"); }
/////////////////////////////////////////////////////////////////////////// ////scvalConvToInt///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// void scvalConvToInt(_value * val) { if (scvalGetValType(val) == valINT || scvalGetValType(val) == valPOINTER) return; deb0("ToINT\n"); if (scvalIsImmidiate(val)) { switch (scvalGetValType(val)) { case valDOUBLE: val->adr.val.ival = (int) val->adr.val.dval; break; case valFLOAT: val->adr.val.fval = (float) val->adr.val.dval; //??? break; case valFIXED: val->adr.val.ival >>= 16; break; default: scError(scvalConvToInt); } scAssert(scvalConvToInt, (val->type.flags & typTYPE) == typPREDEFINED); (valTYPE) val->type.main = valINT; } else {
/////////////////////////////////////////////////////////////////////////// ////sctypInsistsAlignment////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// int sctypInsistsAlignment(scType * type) { int i, j; i = sctypSizeOf(type); j = sctypGetValType(type); switch (j) { case valINT: case valDOUBLE: case valFLOAT: return 4; case valSHORT: return 2; case valSTRUCT: return sctypInsistsAlignment(&type->main->type); case valSCRIPT: return 4; case valPOINTER: //depends on if it's array or pointer scAssert(sctypInsistsAlignment, TYPESTR); if (TYPESTR[0] == '*') return 4; //pointer requires 4 //array:depends on of what does it consist { scType typ2; typ2 = *type; sctypGoDeeper(&typ2); return sctypInsistsAlignment(&typ2); } } return 0; //doesn't need alignment }
void scUiAlphaAnimation::createKeyFrame( u32 time, f32 alpha, scKeyFrame::InterpolationType itype /*= scKeyFrame::IT_LINEAR*/ ) { scAssert(alpha >= 0.f && alpha <= 1.f, "Widget alpha must in range 0 to 1! Current: " + scToString(alpha)); scContinuousKeyFrame<f32>* keyFrame = new scContinuousKeyFrame<f32>(time, alpha); keyFrame->setInterpolationType(itype); addKeyFrame(scKeyFramePtr(keyFrame)); }
void scTimeLine::removeRunCallBack( string const& name ) { auto iter = mCallBackMap.find(name); // 确保存在 scAssert(iter != mCallBackMap.end(), "Timeline call back named \"" + name + "\" do not exist."); mCallBackMap.erase(iter); }
void CBaselinePositions::Init( const scMuPoint& org, MicroPoint vjOffset, TypeSpec spec, const scFlowDir& fd ) { scAssert( spec != 0 ); MicroPoint ptsize = scCachedStyle::GetCachedStyle( spec ).GetPtSize(); if ( fd.IsHorizontal() ) { fTop = org.y - scRoundMP( (REAL)ptsize * RLU_BASEfmTop / scBaseRLUsystem ); fMiddle = org.y - scRoundMP( (REAL)ptsize * ( RLU_BASEfmTop - (scBaseRLUsystem/2)) / scBaseRLUsystem ); fRoman = org.y; fBottom = org.y + scRoundMP( (REAL)ptsize * RLU_BASEfmBottom / scBaseRLUsystem ); fTop += vjOffset; fMiddle += vjOffset; fRoman += vjOffset; fBottom += vjOffset; } else { fLeft = org.x - ptsize / 2; fMiddle = org.x; fRight = org.x + ptsize / 2; fLeft -= vjOffset; fMiddle -= vjOffset; fRight -= vjOffset; } }
/////////////////////////////////////////////////////////////////////////// ////sctypIsReference/////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// bool sctypIsReference(scType * type) { scAssert(sctypIsReference, type); if (TYPESTR && TYPESTR[0]) { if (TYPESTR[0] == '&') return true; if (TYPESTR[0] == '(') //function { bool x; char *c = type->params; while (*type->params++ != ')'); //omit parameter list if (!*type->params) type->params = NULL; x = sctypIsReference(type); type->params = c; return x; } return false; } else { switch (type->flags & typTYPE) { case typUSERDEFINED: { return (sctypIsReference(&type->main->type)); } default: return false; } } }
int scContUnit::ReplaceToken( const stUnivString& ustr, int32 start, int32& end ) { ForceRepaint( start, end ); Mark( scREBREAK ); if ( ustr.len == (ulong)(end - start) && fCharArray.ReplaceToken( ustr, start, end ) ) { fCharArray.RepairText( fSpecRun, start, end ); } else if ( fCharArray.Insert( ustr, start, end ) ) { int32 diff = ( ustr.len - ( end - start ) ); fSpecRun.BumpOffset( start, diff ); end += diff; TypeSpec ts; fCharArray.Retabulate( fSpecRun, start, end, ts, fCharArray.GetContentSize() ); } else { scAssert( 0 ); } #if SCDEBUG > 0 fCharArray.Validate(); fSpecRun.DebugRun( "ReplaceToken" ); #endif return 1; }
static long MemWrite( APPCtxPtr ctxPtr, void* ptr, long size ) { MemFileStruct* mfs = (MemFileStruct*)ctxPtr; if ( ( mfs->fBytesWritten + size ) > mfs->fTotalSize ) { mfs->fTheSysMemObj->UnlockHandle(); status stat = mfs->fTheSysMemObj->SetHandleSize( mfs->fBytesWritten + size ); if ( stat != scSuccess ) return 0; mfs->fStartMem = (scChar*)mfs->fTheSysMemObj->LockHandle( ); mfs->fTotalSize = mfs->fBytesWritten + size; mfs->fDstPtr = mfs->fStartMem + mfs->fBytesWritten; } SCmemmove( mfs->fDstPtr, ptr, size ); mfs->fDstPtr += size; mfs->fBytesWritten += size; scAssert( (long)(mfs->fDstPtr - mfs->fStartMem) <= mfs->fTotalSize ); return size; }
/* ==================================================================== */ void scTextline::scAssertValid( BOOL recurse ) const { scTBObj::scAssertValid(); scAssert( !Marked( scINVALID ) ); scAssert( fMaxLeadSpec != 0 ); if ( recurse ) { fColumn->scAssertValid( false ); fPara->scAssertValid( false ); } else { scAssert( fColumn != 0 ); scAssert( fPara != 0 ); } scAssert( fStartOffset >= 0 && fEndOffset <= fPara->GetContentSize() ); }
Bool scCOLRefData::AllocLine( Bool leadRetry ) { if ( leadRetry ) { scAssert( fPData.fTextline != 0 ); return true; } if ( !fPData.fPrevline ) { fPData.fTextline = fCol->GetFirstline(); if ( fPData.fTextline && fPData.fTextline->GetPara()->GetCount() < fPData.fPara->GetCount() ) { fCol->FreeLines( true, fLineDamage ); fPData.fTextline = NULL; } } else fPData.fTextline = fPData.fPrevline->GetNext(); if ( !fPData.fTextline ) { fPData.fTextline = scTextline::Allocate( fPData.fPara, fCol, fPData.fPrevline ); } else if ( fPData.fTextline->GetPara() != fPData.fPara ) { fPData.fPrevline = fPData.fTextline; fPData.fTextline = LNInsertNew( fPData.fPara, fCol, fPData.fTextline ); } else fPData.fTextline->InitForReuse( fPData.fPara ); return fPData.fTextline != NULL; }
scMemHandle MEMResizeHndDebug( scMemHandle obj, ulong reqSize, const char* file, int line ) { int size1 = 0; if ( obj ) size1 = _msize( obj ); if ( !obj ) obj = MEMAllocHndDebug( reqSize, file, line ); else { scAssert( ((MacHandle*)obj)->Count() == 0 ); // don't resize a locked handle obj = (scMemHandle)realloc( obj, reqSize + sizeof( MacHandle ) ); } MacHandle macHandle( obj ); *(MacHandle*)obj = macHandle; int size2 = _msize( obj ) - sizeof( MacHandle ); dbgTrackAmount( reqSize - size1 ); return obj; }
void* Lock( void ) { Validate(); scAssert( count_ >= 0 ); count_++; return (void*)block_; }
void scRedispList::AddCell( scColumn* col ) { scAssert( !FindCell( col ) ); scColRedisplay colredisp( col, col->GetAPPName() ); AppendData( (ElementPtr)&colredisp ); }
static void BuildRepaintList( scColumn* col ) { // SCDebugTrace( 2, scString( "BuildRepaintList - in\n" ) ); for ( col = (scColumn*)col->FirstInChain(); col; col = col->GetNext() ) { scAssert( !col->Marked( scLAYACTIVE ) ); // scAssert( !col->Marked( scREPAINT ) ); } }
/* ==================================================================== */ void scDrawLine::ProcessRenMoji() { scRenMojiStr rm; CharRecord fauxChar; unsigned i; unsigned numChars = fChRec->flags.GetRenMoji(); // save spec rm.fSpec = fSpec; scAssert( numChars < 7 ); // process characters for ( i = 0; i < numChars; i++ ) { rm.fRenMojiStr[i] = *fChRec; rm.fRenMojiStr[i+1].character = 0; IncrementBackingStore(); } fauxChar.Set( emSpace, (fChRec-1)->escapement ); SetCharArray( fauxChar, false ); rm.fPosition = fCurPos; if ( fFlowDir.IsHorizontal() ) { switch ( scCachedStyle::GetCachedStyle().GetHorzBaseline() ) { case kTopBaseline: rm.fPosition.y = fBaselinePositions.fTop; break; case kMiddleBaseline: rm.fPosition.y = fBaselinePositions.fMiddle; break; case kBottomBaseline: rm.fPosition.y = fBaselinePositions.fBottom; break; default: case kRomanBaseline: rm.fPosition.y = fBaselinePositions.fRoman; break; } } else { switch ( scCachedStyle::GetCachedStyle().GetVertBaseline() ) { case kLeftBaseline: rm.fPosition.x = fBaselinePositions.fLeft; break; default: case kCenterBaseline: rm.fPosition.x = fBaselinePositions.fMiddle; break; case kRightBaseline: rm.fPosition.x = fBaselinePositions.fRight; break; } } fRenMojiArray.AppendData( (ElementPtr)&rm ); }
inline void STRVerifyCount( scContUnit* para ) { long count = 0; for ( ; para; para = para->GetNext(), count++ ) { scAssert( count == para->GetCount() ); } }
/////////////////////////////////////////////////////////////////////////// ////sctypIsFunction//////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// bool sctypIsFunction(scType * type) { scAssert(sctypIsFunction, type); if (!TYPESTR) return false; if (TYPESTR[0] == '(') return true; return false; }
/////////////////////////////////////////////////////////////////////////// ////scvalConvToDouble////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// void scvalConvToDouble(_value * val) { if (scvalGetValType(val) == valDOUBLE) return; if (scvalIsImmidiate(val)) { switch ((int) scvalGetValType(val)) { case valINT: val->adr.val.dval = val->adr.val.ival; break; case valFIXED: val->adr.val.dval = val->adr.val.ival / 65536.0; break; case valFLOAT: val->adr.val.dval = val->adr.val.fval; break; } scAssert(scvalConvToDouble, (val->type.flags & typTYPE) == typPREDEFINED); (valTYPE) val->type.main = valDOUBLE; } else //----------------------------------------------------------- { _value v1 = { { /*ADDRESS*/ 0, adrREGISTER, {0} } , { /*type */ typPREDEFINED, NULL, (void *) valDOUBLE}, NULL }; switch (scvalGetValType(val)) { case valINT: v1.adr.address = scvalFindFreeDoubleRegister(val); Gen_Opcode(opvcpuIDBL, &v1, val); *val = v1; break; case valSHORT: case valCHAR: scvalConvToInt(val); scvalConvToDouble(val); return; break; case valFLOAT: v1.adr.address = scvalFindFreeDoubleRegister(val); Gen_Opcode(opvcpuFDBL, &v1, val); *val = v1; break; case valFIXED: v1.adr.address = scvalFindFreeDoubleRegister(val); Gen_Opcode(opvcpuFIXDBL, &v1, val); *val = v1; break; default: serr2(scErr_Cast, illegal_type_conversion, " to double"); } } }
int TextMarker::SelectEndWord( ) { scAssert( fOffset <= fPara->GetContentSize() ); scHandleArrayLock h( fPara->GetCharArray() ); CharRecordP chRec = (CharRecordP)*h; fOffset = TXTEndSelectableWord( chRec, fOffset ); return fPara != 0; }
scTBObj* scTBObj::FirstInChain( void ) const { scTBObj* prev; scTBObj* obj = (scTBObj*)this; scAssert( this != 0 ); for ( prev = Prev(); prev; prev = obj->Prev() ) obj = prev; return obj; }
void MEMFreeHnd( scMemHandle hnd ) { if ( hnd == 0 ) return; MacHandle* mh = (MacHandle*)hnd; scAssert( !mh->Count() ); dbgTrackAmount( -(int)_msize( hnd ) ); free( hnd ); }
/* ===================================================================== */ int scCharArray::GetToken( USTR& ustr, int32 start, int32 end ) const { scAssert( ustr.len > (ulong)(end - start) ); scAssert( end - start > 0 ); scHandleArrayLock h( (scCharArray*)this ); CharRecordP chRec = (CharRecordP)*h; chRec += start; int len = end - start; WCHAR* ptr = (WCHAR*)ustr.ptr; for ( int i = 0; i < len; i++, chRec++ ) ptr[i] = chRec->character; ustr.len = len; return len; }
int TextMarker::SelectStartColumn( ) { scTextline* txl; scAssert( fCol != 0 ); txl = fCol->GetFirstline(); fTxl = txl; fPara = txl->GetPara(); fParaCount = fPara->GetCount(); return SelectStartLine(); }
/////////////////////////////////////////////////////////////////////////// ////scvalConvToFloat/////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// void scvalConvToFloat(_value * val) { if (scvalGetValType(val) == valFLOAT) return; deb0("ToFloat\n"); if (scvalIsImmidiate(val)) { switch (scvalGetValType(val)) { case valDOUBLE: val->adr.val.fval = (float) val->adr.val.dval; break; case valINT: val->adr.val.fval = (float) val->adr.val.ival; break; case valFIXED: val->adr.val.fval = (float) (val->adr.val.ival / 65536.0); break; default: // (float)val->val=val->val; // val->vald=val->val; scError(scvalConvToFloat); } scAssert(scvalConvToFloat, (val->type.flags & typTYPE) == typPREDEFINED); (valTYPE) val->type.main = valFLOAT; } else { _value v1 = { { /*ADDRESS*/ 0, adrREGISTER, {0} } , { /*type */ typPREDEFINED, NULL, (void *) valFLOAT}, NULL }; switch (scvalGetValType(val)) { case valDOUBLE: Gen_Opcode(opvcpuDFLT, &v1, val); *val = v1; break; case valSHORT: case valCHAR: case valFIXED: case valINT: scvalConvToDouble(val); scvalConvToFloat(val); return; break; default: serr2(scErr_Cast, illegal_type_conversion, " to float"); } } }
void scTBObj::Write( APPCtxPtr ctxPtr, IOFuncPtr writeFunc ) { uchar abuf[FILE_SIZE_OBJECT]; uchar* pbuf = abuf; pbuf = BufSet_long( pbuf, GetBits( ), kIntelOrder ); pbuf = BufSet_long( pbuf, fNext ? fNext->GetEnumCount() : 0, kIntelOrder ); pbuf = BufSet_long( pbuf, fPrev ? fPrev->GetEnumCount() : 0, kIntelOrder ); scAssert ((size_t)(pbuf-abuf) == FILE_SIZE_OBJECT ); WriteBytes( abuf, ctxPtr, writeFunc, FILE_SIZE_OBJECT ); }