Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Mar 30, 2024
1 parent 46ff6bf commit 5fb63d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
16 changes: 8 additions & 8 deletions new/AutoItInterpreter/Runtime/ScriptScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public sealed class ScriptScanner
ResolveHTTP,
ResolveFTP,
];
private readonly ConcurrentDictionary<string, ScriptFunction> _cached_functions = new();
private readonly ConcurrentDictionary<string, ScriptFunction> _cached_functions = new(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentDictionary<int, ScannedScript> _cached_scripts = new();
Expand Down Expand Up @@ -88,12 +88,12 @@ internal void ScanNativeFunctions() => Interpreter.Telemetry.Measure(TelemetryCa
SystemScript.AddFunction(function);

foreach ((string name, ScriptFunction func) in SystemScript.Functions)
_cached_functions.TryAdd(name.ToUpperInvariant(), func);
_cached_functions.TryAdd(name, func);
});

public ScriptFunction? TryResolveFunction(string name)
{
_cached_functions.TryGetValue(name.ToUpperInvariant(), out ScriptFunction? func);
_cached_functions.TryGetValue(name, out ScriptFunction? func);

return func;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ internal Union<InterpreterError, ScannedScript> ProcessScriptFile(FileInfo file,
return InterpreterError.WellKnown(loc, "error.reserved_name", name);
else if (!curr_func.IsMainFunction)
return InterpreterError.WellKnown(loc, "error.unexpected_func", curr_func.Name);
else if (_cached_functions.TryGetValue(name.ToUpperInvariant(), out ScriptFunction? existing) && !existing.IsMainFunction)
else if (_cached_functions.TryGetValue(name, out ScriptFunction? existing) && !existing.IsMainFunction)
return InterpreterError.WellKnown(loc, "error.duplicate_function", existing.Name, existing.Location);

IEnumerable<PARAMETER_DECLARATION> @params;
Expand Down Expand Up @@ -300,7 +300,7 @@ internal Union<InterpreterError, ScannedScript> ProcessScriptFile(FileInfo file,
curr_func = script.GetOrCreateAU3Function(name, @params);
curr_func.IsVolatile = mods.Contains("volatile", StringComparison.OrdinalIgnoreCase);
curr_func.IsCached = mods.Contains("cached", StringComparison.OrdinalIgnoreCase);
_cached_functions.TryAdd(name.ToUpperInvariant(), curr_func);
_cached_functions.TryAdd(name, curr_func);

if (MainProgram.CommandLineOptions.StrictMode && curr_func.IsCached)
return InterpreterError.WellKnown(loc, "error.experimental.cached_functions");
Expand Down Expand Up @@ -472,15 +472,15 @@ public ScannedScript(FileInfo location, string original_content)

public AU3Function GetOrCreateAU3Function(string name, IEnumerable<PARAMETER_DECLARATION>? @params)
{
_functions.TryGetValue(name.ToUpperInvariant(), out ScriptFunction? func);
_functions.TryGetValue(name, out ScriptFunction? func);

return func as AU3Function ?? AddFunction(new AU3Function(this, name, @params));
}

public T AddFunction<T>(T function)
where T : ScriptFunction
{
_functions[function.Name.ToUpperInvariant()] = function;
_functions[function.Name] = function;

return function;
}
Expand Down Expand Up @@ -539,7 +539,7 @@ private FunctionReturnValue HandleLoading(CallFrame frame, bool unloading)

public bool Equals(ScannedScript? other) => other is ScannedScript script && GetHashCode() == script.GetHashCode();

public bool HasFunction(string name) => _functions.ContainsKey(name.ToUpperInvariant());
public bool HasFunction(string name) => _functions.ContainsKey(name);

public static int GetHashCode(FileInfo location, string content) => HashCode.Combine(Path.GetFullPath(location.FullName), content);

Expand Down
2 changes: 2 additions & 0 deletions new/AutoItInterpreter/Runtime/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Unknown6656.AutoIt3.Runtime;


/// <summary>
/// Represents a variable capable of holding a value of the type <see cref="Variant"/>.
/// Variables are identified using their case-insensitive name and a '$'-prefix.
Expand All @@ -12,6 +13,7 @@ public sealed class Variable
private readonly object _mutex = new();
private Variant _value;


/// <summary>
/// The variable's lower-case name without the '$'-prefix.
/// </summary>
Expand Down
13 changes: 7 additions & 6 deletions new/util/AutoIt3.Common/LanguageLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
Expand All @@ -12,7 +12,8 @@ namespace Unknown6656.AutoIt3.Localization;

public sealed class LanguageLoader
{
private readonly Dictionary<string, LanguagePack> _packs = [];
private readonly Dictionary<string, LanguagePack> _packs = new(StringComparer.OrdinalIgnoreCase);


public string[] LoadedLanguageCodes => [.. _packs.Keys];

Expand Down Expand Up @@ -54,7 +55,7 @@ private void LoadLanguagePackFromYAML(string path, string yaml, bool overwrite_e
try
{
LanguagePack lang = LanguagePack.FromYAML(yaml);
string code = lang.LanguageCode.ToLowerInvariant();
string code = lang.LanguageCode;

lang.FilePath = path;

Expand All @@ -69,9 +70,9 @@ private void LoadLanguagePackFromYAML(string path, string yaml, bool overwrite_e
}
}

public void HasLanguagePack(string code) => _packs.ContainsKey(code.ToLowerInvariant());
public void HasLanguagePack(string code) => _packs.ContainsKey(code);

public bool TryGetLanguagePack(string code, out LanguagePack? pack) => _packs.TryGetValue(code.ToLowerInvariant(), out pack);
public bool TryGetLanguagePack(string code, out LanguagePack? pack) => _packs.TryGetValue(code, out pack);

public bool TrySetCurrentLanguagePack(string code)
{
Expand Down Expand Up @@ -99,7 +100,7 @@ public sealed class LanguagePack
private readonly IDictionary<string, string> _strings;


public string this[string key, params object?[] args] => TryGetString(key, args, out string? s) ? s! : $"[{key.ToUpperInvariant()}]";
public string this[string key, params object?[] args] => TryGetString(key, args, out string? s) ? s! : $"[{key.ToUpper()}]";

internal string FilePath { get; set; } = "";

Expand Down

0 comments on commit 5fb63d8

Please sign in to comment.