Skip to content

Commit

Permalink
switched to collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Nov 8, 2023
1 parent 7d95ec5 commit 19cc97f
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class InteractiveShell
{
public const int MIN_WIDTH = 128;

internal static readonly string[] KNOWN_OPERATORS = { "+", "-", "*", "/", "+=", "-=", "*=", "/=", "&", "&=", "^", "<=", "<", ">", ">=", "<>", "=", "==" };
internal static readonly string[] KNOWN_OPERATORS = ["+", "-", "*", "/", "+=", "-=", "*=", "/=", "&", "&=", "^", "<=", "<", ">", ">=", "<>", "=", "=="];
private static readonly Regex REGEX_END_OF_MULTILINE = new(@"^(.*\s+)?(?<sep>_)$", RegexOptions.Compiled);
private static readonly RGBAColor COLOR_HELP_FG = 0xffff;
private static readonly RGBAColor COLOR_SEPARATOR = 0xfaaa;
Expand Down Expand Up @@ -230,15 +230,15 @@ private void MainLoop()

private void DrawResizeWarning()
{
string[] message = new[]
{
string[] message =
[
" CONSOLE WINDOW TOO SMALL! ",
"-----------------------------",
" Please resize this window ",
$" to a minimum size of {MIN_WIDTH}x32 ",
"to use the interactive shell.",
$" Current window size: {WIDTH}x{HEIGHT}"
};
];
int w = message.Max(l => l.Length);

ConsoleExtensions.RGBForegroundColor = RGBAColor.Red;
Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/CommandLineInterface/MainProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public static void PrintReturnCodeAndTelemetry(int retcode, Telemetry telemetry)
RGBAColor col_hotpath = RGBAColor.Salmon;

Regex regex_trimstart = new(@"^(?<space>\s*)0(?<rest>\d[:\.].+)$", RegexOptions.Compiled);
string[] headers = {
string[] headers = [
lang["debug.telemetry.columns.category"],
lang["debug.telemetry.columns.count"],
lang["debug.telemetry.columns.total"],
Expand All @@ -716,7 +716,7 @@ public static void PrintReturnCodeAndTelemetry(int retcode, Telemetry telemetry)
lang["debug.telemetry.columns.max"],
lang["debug.telemetry.columns.parent"],
lang["debug.telemetry.columns.relative"],
};
];
List<(string[] cells, TelemetryTimingsNode node)> rows = [];
static string ReplaceStart(string input, params (string search, string replace)[] substitutions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static FunctionReturnValue ConsoleClear(CallFrame frame, Variant[] args
}

internal static FunctionReturnValue ConsoleWriteLine(CallFrame frame, Variant[] args) =>
FrameworkFunctions.ConsoleWrite(frame, new[] { (args.Length > 0 ? args[0] : "") & "\r\n" });
FrameworkFunctions.ConsoleWrite(frame, [(args.Length > 0 ? args[0] : "") & "\r\n"]);

internal static FunctionReturnValue ConsoleReadLine(CallFrame frame, Variant[] args) => (Variant)Console.ReadLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ internal static FunctionReturnValue ConsoleRead(CallFrame frame, Variant[] args)
if (input < 0)
return FunctionReturnValue.Error(1);
else if (binary)
return Variant.FromBinary(new[] { (byte)(input & 0xff) });
return Variant.FromBinary([(byte)(input & 0xff)]);
else
return Variant.FromString(new string(new[] { (char)input }));
});
Expand Down Expand Up @@ -1855,14 +1855,14 @@ internal static FunctionReturnValue InetGetInfo(CallFrame frame, Variant[] args)
{
int index = (int)args[1];
Variant[] array =
{
[
0, // TODO : currently downloaded
0,
inet.Complete,
inet.Complete && !inet.Error,
inet.Error,
args[0]
};
];

return index >= 0 && index < array.Length ? array[index] : Variant.FromArray(frame.Interpreter, array);
}
Expand Down Expand Up @@ -2743,10 +2743,10 @@ internal static unsafe FunctionReturnValue Shutdown(CallFrame frame, Variant[] a
TOKEN_PRIVILEGES tk = new()
{
PrivilegeCount = 1,
Privileges = new[]
{
Privileges =
[
new LUID_AND_ATTRIBUTES { Attributes = 0x00000002 }
}
]
};
NativeInterop.LookupPrivilegeValue(null, "SeShutdownPrivilege", ref tk.Privileges[0].Luid);
NativeInterop.AdjustTokenPrivileges(token, false, ref tk, 0, null, null);
Expand Down
20 changes: 10 additions & 10 deletions new/AutoItInterpreter/Runtime/DelegateBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Reflection.Emit;
using System.Reflection;
Expand Down Expand Up @@ -63,7 +63,7 @@ private DelegateBuilder()
method_il.Emit(OpCodes.Stloc_0);

MethodInfo gettypefromhnd = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle))!;
ConstructorInfo tuplector = typeof((object, Type)).GetConstructor(new[] { typeof(object), typeof(Type) })!;
ConstructorInfo tuplector = typeof((object, Type)).GetConstructor([typeof(object), typeof(Type)])!;

