Guest User

Untitled

a guest
Mar 15th, 2026
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /**
  2. * This used for testing whether else or else-if blocks could be inserted, or replace the selection
  3. * If @p replace is true, replace selection with @p item, else insert @p item before selection
  4. * Returns true if resulting instruction list passes validation
  5. */
  6. bool GenericElseInsertionDryRun(TraceRestrictItem item, bool replace)
  7. {
  8. if (this->selected_instruction < 1) return false;
  9. uint offset = this->selected_instruction - 1;
  10.  
  11. const TraceRestrictProgram *prog = this->GetProgram();
  12. if (!prog) return false;
  13.  
  14. std::vector<TraceRestrictItem> items = prog->items; // copy
  15.  
  16. if (offset >= (TraceRestrictProgram::GetInstructionCount(items) + (replace ? 0 : 1))) return false; // off the end of the program
  17.  
  18. uint array_offset = TraceRestrictProgram::InstructionOffsetToArrayOffset(items, offset);
  19.  
  20. if (replace) {
  21. bool is_dual = IsTraceRestrictDoubleItem(items[array_offset]);
  22. items[array_offset] = item;
  23. if (is_dual)
  24. items.erase(items.begin() + array_offset + 1);
  25. } else {
  26. items.insert(items.begin() + array_offset, item);
  27. }
  28.  
  29. TraceRestrictProgramActionsUsedFlags actions_used_flags;
  30. return TraceRestrictProgram::Validate(items, actions_used_flags).Succeeded();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment