Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This used for testing whether else or else-if blocks could be inserted, or replace the selection
- * If @p replace is true, replace selection with @p item, else insert @p item before selection
- * Returns true if resulting instruction list passes validation
- */
- bool GenericElseInsertionDryRun(TraceRestrictItem item, bool replace)
- {
- if (this->selected_instruction < 1) return false;
- uint offset = this->selected_instruction - 1;
- const TraceRestrictProgram *prog = this->GetProgram();
- if (!prog) return false;
- std::vector<TraceRestrictItem> items = prog->items; // copy
- if (offset >= (TraceRestrictProgram::GetInstructionCount(items) + (replace ? 0 : 1))) return false; // off the end of the program
- uint array_offset = TraceRestrictProgram::InstructionOffsetToArrayOffset(items, offset);
- if (replace) {
- bool is_dual = IsTraceRestrictDoubleItem(items[array_offset]);
- items[array_offset] = item;
- if (is_dual)
- items.erase(items.begin() + array_offset + 1);
- } else {
- items.insert(items.begin() + array_offset, item);
- }
- TraceRestrictProgramActionsUsedFlags actions_used_flags;
- return TraceRestrictProgram::Validate(items, actions_used_flags).Succeeded();
- }
Advertisement
Add Comment
Please, Sign In to add comment