2015-06-01 22:15:17 +03:00
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
|
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
2015-05-14 22:35:07 +03:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace PascalABCCompiler.SemanticTreeConverters
|
|
|
|
|
{
|
|
|
|
|
public class SemanticTreeConvertersController
|
|
|
|
|
{
|
|
|
|
|
public enum State
|
|
|
|
|
{
|
|
|
|
|
ConnectConverter, Convert
|
|
|
|
|
}
|
|
|
|
|
ICompiler Compiler;
|
|
|
|
|
|
|
|
|
|
private List<ISemanticTreeConverter> semanticTreeConverters = new List<ISemanticTreeConverter>();
|
|
|
|
|
public List<ISemanticTreeConverter> SemanticTreeConverters
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return semanticTreeConverters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public delegate void ChangeStateDelegate(State State, ISemanticTreeConverter SemanticTreeConverter);
|
|
|
|
|
public event ChangeStateDelegate ChangeState;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SemanticTreeConvertersController(ICompiler Compiler)
|
|
|
|
|
{
|
|
|
|
|
this.Compiler = Compiler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddConverters()
|
|
|
|
|
{
|
|
|
|
|
AddConverters(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName));
|
|
|
|
|
}
|
|
|
|
|
private void AddConverters(string DirectoryName)
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo di = new DirectoryInfo(DirectoryName);
|
|
|
|
|
FileInfo[] dllfiles = di.GetFiles("*Conversion.dll");
|
|
|
|
|
System.Reflection.Assembly asssembly = null;
|
|
|
|
|
ISemanticTreeConverter Converter;
|
|
|
|
|
foreach (FileInfo fi in dllfiles)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
asssembly = System.Reflection.Assembly.LoadFile(fi.FullName);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Type[] types = asssembly.GetTypes();
|
|
|
|
|
if (asssembly != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (Type type in types)
|
|
|
|
|
{
|
|
|
|
|
if (type.Name.IndexOf("SemanticTreeConverter") >= 0 && type.IsClass)
|
|
|
|
|
{
|
|
|
|
|
Object obj = Activator.CreateInstance(type);
|
|
|
|
|
if (obj is ISemanticTreeConverter)
|
|
|
|
|
{
|
|
|
|
|
Converter = obj as ISemanticTreeConverter;
|
|
|
|
|
semanticTreeConverters.Add(Converter);
|
|
|
|
|
ChangeState(State.ConnectConverter, Converter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
//ErrorList.Add(new PluginLoadingError(fi.FullName, e));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2015-12-28 14:25:15 +03:00
|
|
|
//если dll не нетовская
|
2015-05-14 22:35:07 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SemanticTree.IProgramNode Convert(SemanticTree.IProgramNode ProgramNode)
|
|
|
|
|
{
|
|
|
|
|
foreach (ISemanticTreeConverter SemanticTreeConverter in semanticTreeConverters)
|
|
|
|
|
{
|
|
|
|
|
ChangeState(State.Convert, SemanticTreeConverter);
|
|
|
|
|
ProgramNode = SemanticTreeConverter.Convert(Compiler, ProgramNode);
|
|
|
|
|
}
|
|
|
|
|
return ProgramNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|