Tue, 04 Feb 2014 14:21:06 +0200
- ternary operator now works properly
src/DataBuffer.cc | file | annotate | diff | comparison | revisions | |
src/DataBuffer.h | file | annotate | diff | comparison | revisions | |
src/Expression.cc | file | annotate | diff | comparison | revisions |
--- a/src/DataBuffer.cc Tue Feb 04 13:38:22 2014 +0200 +++ b/src/DataBuffer.cc Tue Feb 04 14:21:06 2014 +0200 @@ -52,30 +52,23 @@ if (!other) return; - int oldsize = GetWrittenSize(); + // Note: We transfer the marks before the buffer is copied, so that the + // offset uses the proper value (which is the written size of @other, which + // we don't want our written size to be added to yet). + other->TransferMarks (this); CopyBuffer (other); - - // Assimilate in its marks and references - for (ByteMark* mark : other->GetMarks()) - { - mark->pos += oldsize; - PushToMarks (mark); - } - - for (MarkReference* ref : other->GetReferences()) - { - ref->pos += oldsize; - PushToReferences (ref); - } - delete other; } // ============================================================================ // +// Clones this databuffer to a new one and returns it. Note that the original +// transfers its marks and references and loses them in the process. +// DataBuffer* DataBuffer::Clone() { DataBuffer* other = new DataBuffer; + TransferMarks (other); other->CopyBuffer (this); return other; } @@ -91,6 +84,28 @@ // ============================================================================ // +void DataBuffer::TransferMarks (DataBuffer* other) +{ + int offset = other->GetWrittenSize(); + + for (ByteMark* mark : GetMarks()) + { + mark->pos += offset; + other->PushToMarks (mark); + } + + for (MarkReference* ref : GetReferences()) + { + ref->pos += offset; + other->PushToReferences (ref); + } + + ClearMarks(); + ClearReferences(); +} + +// ============================================================================ +// ByteMark* DataBuffer::AddMark (String name) { ByteMark* mark = new ByteMark;
--- a/src/DataBuffer.h Tue Feb 04 13:38:22 2014 +0200 +++ b/src/DataBuffer.h Tue Feb 04 14:21:06 2014 +0200 @@ -66,17 +66,16 @@ // Note: @other is destroyed in the process! void MergeAndDestroy (DataBuffer* other); - // Clones this databuffer to a new one and returns it. - DataBuffer* Clone(); - ByteMark* AddMark (String name); MarkReference* AddReference (ByteMark* mark); void CheckSpace (int bytes); + DataBuffer* Clone(); void DeleteMark (int marknum); void AdjustMark (ByteMark* mark); void OffsetMark (ByteMark* mark, int offset); ByteMark* FindMarkByName (const String& target); void Dump(); + void TransferMarks (DataBuffer* other); void WriteFloat (float a); void WriteStringIndex (const String& a); void WriteString (const String& a);
--- a/src/Expression.cc Tue Feb 04 13:38:22 2014 +0200 +++ b/src/Expression.cc Tue Feb 04 14:21:06 2014 +0200 @@ -403,6 +403,7 @@ const List<ExpressionValue*>& values) { const OperatorInfo* info = &gOperators[op->GetID()]; + Print ("Process operator %1\n", info - gOperators); bool isconstexpr = true; for (ExpressionValue* val : values) @@ -449,6 +450,11 @@ buf->AdjustMark (mark1); // move mark1 at the end of the true case buf->MergeAndDestroy (b2); // perform third operand (false case) buf->AdjustMark (mark2); // move the ending mark2 here + + Print ("Mark positions: %1 %2\n", mark1->pos, mark2->pos); + + for (int i = 0; i < 3; ++i) + values[i]->SetBuffer (null); } else {