diff --git a/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt b/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt index af4b99d36..b821d41cd 100644 --- a/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt +++ b/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt @@ -1,8 +1,9 @@ public <#NodeName#> Add(<#ListElementType#> elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); <#ListName#>.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -10,12 +11,16 @@ public <#NodeName#> Add(<#ListElementType#> elem, SourceContext sc = null) public void AddFirst(<#ListElementType#> el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); <#ListName#>.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable<<#ListElementType#>> els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); <#ListName#>.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -24,6 +29,8 @@ public void AddFirst(IEnumerable<<#ListElementType#>> els) public void AddMany(params <#ListElementType#>[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); <#ListName#>.AddRange(els); foreach (var el in els) if (el != null) @@ -32,6 +39,8 @@ public void AddMany(params <#ListElementType#>[] els) private int FindIndexInList(<#ListElementType#> el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = <#ListName#>.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -40,13 +49,20 @@ private int FindIndexInList(<#ListElementType#> el) public void InsertAfter(<#ListElementType#> el, <#ListElementType#> newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); <#ListName#>.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); <#ListName#>.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -55,13 +71,20 @@ public void InsertAfter(<#ListElementType#> el, IEnumerable<<#ListElementType#>> public void InsertBefore(<#ListElementType#> el, <#ListElementType#> newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); <#ListName#>.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); <#ListName#>.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -75,13 +98,20 @@ public bool Remove(<#ListElementType#> el) public void ReplaceInList(<#ListElementType#> el, <#ListElementType#> newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); <#ListName#>[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); <#ListName#>.RemoveAt(ind); <#ListName#>.InsertRange(ind, newels); @@ -97,7 +127,9 @@ public int RemoveAll(Predicate<<#ListElementType#>> match) public <#ListElementType#> Last() { - return <#ListName#>[<#ListName#>.Count - 1]; + if (<#ListName#>.Count > 0) + return <#ListName#>[<#ListName#>.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -107,6 +139,8 @@ public int Count public void Insert(int pos, <#ListElementType#> el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); <#ListName#>.Insert(pos,el); if (el != null) el.Parent = this; diff --git a/SyntaxTree/tree/Tree.cs b/SyntaxTree/tree/Tree.cs index 734d4637e..59a616e97 100644 --- a/SyntaxTree/tree/Tree.cs +++ b/SyntaxTree/tree/Tree.cs @@ -446,9 +446,10 @@ namespace PascalABCCompiler.SyntaxTree public statement_list Add(statement elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); subnodes.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -456,12 +457,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); subnodes.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); subnodes.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -470,6 +475,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params statement[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); subnodes.AddRange(els); foreach (var el in els) if (el != null) @@ -478,6 +485,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = subnodes.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -486,13 +495,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(statement el, statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); subnodes.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); subnodes.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -501,13 +517,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(statement el, statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); subnodes.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); subnodes.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -521,13 +544,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(statement el, statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); subnodes[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); subnodes.RemoveAt(ind); subnodes.InsertRange(ind, newels); @@ -543,7 +573,9 @@ namespace PascalABCCompiler.SyntaxTree public statement Last() { - return subnodes[subnodes.Count - 1]; + if (subnodes.Count > 0) + return subnodes[subnodes.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -553,6 +585,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); subnodes.Insert(pos,el); if (el != null) el.Parent = this; @@ -2601,9 +2635,10 @@ namespace PascalABCCompiler.SyntaxTree public named_type_reference Add(ident elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); names.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -2611,12 +2646,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); names.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); names.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -2625,6 +2664,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params ident[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); names.AddRange(els); foreach (var el in els) if (el != null) @@ -2633,6 +2674,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = names.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -2641,13 +2684,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); names.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); names.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -2656,13 +2706,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); names.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); names.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -2676,13 +2733,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); names[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); names.RemoveAt(ind); names.InsertRange(ind, newels); @@ -2698,7 +2762,9 @@ namespace PascalABCCompiler.SyntaxTree public ident Last() { - return names[names.Count - 1]; + if (names.Count > 0) + return names[names.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -2708,6 +2774,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); names.Insert(pos,el); if (el != null) el.Parent = this; @@ -2918,9 +2986,10 @@ namespace PascalABCCompiler.SyntaxTree public variable_definitions Add(var_def_statement elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); var_definitions.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -2928,12 +2997,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(var_def_statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var_definitions.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); var_definitions.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -2942,6 +3015,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params var_def_statement[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); var_definitions.AddRange(els); foreach (var el in els) if (el != null) @@ -2950,6 +3025,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(var_def_statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = var_definitions.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -2958,13 +3035,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(var_def_statement el, var_def_statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); var_definitions.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(var_def_statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var_definitions.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -2973,13 +3057,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(var_def_statement el, var_def_statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); var_definitions.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(var_def_statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var_definitions.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -2993,13 +3084,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(var_def_statement el, var_def_statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); var_definitions[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(var_def_statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); var_definitions.RemoveAt(ind); var_definitions.InsertRange(ind, newels); @@ -3015,7 +3113,9 @@ namespace PascalABCCompiler.SyntaxTree public var_def_statement Last() { - return var_definitions[var_definitions.Count - 1]; + if (var_definitions.Count > 0) + return var_definitions[var_definitions.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -3025,6 +3125,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, var_def_statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var_definitions.Insert(pos,el); if (el != null) el.Parent = this; @@ -3216,9 +3318,10 @@ namespace PascalABCCompiler.SyntaxTree public ident_list Add(ident elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); idents.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -3226,12 +3329,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); idents.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); idents.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -3240,6 +3347,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params ident[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); idents.AddRange(els); foreach (var el in els) if (el != null) @@ -3248,6 +3357,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = idents.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -3256,13 +3367,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); idents.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); idents.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -3271,13 +3389,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); idents.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); idents.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -3291,13 +3416,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); idents[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); idents.RemoveAt(ind); idents.InsertRange(ind, newels); @@ -3313,7 +3445,9 @@ namespace PascalABCCompiler.SyntaxTree public ident Last() { - return idents[idents.Count - 1]; + if (idents.Count > 0) + return idents[idents.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -3323,6 +3457,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); idents.Insert(pos,el); if (el != null) el.Parent = this; @@ -3909,9 +4045,10 @@ namespace PascalABCCompiler.SyntaxTree public declarations Add(declaration elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); defs.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -3919,12 +4056,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -3933,6 +4074,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params declaration[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.AddRange(els); foreach (var el in els) if (el != null) @@ -3941,6 +4084,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = defs.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -3949,13 +4094,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -3964,13 +4116,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -3984,13 +4143,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); defs.RemoveAt(ind); defs.InsertRange(ind, newels); @@ -4006,7 +4172,9 @@ namespace PascalABCCompiler.SyntaxTree public declaration Last() { - return defs[defs.Count - 1]; + if (defs.Count > 0) + return defs[defs.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -4016,6 +4184,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(pos,el); if (el != null) el.Parent = this; @@ -4199,9 +4369,10 @@ namespace PascalABCCompiler.SyntaxTree public program_tree Add(compilation_unit elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); compilation_units.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -4209,12 +4380,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(compilation_unit el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); compilation_units.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); compilation_units.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -4223,6 +4398,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params compilation_unit[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); compilation_units.AddRange(els); foreach (var el in els) if (el != null) @@ -4231,6 +4408,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(compilation_unit el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = compilation_units.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -4239,13 +4418,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(compilation_unit el, compilation_unit newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); compilation_units.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(compilation_unit el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); compilation_units.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -4254,13 +4440,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(compilation_unit el, compilation_unit newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); compilation_units.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(compilation_unit el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); compilation_units.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -4274,13 +4467,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(compilation_unit el, compilation_unit newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); compilation_units[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(compilation_unit el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); compilation_units.RemoveAt(ind); compilation_units.InsertRange(ind, newels); @@ -4296,7 +4496,9 @@ namespace PascalABCCompiler.SyntaxTree public compilation_unit Last() { - return compilation_units[compilation_units.Count - 1]; + if (compilation_units.Count > 0) + return compilation_units[compilation_units.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -4306,6 +4508,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, compilation_unit el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); compilation_units.Insert(pos,el); if (el != null) el.Parent = this; @@ -4773,9 +4977,10 @@ namespace PascalABCCompiler.SyntaxTree public expression_list Add(expression elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); expressions.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -4783,12 +4988,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(expression el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); expressions.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); expressions.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -4797,6 +5006,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params expression[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); expressions.AddRange(els); foreach (var el in els) if (el != null) @@ -4805,6 +5016,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(expression el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = expressions.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -4813,13 +5026,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(expression el, expression newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); expressions.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(expression el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); expressions.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -4828,13 +5048,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(expression el, expression newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); expressions.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(expression el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); expressions.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -4848,13 +5075,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(expression el, expression newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); expressions[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(expression el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); expressions.RemoveAt(ind); expressions.InsertRange(ind, newels); @@ -4870,7 +5104,9 @@ namespace PascalABCCompiler.SyntaxTree public expression Last() { - return expressions[expressions.Count - 1]; + if (expressions.Count > 0) + return expressions[expressions.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -4880,6 +5116,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, expression el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); expressions.Insert(pos,el); if (el != null) el.Parent = this; @@ -6795,9 +7033,10 @@ namespace PascalABCCompiler.SyntaxTree public indexers_types Add(type_definition elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); indexers.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -6805,12 +7044,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); indexers.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); indexers.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -6819,6 +7062,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params type_definition[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); indexers.AddRange(els); foreach (var el in els) if (el != null) @@ -6827,6 +7072,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = indexers.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -6835,13 +7082,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); indexers.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); indexers.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -6850,13 +7104,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); indexers.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); indexers.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -6870,13 +7131,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); indexers[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); indexers.RemoveAt(ind); indexers.InsertRange(ind, newels); @@ -6892,7 +7160,9 @@ namespace PascalABCCompiler.SyntaxTree public type_definition Last() { - return indexers[indexers.Count - 1]; + if (indexers.Count > 0) + return indexers[indexers.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -6902,6 +7172,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); indexers.Insert(pos,el); if (el != null) el.Parent = this; @@ -7884,9 +8156,10 @@ namespace PascalABCCompiler.SyntaxTree public formal_parameters Add(typed_parameters elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); params_list.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -7894,12 +8167,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(typed_parameters el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); params_list.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); params_list.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -7908,6 +8185,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params typed_parameters[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); params_list.AddRange(els); foreach (var el in els) if (el != null) @@ -7916,6 +8195,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(typed_parameters el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = params_list.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -7924,13 +8205,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(typed_parameters el, typed_parameters newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); params_list.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(typed_parameters el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); params_list.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -7939,13 +8227,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(typed_parameters el, typed_parameters newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); params_list.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(typed_parameters el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); params_list.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -7959,13 +8254,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(typed_parameters el, typed_parameters newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); params_list[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(typed_parameters el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); params_list.RemoveAt(ind); params_list.InsertRange(ind, newels); @@ -7981,7 +8283,9 @@ namespace PascalABCCompiler.SyntaxTree public typed_parameters Last() { - return params_list[params_list.Count - 1]; + if (params_list.Count > 0) + return params_list[params_list.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -7991,6 +8295,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, typed_parameters el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); params_list.Insert(pos,el); if (el != null) el.Parent = this; @@ -8174,9 +8480,10 @@ namespace PascalABCCompiler.SyntaxTree public procedure_attributes_list Add(procedure_attribute elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); proc_attributes.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -8184,12 +8491,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(procedure_attribute el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); proc_attributes.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); proc_attributes.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -8198,6 +8509,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params procedure_attribute[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); proc_attributes.AddRange(els); foreach (var el in els) if (el != null) @@ -8206,6 +8519,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(procedure_attribute el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = proc_attributes.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -8214,13 +8529,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(procedure_attribute el, procedure_attribute newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); proc_attributes.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(procedure_attribute el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); proc_attributes.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -8229,13 +8551,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(procedure_attribute el, procedure_attribute newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); proc_attributes.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(procedure_attribute el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); proc_attributes.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -8249,13 +8578,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(procedure_attribute el, procedure_attribute newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); proc_attributes[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(procedure_attribute el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); proc_attributes.RemoveAt(ind); proc_attributes.InsertRange(ind, newels); @@ -8271,7 +8607,9 @@ namespace PascalABCCompiler.SyntaxTree public procedure_attribute Last() { - return proc_attributes[proc_attributes.Count - 1]; + if (proc_attributes.Count > 0) + return proc_attributes[proc_attributes.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -8281,6 +8619,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, procedure_attribute el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); proc_attributes.Insert(pos,el); if (el != null) el.Parent = this; @@ -9488,9 +9828,10 @@ namespace PascalABCCompiler.SyntaxTree public type_declarations Add(type_declaration elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); types_decl.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -9498,12 +9839,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(type_declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); types_decl.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); types_decl.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -9512,6 +9857,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params type_declaration[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); types_decl.AddRange(els); foreach (var el in els) if (el != null) @@ -9520,6 +9867,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(type_declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = types_decl.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -9528,13 +9877,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(type_declaration el, type_declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); types_decl.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(type_declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); types_decl.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -9543,13 +9899,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(type_declaration el, type_declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); types_decl.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(type_declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); types_decl.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -9563,13 +9926,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(type_declaration el, type_declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); types_decl[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(type_declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); types_decl.RemoveAt(ind); types_decl.InsertRange(ind, newels); @@ -9585,7 +9955,9 @@ namespace PascalABCCompiler.SyntaxTree public type_declaration Last() { - return types_decl[types_decl.Count - 1]; + if (types_decl.Count > 0) + return types_decl[types_decl.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -9595,6 +9967,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, type_declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); types_decl.Insert(pos,el); if (el != null) el.Parent = this; @@ -10329,9 +10703,10 @@ namespace PascalABCCompiler.SyntaxTree public consts_definitions_list Add(const_definition elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); const_defs.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -10339,12 +10714,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(const_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); const_defs.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); const_defs.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -10353,6 +10732,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params const_definition[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); const_defs.AddRange(els); foreach (var el in els) if (el != null) @@ -10361,6 +10742,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(const_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = const_defs.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -10369,13 +10752,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(const_definition el, const_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); const_defs.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(const_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); const_defs.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -10384,13 +10774,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(const_definition el, const_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); const_defs.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(const_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); const_defs.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -10404,13 +10801,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(const_definition el, const_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); const_defs[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(const_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); const_defs.RemoveAt(ind); const_defs.InsertRange(ind, newels); @@ -10426,7 +10830,9 @@ namespace PascalABCCompiler.SyntaxTree public const_definition Last() { - return const_defs[const_defs.Count - 1]; + if (const_defs.Count > 0) + return const_defs[const_defs.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -10436,6 +10842,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, const_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); const_defs.Insert(pos,el); if (el != null) el.Parent = this; @@ -11121,9 +11529,10 @@ namespace PascalABCCompiler.SyntaxTree public uses_list Add(unit_or_namespace elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); units.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -11131,12 +11540,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(unit_or_namespace el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); units.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); units.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -11145,6 +11558,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params unit_or_namespace[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); units.AddRange(els); foreach (var el in els) if (el != null) @@ -11153,6 +11568,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(unit_or_namespace el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = units.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -11161,13 +11578,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(unit_or_namespace el, unit_or_namespace newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); units.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(unit_or_namespace el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); units.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -11176,13 +11600,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(unit_or_namespace el, unit_or_namespace newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); units.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(unit_or_namespace el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); units.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -11196,13 +11627,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(unit_or_namespace el, unit_or_namespace newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); units[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(unit_or_namespace el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); units.RemoveAt(ind); units.InsertRange(ind, newels); @@ -11218,7 +11656,9 @@ namespace PascalABCCompiler.SyntaxTree public unit_or_namespace Last() { - return units[units.Count - 1]; + if (units.Count > 0) + return units[units.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -11228,6 +11668,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, unit_or_namespace el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); units.Insert(pos,el); if (el != null) el.Parent = this; @@ -11687,9 +12129,10 @@ namespace PascalABCCompiler.SyntaxTree public compilation_unit Add(compiler_directive elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); compiler_directives.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -11697,12 +12140,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(compiler_directive el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); compiler_directives.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); compiler_directives.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -11711,6 +12158,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params compiler_directive[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); compiler_directives.AddRange(els); foreach (var el in els) if (el != null) @@ -11719,6 +12168,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(compiler_directive el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = compiler_directives.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -11727,13 +12178,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(compiler_directive el, compiler_directive newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); compiler_directives.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(compiler_directive el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); compiler_directives.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -11742,13 +12200,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(compiler_directive el, compiler_directive newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); compiler_directives.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(compiler_directive el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); compiler_directives.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -11762,13 +12227,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(compiler_directive el, compiler_directive newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); compiler_directives[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(compiler_directive el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); compiler_directives.RemoveAt(ind); compiler_directives.InsertRange(ind, newels); @@ -11784,7 +12256,9 @@ namespace PascalABCCompiler.SyntaxTree public compiler_directive Last() { - return compiler_directives[compiler_directives.Count - 1]; + if (compiler_directives.Count > 0) + return compiler_directives[compiler_directives.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -11794,6 +12268,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, compiler_directive el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); compiler_directives.Insert(pos,el); if (el != null) el.Parent = this; @@ -13405,9 +13881,10 @@ namespace PascalABCCompiler.SyntaxTree public method_name Add(ident elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); ln.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -13415,12 +13892,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); ln.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); ln.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -13429,6 +13910,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params ident[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); ln.AddRange(els); foreach (var el in els) if (el != null) @@ -13437,6 +13920,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = ln.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -13445,13 +13930,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); ln.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); ln.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -13460,13 +13952,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); ln.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); ln.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -13480,13 +13979,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(ident el, ident newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); ln[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(ident el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); ln.RemoveAt(ind); ln.InsertRange(ind, newels); @@ -13502,7 +14008,9 @@ namespace PascalABCCompiler.SyntaxTree public ident Last() { - return ln[ln.Count - 1]; + if (ln.Count > 0) + return ln[ln.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -13512,6 +14020,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, ident el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); ln.Insert(pos,el); if (el != null) el.Parent = this; @@ -16171,9 +16681,10 @@ namespace PascalABCCompiler.SyntaxTree public class_members Add(declaration elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); members.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -16181,12 +16692,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); members.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); members.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -16195,6 +16710,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params declaration[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); members.AddRange(els); foreach (var el in els) if (el != null) @@ -16203,6 +16720,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = members.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -16211,13 +16730,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); members.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); members.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -16226,13 +16752,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); members.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); members.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -16246,13 +16779,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); members[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); members.RemoveAt(ind); members.InsertRange(ind, newels); @@ -16268,7 +16808,9 @@ namespace PascalABCCompiler.SyntaxTree public declaration Last() { - return members[members.Count - 1]; + if (members.Count > 0) + return members[members.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -16278,6 +16820,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); members.Insert(pos,el); if (el != null) el.Parent = this; @@ -16609,9 +17153,10 @@ namespace PascalABCCompiler.SyntaxTree public class_body Add(class_members elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); class_def_blocks.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -16619,12 +17164,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(class_members el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); class_def_blocks.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); class_def_blocks.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -16633,6 +17182,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params class_members[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); class_def_blocks.AddRange(els); foreach (var el in els) if (el != null) @@ -16641,6 +17192,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(class_members el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = class_def_blocks.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -16649,13 +17202,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(class_members el, class_members newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); class_def_blocks.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(class_members el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); class_def_blocks.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -16664,13 +17224,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(class_members el, class_members newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); class_def_blocks.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(class_members el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); class_def_blocks.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -16684,13 +17251,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(class_members el, class_members newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); class_def_blocks[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(class_members el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); class_def_blocks.RemoveAt(ind); class_def_blocks.InsertRange(ind, newels); @@ -16706,7 +17280,9 @@ namespace PascalABCCompiler.SyntaxTree public class_members Last() { - return class_def_blocks[class_def_blocks.Count - 1]; + if (class_def_blocks.Count > 0) + return class_def_blocks[class_def_blocks.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -16716,6 +17292,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, class_members el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); class_def_blocks.Insert(pos,el); if (el != null) el.Parent = this; @@ -17927,9 +18505,10 @@ namespace PascalABCCompiler.SyntaxTree public record_const Add(record_const_definition elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); rec_consts.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -17937,12 +18516,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(record_const_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); rec_consts.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); rec_consts.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -17951,6 +18534,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params record_const_definition[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); rec_consts.AddRange(els); foreach (var el in els) if (el != null) @@ -17959,6 +18544,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(record_const_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = rec_consts.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -17967,13 +18554,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(record_const_definition el, record_const_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); rec_consts.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(record_const_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); rec_consts.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -17982,13 +18576,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(record_const_definition el, record_const_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); rec_consts.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(record_const_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); rec_consts.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -18002,13 +18603,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(record_const_definition el, record_const_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); rec_consts[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(record_const_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); rec_consts.RemoveAt(ind); rec_consts.InsertRange(ind, newels); @@ -18024,7 +18632,9 @@ namespace PascalABCCompiler.SyntaxTree public record_const_definition Last() { - return rec_consts[rec_consts.Count - 1]; + if (rec_consts.Count > 0) + return rec_consts[rec_consts.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -18034,6 +18644,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, record_const_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); rec_consts.Insert(pos,el); if (el != null) el.Parent = this; @@ -19065,9 +19677,10 @@ namespace PascalABCCompiler.SyntaxTree public literal_const_line Add(literal elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); literals.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -19075,12 +19688,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(literal el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); literals.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); literals.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -19089,6 +19706,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params literal[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); literals.AddRange(els); foreach (var el in els) if (el != null) @@ -19097,6 +19716,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(literal el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = literals.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -19105,13 +19726,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(literal el, literal newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); literals.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(literal el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); literals.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -19120,13 +19748,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(literal el, literal newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); literals.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(literal el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); literals.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -19140,13 +19775,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(literal el, literal newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); literals[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(literal el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); literals.RemoveAt(ind); literals.InsertRange(ind, newels); @@ -19162,7 +19804,9 @@ namespace PascalABCCompiler.SyntaxTree public literal Last() { - return literals[literals.Count - 1]; + if (literals.Count > 0) + return literals[literals.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -19172,6 +19816,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, literal el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); literals.Insert(pos,el); if (el != null) el.Parent = this; @@ -19763,9 +20409,10 @@ namespace PascalABCCompiler.SyntaxTree public variant_list Add(variant elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); vars.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -19773,12 +20420,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(variant el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); vars.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); vars.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -19787,6 +20438,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params variant[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); vars.AddRange(els); foreach (var el in els) if (el != null) @@ -19795,6 +20448,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(variant el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = vars.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -19803,13 +20458,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(variant el, variant newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(variant el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); vars.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -19818,13 +20480,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(variant el, variant newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(variant el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); vars.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -19838,13 +20507,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(variant el, variant newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(variant el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); vars.RemoveAt(ind); vars.InsertRange(ind, newels); @@ -19860,7 +20536,9 @@ namespace PascalABCCompiler.SyntaxTree public variant Last() { - return vars[vars.Count - 1]; + if (vars.Count > 0) + return vars[vars.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -19870,6 +20548,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, variant el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); vars.Insert(pos,el); if (el != null) el.Parent = this; @@ -20231,9 +20911,10 @@ namespace PascalABCCompiler.SyntaxTree public variant_types Add(variant_type elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); vars.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -20241,12 +20922,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(variant_type el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); vars.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); vars.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -20255,6 +20940,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params variant_type[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); vars.AddRange(els); foreach (var el in els) if (el != null) @@ -20263,6 +20950,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(variant_type el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = vars.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -20271,13 +20960,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(variant_type el, variant_type newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(variant_type el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); vars.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -20286,13 +20982,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(variant_type el, variant_type newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(variant_type el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); vars.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -20306,13 +21009,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(variant_type el, variant_type newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(variant_type el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); vars.RemoveAt(ind); vars.InsertRange(ind, newels); @@ -20328,7 +21038,9 @@ namespace PascalABCCompiler.SyntaxTree public variant_type Last() { - return vars[vars.Count - 1]; + if (vars.Count > 0) + return vars[vars.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -20338,6 +21050,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, variant_type el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); vars.Insert(pos,el); if (el != null) el.Parent = this; @@ -23508,9 +24222,10 @@ namespace PascalABCCompiler.SyntaxTree public case_variants Add(case_variant elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); variants.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -23518,12 +24233,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(case_variant el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); variants.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); variants.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -23532,6 +24251,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params case_variant[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); variants.AddRange(els); foreach (var el in els) if (el != null) @@ -23540,6 +24261,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(case_variant el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = variants.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -23548,13 +24271,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(case_variant el, case_variant newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); variants.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(case_variant el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); variants.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -23563,13 +24293,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(case_variant el, case_variant newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); variants.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(case_variant el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); variants.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -23583,13 +24320,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(case_variant el, case_variant newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); variants[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(case_variant el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); variants.RemoveAt(ind); variants.InsertRange(ind, newels); @@ -23605,7 +24349,9 @@ namespace PascalABCCompiler.SyntaxTree public case_variant Last() { - return variants[variants.Count - 1]; + if (variants.Count > 0) + return variants[variants.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -23615,6 +24361,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, case_variant el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); variants.Insert(pos,el); if (el != null) el.Parent = this; @@ -23984,9 +24732,10 @@ namespace PascalABCCompiler.SyntaxTree public var_def_list_for_record Add(var_def_statement elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); vars.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -23994,12 +24743,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(var_def_statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); vars.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); vars.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -24008,6 +24761,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params var_def_statement[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); vars.AddRange(els); foreach (var el in els) if (el != null) @@ -24016,6 +24771,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(var_def_statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = vars.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -24024,13 +24781,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(var_def_statement el, var_def_statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(var_def_statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); vars.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -24039,13 +24803,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(var_def_statement el, var_def_statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(var_def_statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); vars.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -24059,13 +24830,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(var_def_statement el, var_def_statement newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); vars[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(var_def_statement el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); vars.RemoveAt(ind); vars.InsertRange(ind, newels); @@ -24081,7 +24859,9 @@ namespace PascalABCCompiler.SyntaxTree public var_def_statement Last() { - return vars[vars.Count - 1]; + if (vars.Count > 0) + return vars[vars.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -24091,6 +24871,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, var_def_statement el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); vars.Insert(pos,el); if (el != null) el.Parent = this; @@ -24931,9 +25713,10 @@ namespace PascalABCCompiler.SyntaxTree public property_parameter_list Add(property_parameter elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); parameters.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -24941,12 +25724,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(property_parameter el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); parameters.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); parameters.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -24955,6 +25742,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params property_parameter[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); parameters.AddRange(els); foreach (var el in els) if (el != null) @@ -24963,6 +25752,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(property_parameter el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = parameters.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -24971,13 +25762,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(property_parameter el, property_parameter newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); parameters.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(property_parameter el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); parameters.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -24986,13 +25784,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(property_parameter el, property_parameter newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); parameters.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(property_parameter el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); parameters.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -25006,13 +25811,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(property_parameter el, property_parameter newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); parameters[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(property_parameter el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); parameters.RemoveAt(ind); parameters.InsertRange(ind, newels); @@ -25028,7 +25840,9 @@ namespace PascalABCCompiler.SyntaxTree public property_parameter Last() { - return parameters[parameters.Count - 1]; + if (parameters.Count > 0) + return parameters[parameters.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -25038,6 +25852,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, property_parameter el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); parameters.Insert(pos,el); if (el != null) el.Parent = this; @@ -26937,9 +27753,10 @@ namespace PascalABCCompiler.SyntaxTree public exception_handler_list Add(exception_handler elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); handlers.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -26947,12 +27764,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(exception_handler el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); handlers.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); handlers.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -26961,6 +27782,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params exception_handler[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); handlers.AddRange(els); foreach (var el in els) if (el != null) @@ -26969,6 +27792,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(exception_handler el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = handlers.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -26977,13 +27802,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(exception_handler el, exception_handler newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); handlers.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(exception_handler el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); handlers.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -26992,13 +27824,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(exception_handler el, exception_handler newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); handlers.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(exception_handler el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); handlers.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -27012,13 +27851,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(exception_handler el, exception_handler newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); handlers[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(exception_handler el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); handlers.RemoveAt(ind); handlers.InsertRange(ind, newels); @@ -27034,7 +27880,9 @@ namespace PascalABCCompiler.SyntaxTree public exception_handler Last() { - return handlers[handlers.Count - 1]; + if (handlers.Count > 0) + return handlers[handlers.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -27044,6 +27892,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, exception_handler el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); handlers.Insert(pos,el); if (el != null) el.Parent = this; @@ -28286,9 +29136,10 @@ namespace PascalABCCompiler.SyntaxTree public using_list Add(unit_or_namespace elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); namespaces.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -28296,12 +29147,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(unit_or_namespace el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); namespaces.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); namespaces.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -28310,6 +29165,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params unit_or_namespace[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); namespaces.AddRange(els); foreach (var el in els) if (el != null) @@ -28318,6 +29175,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(unit_or_namespace el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = namespaces.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -28326,13 +29185,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(unit_or_namespace el, unit_or_namespace newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); namespaces.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(unit_or_namespace el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); namespaces.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -28341,13 +29207,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(unit_or_namespace el, unit_or_namespace newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); namespaces.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(unit_or_namespace el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); namespaces.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -28361,13 +29234,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(unit_or_namespace el, unit_or_namespace newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); namespaces[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(unit_or_namespace el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); namespaces.RemoveAt(ind); namespaces.InsertRange(ind, newels); @@ -28383,7 +29263,9 @@ namespace PascalABCCompiler.SyntaxTree public unit_or_namespace Last() { - return namespaces[namespaces.Count - 1]; + if (namespaces.Count > 0) + return namespaces[namespaces.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -28393,6 +29275,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, unit_or_namespace el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); namespaces.Insert(pos,el); if (el != null) el.Parent = this; @@ -29253,9 +30137,10 @@ namespace PascalABCCompiler.SyntaxTree public named_type_reference_list Add(named_type_reference elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); types.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -29263,12 +30148,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(named_type_reference el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); types.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); types.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -29277,6 +30166,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params named_type_reference[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); types.AddRange(els); foreach (var el in els) if (el != null) @@ -29285,6 +30176,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(named_type_reference el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = types.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -29293,13 +30186,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(named_type_reference el, named_type_reference newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); types.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(named_type_reference el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); types.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -29308,13 +30208,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(named_type_reference el, named_type_reference newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); types.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(named_type_reference el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); types.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -29328,13 +30235,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(named_type_reference el, named_type_reference newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); types[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(named_type_reference el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); types.RemoveAt(ind); types.InsertRange(ind, newels); @@ -29350,7 +30264,9 @@ namespace PascalABCCompiler.SyntaxTree public named_type_reference Last() { - return types[types.Count - 1]; + if (types.Count > 0) + return types[types.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -29360,6 +30276,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, named_type_reference el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); types.Insert(pos,el); if (el != null) el.Parent = this; @@ -29564,9 +30482,10 @@ namespace PascalABCCompiler.SyntaxTree public template_param_list Add(type_definition elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); params_list.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -29574,12 +30493,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); params_list.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); params_list.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -29588,6 +30511,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params type_definition[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); params_list.AddRange(els); foreach (var el in els) if (el != null) @@ -29596,6 +30521,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = params_list.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -29604,13 +30531,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); params_list.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); params_list.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -29619,13 +30553,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); params_list.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); params_list.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -29639,13 +30580,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); params_list[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); params_list.RemoveAt(ind); params_list.InsertRange(ind, newels); @@ -29661,7 +30609,9 @@ namespace PascalABCCompiler.SyntaxTree public type_definition Last() { - return params_list[params_list.Count - 1]; + if (params_list.Count > 0) + return params_list[params_list.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -29671,6 +30621,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); params_list.Insert(pos,el); if (el != null) el.Parent = this; @@ -30656,9 +31608,10 @@ namespace PascalABCCompiler.SyntaxTree public where_type_specificator_list Add(type_definition elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); defs.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -30666,12 +31619,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -30680,6 +31637,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params type_definition[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.AddRange(els); foreach (var el in els) if (el != null) @@ -30688,6 +31647,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = defs.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -30696,13 +31657,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -30711,13 +31679,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -30731,13 +31706,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(type_definition el, type_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(type_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); defs.RemoveAt(ind); defs.InsertRange(ind, newels); @@ -30753,7 +31735,9 @@ namespace PascalABCCompiler.SyntaxTree public type_definition Last() { - return defs[defs.Count - 1]; + if (defs.Count > 0) + return defs[defs.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -30763,6 +31747,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, type_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(pos,el); if (el != null) el.Parent = this; @@ -31124,9 +32110,10 @@ namespace PascalABCCompiler.SyntaxTree public where_definition_list Add(where_definition elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); defs.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -31134,12 +32121,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(where_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -31148,6 +32139,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params where_definition[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.AddRange(els); foreach (var el in els) if (el != null) @@ -31156,6 +32149,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(where_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = defs.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -31164,13 +32159,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(where_definition el, where_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(where_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -31179,13 +32181,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(where_definition el, where_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(where_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -31199,13 +32208,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(where_definition el, where_definition newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(where_definition el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); defs.RemoveAt(ind); defs.InsertRange(ind, newels); @@ -31221,7 +32237,9 @@ namespace PascalABCCompiler.SyntaxTree public where_definition Last() { - return defs[defs.Count - 1]; + if (defs.Count > 0) + return defs[defs.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -31231,6 +32249,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, where_definition el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(pos,el); if (el != null) el.Parent = this; @@ -33587,9 +34607,10 @@ namespace PascalABCCompiler.SyntaxTree public enumerator_list Add(enumerator elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); enumerators.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -33597,12 +34618,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(enumerator el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); enumerators.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); enumerators.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -33611,6 +34636,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params enumerator[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); enumerators.AddRange(els); foreach (var el in els) if (el != null) @@ -33619,6 +34646,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(enumerator el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = enumerators.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -33627,13 +34656,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(enumerator el, enumerator newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); enumerators.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(enumerator el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); enumerators.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -33642,13 +34678,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(enumerator el, enumerator newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); enumerators.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(enumerator el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); enumerators.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -33662,13 +34705,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(enumerator el, enumerator newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); enumerators[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(enumerator el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); enumerators.RemoveAt(ind); enumerators.InsertRange(ind, newels); @@ -33684,7 +34734,9 @@ namespace PascalABCCompiler.SyntaxTree public enumerator Last() { - return enumerators[enumerators.Count - 1]; + if (enumerators.Count > 0) + return enumerators[enumerators.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -33694,6 +34746,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, enumerator el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); enumerators.Insert(pos,el); if (el != null) el.Parent = this; @@ -34330,9 +35384,10 @@ namespace PascalABCCompiler.SyntaxTree public type_definition_attr_list Add(type_definition_attr elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); attributes.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -34340,12 +35395,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(type_definition_attr el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); attributes.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); attributes.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -34354,6 +35413,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params type_definition_attr[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); attributes.AddRange(els); foreach (var el in els) if (el != null) @@ -34362,6 +35423,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(type_definition_attr el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = attributes.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -34370,13 +35433,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(type_definition_attr el, type_definition_attr newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(type_definition_attr el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); attributes.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -34385,13 +35455,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(type_definition_attr el, type_definition_attr newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(type_definition_attr el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); attributes.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -34405,13 +35482,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(type_definition_attr el, type_definition_attr newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(type_definition_attr el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); attributes.RemoveAt(ind); attributes.InsertRange(ind, newels); @@ -34427,7 +35511,9 @@ namespace PascalABCCompiler.SyntaxTree public type_definition_attr Last() { - return attributes[attributes.Count - 1]; + if (attributes.Count > 0) + return attributes[attributes.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -34437,6 +35523,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, type_definition_attr el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); attributes.Insert(pos,el); if (el != null) el.Parent = this; @@ -35006,9 +36094,10 @@ namespace PascalABCCompiler.SyntaxTree public compiler_directive_list Add(compiler_directive elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); directives.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -35016,12 +36105,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(compiler_directive el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); directives.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); directives.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -35030,6 +36123,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params compiler_directive[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); directives.AddRange(els); foreach (var el in els) if (el != null) @@ -35038,6 +36133,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(compiler_directive el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = directives.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -35046,13 +36143,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(compiler_directive el, compiler_directive newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); directives.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(compiler_directive el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); directives.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -35061,13 +36165,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(compiler_directive el, compiler_directive newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); directives.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(compiler_directive el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); directives.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -35081,13 +36192,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(compiler_directive el, compiler_directive newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); directives[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(compiler_directive el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); directives.RemoveAt(ind); directives.InsertRange(ind, newels); @@ -35103,7 +36221,9 @@ namespace PascalABCCompiler.SyntaxTree public compiler_directive Last() { - return directives[directives.Count - 1]; + if (directives.Count > 0) + return directives[directives.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -35113,6 +36233,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, compiler_directive el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); directives.Insert(pos,el); if (el != null) el.Parent = this; @@ -35557,9 +36679,10 @@ namespace PascalABCCompiler.SyntaxTree public documentation_comment_list Add(documentation_comment_section elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); sections.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -35567,12 +36690,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(documentation_comment_section el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); sections.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); sections.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -35581,6 +36708,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params documentation_comment_section[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); sections.AddRange(els); foreach (var el in els) if (el != null) @@ -35589,6 +36718,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(documentation_comment_section el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = sections.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -35597,13 +36728,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(documentation_comment_section el, documentation_comment_section newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); sections.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(documentation_comment_section el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); sections.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -35612,13 +36750,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(documentation_comment_section el, documentation_comment_section newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); sections.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(documentation_comment_section el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); sections.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -35632,13 +36777,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(documentation_comment_section el, documentation_comment_section newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); sections[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(documentation_comment_section el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); sections.RemoveAt(ind); sections.InsertRange(ind, newels); @@ -35654,7 +36806,9 @@ namespace PascalABCCompiler.SyntaxTree public documentation_comment_section Last() { - return sections[sections.Count - 1]; + if (sections.Count > 0) + return sections[sections.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -35664,6 +36818,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, documentation_comment_section el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); sections.Insert(pos,el); if (el != null) el.Parent = this; @@ -35883,9 +37039,10 @@ namespace PascalABCCompiler.SyntaxTree public documentation_comment_tag Add(documentation_comment_tag_param elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); parameters.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -35893,12 +37050,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(documentation_comment_tag_param el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); parameters.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); parameters.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -35907,6 +37068,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params documentation_comment_tag_param[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); parameters.AddRange(els); foreach (var el in els) if (el != null) @@ -35915,6 +37078,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(documentation_comment_tag_param el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = parameters.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -35923,13 +37088,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(documentation_comment_tag_param el, documentation_comment_tag_param newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); parameters.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(documentation_comment_tag_param el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); parameters.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -35938,13 +37110,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(documentation_comment_tag_param el, documentation_comment_tag_param newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); parameters.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(documentation_comment_tag_param el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); parameters.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -35958,13 +37137,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(documentation_comment_tag_param el, documentation_comment_tag_param newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); parameters[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(documentation_comment_tag_param el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); parameters.RemoveAt(ind); parameters.InsertRange(ind, newels); @@ -35980,7 +37166,9 @@ namespace PascalABCCompiler.SyntaxTree public documentation_comment_tag_param Last() { - return parameters[parameters.Count - 1]; + if (parameters.Count > 0) + return parameters[parameters.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -35990,6 +37178,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, documentation_comment_tag_param el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); parameters.Insert(pos,el); if (el != null) el.Parent = this; @@ -36341,9 +37531,10 @@ namespace PascalABCCompiler.SyntaxTree public documentation_comment_section Add(documentation_comment_tag elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); tags.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -36351,12 +37542,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(documentation_comment_tag el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); tags.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); tags.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -36365,6 +37560,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params documentation_comment_tag[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); tags.AddRange(els); foreach (var el in els) if (el != null) @@ -36373,6 +37570,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(documentation_comment_tag el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = tags.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -36381,13 +37580,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(documentation_comment_tag el, documentation_comment_tag newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); tags.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(documentation_comment_tag el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); tags.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -36396,13 +37602,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(documentation_comment_tag el, documentation_comment_tag newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); tags.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(documentation_comment_tag el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); tags.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -36416,13 +37629,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(documentation_comment_tag el, documentation_comment_tag newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); tags[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(documentation_comment_tag el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); tags.RemoveAt(ind); tags.InsertRange(ind, newels); @@ -36438,7 +37658,9 @@ namespace PascalABCCompiler.SyntaxTree public documentation_comment_tag Last() { - return tags[tags.Count - 1]; + if (tags.Count > 0) + return tags[tags.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -36448,6 +37670,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, documentation_comment_tag el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); tags.Insert(pos,el); if (el != null) el.Parent = this; @@ -37863,9 +39087,10 @@ namespace PascalABCCompiler.SyntaxTree public simple_attribute_list Add(attribute elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); attributes.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -37873,12 +39098,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(attribute el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); attributes.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); attributes.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -37887,6 +39116,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params attribute[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); attributes.AddRange(els); foreach (var el in els) if (el != null) @@ -37895,6 +39126,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(attribute el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = attributes.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -37903,13 +39136,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(attribute el, attribute newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(attribute el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); attributes.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -37918,13 +39158,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(attribute el, attribute newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(attribute el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); attributes.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -37938,13 +39185,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(attribute el, attribute newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(attribute el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); attributes.RemoveAt(ind); attributes.InsertRange(ind, newels); @@ -37960,7 +39214,9 @@ namespace PascalABCCompiler.SyntaxTree public attribute Last() { - return attributes[attributes.Count - 1]; + if (attributes.Count > 0) + return attributes[attributes.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -37970,6 +39226,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, attribute el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); attributes.Insert(pos,el); if (el != null) el.Parent = this; @@ -38153,9 +39411,10 @@ namespace PascalABCCompiler.SyntaxTree public attribute_list Add(simple_attribute_list elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); attributes.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -38163,12 +39422,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(simple_attribute_list el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); attributes.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); attributes.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -38177,6 +39440,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params simple_attribute_list[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); attributes.AddRange(els); foreach (var el in els) if (el != null) @@ -38185,6 +39450,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(simple_attribute_list el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = attributes.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -38193,13 +39460,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(simple_attribute_list el, simple_attribute_list newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(simple_attribute_list el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); attributes.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -38208,13 +39482,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(simple_attribute_list el, simple_attribute_list newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(simple_attribute_list el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); attributes.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -38228,13 +39509,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(simple_attribute_list el, simple_attribute_list newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); attributes[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(simple_attribute_list el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); attributes.RemoveAt(ind); attributes.InsertRange(ind, newels); @@ -38250,7 +39538,9 @@ namespace PascalABCCompiler.SyntaxTree public simple_attribute_list Last() { - return attributes[attributes.Count - 1]; + if (attributes.Count > 0) + return attributes[attributes.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -38260,6 +39550,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, simple_attribute_list el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); attributes.Insert(pos,el); if (el != null) el.Parent = this; @@ -38623,9 +39915,10 @@ namespace PascalABCCompiler.SyntaxTree public function_lambda_definition Add(declaration elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); defs.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -38633,12 +39926,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -38647,6 +39944,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params declaration[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); defs.AddRange(els); foreach (var el in els) if (el != null) @@ -38655,6 +39954,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = defs.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -38663,13 +39964,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -38678,13 +39986,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); defs.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -38698,13 +40013,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(declaration el, declaration newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); defs[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(declaration el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); defs.RemoveAt(ind); defs.InsertRange(ind, newels); @@ -38720,7 +40042,9 @@ namespace PascalABCCompiler.SyntaxTree public declaration Last() { - return defs[defs.Count - 1]; + if (defs.Count > 0) + return defs[defs.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -38730,6 +40054,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, declaration el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); defs.Insert(pos,el); if (el != null) el.Parent = this; @@ -39243,9 +40569,10 @@ namespace PascalABCCompiler.SyntaxTree public semantic_check Add(syntax_tree_node elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); param.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -39253,12 +40580,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(syntax_tree_node el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); param.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); param.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -39267,6 +40598,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params syntax_tree_node[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); param.AddRange(els); foreach (var el in els) if (el != null) @@ -39275,6 +40608,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(syntax_tree_node el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = param.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -39283,13 +40618,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(syntax_tree_node el, syntax_tree_node newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); param.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(syntax_tree_node el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); param.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -39298,13 +40640,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(syntax_tree_node el, syntax_tree_node newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); param.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(syntax_tree_node el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); param.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -39318,13 +40667,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(syntax_tree_node el, syntax_tree_node newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); param[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(syntax_tree_node el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); param.RemoveAt(ind); param.InsertRange(ind, newels); @@ -39340,7 +40696,9 @@ namespace PascalABCCompiler.SyntaxTree public syntax_tree_node Last() { - return param[param.Count - 1]; + if (param.Count > 0) + return param[param.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -39350,6 +40708,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, syntax_tree_node el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); param.Insert(pos,el); if (el != null) el.Parent = this; @@ -40087,9 +41447,10 @@ namespace PascalABCCompiler.SyntaxTree public name_assign_expr_list Add(name_assign_expr elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); name_expr.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -40097,12 +41458,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(name_assign_expr el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); name_expr.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); name_expr.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -40111,6 +41476,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params name_assign_expr[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); name_expr.AddRange(els); foreach (var el in els) if (el != null) @@ -40119,6 +41486,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(name_assign_expr el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = name_expr.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -40127,13 +41496,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(name_assign_expr el, name_assign_expr newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); name_expr.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(name_assign_expr el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); name_expr.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -40142,13 +41518,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(name_assign_expr el, name_assign_expr newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); name_expr.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(name_assign_expr el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); name_expr.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -40162,13 +41545,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(name_assign_expr el, name_assign_expr newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); name_expr[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(name_assign_expr el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); name_expr.RemoveAt(ind); name_expr.InsertRange(ind, newels); @@ -40184,7 +41574,9 @@ namespace PascalABCCompiler.SyntaxTree public name_assign_expr Last() { - return name_expr[name_expr.Count - 1]; + if (name_expr.Count > 0) + return name_expr[name_expr.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -40194,6 +41586,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, name_assign_expr el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); name_expr.Insert(pos,el); if (el != null) el.Parent = this; @@ -42761,9 +44155,10 @@ namespace PascalABCCompiler.SyntaxTree public addressed_value_list Add(addressed_value elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); variables.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -42771,12 +44166,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(addressed_value el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); variables.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); variables.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -42785,6 +44184,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params addressed_value[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); variables.AddRange(els); foreach (var el in els) if (el != null) @@ -42793,6 +44194,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(addressed_value el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = variables.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -42801,13 +44204,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(addressed_value el, addressed_value newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); variables.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(addressed_value el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); variables.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -42816,13 +44226,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(addressed_value el, addressed_value newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); variables.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(addressed_value el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); variables.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -42836,13 +44253,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(addressed_value el, addressed_value newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); variables[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(addressed_value el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); variables.RemoveAt(ind); variables.InsertRange(ind, newels); @@ -42858,7 +44282,9 @@ namespace PascalABCCompiler.SyntaxTree public addressed_value Last() { - return variables[variables.Count - 1]; + if (variables.Count > 0) + return variables[variables.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -42868,6 +44294,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, addressed_value el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); variables.Insert(pos,el); if (el != null) el.Parent = this; @@ -43227,9 +44655,10 @@ namespace PascalABCCompiler.SyntaxTree public uses_closure Add(uses_list elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); listunitsections.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -43237,12 +44666,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(uses_list el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); listunitsections.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); listunitsections.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -43251,6 +44684,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params uses_list[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); listunitsections.AddRange(els); foreach (var el in els) if (el != null) @@ -43259,6 +44694,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(uses_list el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = listunitsections.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -43267,13 +44704,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(uses_list el, uses_list newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); listunitsections.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(uses_list el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); listunitsections.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -43282,13 +44726,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(uses_list el, uses_list newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); listunitsections.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(uses_list el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); listunitsections.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -43302,13 +44753,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(uses_list el, uses_list newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); listunitsections[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(uses_list el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); listunitsections.RemoveAt(ind); listunitsections.InsertRange(ind, newels); @@ -43324,7 +44782,9 @@ namespace PascalABCCompiler.SyntaxTree public uses_list Last() { - return listunitsections[listunitsections.Count - 1]; + if (listunitsections.Count > 0) + return listunitsections[listunitsections.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -43334,6 +44794,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, uses_list el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); listunitsections.Insert(pos,el); if (el != null) el.Parent = this; @@ -45125,9 +46587,10 @@ namespace PascalABCCompiler.SyntaxTree public semantic_check_sugared_statement_node Add(syntax_tree_node elem, SourceContext sc = null) { + if (elem == null) + throw new ArgumentNullException(nameof(elem)); lst.Add(elem); - if (elem != null) - elem.Parent = this; + elem.Parent = this; if (sc != null) source_context = sc; return this; @@ -45135,12 +46598,16 @@ namespace PascalABCCompiler.SyntaxTree public void AddFirst(syntax_tree_node el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); lst.Insert(0, el); FillParentsInDirectChilds(); } public void AddFirst(IEnumerable els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); lst.InsertRange(0, els); foreach (var el in els) if (el != null) @@ -45149,6 +46616,8 @@ namespace PascalABCCompiler.SyntaxTree public void AddMany(params syntax_tree_node[] els) { + if (els == null) + throw new ArgumentNullException(nameof(els)); lst.AddRange(els); foreach (var el in els) if (el != null) @@ -45157,6 +46626,8 @@ namespace PascalABCCompiler.SyntaxTree private int FindIndexInList(syntax_tree_node el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); var ind = lst.FindIndex(x => x == el); if (ind == -1) throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el)); @@ -45165,13 +46636,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertAfter(syntax_tree_node el, syntax_tree_node newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); lst.Insert(FindIndexInList(el) + 1, newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertAfter(syntax_tree_node el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); lst.InsertRange(FindIndexInList(el) + 1, newels); foreach (var newel in newels) if (newel != null) @@ -45180,13 +46658,20 @@ namespace PascalABCCompiler.SyntaxTree public void InsertBefore(syntax_tree_node el, syntax_tree_node newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); lst.Insert(FindIndexInList(el), newel); - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void InsertBefore(syntax_tree_node el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); lst.InsertRange(FindIndexInList(el), newels); foreach (var newel in newels) if (newel != null) @@ -45200,13 +46685,20 @@ namespace PascalABCCompiler.SyntaxTree public void ReplaceInList(syntax_tree_node el, syntax_tree_node newel) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newel == null) + throw new ArgumentNullException(nameof(newel)); lst[FindIndexInList(el)] = newel; - if (newel != null) - newel.Parent = this; + newel.Parent = this; } public void ReplaceInList(syntax_tree_node el, IEnumerable newels) { + if (el == null) + throw new ArgumentNullException(nameof(el)); + if (newels == null) + throw new ArgumentNullException(nameof(newels)); var ind = FindIndexInList(el); lst.RemoveAt(ind); lst.InsertRange(ind, newels); @@ -45222,7 +46714,9 @@ namespace PascalABCCompiler.SyntaxTree public syntax_tree_node Last() { - return lst[lst.Count - 1]; + if (lst.Count > 0) + return lst[lst.Count - 1]; + throw new InvalidOperationException("Список пуст"); } public int Count @@ -45232,6 +46726,8 @@ namespace PascalABCCompiler.SyntaxTree public void Insert(int pos, syntax_tree_node el) { + if (el == null) + throw new ArgumentNullException(nameof(el)); lst.Insert(pos,el); if (el != null) el.Parent = this;