diff --git a/DataScraping/XML/NamedItems.pas b/DataScraping/XML/NamedItems.pas index b60891fd..6336688a 100644 --- a/DataScraping/XML/NamedItems.pas +++ b/DataScraping/XML/NamedItems.pas @@ -289,10 +289,9 @@ {$region Pre-saving} - //TODO #3059: as, use operator explicit - protected function NameApi: string; virtual := (self.Name as IComplexName).ApiName; - protected function NameSuffix: string; virtual := (self.Name as IComplexName).VendorSuffix; - protected function NameLocal: string; virtual := (self.Name as IComplexName).LocalName; + protected function NameApi: string; virtual := IComplexName(self.Name).ApiName; + protected function NameSuffix: string; virtual := IComplexName(self.Name).VendorSuffix; + protected function NameLocal: string; virtual := IComplexName(self.Name).LocalName; protected function NameWithoutSuffix: TName; virtual; begin @@ -362,8 +361,7 @@ Sort(save_ready, item->item.Name); for var i := 0 to save_ready.Length-1 do - //TODO #3060: as - (save_ready[i] as NamedItem).bin_index := i; + save_ready[i].bin_index := i; end; @@ -417,8 +415,7 @@ end; public static function DistillAllUnique(inp: sequence of TSelf) := DistillAllUnique(inp, o->o, nil).ConvertAll(o->o.AfterMerges); - //TODO #3059: as, use operator explicit - protected procedure SaveName(bw: BinWriter); virtual := (Name as IBinSavable).Save(bw); + protected procedure SaveName(bw: BinWriter); virtual := IBinSavable(Name).Save(bw); protected procedure SaveBody(bw: BinWriter); abstract; private saved := false; public procedure Save(bw: BinWriter); diff --git a/Packing/Template/LowLvl/BinUtils.pas b/Packing/Template/LowLvl/BinUtils.pas index 5104ca15..85c83aea 100644 --- a/Packing/Template/LowLvl/BinUtils.pas +++ b/Packing/Template/LowLvl/BinUtils.pas @@ -1,8 +1,7 @@ unit BinUtils; -{$savepcu false} //TODO #3057 - uses System; +uses '..\..\..\Utils\TypeMagic'; type BinReader = System.IO.BinaryReader; @@ -51,8 +50,7 @@ function ReadEnum(self: BinReader): T; extensionmethod; if typeof(T).GetEnumUnderlyingType <> typeof(Int32) then raise new NotSupportedException; {$endif DEBUG} - //TODO #3056: as object - Result := T(self.ReadInt32() as object); + Result := ConvertTo&.FromUnchecked(self.ReadInt32()); end; end. \ No newline at end of file diff --git a/Packing/Template/LowLvl/Essentials.pas b/Packing/Template/LowLvl/Essentials.pas index 6317b55a..fece54b2 100644 --- a/Packing/Template/LowLvl/Essentials.pas +++ b/Packing/Template/LowLvl/Essentials.pas @@ -1,7 +1,5 @@ unit Essentials; -{$savepcu false} //TODO #3058 - interface uses System; diff --git a/Packing/Template/LowLvl/NamedItemHelpers.pas b/Packing/Template/LowLvl/NamedItemHelpers.pas index b9cf567d..2bd2ccf9 100644 --- a/Packing/Template/LowLvl/NamedItemHelpers.pas +++ b/Packing/Template/LowLvl/NamedItemHelpers.pas @@ -50,11 +50,8 @@ Otp($'WARNING: {kvp.Key} referenced itself'); end; - foreach var kvp in all_unused_reports do - kvp.Value(); - //TODO #3061: Заменить предыдущий цикл -// foreach var rep in all_unused_reports.Values do -// rep.Invoke(); + foreach var rep in all_unused_reports.values do + rep.Invoke(); all_unused_reports := nil; end; diff --git a/Packing/Template/LowLvl/NamedTypeItems.pas b/Packing/Template/LowLvl/NamedTypeItems.pas index e418d40d..cfa0c26c 100644 --- a/Packing/Template/LowLvl/NamedTypeItems.pas +++ b/Packing/Template/LowLvl/NamedTypeItems.pas @@ -2038,9 +2038,7 @@ interface begin if org_t1.Name.IsMatrix <> org_t2.Name.IsMatrix then exit; - //TODO #3062 -// foreach var (t1,t2) in |org_t1,org_t2|.Permutations do - foreach var (t1,t2) in |(org_t1,org_t2),(org_t2,org_t1)| do + foreach var (t1,t2) in |org_t1,org_t2|.Permutations do begin var t1_name := t1.Name.ToString(true); var t2_name := t2.Name.ToString(true); diff --git a/Packing/Template/LowLvl/ParData.pas b/Packing/Template/LowLvl/ParData.pas index f1af5cbe..822ccba0 100644 --- a/Packing/Template/LowLvl/ParData.pas +++ b/Packing/Template/LowLvl/ParData.pas @@ -27,8 +27,7 @@ interface private static inst := new ParArrSizeNotArray; public static property Instance: ParArrSizeNotArray read inst; - //TODO #3063: use Instance - static constructor := DefineLoader(PASK_NotArray, br->inst); + static constructor := DefineLoader(PASK_NotArray, br->Instance); end; @@ -39,8 +38,7 @@ interface private static inst := new ParArrSizeArbitrary; public static property Instance: ParArrSizeArbitrary read inst; - //TODO #3063: use Instance - static constructor := DefineLoader(PASK_Arbitrary, br->inst); + static constructor := DefineLoader(PASK_Arbitrary, br->Instance); end; diff --git a/Utils/Fixers.pas b/Utils/Fixers.pas index b96fae5d..4dfc97ea 100644 --- a/Utils/Fixers.pas +++ b/Utils/Fixers.pas @@ -53,7 +53,7 @@ interface var start := true; var bl_start := true; - //TODO #2683 + //TODO #2715 var make_res: function: (array of string,array of string) := ()-> begin var lc := res.Count; diff --git a/Utils/Patterns.pas b/Utils/Patterns.pas index f884fee3..7c9ce696 100644 --- a/Utils/Patterns.pas +++ b/Utils/Patterns.pas @@ -1,9 +1,6 @@ unit Patterns; {$zerobasedstrings} -//TODO #2739 -{$savepcu false} - interface uses System; diff --git a/Utils/Patterns/MergedStrings.pas b/Utils/Patterns/MergedStrings.pas index acab1d7c..afe13026 100644 --- a/Utils/Patterns/MergedStrings.pas +++ b/Utils/Patterns/MergedStrings.pas @@ -529,7 +529,7 @@ implementation private parts: array of MergedStringPart; private len_caps: array of MergedStringLength; - private constructor(parts: array of MergedStringPart); + private constructor(params parts: array of MergedStringPart); begin self.parts := parts; SetLength(len_caps, parts.Count); @@ -675,8 +675,7 @@ implementation function MergedStringPointer.IsOut := data.part_i = s.parts.Length; static function MergedString.Literal(s: string) := -//TODO #3064: adding params breaks case where array is passed to "new MergedString" -new MergedString(new MergedStringPart[](new MergedStringPartSolid(s))); +new MergedString(new MergedStringPartSolid(s)); static function MergedString.Parse(s: StringSection; escape_sym: char) := new MergedString(OptimizeParts(MakeParts(s, escape_sym)).ToArray); diff --git a/Utils/Patterns/test.pas b/Utils/Patterns/test.pas index 104e569a..a0aca4c9 100644 --- a/Utils/Patterns/test.pas +++ b/Utils/Patterns/test.pas @@ -37,9 +37,9 @@ var p: MergedString; begin - var ps := EnumerateFiles('G:/0Prog/AutoMaximize/Classes/1 What') + var ps := EnumerateFiles('G:\0Prog\AutoMaximize\Classes\1 What') .Select(System.IO.Path.GetFileName) - .Where(fname->fname.StartsWith('HwndWrapper')) +// .Where(fname->fname.StartsWith('HwndWrapper')) .Select(MergedString.Literal) .ToHashSet; while ps.Count.Println>1 do diff --git a/Utils/SubExecuters.pas b/Utils/SubExecuters.pas index 6dc573cf..4bb92537 100644 --- a/Utils/SubExecuters.pas +++ b/Utils/SubExecuters.pas @@ -7,8 +7,6 @@ uses PathUtils; uses Timers; -uses AQueue; //TODO #2543 - {$region Helpers} type diff --git a/Utils/TypeMagic.pas b/Utils/TypeMagic.pas new file mode 100644 index 00000000..fc72491a --- /dev/null +++ b/Utils/TypeMagic.pas @@ -0,0 +1,68 @@ +unit TypeMagic; + +interface + +type + + {$region Convert} + + ConvertTo = sealed class + + private constructor := raise new System.InvalidOperationException; + + public static function FromChecked(o: T2): T; + public static function FromUnchecked(o: T2): T; + public static function From(o: T2; checked: boolean := true) := + if checked then FromChecked(o) else FromUnchecked(o); + + end; + + {$endregion Convert} + +implementation + +uses System.Linq.Expressions; + +{$region Convert} + +type ConvertCache = sealed class + + private constructor := raise new System.InvalidOperationException; + + public static checked, unchecked: T2->T1; + private static function MakeFunc(conv: (Expression,System.Type)->Expression): T2->T1; + begin + try + var p := Expression.Parameter(typeof(T2)); + var c := conv(p, typeof(T1)); + var l := Expression.Lambda&>(c, p); + Result := l.Compile(); + except + on e: Exception do + begin + Result := o-> + begin + Result := default(T1); + raise new System.InvalidCastException($'Failed to make [{TypeToTypeName(typeof(T2))}]=>[{TypeToTypeName(typeof(T1))}] conversion', e); + end; + exit; + end; + end; + + end; + static constructor; + begin + checked := MakeFunc(Expression.ConvertChecked); + unchecked := MakeFunc(Expression.Convert); + end; + +end; + +static function ConvertTo.FromChecked(o: T2) := + ConvertCache&.checked(o); +static function ConvertTo.FromUnchecked(o: T2) := + ConvertCache&.unchecked(o); + +{$endregion Convert} + +end. \ No newline at end of file