Ejemplo n.º 1
0
        public static CIList ciInsert(CIList list, CIPredicate predicate, int indexDelta, int maxMatchCount, params object[] cinsToInsert)
        {
            bool anyInserts = false;             // just for assert
            int  index, index0 = 0;

            var listToInsert   = toCIList(cinsToInsert);
            int indexIncrement = listToInsert.Count + Math.Max(1, indexDelta);

            while ((index = list.FindIndex(index0, predicate)) != -1 && (anyInserts = true))
            {
                ciInsert(list, index + indexDelta, listToInsert);
                Debug.assert(indexDelta <= 1 || list.FindIndex(index + 1, indexDelta - 1, predicate) == -1); // just in case if indexDelta > 1

                index0 = index + indexIncrement;                                                             // next after finded or next after inserted

                if (--maxMatchCount == 0)
                {
                    break;
                }

                listToInsert = copyCIList(listToInsert);                 // better make copy if need to insert this more than once (there might be a problems with labels otherwise)
            }

            Debug.assert(anyInserts, $"ciInsert: no insertions were made");
            Debug.assert(maxMatchCount <= 0, $"ciInsert: matchCount {maxMatchCount}");

            return(list);
        }
Ejemplo n.º 2
0
 // for just first predicate match (insert right after finded instruction)
 public static CIList ciInsert(CIEnumerable cins, CIPredicate predicate, params object[] cinsToInsert) =>
 ciInsert(cins.ToList(), predicate, cinsToInsert);
Ejemplo n.º 3
0
 // for just first predicate match (insert right after finded instruction)
 public static CIList ciInsert(CIList list, CIPredicate predicate, params object[] cinsToInsert) =>
 ciInsert(list, predicate, 1, 1, cinsToInsert);
Ejemplo n.º 4
0
 // maxMatchCount = 0 for all predicate matches
 // indexDelta - change actual index from matched for insertion
 // if indexDelta is 0 than cinsToInsert will be inserted right before finded instruction
 // throws assert exception if there were no matches at all or if maxMatchCount > 0 and there were less predicate matches
 public static CIList ciInsert(CIEnumerable cins, CIPredicate predicate, int indexDelta, int maxMatchCount, params object[] cinsToInsert) =>
 ciInsert(cins.ToList(), predicate, indexDelta, maxMatchCount, cinsToInsert);
Ejemplo n.º 5
0
 public static CIList ciReplace(CIList list, CIPredicate predicate, params object[] cinsForReplace) =>
 ciReplace(list, list.FindIndex(predicate), cinsForReplace);
Ejemplo n.º 6
0
 // replaces first matched CodeInstruction with cinsForReplace CodeInstructions
 public static CIList ciReplace(CIEnumerable cins, CIPredicate predicate, params object[] cinsForReplace) =>
 ciReplace(cins.ToList(), predicate, cinsForReplace);
Ejemplo n.º 7
0
        public static CIList ciRemove(CIList list, CIPredicate predicate, int indexDelta, int countToRemove)
        {
            int index = list.FindIndex(predicate);

            return(ciRemove(list, (index == -1? -1: index + indexDelta), countToRemove));
        }
Ejemplo n.º 8
0
 // indexDelta - change actual index from matched for removing
 // countToRemove - instructions count to be removed
 public static CIList ciRemove(CIEnumerable cins, CIPredicate predicate, int indexDelta, int countToRemove) =>
 ciRemove(cins.ToList(), predicate, indexDelta, countToRemove);