Skip to content

Commit

Permalink
Переименовал класс в более понятный
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilBeaver committed Nov 4, 2024
1 parent 081ca65 commit 59c8983
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/OneScript.Core/Compilation/CompilerFrontendBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected CompilerFrontendBase(

public SymbolScope FillSymbols(Type targetType)
{
var symbolsProvider = Services.Resolve<CompileTimeSymbolsProvider>();
var symbolsProvider = Services.Resolve<TypeSymbolsProviderFactory>();
var typeSymbols = symbolsProvider.Get(targetType);
ModuleSymbols = new SymbolScope();
typeSymbols.FillSymbols(ModuleSymbols);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ This Source Code Form is subject to the terms of the

namespace OneScript.Compilation
{
public interface IModuleSymbolsProvider
/// <summary>
/// Провайдер дополнительных внешних символов для класса при компиляции.
/// </summary>
public interface ITypeSymbolsProvider
{
void FillSymbols(SymbolScope moduleScope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ This Source Code Form is subject to the terms of the

namespace OneScript.Compilation
{
public class CompileTimeSymbolsProvider
/// <summary>
/// Фабрика провайдеров дополнительных внешних символов для класса при компиляции.
/// </summary>
public class TypeSymbolsProviderFactory
{
private delegate void Filler(CompileTimeSymbolsProvider provider, SymbolScope scope);
private delegate void Filler(TypeSymbolsProviderFactory providerFactory, SymbolScope scope);

private readonly ConcurrentDictionary<Type, SymbolProvider> _providers =
new ConcurrentDictionary<Type, SymbolProvider>();

public IModuleSymbolsProvider Get<T>()
public ITypeSymbolsProvider Get<T>()
{
return Get(typeof(T));
}

public IModuleSymbolsProvider Get(Type type)
public ITypeSymbolsProvider Get(Type type)
{
return _providers.GetOrAdd(type, CreateProvider);
}
Expand All @@ -46,32 +49,32 @@ private static Filler FindFillerMethod(Type type)
return filler;
}

private static void DoNothing(CompileTimeSymbolsProvider provider, SymbolScope scope)
private static void DoNothing(TypeSymbolsProviderFactory providerFactory, SymbolScope scope)
{
}

private static bool IsFiller(MethodInfo methodInfo)
{
var parameters = methodInfo.GetParameters();
return parameters.Length == 2
&& parameters[0].ParameterType == typeof(CompileTimeSymbolsProvider)
&& parameters[0].ParameterType == typeof(TypeSymbolsProviderFactory)
&& parameters[1].ParameterType == typeof(SymbolScope);
}

private class SymbolProvider : IModuleSymbolsProvider
private class SymbolProvider : ITypeSymbolsProvider
{
private readonly CompileTimeSymbolsProvider _provider;
private readonly TypeSymbolsProviderFactory _providerFactory;
private readonly Filler _filler;

public SymbolProvider(CompileTimeSymbolsProvider provider, Filler filler)
public SymbolProvider(TypeSymbolsProviderFactory providerFactory, Filler filler)
{
_provider = provider;
_providerFactory = providerFactory;
_filler = filler;
}

public void FillSymbols(SymbolScope moduleScope)
{
_filler(_provider, moduleScope);
_filler(_providerFactory, moduleScope);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ScriptEngine/Hosting/EngineBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static IEngineBuilder SetDefaultOptions(this IEngineBuilder builder)
services.RegisterSingleton<IGlobalsManager, GlobalInstancesManager>();
services.RegisterSingleton<RuntimeEnvironment>();
services.RegisterSingleton<IRuntimeEnvironment>(sp => sp.Resolve<RuntimeEnvironment>());
services.RegisterSingleton<CompileTimeSymbolsProvider>();
services.RegisterSingleton<TypeSymbolsProviderFactory>();
services.RegisterSingleton<IErrorSink>(svc => new ThrowingErrorSink(CompilerException.FromCodeError));
services.RegisterSingleton<IExceptionInfoFactory, ExceptionInfoFactory>();

Expand Down
4 changes: 2 additions & 2 deletions src/ScriptEngine/Machine/Contexts/AutoScriptDrivenObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ protected override void CallOwnProcedure(int index, IValue[] arguments)
#endregion

[SymbolsProvider]
private static void FillSymbols(CompileTimeSymbolsProvider provider, SymbolScope moduleScope)
private static void FillSymbols(TypeSymbolsProviderFactory providerFactory, SymbolScope moduleScope)
{
var baseProvider = provider.Get<ThisAwareScriptedObjectBase>();
var baseProvider = providerFactory.Get<ThisAwareScriptedObjectBase>();
baseProvider.FillSymbols(moduleScope);

for (int i = 0; i < _ownProperties.Count; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected override BslPropertyInfo GetOwnPropertyInfo(int index)

[SymbolsProvider]
// ReSharper disable once UnusedMember.Local
private static void CompileTimeSymbols(CompileTimeSymbolsProvider provider, SymbolScope moduleScope)
private static void CompileTimeSymbols(TypeSymbolsProviderFactory providerFactory, SymbolScope moduleScope)
{
moduleScope.Variables.Add(BslFieldBuilder.Create()
.Name(THISOBJ_RU)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ protected override BslPropertyInfo GetOwnPropertyInfo(int index)
}

[SymbolsProvider]
private static void PrepareCompilation(CompileTimeSymbolsProvider provider, SymbolScope scope)
private static void PrepareCompilation(TypeSymbolsProviderFactory providerFactory, SymbolScope scope)
{
var baseSymbols = provider.Get<ThisAwareScriptedObjectBase>();
var baseSymbols = providerFactory.Get<ThisAwareScriptedObjectBase>();
baseSymbols.FillSymbols(scope);
GetOwnMethodsDefinition().ForEach(x => scope.DefineMethod(x.ToSymbol()));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/OneScript.Dynamic.Tests/NativeSdoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public NativeSdoTests()
testServices.Register(sp => sp);
testServices.RegisterSingleton<ITypeManager, DefaultTypeManager>();
testServices.RegisterSingleton<IGlobalsManager, GlobalInstancesManager>();
testServices.RegisterSingleton<CompileTimeSymbolsProvider>();
testServices.RegisterSingleton<TypeSymbolsProviderFactory>();
testServices.RegisterEnumerable<IDirectiveHandler, EmptyDirectiveHandler>();
testServices.Register<IErrorSink, ThrowingErrorSink>();
testServices.UseImports();
Expand Down Expand Up @@ -437,7 +437,7 @@ Функция НайтиСовпадения(Текст) Экспорт

private DynamicModule CreateModule(string code, IServiceContainer services, SymbolTable symbols)
{
var symbolProvider = services.Resolve<CompileTimeSymbolsProvider>();
var symbolProvider = services.Resolve<TypeSymbolsProviderFactory>();
var moduleScope = new SymbolScope();
symbolProvider.Get<UserScriptContextInstance>().FillSymbols(moduleScope);
symbols.PushScope(moduleScope, null);
Expand Down

0 comments on commit 59c8983

Please sign in to comment.