for (int i = 0; i < @params.Length; ++i)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ private DelegateBuilder()
ILGenerator il_cctor = cctor_builder.GetILGenerator();

il_cctor.Emit(OpCodes.Ldftn, method_builder);
il_cctor.Emit(OpCodes.Call, typeof(IntPtr).GetMethod("op_Explicit", new[] { typeof(void*) })!);
il_cctor.Emit(OpCodes.Call, typeof(IntPtr).GetMethod("op_Explicit", [typeof(void*)])!);
il_cctor.Emit(OpCodes.Stsfld, field_ptr_builder);
il_cctor.Emit(OpCodes.Ret);

Expand Down Expand Up @@ -131,14 +131,14 @@ private DelegateBuilder()
signature.ReturnType.CallConvention.IsWinAPI ? CallingConvention.Winapi : CallingConvention.Cdecl;

delegate_builder.SetCustomAttribute(new CustomAttributeBuilder(
typeof(UnmanagedFunctionPointerAttribute).GetConstructor(new[] { typeof(CallingConvention) })!,
typeof(UnmanagedFunctionPointerAttribute).GetConstructor([typeof(CallingConvention)])!,
new object[] { callconv }
));

ConstructorBuilder constructor = delegate_builder.DefineConstructor(
MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
CallingConventions.Standard,
new[] { typeof(object), typeof(nint) }
[typeof(object), typeof(nint)]
);
constructor.SetImplementationFlags(MethodImplAttributes.CodeTypeMask);
constructor.DefineParameter(1, ParameterAttributes.None, "object");
Expand All @@ -156,7 +156,7 @@ private DelegateBuilder()
CallingConventions.Standard,
rettype,
null,
new[] {
[
callconv switch
{
CallingConvention.Cdecl => typeof(CallConvCdecl),
Expand All @@ -166,7 +166,7 @@ private DelegateBuilder()
CallingConvention.Winapi when NativeInterop.OperatingSystem == OS.Windows => typeof(CallConvStdcall),
_ => typeof(CallConvCdecl),
}
},
],
@params!,
null,
null
Expand All @@ -184,7 +184,7 @@ ParameterBuilder ProcessParameter(int index, TYPE type)

if (type.IsWSTR || type.IsSTR)
parameter.SetCustomAttribute(new CustomAttributeBuilder(
typeof(MarshalAsAttribute).GetConstructor(new[] { typeof(UnmanagedType) })!,
typeof(MarshalAsAttribute).GetConstructor([typeof(UnmanagedType)])!,
new object[] { type.IsWSTR ? UnmanagedType.LPWStr : UnmanagedType.LPStr }
));

Expand Down Expand Up @@ -276,11 +276,11 @@ ParameterBuilder ProcessParameter(int index, TYPE type)
// if (otypes[i].IsWSTR || otypes[i].IsSTR)
// attr |= FieldAttributes.HasFieldMarshal;

FieldBuilder field = builder.DefineField("Item" + i, ftype, new[] { typeof(MarshalAsAttribute) }, null, attr);
FieldBuilder field = builder.DefineField("Item" + i, ftype, [typeof(MarshalAsAttribute)], null, attr);

if (otypes[i].IsWSTR || otypes[i].IsSTR)
field.SetCustomAttribute(new CustomAttributeBuilder(
typeof(MarshalAsAttribute).GetConstructor(new[] { typeof(UnmanagedType) })!,
typeof(MarshalAsAttribute).GetConstructor([typeof(UnmanagedType)])!,
new object[] { otypes[i].IsWSTR ? UnmanagedType.LPWStr : UnmanagedType.LPStr }
));
}
Expand Down
6 changes: 3 additions & 3 deletions new/AutoItInterpreter/Runtime/Function.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
Expand All @@ -25,12 +25,12 @@ public abstract class ScriptFunction
/// A collection of reserved function names.
/// </summary>
public static readonly string[] RESERVED_NAMES =
{
[
"_", "$_", VARIABLE.Discard.Name, "$GLOBAL", "GLOBAL", "STATIC", "CONST", "DIM", "REDIM", "ENUM", "STEP", "LOCAL", "FOR", "IN",
"NEXT", "TO", "FUNC", "ENDFUNC", "DO", "UNTIL", "WHILE", "WEND", "IF", "THEN", "ELSE", "ENDIF", "ELSEIF", "SELECT", "ENDSELECT",
"CASE", "SWITCH", "ENDSWITCH", "WITH", "ENDWITH", "CONTINUECASE", "CONTINUELOOP", "EXIT", "EXITLOOP", "CACHED", "VOLATILE",
"RETURN", "TRUE", "FALSE", "DEFAULT", "NULL", "BYREF", "REF", "AND", "OR", "NOT", "CLEAR", "NEW", "DELETE", "CLASS",
};
];


/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/Runtime/GlobalObjectStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ orderby pars.Length descending
return false;
}

public bool TrySetNETIndex(object instance, Variant index, Variant value) => TryInvokeNETMember(instance, "set_Item", new[] { index, value }, out _);
public bool TrySetNETIndex(object instance, Variant index, Variant value) => TryInvokeNETMember(instance, "set_Item", [index, value], out _);

public bool TryGetNETIndex(object instance, Variant index, out Variant value) => TryInvokeNETMember(instance, "get_Item", new[] { index }, out value);
public bool TryGetNETIndex(object instance, Variant index, out Variant value) => TryInvokeNETMember(instance, "get_Item", [index], out value);

public bool TrySetNETMember(object instance, string member, Variant value)
{
Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/Runtime/NativeInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ public static void AddFolderToEnvPath(string dir)
}

public static (string stdout, int code) Exec(string command, bool use_shellexec = false) => DoPlatformDependent(
() => InternalRun("cmd.exe", new[] { "/c", command }, use_shellexec),
() => InternalRun("/bin/bash", new[] { "-c", command }, use_shellexec)
() => InternalRun("cmd.exe", ["/c", command], use_shellexec),
() => InternalRun("/bin/bash", ["-c", command], use_shellexec)
);

private static (string stdout, int code) InternalRun(string filename, string[] arguments, bool use_shexec)
Expand Down
6 changes: 3 additions & 3 deletions new/AutoItInterpreter/Runtime/ScriptScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Unknown6656.AutoIt3.Runtime;
/// </summary>
public sealed class ScriptScanner
{
private static readonly string[] AUTOIT_FILE_EXTENSIONS = { "", ".au3", ".au2", ".au", ".aupp", ".au++" };
private static readonly string[] AUTOIT_FILE_EXTENSIONS = ["", ".au3", ".au2", ".au", ".aupp", ".au++"];

private const RegexOptions REGEX_OPTIONS = RegexOptions.IgnoreCase | RegexOptions.Compiled;
private const string REGEX_FUNC_MODIFIERS = /*lang=regex*/@"((\s+|\b)(?<modifiers>volatile(\s+cached)?|cached(\s+volatile)?)(\s+|\b))?";
Expand All @@ -51,14 +51,14 @@ public sealed class ScriptScanner
private static readonly Regex REGEX_NOTRYICON = new(@"^#notrayicon\b", REGEX_OPTIONS);

private static readonly Func<string, (FileInfo physical, string content)?>[] _existing_resolvers =
{
[
ResolveUNC,
ResolveHTTP,
ResolveFTP,
#if SUPPORT_SSH
ResolveSSH,
#endif
};
];
private readonly ConcurrentDictionary<string, ScriptFunction> _cached_functions = new();
private readonly ConcurrentDictionary<int, ScannedScript> _cached_scripts = new();
Expand Down
2 changes: 1 addition & 1 deletion new/AutoItInterpreter/Runtime/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ string s when s.StartsWith("0x", StringComparison.OrdinalIgnoreCase) => long.Try
/// <returns>Binary representation</returns>
public readonly byte[] ToBinary() => RawData switch
{
bool b => new[] { (byte)(b ? 1 : 0) },
bool b => [(byte)(b ? 1 : 0)],
_ when Type is VariantType.Default => DataStream.FromUnmanaged(-1),
null => DataStream.FromUnmanaged(0),
int i => DataStream.FromUnmanaged(i),
Expand Down
2 changes: 1 addition & 1 deletion new/plugins/Plugins.Serial/SerialFunctionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class SerialFunctionProvider
public SerialFunctionProvider(Interpreter interpreter)
: base(interpreter)
{
RegisterFunction(nameof(SerialOpen), 2, 5, SerialOpen, new Variant[] { (int)Parity.None, 8, (int)StopBits.One });
RegisterFunction(nameof(SerialOpen), 2, 5, SerialOpen, [(int)Parity.None, 8, (int)StopBits.One]);
RegisterFunction(nameof(SerialClose), 1, SerialClose);
}

Expand Down
4 changes: 2 additions & 2 deletions new/util/AutoIt3.COM.Server/COMServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public bool TryGetIndex(COMData index, out COMData? value)
{
if (FindMembers(INDEX_NAME, MemberFindMode.Getter) is { Count: > 0 } match)
{
object? data = GetMember(match[0], new[] { index.Data });
object? data = GetMember(match[0], [index.Data]);

value = COMData.FromArbitrary(data);

Expand All @@ -501,7 +501,7 @@ public bool TrySetIndex(COMData index, COMData value)
{
if (FindMembers(INDEX_NAME, MemberFindMode.Setter) is { Count: > 0 } match)
{
SetMember(match[0], value.Data, new[] { index.Data });
SetMember(match[0], value.Data, [index.Data]);

return true;
}
Expand Down

0 comments on commit 19cc97f

Please sign in to comment.