From d146d5bdd77e0585836b83bf0baab15bc67841a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Thu, 14 May 2015 22:56:23 +0200 Subject: [PATCH] missing plugins added --- .../LanguageConverter.csproj | 148 ++ .../Properties/AssemblyInfo.cs | 35 + .../Properties/Resources.Designer.cs | 63 + .../Properties/Resources.resx | 120 ++ .../Source/ISemanticNodeConverter.cs | 77 + .../Source/LanguageConverterPlugin.cs | 169 ++ .../LanguageConverter/Source/ListSyntRules.cs | 68 + .../LanguageConverter/Source/Rules_CS.txt | 183 ++ .../Source/SemanticNodeConverter.cs | 9 + .../Source/SourceTextBilder.cs | 91 + .../LanguageConverter/Source/TextFormatter.cs | 420 +++++ .../Source/TextFormatterForm.Designer.cs | 310 ++++ .../Source/TextFormatterForm.cs | 115 ++ .../Source/TextFormatterForm.resx | 157 ++ .../LanguageConverter/Source/Visitor.cs | 1552 +++++++++++++++++ VisualPlugins/LanguageConverter/icon.png | Bin 0 -> 820 bytes .../Properties/AssemblyInfo.cs | 35 + .../SCharpLanguageConverter.csproj | 99 ++ .../SemanticNodeConverter.cs | 398 +++++ 19 files changed, 4049 insertions(+) create mode 100644 VisualPlugins/LanguageConverter/LanguageConverter.csproj create mode 100644 VisualPlugins/LanguageConverter/Properties/AssemblyInfo.cs create mode 100644 VisualPlugins/LanguageConverter/Properties/Resources.Designer.cs create mode 100644 VisualPlugins/LanguageConverter/Properties/Resources.resx create mode 100644 VisualPlugins/LanguageConverter/Source/ISemanticNodeConverter.cs create mode 100644 VisualPlugins/LanguageConverter/Source/LanguageConverterPlugin.cs create mode 100644 VisualPlugins/LanguageConverter/Source/ListSyntRules.cs create mode 100644 VisualPlugins/LanguageConverter/Source/Rules_CS.txt create mode 100644 VisualPlugins/LanguageConverter/Source/SemanticNodeConverter.cs create mode 100644 VisualPlugins/LanguageConverter/Source/SourceTextBilder.cs create mode 100644 VisualPlugins/LanguageConverter/Source/TextFormatter.cs create mode 100644 VisualPlugins/LanguageConverter/Source/TextFormatterForm.Designer.cs create mode 100644 VisualPlugins/LanguageConverter/Source/TextFormatterForm.cs create mode 100644 VisualPlugins/LanguageConverter/Source/TextFormatterForm.resx create mode 100644 VisualPlugins/LanguageConverter/Source/Visitor.cs create mode 100644 VisualPlugins/LanguageConverter/icon.png create mode 100644 VisualPlugins/SCharpLanguageConverter/Properties/AssemblyInfo.cs create mode 100644 VisualPlugins/SCharpLanguageConverter/SCharpLanguageConverter.csproj create mode 100644 VisualPlugins/SCharpLanguageConverter/SemanticNodeConverter.cs diff --git a/VisualPlugins/LanguageConverter/LanguageConverter.csproj b/VisualPlugins/LanguageConverter/LanguageConverter.csproj new file mode 100644 index 000000000..6eb83f660 --- /dev/null +++ b/VisualPlugins/LanguageConverter/LanguageConverter.csproj @@ -0,0 +1,148 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {43879684-ADBE-470A-AAC6-2ACA36603971} + Library + Properties + Converter + LanguageConverter + + + 4.0 + + + v4.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + true + full + false + ..\..\bin\ + DEBUG;TRACE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + AllRules.ruleset + + + + + + + + + + + True + True + Resources.resx + + + + + + + + + Form + + + TextFormatterForm.cs + + + + + + + Designer + ResXFileCodeGenerator + Resources.Designer.cs + + + Designer + TextFormatterForm.cs + + + + + + + + {A25D26FB-3043-4BCF-833E-E3F4C3BE795E} + CompilerTools + + + {1E42361A-EDA3-4872-88AF-A3AAF600D36D} + Compiler + + + {44A01F9E-DCE7-470C-AAE5-C3DE0CCBEE3B} + Errors + + + {2DE2842F-0912-4251-BC0F-480854C44A13} + Localization + + + {CFC683F8-0165-4A9F-9C3F-BB8C5BAB507F} + PluginsSupport + + + {613E0DDA-AA8A-437C-AC45-507B47429FF9} + SemanticTree + + + + + False + КлиентÑ�кий профиль .NET Framework 3.5 SP1 + false + + + False + .NET Framework 3.5 SP1 + true + + + False + УÑ�тановщик Windows 3.1 + true + + + + + \ No newline at end of file diff --git a/VisualPlugins/LanguageConverter/Properties/AssemblyInfo.cs b/VisualPlugins/LanguageConverter/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..ef8f74444 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Converter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Luba-slon")] +[assembly: AssemblyProduct("Converter")] +[assembly: AssemblyCopyright("Copyright © Luba-slon 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ce68e2c8-c330-4005-8b30-bf47130600a8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VisualPlugins/LanguageConverter/Properties/Resources.Designer.cs b/VisualPlugins/LanguageConverter/Properties/Resources.Designer.cs new file mode 100644 index 000000000..b60ab23af --- /dev/null +++ b/VisualPlugins/LanguageConverter/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код Ñ�оздан программой. +// ИÑ�полнÑ�емаÑ� верÑ�иÑ�:4.0.30319.1 +// +// ИзменениÑ� в Ñ�том файле могут привеÑ�ти к неправильной работе и будут потерÑ�ны в Ñ�лучае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Converter.Properties { + using System; + + + /// + /// КлаÑ�Ñ� реÑ�урÑ�а Ñ�о Ñ�трогой типизацией длÑ� поиÑ�ка локализованных Ñ�трок и Ñ‚.д. + /// + // Этот клаÑ�Ñ� Ñ�оздан автоматичеÑ�ки клаÑ�Ñ�ом StronglyTypedResourceBuilder + // Ñ� помощью такого Ñ�редÑ�тва, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и Ñ�нова запуÑ�тите ResGen + // Ñ� параметром /str или переÑ�тройте Ñ�вой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кÑ�шированный Ñ�кземплÑ�Ñ€ ResourceManager, иÑ�пользованный Ñ�тим клаÑ�Ñ�ом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Converter.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// ПерезапиÑ�ывает Ñ�войÑ�тво CurrentUICulture текущего потока длÑ� вÑ�ех + /// обращений к реÑ�урÑ�у Ñ� помощью Ñ�того клаÑ�Ñ�а реÑ�урÑ�а Ñ�о Ñ�трогой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/VisualPlugins/LanguageConverter/Properties/Resources.resx b/VisualPlugins/LanguageConverter/Properties/Resources.resx new file mode 100644 index 000000000..7080a7d11 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/VisualPlugins/LanguageConverter/Source/ISemanticNodeConverter.cs b/VisualPlugins/LanguageConverter/Source/ISemanticNodeConverter.cs new file mode 100644 index 000000000..d53c4d3b0 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/ISemanticNodeConverter.cs @@ -0,0 +1,77 @@ +using System; +namespace Converter +{ + public interface ISemanticNodeConverter + { + string ConvertPABCNETNodeAdd(string _nodeName, object _node); + string ConvertPABCNETNodeAnd(string _nodeName, object _node); + string ConvertPABCNETNodeAssign(string _nodeName, object _node); + string ConvertPABCNETNodeBlock(string _nodeName, object _node); + string ConvertPABCNETNodeBoolConstant(string _nodeName, object _node); + string ConvertPABCNETNodeByteConstant(string _nodeName, object _node); + string ConvertPABCNETNodeCharConstant(string _nodeName, object _node); + string ConvertPABCNETNodeClass(string _nodeName, object _node); + string ConvertPABCNETNodeDec(string _nodeName, object _node); + string ConvertPABCNETNodeDiv(string _nodeName, object _node); + string ConvertPABCNETNodeDoubleConstant(string _nodeName, object _node); + string ConvertPABCNETNodeEq(string _nodeName, object _node); + string ConvertPABCNETNodeFloatConstant(string _nodeName, object _node); + string ConvertPABCNETNodeFor(string _nodeName, object _node); + string ConvertPABCNETNodeFunction(string _nodeName, object _node); + string ConvertPABCNETNodeFunctionCall(string _nodeName, object _node); + string ConvertPABCNETNodeGr(string _nodeName, object _node); + string ConvertPABCNETNodeGrEq(string _nodeName, object _node); + string ConvertPABCNETNodeIf(string _nodeName, object _node); + string ConvertPABCNETNodeInc(string _nodeName, object _node); + string ConvertPABCNETNodeIntConstant(string _nodeName, object _node); + string ConvertPABCNETNodeLocalBlockVariable(string _nodeName, object _node); + string ConvertPABCNETNodeLocVariableReference(string _nodeName, object _node); + string ConvertPABCNETNodeLongConstant(string _nodeName, object _node); + string ConvertPABCNETNodeMod(string _nodeName, object _node); + string ConvertPABCNETNodeMult(string _nodeName, object _node); + string ConvertPABCNETNodeNamespace(string _nodeName, object _node); + string ConvertPABCNETNodeNamespaceConst(string _nodeName, object _node); + string ConvertPABCNETNodeNamespaceVariable(string _nodeName, object _node); + string ConvertPABCNETNodeBinNot(string _nodeName, object _node); + string ConvertPABCNETNodeUnNot(string _nodeName, object _node); + string ConvertPABCNETNodeNotEq(string _nodeName, object _node); + string ConvertPABCNETNodeNullConst(string _nodeName, object _node); + string ConvertPABCNETNodeOr(string _nodeName, object _node); + string ConvertPABCNETNodeParameter(string _nodeName, object _node); + string ConvertPABCNETNodeParameterReference(string _nodeName, object _node); + string ConvertPABCNETNodeProgram(string _nodeName, object _node); + string ConvertPABCNETNodeRepeat(string _nodeName, object _node); + string ConvertPABCNETNodeReturn(string _nodeName, object _node); + string ConvertPABCNETNodeSByteConstant(string _nodeName, object _node); + string ConvertPABCNETNodeShl(string _nodeName, object _node); + string ConvertPABCNETNodeShortConstant(string _nodeName, object _node); + string ConvertPABCNETNodeShr(string _nodeName, object _node); + string ConvertPABCNETNodeSimpleArrInd(string _nodeName, object _node); + string ConvertPABCNETNodeSm(string _nodeName, object _node); + string ConvertPABCNETNodeSmEq(string _nodeName, object _node); + string ConvertPABCNETNodeStatements(string _nodeName, object _node); + string ConvertPABCNETNodeStatementsNested(string _nodeName, object _node); + string ConvertPABCNETNodeStaticMethodCall(string _nodeName, object _node); + string ConvertPABCNETNodeStringConstant(string _nodeName, object _node); + string ConvertPABCNETNodeSubtract(string _nodeName, object _node); + string ConvertPABCNETNodeType(string _nodeName, object _node); + string ConvertPABCNETNodeTypeOf(string _nodeName, object _node); + string ConvertPABCNETNodeUIntConstant(string _nodeName, object _node); + string ConvertPABCNETNodeULongConstant(string _nodeName, object _node); + string ConvertPABCNETNodeUnMin(string _nodeName, object _node); + string ConvertPABCNETNodeUShortConstant(string _nodeName, object _node); + string ConvertPABCNETNodeVariable(string _nodeName, object _node); + string ConvertPABCNETNodeVariableReference(string _nodeName, object _node); + string ConvertPABCNETNodeWhile(string _nodeName, object _node); + string ConvertPABCNETNodeXor(string _nodeName, object _node); + string GetConvertedText(); + SourceTextBilder SourceTextBuilder { get; set; } + + string ConvertPABCNETNodeConstructorCall(string _nodeName, object _node); + string ConvertPABCNETNodeCompMethodCall(string _nodeName, object _node); + string ConvertPABCNETNodeIfElse(string _nodeName, object _node); + string ConvertPABCNETNodeUnInc(string _nodeName, object _node); + string ConvertPABCNETNodeUnDec(string _nodeName, object _node); + + } +} diff --git a/VisualPlugins/LanguageConverter/Source/LanguageConverterPlugin.cs b/VisualPlugins/LanguageConverter/Source/LanguageConverterPlugin.cs new file mode 100644 index 000000000..189e0824a --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/LanguageConverterPlugin.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Converter; +using System.IO; + +namespace VisualPascalABCPlugins +{ + public class LanguageConverter_VisualPascalABCPlugin : IVisualPascalABCPlugin + { + public static string StringsPrefix = "VPP_LNGCONVERT_"; + IVisualEnvironmentCompiler VisualEnvironmentCompiler; + internal ISemanticNodeConverter currentLanguage; + private TextFormatterForm TextFormatterForm; + //public TextFormatter TextFormatter; + public List Languages; + + public string Name + { + get + { + return "Language Converter"; + } + } + public string Version + { + get + { + return "0.1"; + } + } + public string Copyright + { + get + { + return "(c) 2008"; + } + } + + public void OpenFilesInEnvironment(List fileNames) + { + foreach (string name in fileNames) + VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.OpenFile, name); + } + + public void ExecuteBuild() + { + MyCompilation = true; + VisualEnvironmentCompiler.StandartCompiler.InternalDebug.CodeGeneration = false; + PascalABCCompiler.CompilerType ct = VisualEnvironmentCompiler.DefaultCompilerType; + VisualEnvironmentCompiler.DefaultCompilerType = PascalABCCompiler.CompilerType.Standart; + VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.Build, null); + VisualEnvironmentCompiler.DefaultCompilerType = ct; + VisualEnvironmentCompiler.StandartCompiler.InternalDebug.CodeGeneration = true; + } + + public void ExecuteOptions() + { + TextFormatterForm.ShowDialog(); + } + + public LanguageConverter_VisualPascalABCPlugin(IWorkbench Workbench) + { + Languages = LoadLanguages(); + currentLanguage = Languages[0]; + this.VisualEnvironmentCompiler = Workbench.VisualEnvironmentCompiler; + //TextFormatter = new TextFormatter(); + TextFormatterForm = new TextFormatterForm(); + TextFormatterForm.Plugin = this; + TextFormatterForm.Init(); + VisualEnvironmentCompiler.StandartCompiler.OnChangeCompilerState += new PascalABCCompiler.ChangeCompilerStateEventDelegate(Compiler_OnChangeCompilerState); + } + + public void ConvertSourceText() + { + try + { + PascalABCCompiler.SemanticTree.IProgramNode Root = VisualEnvironmentCompiler.StandartCompiler.SemanticTree; + //SemanticNodeConverter semanticNodeConverter = new SemanticNodeConverter(new ListSyntRules( + // System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName) + "\\Rules_CS.txt"), TextFormatter/*new TextFormatter()*/); + + //TextFormatterForm.TextFormatter=new TextFormatter(); + //TextFormatterForm.SaveTextFormater(currentLanguage.SourceTextBuilder.TextFormatter); + //currentLanguage.SourceTextBuilder.TextFormatter = TextFormatterForm.TextFormatter; + TextFormatterForm.SaveTextFormater(currentLanguage.SourceTextBuilder.TextFormatter); + SemanticTreeVisitor Visitor = new SemanticTreeVisitor(currentLanguage);//new SemanticNodeConverter(new ListSyntRules("Rules_CS.txt"), new TextFormatter())); + Root.visit(Visitor); + + //ConvertTextViewer.Text = Visitor.GetConvertedText(); + OpenFilesInEnvironment(Visitor.nmspaceFiles); + } + catch (NotSupportedException e) + { + System.Windows.Forms.MessageBox.Show(string.Format("Èçâèíèòå, ãåíåðàöèÿ êîäà äëÿ óçëà {0} íå ïîääåðæèâàåòñÿ. Òåêñò íå áûë ñãåíåðèðîâàí.", e.Message)); + } + catch (Exception e) + { + VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.AddTextToCompilerMessages, "LanguageConverter Exception: " + e.ToString()); + } + } + + bool MyCompilation = false; + void Compiler_OnChangeCompilerState(PascalABCCompiler.ICompiler sender, PascalABCCompiler.CompilerState State, string FileName) + { + if (!MyCompilation) return; + switch (State) + { + case PascalABCCompiler.CompilerState.CompilationStarting: + //this.Refresh(); + break; + case PascalABCCompiler.CompilerState.CompilationFinished: + ConvertSourceText(); + MyCompilation = false; + break; + } + } + + // ñòûðåíî + private List LoadLanguages() + { + List Langs = new List(); + // äèðåêòîðèÿ ýòîãî ïëàãèíà + string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName); + DirectoryInfo di = new DirectoryInfo(dir); + FileInfo[] dllfiles = di.GetFiles("*LanguageConverter.dll"); + System.Reflection.Assembly asssembly = null; + Type constr = null; + ISemanticNodeConverter pc = null; + foreach (FileInfo fi in dllfiles) + { + asssembly = System.Reflection.Assembly.LoadFile(fi.FullName); + try + { + if (asssembly != null && asssembly.FullName != System.Reflection.Assembly.GetExecutingAssembly().FullName) + { + Type[] types = asssembly.GetTypes(); + foreach (Type type in types) + { + if (type.Name.IndexOf("SemanticNodeConverter") >= 0) + { + Object obj = Activator.CreateInstance(type); + if (obj is ISemanticNodeConverter) + { + Langs.Add(obj as ISemanticNodeConverter); + } + } + } + } + } + catch (Exception e) + { + } + } + return Langs; + } + + public void GetGUI(List MenuItems, List ToolBarItems) + { + PluginGUIItem Item = new PluginGUIItem(StringsPrefix + "BUILD", StringsPrefix + "BUILD", TextFormatterForm.ImageBuild.Image, TextFormatterForm.ImageBuild.BackColor, ExecuteBuild); + MenuItems.Add(Item); + ToolBarItems.Add(Item); + Item = new PluginGUIItem(StringsPrefix + "OPTIONS", StringsPrefix + "OPTIONS", TextFormatterForm.ImageOptions.Image, TextFormatterForm.ImageOptions.BackColor, ExecuteOptions); + MenuItems.Add(Item); + ToolBarItems.Add(Item); + } + + } +} + diff --git a/VisualPlugins/LanguageConverter/Source/ListSyntRules.cs b/VisualPlugins/LanguageConverter/Source/ListSyntRules.cs new file mode 100644 index 000000000..77ae49ffa --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/ListSyntRules.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace Converter +{ + public class ListSyntRules + { + // õðàíèò ñîîòâåòñòâèå ìåæäó óçëàìè ñåìàíòè÷åñêîãî äåðåâà ÐÀÂÑNET è ñîîòâåòñòâóþùèìè ñèíòàêñè÷åñêèìè ïðàâèëàìè äðóãîãî ÿçûêà + private Dictionary Rules; + private string fileName; + + private const string nodeSeparator = "@", ruleSeparator = "::"; + + public ListSyntRules(string _fileName) + { + fileName = _fileName; + + initialisation(); + } + + public string GetRule(string _nodeName) + { + string result; + if (Rules.TryGetValue(_nodeName, out result)) + { + return result; + } + else + return ""; + } + + public string[] GetWordsFromRule(string _node) + { + return GetRule(_node).Split(' '); + } + + private void initialisation() + { + Rules = new Dictionary(); + initRules(readRulesTXTInToStr()); + } + + private string readRulesTXTInToStr() + { + TextReader readerTXT = File.OpenText(fileName); + return readerTXT.ReadToEnd(); + } + + private void initRules(string _rulesTXT) + { + string[] nameNodeAndRule; + string[] nodes; + string[] nodeSeparators = new string[1], ruleSeparators = new string[1]; + nodeSeparators[0] = nodeSeparator; + ruleSeparators[0] = ruleSeparator; + nodes = _rulesTXT.Split(nodeSeparators, StringSplitOptions.RemoveEmptyEntries); + foreach (string node in nodes) + { + nameNodeAndRule = node.Split(ruleSeparators, StringSplitOptions.RemoveEmptyEntries); + nameNodeAndRule[0] = nameNodeAndRule[0].Replace(" ", ""); + Rules.Add(nameNodeAndRule[0], nameNodeAndRule[1]); + } + } + + } +} diff --git a/VisualPlugins/LanguageConverter/Source/Rules_CS.txt b/VisualPlugins/LanguageConverter/Source/Rules_CS.txt new file mode 100644 index 000000000..666e291da --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/Rules_CS.txt @@ -0,0 +1,183 @@ +@namespace :: +$namespace name *BlockBegin *BlockBody +${ *BlockBegin *BlockBody *BlockBody + $public $class name *BlockBegin *BlockBody + ${ *BlockBegin + body + *BlockEnd *BlockBody $} + *BlockEnd *BlockBody $} + +@class :: +access_modifier_type $class name *BlockBegin *BlockBody +${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@struct :: +access_modifier_type $struct name *BlockBegin *BlockBody +${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@function :: +$public $static type name $( parameters $) *BlockBegin *BlockBody +${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@return :: +$return expr + +@array_indexing :: +expr $[ expr $] + +@function_call :: +name $( parameters $) + +@comp_method_call :: +obj_name $. name $( parameters $) + +@comp_stat_method_call :: +name $( parameters $) + +@comm_stat_method_call :: +type $. name $( parameters $) + +@type_of :: +$typeof $( type $) + +@if :: +$if $( parameters $) + *BlockBegin *BlockBody +${ + ${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@for :: +$for $( body $) + *BlockBegin *BlockBody +${ + ${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@while :: +$while $( body $) + *BlockBegin *BlockBody +${ + ${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@repeat :: +$do + *BlockBegin *BlockBody +${ +${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + $while $( parameters $) + +@namespace_var :: +$public $static type name + +@var :: +type name + +@var_init :: +type name $= body + +@const :: +$public $const type name + +@statements :: +body + +@statements_nested :: *BlockBegin *BlockBody +${ + *BlockBegin + body + *BlockEnd + *BlockBody $} + +@binop_assign :: +expr $= expr + +@binop_add :: +expr $+ expr + +@binop_subtract :: +expr $- expr + +@binop_mult :: +expr $* expr + +@binop_div :: +expr $/ expr + +@unop_plus :: +$+ expr + +@unop_minus :: +$- expr + +@binop_mod :: +expr $% expr + +@binop_eq :: +expr $== expr + +@binop_gr :: +expr $> expr + +@binop_sm :: +expr $< expr + +@binop_greq :: +expr $>= expr + +@binop_smeq :: +expr $<= expr + +@binop_and :: +expr $&& expr + +@binop_or :: +expr $|| expr + +@binop_xor :: +expr $^ expr + +@unop_inc :: +$++ expr + +@unop_dec :: +$-- expr + +@unop_unmin :: +$- $( expr $) + +@unop_not :: +$not expr + +@binop_shl :: +expr $<< expr + +@binop_shr :: +expr $>> expr + diff --git a/VisualPlugins/LanguageConverter/Source/SemanticNodeConverter.cs b/VisualPlugins/LanguageConverter/Source/SemanticNodeConverter.cs new file mode 100644 index 000000000..ed0f1bfa4 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/SemanticNodeConverter.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +using System.Text; +using PascalABCCompiler.SemanticTree; + +namespace Converter +{ + +} diff --git a/VisualPlugins/LanguageConverter/Source/SourceTextBilder.cs b/VisualPlugins/LanguageConverter/Source/SourceTextBilder.cs new file mode 100644 index 000000000..94f231578 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/SourceTextBilder.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Converter +{ + public class SourceTextBilder + { + public ListSyntRules ListSyntRules; + public TextFormatter TextFormatter; + private StringBuilder sourceString = new StringBuilder(""); + private StringBuilder sourceStringNode = new StringBuilder(""); + private StringBuilder sourceStringNodeBlock = new StringBuilder(""); + private Stack nodeStringStack = new Stack(); + public Dictionary namespacesStr = new Dictionary(); + + public SourceTextBilder() + { + TextFormatter = new TextFormatter(); + // todo + ListSyntRules = new ListSyntRules( + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName) + "\\Rules_CS.txt"); + + TextFormatter.GetBodyBlock += getBodyBlock; + } + + public SourceTextBilder(ListSyntRules _listSyntRules, TextFormatter _textFormatter) + { + ListSyntRules = _listSyntRules; + TextFormatter = _textFormatter; + + TextFormatter.GetBodyBlock += getBodyBlock; + } + + private bool isEmptyString(string res) + { + // Ñ�оÑ�тоит ли Ñ�трока только из пробелов + for (int i = 0; i < res.Length; i++) + { + if (!(res[i] == ' ' || res[i] == '\r' || res[i] == '\n')) + return false; + } + return true; + } + + private string getBodyBlock() + { + string res = ""; + while (isEmptyString(res) && (nodeStringStack.Count != 0)) + //if ((nodeStringStack.Count != 0)) + { + res = nodeStringStack.Pop(); + } + if (res == "%empty%") + res = ""; + return res; + } + + private void addNodeInToString(StringBuilder _string, string _nodeName, object _node) + { + _string.Append(TextFormatter.Indents.BlockBody); + _string.Append(TextFormatter.FormatRuleNode(ListSyntRules.GetRule(_nodeName), _node)); + _string.Append(Environment.NewLine); + } + + public void AddNodeInToStack(string _node) + { + nodeStringStack.Push(_node); + } + + public string GetNodeFromStack() + { + if (nodeStringStack.Count != 0) + return nodeStringStack.Pop(); + else + return ""; + + } + + public string ConvertNode (string _nodeName, object _node) + { + //addNodeInToString(sourceString, _nodeName, _node); + return TextFormatter.FormatRuleNode(ListSyntRules.GetRule(_nodeName), _node); + } + + public void AddInToSourceText(string _text) + { + sourceString.Append(_text); + } + } +} diff --git a/VisualPlugins/LanguageConverter/Source/TextFormatter.cs b/VisualPlugins/LanguageConverter/Source/TextFormatter.cs new file mode 100644 index 000000000..c1ed14d3c --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/TextFormatter.cs @@ -0,0 +1,420 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using PascalABCCompiler.SemanticTree; +using System.Text.RegularExpressions; + +namespace Converter +{ + public class TextFormatter + { + private Dictionary FieldValuesFromSemanticNode = new Dictionary(); + private List SpecSymbols = new List(); + + private delegate string getFieldValueFromSemanticNode(object node); + public delegate string convertKeyWord(string _nameKeyWord, string _factVaulekeyWord); + public delegate string getBodyBlock(); + + public convertKeyWord ConvertKeyWord; + public getBodyBlock GetBodyBlock; + + public IndentValues Indents = new IndentValues(); + + public struct IndentValues + { + private Dictionary indents; + private string blockBodyInSourceText; + private string blockBody; + public void init() + { + indents = new Dictionary(); + indents.Add(IndentNames.BlockBegin, Environment.NewLine); + indents.Add(IndentNames.BlockEnd, Environment.NewLine); + indents.Add(IndentNames.BlockBody, " "); + indents.Add(IndentNames.BetweenWords, " "); + + blockBody = indents[IndentNames.BlockBody]; + blockBodyInSourceText = indents[IndentNames.BlockBody]; + } + public string BlockBodyIncrement() + { + return indents[IndentNames.BlockBody] += blockBody; + } + public string BlockBodyDecrement() + { + return indents[IndentNames.BlockBody] = indents[IndentNames.BlockBody].Remove(indents[IndentNames.BlockBody].Length - blockBody.Length); + } + public string BlockBodyInSourceText + { + get + { + return blockBodyInSourceText; + } + } + public string BlockBegin + { + set + { + indents[IndentNames.BlockBegin] = value; + + } + get + { + return indents[IndentNames.BlockBegin]; + } + } + public string BlockEnd + { + set + { + indents[IndentNames.BlockEnd] = value; + } + get + { + return indents[IndentNames.BlockEnd]; + } + } + public string BlockBody + { + set + { + blockBody = value; + indents[IndentNames.BlockBody] = value; + } + get + { + return indents[IndentNames.BlockBody]; + } + } + public string BetweenWords + { + set + { + indents[IndentNames.BetweenWords] = value; + } + get + { + return indents[IndentNames.BetweenWords]; + } + } + public string GetIndent(string _indentName) + { + if (indents.ContainsKey(_indentName)) + return indents[_indentName]; + return ""; + } + } + + public struct IndentNames + { + public static string BlockBegin = "BlockBegin"; + public static string BlockEnd = "BlockEnd"; + public static string BlockBody = "BlockBody"; + public static string BetweenWords = "BW"; + } + + public struct SpecSymbValues + { + public static string KeyWord = "$"; + public static string Indent = "*"; + } + + public struct SemanticNodeFields + { + public static string Body = "body"; + public static string Expr = "expr"; + public static string ObjName = "obj_name"; + public static string Parameters = "parameters"; + public static string Name = "name"; + public static string Type = "type"; + public static string Value = "value"; + public static string AccessModifierField = "access_modifier_field"; + public static string AccessModifierType = "access_modifier_type"; + } + + + + public TextFormatter() + { + init(); + } + + private void init() + { + Indents.init(); + specSymbolsInit(); + semanticNodeFieldsMethodsInit(); + } + private void specSymbolsInit() + { + SpecSymbols.Add(SpecSymbValues.KeyWord); + SpecSymbols.Add(SpecSymbValues.Indent); + } + + private void semanticNodeFieldsMethodsInit() + { + FieldValuesFromSemanticNode.Add(SemanticNodeFields.Name, getFieldValueFromSemanticNodeName); + FieldValuesFromSemanticNode.Add(SemanticNodeFields.Type, getFieldValueFromSemanticNodeType); + FieldValuesFromSemanticNode.Add(SemanticNodeFields.AccessModifierField, getFieldValueFromSemanticNodeAccessModifierField); + FieldValuesFromSemanticNode.Add(SemanticNodeFields.AccessModifierType, getFieldValueFromSemanticNodeAccessModifierType); + } + + // методы, возвращающие фактичеÑ�кое значение Ñ�оответÑ�твующего полÑ� длÑ� данного узла + #region + // вот они: + private string getFieldValueFromSemanticNodeName(object _node) + { + if (_node is ICommonNamespaceNode) + { + string name = (_node as ICommonNamespaceNode).namespace_name; + if (name == "") + // Задавать пользователем дефолтное имÑ� главного неймÑ�пейÑ�а!!! + name = "Program"; + return name; + } + + if (_node is ILocalVariableReferenceNode) + return (_node as ILocalVariableReferenceNode).Variable.name; + + if (_node is INamespaceVariableReferenceNode) + return (_node as INamespaceVariableReferenceNode).Variable.name; + + if (_node is ILocalBlockVariableReferenceNode) + return (_node as ILocalBlockVariableReferenceNode).Variable.name; + + if (_node is ICompiledStaticMethodCallNode) + return (_node as ICompiledStaticMethodCallNode).compiled_type.compiled_type.ToString() + "." + (_node as ICompiledStaticMethodCallNode).static_method.name; + + if (_node is ICompiledMethodCallNode) + return (_node as ICompiledMethodCallNode).compiled_method.name; + + if (_node is ITypeNode) + return (_node as ITypeNode).name; + + if (_node is ITypeSynonym) + return (_node as ITypeSynonym).name; + + if (_node is IFunctionNode) + return (_node as IFunctionNode).name; + + if (_node is ICommonNamespaceFunctionCallNode) + return (_node as ICommonNamespaceFunctionCallNode).function.name; + + if (_node is IExternalStatementNode) + return (_node as IExternalStatementNode).name; + + if (_node is IVAriableDefinitionNode) + return (_node as IVAriableDefinitionNode).name; + + if (_node is IConstantDefinitionNode) + return (_node as IConstantDefinitionNode).name; + + if (_node is IPropertyNode) + return (_node as IPropertyNode).name; + + if (_node is ILabelNode) + return (_node as ILabelNode).name; + + return ""; + } + + private string getType(object _node) + { + if (_node is ICompiledTypeNode) + return (_node as ICompiledTypeNode).compiled_type.ToString(); + if (_node is ICommonTypeNode) + if ((_node as ICommonTypeNode).comprehensive_namespace.namespace_name != "") + return (_node as ICommonTypeNode).comprehensive_namespace.namespace_name + "." + (_node as ICommonTypeNode).name; + else + return (_node as ICommonTypeNode).name; + return ""; + } + + private string getFieldValueFromSemanticNodeType(object _node) + { + if (_node is ICommonNamespaceFunctionNode) + {// TODO: Ñ�делать определениÑ� длÑ� разных Ñ�зыков нормальное + if ((_node as ICommonNamespaceFunctionNode).return_value_type == null) + return "void"; + else + return getType((_node as ICommonNamespaceFunctionNode).return_value_type); + } + + if (_node is ITypeOfOperator) + return getType((_node as ITypeOfOperator).oftype); + + if (_node is ICommonConstructorCall) + return getType((_node as ICommonConstructorCall).common_type); + + if (_node is ICompiledTypeNode) + return (_node as ICompiledTypeNode).compiled_type.ToString(); + + if (_node is IExpressionNode) + return getType((_node as IExpressionNode).type); + + if (_node is IVAriableDefinitionNode) + return getType((_node as IVAriableDefinitionNode).type); + + if (_node is IConstantDefinitionNode) + return getType((_node as IConstantDefinitionNode).type); + + return ""; + } + + private string getFieldValueFromSemanticNodeAccessModifierField(object _node) + { + //fal_private, fal_internal, fal_protected, fal_public + if (_node is IClassMemberNode) + { + //помеÑ�тить в клаÑ�Ñ� Ñ�емант. правил Ñ�труктуру Ñ� их Ñ�троковыми значениÑ�ми + IClassMemberNode node = _node as IClassMemberNode; + + if ((node).field_access_level == field_access_level.fal_internal) + return "internal" + Indents.BetweenWords; + + if ((node).field_access_level == field_access_level.fal_private) + return "private" + Indents.BetweenWords; + + if ((node).field_access_level == field_access_level.fal_protected) + return "protected" + Indents.BetweenWords; + + if ((node).field_access_level == field_access_level.fal_public) + return "public" + Indents.BetweenWords; + } + + return ""; + } + + private string getFieldValueFromSemanticNodeAccessModifierType(object _node) + { + // Ñ�труктуру в абÑ�тр. клаÑ�Ñ� длÑ� хранениÑ� Ñ�оотв. значений в Сишарпе (и других Ñ�зыках) + string fieldValue = ""; + if (_node is ICommonTypeNode) + { + ICommonTypeNode node = _node as ICommonTypeNode; + + if ((node).type_access_level == type_access_level.tal_internal) + return "internal" + Indents.BetweenWords; + + if ((node).type_access_level == type_access_level.tal_public) + return "public" + Indents.BetweenWords; + } + return ""; + } + + #endregion + + private string getWordValue(string _word, string _specSymb) + { + if (_specSymb == SpecSymbValues.KeyWord) + return _word; + + if (_specSymb == SpecSymbValues.Indent) + return Indents.GetIndent(_word); + + return ""; + } + + public string FormatWord(string _word, object _node) + { + // cltkfnm yjhvfkmyj + if (_word != "") + { + _word = _word.Replace(" ", ""); + _word = _word.Replace("\r", ""); + _word = _word.Replace("\n", ""); + } + else return _word; + + foreach (string specSymbol in this.SpecSymbols) + { + if (_word.Contains(specSymbol)) + { + _word = _word.Replace(specSymbol, ""); + return getWordValue(_word, specSymbol); + } + } + if (_word == SemanticNodeFields.Body || _word == SemanticNodeFields.Expr || _word == SemanticNodeFields.Parameters || _word == SemanticNodeFields.ObjName) + { + if (GetBodyBlock != null) + return GetBodyBlock(); + } + if (FieldValuesFromSemanticNode.ContainsKey(_word)) + { + string word = FieldValuesFromSemanticNode[_word](_node); + return replSymb(word); + } + return _word; + } + + private string replSymb(string _word) + { + _word = _word.Replace("$", "S"); + return _word; + } + + private string deleteSymbolsFromWord(string _word) + { + // переделать Ñ�тот ужаÑ�!!! + _word = _word.Replace("$", ""); + _word = _word.Replace("#", ""); + return _word; + } + + + // еÑ�ли привÑ�зан Ñ�пец. обработчик длÑ� ключ. Ñ�лов - вызываетÑ�Ñ�, иначе возвр. точное значение, как в PABCNET + public string FormatWordWithKeyWord(string _word, object _node) + { + if (_word != "") + { + _word = _word.Replace(" ", ""); + _word = _word.Replace("\r", ""); + _word = _word.Replace("\n", ""); + } + else return _word; + + foreach (string specSymbol in this.SpecSymbols) + { + if (_word.Contains(specSymbol)) + { + _word.Replace(specSymbol, ""); + return getWordValue(_word, specSymbol); + } + else + { + if (ConvertKeyWord != null) + return ConvertKeyWord(_word, FieldValuesFromSemanticNode[_word](_node)); + else + return FieldValuesFromSemanticNode[_word](_node); + } + } + + return _word; + } + + // значениÑ�, Ñ�оответÑ�твующие ключевым Ñ�ловам в PABCNET, преобразуютÑ�Ñ� методом, привÑ�занным к делегату + public string FormatRuleNodeWithKeyWord(string _ruleNode, object _node) + { + StringBuilder nodeString = new StringBuilder(""); + string[] ruleNode = _ruleNode.Split(' '); + + foreach (string nodeWord in ruleNode) + nodeString.Append(this.FormatWordWithKeyWord(nodeWord, _node)); + + return nodeString.ToString(); + } + + // длÑ� Ñ�зыков, у которых значениÑ� Ñ�пецификаторов(?) Ñ�трого Ñ�овпадают Ñ� Ñ�оответÑ�твующими в PascalABCNET + public string FormatRuleNode(string _ruleNode, object _node) + { + StringBuilder nodeString = new StringBuilder(""); + string[] ruleNode = _ruleNode.Split(' '); + + foreach (string nodeWord in ruleNode) + nodeString.Append(this.FormatWord(nodeWord, _node)); + + return nodeString.ToString(); + } + } +} diff --git a/VisualPlugins/LanguageConverter/Source/TextFormatterForm.Designer.cs b/VisualPlugins/LanguageConverter/Source/TextFormatterForm.Designer.cs new file mode 100644 index 000000000..df649bc63 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/TextFormatterForm.Designer.cs @@ -0,0 +1,310 @@ +namespace Converter +{ + partial class TextFormatterForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TextFormatterForm)); + this.comboBoxBlockBegin = new System.Windows.Forms.ComboBox(); + this.comboBoxBlockEnd = new System.Windows.Forms.ComboBox(); + this.labelBlockBegin = new System.Windows.Forms.Label(); + this.labelBlockEnd = new System.Windows.Forms.Label(); + this.labelBlockBodySymb = new System.Windows.Forms.Label(); + this.labelBetweenWordsSymb = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxBodyBlock = new System.Windows.Forms.ComboBox(); + this.comboBoxBetweenWords = new System.Windows.Forms.ComboBox(); + this.labelBlockBodyCount = new System.Windows.Forms.Label(); + this.labelBetweenWordsCount = new System.Windows.Forms.Label(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.label1 = new System.Windows.Forms.Label(); + this.cbLanguage = new System.Windows.Forms.ComboBox(); + this.ImageOptions = new System.Windows.Forms.PictureBox(); + this.ImageBuild = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.ImageOptions)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.ImageBuild)).BeginInit(); + this.SuspendLayout(); + // + // comboBoxBlockBegin + // + this.comboBoxBlockBegin.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxBlockBegin.FormattingEnabled = true; + this.comboBoxBlockBegin.Items.AddRange(new object[] { + "C новой Ñ�троки", + "C текущей Ñ�троки"}); + this.comboBoxBlockBegin.Location = new System.Drawing.Point(177, 33); + this.comboBoxBlockBegin.Name = "comboBoxBlockBegin"; + this.comboBoxBlockBegin.Size = new System.Drawing.Size(283, 21); + this.comboBoxBlockBegin.TabIndex = 3; + // + // comboBoxBlockEnd + // + this.comboBoxBlockEnd.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxBlockEnd.FormattingEnabled = true; + this.comboBoxBlockEnd.Items.AddRange(new object[] { + "C новой Ñ�троки", + "C текущей Ñ�троки"}); + this.comboBoxBlockEnd.Location = new System.Drawing.Point(177, 60); + this.comboBoxBlockEnd.Name = "comboBoxBlockEnd"; + this.comboBoxBlockEnd.Size = new System.Drawing.Size(283, 21); + this.comboBoxBlockEnd.TabIndex = 4; + // + // labelBlockBegin + // + this.labelBlockBegin.AutoSize = true; + this.labelBlockBegin.Location = new System.Drawing.Point(12, 33); + this.labelBlockBegin.Name = "labelBlockBegin"; + this.labelBlockBegin.Size = new System.Drawing.Size(77, 13); + this.labelBlockBegin.TabIndex = 5; + this.labelBlockBegin.Text = "Ð�ачало блока"; + // + // labelBlockEnd + // + this.labelBlockEnd.AutoSize = true; + this.labelBlockEnd.Location = new System.Drawing.Point(12, 60); + this.labelBlockEnd.Name = "labelBlockEnd"; + this.labelBlockEnd.Size = new System.Drawing.Size(71, 13); + this.labelBlockEnd.TabIndex = 6; + this.labelBlockEnd.Text = "Конец блока"; + // + // labelBlockBodySymb + // + this.labelBlockBodySymb.AutoSize = true; + this.labelBlockBodySymb.Location = new System.Drawing.Point(12, 92); + this.labelBlockBodySymb.Name = "labelBlockBodySymb"; + this.labelBlockBodySymb.Size = new System.Drawing.Size(110, 13); + this.labelBlockBodySymb.TabIndex = 7; + this.labelBlockBodySymb.Text = "ОтÑ�туп в теле блока"; + this.labelBlockBodySymb.Click += new System.EventHandler(this.labelBlockBody_Click); + // + // labelBetweenWordsSymb + // + this.labelBetweenWordsSymb.AutoSize = true; + this.labelBetweenWordsSymb.Location = new System.Drawing.Point(12, 117); + this.labelBetweenWordsSymb.Name = "labelBetweenWordsSymb"; + this.labelBetweenWordsSymb.Size = new System.Drawing.Size(125, 13); + this.labelBetweenWordsSymb.TabIndex = 8; + this.labelBetweenWordsSymb.Text = "ОтÑ�туп между Ñ�ловами"; + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(304, 150); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(75, 23); + this.buttonOk.TabIndex = 9; + this.buttonOk.Text = "Ok"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + // + // buttonCancel + // + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.Location = new System.Drawing.Point(385, 150); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 10; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // comboBoxBodyBlock + // + this.comboBoxBodyBlock.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxBodyBlock.FormattingEnabled = true; + this.comboBoxBodyBlock.Items.AddRange(new object[] { + "Пробел"}); + this.comboBoxBodyBlock.Location = new System.Drawing.Point(177, 87); + this.comboBoxBodyBlock.Name = "comboBoxBodyBlock"; + this.comboBoxBodyBlock.Size = new System.Drawing.Size(121, 21); + this.comboBoxBodyBlock.TabIndex = 11; + // + // comboBoxBetweenWords + // + this.comboBoxBetweenWords.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxBetweenWords.FormattingEnabled = true; + this.comboBoxBetweenWords.Items.AddRange(new object[] { + "Пробел"}); + this.comboBoxBetweenWords.Location = new System.Drawing.Point(177, 114); + this.comboBoxBetweenWords.Name = "comboBoxBetweenWords"; + this.comboBoxBetweenWords.Size = new System.Drawing.Size(121, 21); + this.comboBoxBetweenWords.TabIndex = 12; + this.comboBoxBetweenWords.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged); + // + // labelBlockBodyCount + // + this.labelBlockBodyCount.AutoSize = true; + this.labelBlockBodyCount.Location = new System.Drawing.Point(313, 94); + this.labelBlockBodyCount.Name = "labelBlockBodyCount"; + this.labelBlockBodyCount.Size = new System.Drawing.Size(66, 13); + this.labelBlockBodyCount.TabIndex = 13; + this.labelBlockBodyCount.Text = "КоличеÑ�тво"; + // + // labelBetweenWordsCount + // + this.labelBetweenWordsCount.AutoSize = true; + this.labelBetweenWordsCount.Location = new System.Drawing.Point(313, 122); + this.labelBetweenWordsCount.Name = "labelBetweenWordsCount"; + this.labelBetweenWordsCount.Size = new System.Drawing.Size(66, 13); + this.labelBetweenWordsCount.TabIndex = 14; + this.labelBetweenWordsCount.Text = "КоличеÑ�тво"; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(395, 87); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(65, 20); + this.numericUpDown1.TabIndex = 15; + this.numericUpDown1.Value = new decimal(new int[] { + 4, + 0, + 0, + 0}); + this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); + // + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(395, 115); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(65, 20); + this.numericUpDown2.TabIndex = 16; + this.numericUpDown2.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(35, 13); + this.label1.TabIndex = 17; + this.label1.Text = "Язык"; + // + // cbLanguage + // + this.cbLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbLanguage.FormattingEnabled = true; + this.cbLanguage.Items.AddRange(new object[] { + "C новой Ñ�троки", + "C текущей Ñ�троки"}); + this.cbLanguage.Location = new System.Drawing.Point(177, 6); + this.cbLanguage.Name = "cbLanguage"; + this.cbLanguage.Size = new System.Drawing.Size(283, 21); + this.cbLanguage.TabIndex = 18; + this.cbLanguage.SelectedIndexChanged += new System.EventHandler(this.cbLanguage_SelectedIndexChanged); + // + // ImageOptions + // + this.ImageOptions.BackColor = System.Drawing.Color.Magenta; + this.ImageOptions.Image = ((System.Drawing.Image)(resources.GetObject("ImageOptions.Image"))); + this.ImageOptions.Location = new System.Drawing.Point(88, 150); + this.ImageOptions.Name = "ImageOptions"; + this.ImageOptions.Size = new System.Drawing.Size(16, 16); + this.ImageOptions.TabIndex = 19; + this.ImageOptions.TabStop = false; + this.ImageOptions.Visible = false; + // + // ImageBuild + // + this.ImageBuild.BackColor = System.Drawing.Color.Magenta; + this.ImageBuild.Image = ((System.Drawing.Image)(resources.GetObject("ImageBuild.Image"))); + this.ImageBuild.Location = new System.Drawing.Point(110, 150); + this.ImageBuild.Name = "ImageBuild"; + this.ImageBuild.Size = new System.Drawing.Size(16, 16); + this.ImageBuild.TabIndex = 20; + this.ImageBuild.TabStop = false; + this.ImageBuild.Visible = false; + // + // TextFormatterForm + // + this.AcceptButton = this.buttonOk; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.buttonCancel; + this.ClientSize = new System.Drawing.Size(475, 184); + this.Controls.Add(this.ImageBuild); + this.Controls.Add(this.ImageOptions); + this.Controls.Add(this.cbLanguage); + this.Controls.Add(this.label1); + this.Controls.Add(this.numericUpDown2); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.labelBetweenWordsCount); + this.Controls.Add(this.labelBlockBodyCount); + this.Controls.Add(this.comboBoxBetweenWords); + this.Controls.Add(this.comboBoxBodyBlock); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.labelBetweenWordsSymb); + this.Controls.Add(this.labelBlockBodySymb); + this.Controls.Add(this.labelBlockEnd); + this.Controls.Add(this.labelBlockBegin); + this.Controls.Add(this.comboBoxBlockEnd); + this.Controls.Add(this.comboBoxBlockBegin); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "TextFormatterForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Форматирование"; + this.Shown += new System.EventHandler(this.TextFormatterForm_Shown); + this.Load += new System.EventHandler(this.TextFormatterForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.ImageOptions)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.ImageBuild)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox comboBoxBlockBegin; + private System.Windows.Forms.ComboBox comboBoxBlockEnd; + private System.Windows.Forms.Label labelBlockBegin; + private System.Windows.Forms.Label labelBlockEnd; + private System.Windows.Forms.Label labelBlockBodySymb; + private System.Windows.Forms.Label labelBetweenWordsSymb; + private System.Windows.Forms.Button buttonOk; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.ComboBox comboBoxBodyBlock; + private System.Windows.Forms.ComboBox comboBoxBetweenWords; + private System.Windows.Forms.Label labelBlockBodyCount; + private System.Windows.Forms.Label labelBetweenWordsCount; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cbLanguage; + public System.Windows.Forms.PictureBox ImageOptions; + public System.Windows.Forms.PictureBox ImageBuild; + } +} \ No newline at end of file diff --git a/VisualPlugins/LanguageConverter/Source/TextFormatterForm.cs b/VisualPlugins/LanguageConverter/Source/TextFormatterForm.cs new file mode 100644 index 000000000..5d70effcd --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/TextFormatterForm.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using VisualPascalABCPlugins; + +namespace Converter +{ + public partial class TextFormatterForm : Form + { + public TextFormatter TextFormatter; + internal LanguageConverter_VisualPascalABCPlugin Plugin; + private Dictionary indentsBlockBegin; + private Dictionary indentsBlockEnd; + private Dictionary indentsBodyBlock; + private Dictionary indentsBetweenWords; + public TextFormatterForm(TextFormatter _textFormatter) + { + InitializeComponent(); + + TextFormatter = _textFormatter; + initIndents(); + } + + public TextFormatterForm() + { + InitializeComponent(); + + //TextFormatter = new TextFormatter(); + initIndents(); + } + + private void initIndents() + { + indentsBlockBegin = new Dictionary(); + indentsBlockBegin.Add(comboBoxBlockBegin.Items[0].ToString(), Environment.NewLine); + indentsBlockBegin.Add(comboBoxBlockBegin.Items[1].ToString(), ""); + + indentsBlockEnd = new Dictionary(); + indentsBlockEnd.Add(comboBoxBlockEnd.Items[0].ToString(), Environment.NewLine); + indentsBlockEnd.Add(comboBoxBlockEnd.Items[1].ToString(), ""); + + indentsBodyBlock = new Dictionary(); + indentsBodyBlock.Add(comboBoxBodyBlock.Items[0].ToString(), " "); + + indentsBetweenWords = new Dictionary(); + indentsBetweenWords.Add(comboBoxBetweenWords.Items[0].ToString(), " "); + + } + + private void numericUpDown1_ValueChanged(object sender, EventArgs e) + { + + } + + private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void labelBlockBody_Click(object sender, EventArgs e) + { + + } + + private void TextFormatterForm_Shown(object sender, EventArgs e) + { + + } + + public void SaveTextFormater(TextFormatter _TextFormatter) + { + _TextFormatter.Indents.BlockBegin = indentsBlockBegin[comboBoxBlockBegin.SelectedItem.ToString()]; + _TextFormatter.Indents.BlockEnd = indentsBlockEnd[comboBoxBlockEnd.SelectedItem.ToString()]; + StringBuilder bodyBlock = new StringBuilder(); + for (int i = 0; i < numericUpDown1.Value; i++) + bodyBlock.Append(indentsBodyBlock[comboBoxBodyBlock.SelectedItem.ToString()]); + _TextFormatter.Indents.BlockBody = bodyBlock.ToString(); + _TextFormatter.Indents.BetweenWords = indentsBetweenWords[comboBoxBetweenWords.SelectedItem.ToString()]; + } + + + private void buttonOk_Click(object sender, EventArgs e) + { + SaveTextFormater(Plugin.Languages[cbLanguage.SelectedIndex].SourceTextBuilder.TextFormatter); + this.Close(); + } + + private void cbLanguage_SelectedIndexChanged(object sender, EventArgs e) + { + Plugin.currentLanguage = Plugin.Languages[cbLanguage.SelectedIndex]; + } + + internal void Init() + { + cbLanguage.Items.Clear(); + foreach (ISemanticNodeConverter snc in Plugin.Languages) + { + cbLanguage.Items.Add(snc.ToString()); + } + comboBoxBlockBegin.SelectedItem = comboBoxBlockBegin.Items[0]; + comboBoxBlockEnd.SelectedItem = comboBoxBlockEnd.Items[0]; + comboBoxBodyBlock.SelectedItem = comboBoxBodyBlock.Items[0]; + comboBoxBetweenWords.SelectedItem = comboBoxBetweenWords.Items[0]; + cbLanguage.SelectedIndex = Plugin.Languages.IndexOf(Plugin.currentLanguage); + } + + private void TextFormatterForm_Load(object sender, EventArgs e) + { + } + } +} \ No newline at end of file diff --git a/VisualPlugins/LanguageConverter/Source/TextFormatterForm.resx b/VisualPlugins/LanguageConverter/Source/TextFormatterForm.resx new file mode 100644 index 000000000..9e38f74e4 --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/TextFormatterForm.resx @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAo9JREFUOE99k+1L + U1Ecx69/TQSBL3ogwRe9Ed9bm0iS5VCw9qDTMRIcKjifWjVLE50aKDoxKxNmQ4MlU9JQWlIT57Smqc3N + OXXN3XvP/Xbu8dlFB36ccy/n+/l+z+/ek/Jxah6CQDheJJxISzgsec2KEI4Qib2X17q7mSnc6THm/ob/ + DSJJoAAIogSDuUPeyp0uzuH6+k891UEWi1TICxIi0Rh0lS+SAUOjswxw4+E60vQ/cVntgyQLD10TVBxP + SAiGdlBU3pQMGHR8PkkguxKciHkq3ifYixOsrm8hv8ySDLAPf2IAOXKaPkATLCC1wINLeZO4mOPEhaxB + RGMilgJBaCqeJQO6X0+wyISeVaBxE7JrgiBGXXepcHtPxNaOgHn/GozmtmRA58A467B81rQS2oMHPqQW + eqAweeCY3EC7zY/uvgBm5lZQbppFqf7DGQjX3udi4jhPXfdF7P4hiMquuwJCUQH9vavo7PLBVP2FAYp1 + zrOAlp4xFnkvLotFXKEJRqYjaGxdQn2jF46RGOz9YZjr/TBWfIdGPQ693nWchGt66TxwpeeNUNcwdQ1G + BDx+6kdvzy/Y7duorprF7dwu6EpsDJCtHMK1qxqWhLPYHMeNuk6/gub5Kt5MhPHOvQlz7RwsT35AqeyA + e8oLtaEFWu0MAxz9jVx96zDCtMvBbR4bWwmshXgEggkqXoTR4GKzVvuK9qAfpcZhqFRuBjiCcDXNb/E7 + wsO/sgnv4jo83gCmPctQZLciI6MS97Uu3Lk3CmWeE7riBQbIL7CdHKHKOgiV4RFydbVQFlVDVdYArakJ + 5XVtsNoGkJFZh8L8IaSnF+NmVjObz1ym87fr/HN2jhW3FAd3oKbhPYOc3vMXoHgYXvXB+nwAAAAASUVO + RK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAo9JREFUOE99k+1L + U1Ecx69/TQSBL3ogwRe9Ed9bm0iS5VCw9qDTMRIcKjifWjVLE50aKDoxKxNmQ4MlU9JQWlIT57Smqc3N + OXXN3XvP/Xbu8dlFB36ccy/n+/l+z+/ek/Jxah6CQDheJJxISzgsec2KEI4Qib2X17q7mSnc6THm/ob/ + DSJJoAAIogSDuUPeyp0uzuH6+k891UEWi1TICxIi0Rh0lS+SAUOjswxw4+E60vQ/cVntgyQLD10TVBxP + SAiGdlBU3pQMGHR8PkkguxKciHkq3ifYixOsrm8hv8ySDLAPf2IAOXKaPkATLCC1wINLeZO4mOPEhaxB + RGMilgJBaCqeJQO6X0+wyISeVaBxE7JrgiBGXXepcHtPxNaOgHn/GozmtmRA58A467B81rQS2oMHPqQW + eqAweeCY3EC7zY/uvgBm5lZQbppFqf7DGQjX3udi4jhPXfdF7P4hiMquuwJCUQH9vavo7PLBVP2FAYp1 + zrOAlp4xFnkvLotFXKEJRqYjaGxdQn2jF46RGOz9YZjr/TBWfIdGPQ693nWchGt66TxwpeeNUNcwdQ1G + BDx+6kdvzy/Y7duorprF7dwu6EpsDJCtHMK1qxqWhLPYHMeNuk6/gub5Kt5MhPHOvQlz7RwsT35AqeyA + e8oLtaEFWu0MAxz9jVx96zDCtMvBbR4bWwmshXgEggkqXoTR4GKzVvuK9qAfpcZhqFRuBjiCcDXNb/E7 + wsO/sgnv4jo83gCmPctQZLciI6MS97Uu3Lk3CmWeE7riBQbIL7CdHKHKOgiV4RFydbVQFlVDVdYArakJ + 5XVtsNoGkJFZh8L8IaSnF+NmVjObz1ym87fr/HN2jhW3FAd3oKbhPYOc3vMXoHgYXvXB+nwAAAAASUVO + RK5CYII= + + + \ No newline at end of file diff --git a/VisualPlugins/LanguageConverter/Source/Visitor.cs b/VisualPlugins/LanguageConverter/Source/Visitor.cs new file mode 100644 index 000000000..9835c830e --- /dev/null +++ b/VisualPlugins/LanguageConverter/Source/Visitor.cs @@ -0,0 +1,1552 @@ +using PascalABCCompiler.SemanticTree; +using System.Windows.Forms; +using System.Collections; +using System.Collections.Generic; +using Converter; +using System.Text; +using System.IO; + +namespace VisualPascalABCPlugins +{ + public class SemanticTreeVisitor : ISemanticVisitor + { + private System.Windows.Forms.TreeNodeCollection nodes; + + private ISemanticNodeConverter ISemanticNodeConverter; + + private ICommonNamespaceNode mainNamespace; + private string mainFunction = ""; + private int NumNestedStatement = 0; + // e,hfnm yfabu + public List nmspaceFiles = new List(); + + // óáðàòü îòñþäà + public void SaveTextInFile(string fileName, string text, bool append) + { + StreamWriter sw = new StreamWriter(fileName, append, System.Text.Encoding.GetEncoding(1251)); + sw.Write(text); + sw.Close(); + } + + public string GetConvertedText() + { + return ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack(); + } + + public SemanticTreeVisitor(ISemanticNodeConverter _semanticNodeConverter) + { + ISemanticNodeConverter = _semanticNodeConverter; + } + + // äëÿ îáû÷íîãî node - ïîòîìêà ISemanticNode + public void prepare_node(ISemanticNode subnode, string node_name) + { + + } + + public void visit(ISemanticNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IDefinitionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ITypeNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IBasicTypeNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonTypeNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeType("type", value)); + } + + public void visit(IStatementNode value) + { + // abstract + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(""); + } + + public void visit(IExpressionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IFunctionCallNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IBasicFunctionCallNode value) + { + for (int i = value.real_parameters.Length-1; i >= 0 ;i--) + value.real_parameters[i].visit(this); + + switch (value.basic_function.basic_function_type) + { + case basic_function_type.none: return; + + case basic_function_type.iassign: + case basic_function_type.bassign: + case basic_function_type.lassign: + case basic_function_type.fassign: + case basic_function_type.dassign: + case basic_function_type.uiassign: + case basic_function_type.usassign: + case basic_function_type.ulassign: + case basic_function_type.sassign: + case basic_function_type.sbassign: + case basic_function_type.boolassign: + case basic_function_type.charassign: + case basic_function_type.objassign: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeAssign("binop_assign", value)); + break; + + /////////// + + case basic_function_type.iadd: + case basic_function_type.badd: + case basic_function_type.sadd: + case basic_function_type.ladd: + case basic_function_type.fadd: + case basic_function_type.sbadd: + case basic_function_type.usadd: + case basic_function_type.uladd: + case basic_function_type.dadd: + case basic_function_type.uiadd: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeAdd("binop_add", value)); + break; + + // minus + case basic_function_type.isub: + case basic_function_type.bsub: + case basic_function_type.ssub: + case basic_function_type.lsub: + case basic_function_type.fsub: + //case basic_function_type.uisub: + case basic_function_type.sbsub: + case basic_function_type.ussub: + case basic_function_type.ulsub: + case basic_function_type.dsub: + case basic_function_type.uisub: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeSubtract("binop_subtract", value)); + break; + + case basic_function_type.imul: + case basic_function_type.bmul: + case basic_function_type.smul: + case basic_function_type.lmul: + case basic_function_type.fmul: + //case basic_function_type.uimul: + case basic_function_type.sbmul: + case basic_function_type.usmul: + case basic_function_type.ulmul: + case basic_function_type.dmul: + case basic_function_type.uimul: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeMult("binop_mult", value)); + break; + + case basic_function_type.idiv: + case basic_function_type.bdiv: + case basic_function_type.sdiv: + case basic_function_type.ldiv: + case basic_function_type.fdiv: + //case basic_function_type.uidiv: + case basic_function_type.sbdiv: + case basic_function_type.usdiv: + case basic_function_type.uldiv: + case basic_function_type.ddiv: + case basic_function_type.uidiv: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeDiv("binop_div", value)); + break; + + case basic_function_type.imod: + case basic_function_type.bmod: + case basic_function_type.smod: + //case basic_function_type.uimod: + case basic_function_type.sbmod: + case basic_function_type.usmod: + case basic_function_type.ulmod: + case basic_function_type.lmod: + case basic_function_type.uimod: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeMod("binop_mod", value)); + break; + + // increment + case basic_function_type.isinc: + case basic_function_type.bsinc: + case basic_function_type.sbsinc: + case basic_function_type.ssinc: + case basic_function_type.ussinc: + case basic_function_type.uisinc: + case basic_function_type.ulsinc: + case basic_function_type.lsinc: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeInc("binop_inc", value)); + break; + + // decrement + case basic_function_type.isdec: + case basic_function_type.bsdec: + case basic_function_type.sbsdec: + case basic_function_type.ssdec: + case basic_function_type.ussdec: + case basic_function_type.uisdec: + case basic_function_type.ulsdec: + case basic_function_type.lsdec: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeDec("binop_dec", value)); + break; + + // not + case basic_function_type.inot: + case basic_function_type.bnot: + case basic_function_type.snot: + case basic_function_type.uinot: + case basic_function_type.sbnot: + case basic_function_type.usnot: + case basic_function_type.ulnot: + case basic_function_type.lnot: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeBinNot("binop_not", value)); + break; + case basic_function_type.boolsdec: + case basic_function_type.boolsinc: + throw new System.Exception("UNknown operation!!!"); + case basic_function_type.boolnot: //il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ceq); break; + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeUnNot("unop_not", value)); + break; + + // << + case basic_function_type.ishl: + case basic_function_type.bshl: + case basic_function_type.sshl: + case basic_function_type.lshl: + case basic_function_type.uishl: + case basic_function_type.sbshl: + case basic_function_type.usshl: + case basic_function_type.ulshl: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeShl("binop_shl", value)); + break; + // >> + case basic_function_type.ishr: + case basic_function_type.bshr: + case basic_function_type.sshr: + case basic_function_type.lshr: + case basic_function_type.uishr: + case basic_function_type.sbshr: + case basic_function_type.usshr: + case basic_function_type.ulshr: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeShr("binop_shr", value)); + break; + + // == + case basic_function_type.ieq: + case basic_function_type.seq: + case basic_function_type.beq: + case basic_function_type.leq: + case basic_function_type.uieq: + case basic_function_type.sbeq: + case basic_function_type.useq: + case basic_function_type.uleq: + case basic_function_type.booleq: + case basic_function_type.feq: + case basic_function_type.deq: + case basic_function_type.chareq: + case basic_function_type.objeq: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeEq("binop_eq", value)); + break; + // != + case basic_function_type.inoteq: + case basic_function_type.snoteq: + case basic_function_type.bnoteq: + case basic_function_type.lnoteq: + case basic_function_type.uinoteq: + case basic_function_type.sbnoteq: + case basic_function_type.usnoteq: + case basic_function_type.ulnoteq: + case basic_function_type.boolnoteq: + case basic_function_type.fnoteq: + case basic_function_type.dnoteq: + case basic_function_type.charnoteq: + case basic_function_type.objnoteq: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeNotEq("binop_noteq", value)); + break; + // > + case basic_function_type.igr: + case basic_function_type.sgr: + case basic_function_type.bgr: + case basic_function_type.lgr: + case basic_function_type.uigr: + case basic_function_type.sbgr: + case basic_function_type.usgr: + case basic_function_type.ulgr: + case basic_function_type.boolgr: + case basic_function_type.fgr: + case basic_function_type.dgr: + case basic_function_type.chargr: + case basic_function_type.enumgr: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeGr("binop_gr", value)); + break; + // >= + case basic_function_type.igreq: + case basic_function_type.sgreq: + case basic_function_type.bgreq: + case basic_function_type.lgreq: + case basic_function_type.uigreq: + case basic_function_type.sbgreq: + case basic_function_type.usgreq: + case basic_function_type.ulgreq: + case basic_function_type.boolgreq: + case basic_function_type.fgreq: + case basic_function_type.dgreq: + case basic_function_type.chargreq: + case basic_function_type.enumgreq: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeGrEq("binop_greq", value)); + break; + // < + case basic_function_type.ism: + case basic_function_type.ssm: + case basic_function_type.bsm: + case basic_function_type.lsm: + case basic_function_type.uism: + case basic_function_type.sbsm: + case basic_function_type.ussm: + case basic_function_type.ulsm: + case basic_function_type.boolsm: + case basic_function_type.fsm: + case basic_function_type.dsm: + case basic_function_type.charsm: + case basic_function_type.enumsm: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeSm("binop_sm", value)); + break; + + // <= + case basic_function_type.ismeq: + case basic_function_type.ssmeq: + case basic_function_type.bsmeq: + case basic_function_type.lsmeq: + case basic_function_type.uismeq: + case basic_function_type.sbsmeq: + case basic_function_type.ussmeq: + case basic_function_type.ulsmeq: + case basic_function_type.boolsmeq: + case basic_function_type.fsmeq: + case basic_function_type.dsmeq: + case basic_function_type.charsmeq: + case basic_function_type.enumsmeq: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeSmEq("binop_smeq", value)); + break; + + case basic_function_type.band: + case basic_function_type.iand: + case basic_function_type.land: + case basic_function_type.sand: + case basic_function_type.uiand: + case basic_function_type.sband: + case basic_function_type.usand: + case basic_function_type.uland: + case basic_function_type.booland: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeAnd("binop_and", value)); + break; + + case basic_function_type.bor: + case basic_function_type.ior: + case basic_function_type.lor: + case basic_function_type.sor: + case basic_function_type.uior: + case basic_function_type.sbor: + case basic_function_type.usor: + case basic_function_type.ulor: + case basic_function_type.boolor: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeOr("binop_or", value)); + break; + + case basic_function_type.bxor: + case basic_function_type.ixor: + case basic_function_type.lxor: + case basic_function_type.sxor: + case basic_function_type.uixor: + case basic_function_type.sbxor: + case basic_function_type.usxor: + case basic_function_type.ulxor: + case basic_function_type.boolxor: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeXor("binop_xor", value)); + break; + //case basic_function_type.chareq: il.Emit(OpCodes.Ceq); break; + //case basic_function_type.charnoteq: il.Emit(OpCodes.Ceq); il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ceq); break; + + case basic_function_type.iunmin: + case basic_function_type.bunmin: + case basic_function_type.sunmin: + case basic_function_type.dunmin: + //case basic_function_type.uiunmin: + case basic_function_type.sbunmin: + case basic_function_type.usunmin: + //case basic_function_type.ulunmin: + case basic_function_type.lunmin: + case basic_function_type.uiunmin: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeUnMin("binop_unmin", value)); + break; + + case basic_function_type.iinc: + case basic_function_type.binc: + case basic_function_type.sinc: + case basic_function_type.linc: + case basic_function_type.uiinc: + case basic_function_type.sbinc: + case basic_function_type.usinc: + case basic_function_type.ulinc: + case basic_function_type.boolinc: + case basic_function_type.cinc: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeUnInc("unop_inc", value)); + break; + + case basic_function_type.idec: + case basic_function_type.bdec: + case basic_function_type.sdec: + case basic_function_type.ldec: + case basic_function_type.uidec: + case basic_function_type.sbdec: + case basic_function_type.usdec: + case basic_function_type.uldec: + case basic_function_type.booldec: + case basic_function_type.cdec: + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeUnDec("unop_dec", value)); + break; + + /* + case basic_function_type.chartoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.chartous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.chartoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.chartol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.chartoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.chartof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.chartod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.chartob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.chartosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.chartos: il.Emit(OpCodes.Conv_I2); break; + + case basic_function_type.itod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.itol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.itof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.itob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.itosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.itos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.itous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.itoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.itoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.itochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.btos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.btous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.btoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.btoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.btol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.btoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.btof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.btod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.btosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.btochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.sbtos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.sbtoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.sbtol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.sbtof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.sbtod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.sbtob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.sbtous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.sbtoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.sbtoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.sbtochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.stoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.stol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.stof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.stod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.stob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.stosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.stous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.stoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.stoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.stochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.ustoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.ustoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.ustol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.ustoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.ustof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.ustod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.ustob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.ustosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.ustos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.ustochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.uitoi: il.Emit(OpCodes.Conv_I4); break; + //case basic_function_type.ustoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.uitol: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.uitoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.uitof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.uitod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.uitob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.uitosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.uitos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.uitous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.uitochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.ultof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.ultod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.ultob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.ultosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.ultos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.ultous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.ultoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.ultoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.ultol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.ultochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.ltof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.ltod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.ltob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.ltosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.ltos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.ltous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.ltoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.ltoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.ltoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.ltochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.ftod: il.Emit(OpCodes.Conv_R8); break; + case basic_function_type.ftob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.ftosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.ftos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.ftous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.ftoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.ftoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.ftol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.ftoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.ftochar: il.Emit(OpCodes.Conv_U2); break; + + case basic_function_type.dtob: il.Emit(OpCodes.Conv_U1); break; + case basic_function_type.dtosb: il.Emit(OpCodes.Conv_I1); break; + case basic_function_type.dtos: il.Emit(OpCodes.Conv_I2); break; + case basic_function_type.dtous: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.dtoi: il.Emit(OpCodes.Conv_I4); break; + case basic_function_type.dtoui: il.Emit(OpCodes.Conv_U4); break; + case basic_function_type.dtol: il.Emit(OpCodes.Conv_I8); break; + case basic_function_type.dtoul: il.Emit(OpCodes.Conv_U8); break; + case basic_function_type.dtof: il.Emit(OpCodes.Conv_R4); break; + case basic_function_type.dtochar: il.Emit(OpCodes.Conv_U2); break; + case basic_function_type.booltoi: il.Emit(OpCodes.Conv_I4); break; + + case basic_function_type.objtoobj: + { + NETGeneratorTools.PushCast(il, helper.GetTypeReference(fn.type).tp); + break; + } + */ + } + } + + public void visit(ICommonNamespaceFunctionCallNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + foreach (IExpressionNode nodeParameter in value.real_parameters) + { + nodeParameter.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.real_parameters[value.real_parameters.Length-1] != nodeParameter) + bodyBlock.Append(", "); + } + if (bodyBlock.ToString() == "") + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack("%empty%"); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeFunctionCall("function_call", value)); + } + + public void visit(ICommonNestedInFunctionFunctionCallNode value) + { + //prepare_string_node(value.last_result_function_call.ToString(), "ICommonNestedInFunctionFunctionCallNode.last_result_function_call"); ? + //throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonMethodCallNode value) + { + + } + + public void visit(ICommonStaticMethodCallNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + foreach (IExpressionNode nodeParameter in value.real_parameters) + { + nodeParameter.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.real_parameters[value.real_parameters.Length - 1] != nodeParameter) + bodyBlock.Append(", "); + } + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeStaticMethodCall("comm_stat_method_call", value)); + } + + public void visit(ICompiledMethodCallNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + foreach (IExpressionNode nodeParameter in value.real_parameters) + { + nodeParameter.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.real_parameters[value.real_parameters.Length - 1] != nodeParameter) + bodyBlock.Append(", "); + } + if (bodyBlock.Length == 0) + bodyBlock.Append("%empty%"); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + value.obj.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeCompMethodCall("comp_method_call", value)); + } + + public void visit(ICompiledStaticMethodCallNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + foreach (IExpressionNode nodeParameter in value.real_parameters) + { + nodeParameter.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.real_parameters[value.real_parameters.Length - 1] != nodeParameter) + bodyBlock.Append(", "); + } + if (bodyBlock.Length == 0) + bodyBlock.Append("%empty%"); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeStaticMethodCall("comp_stat_method_call", value)); + } + + public void visit(IFunctionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IClassMemberNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledClassMemberNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonClassMemberNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledTypeNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IFunctionMemberNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(INamespaceMemberNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IBasicFunctionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonFunctionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonNamespaceFunctionNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + StringBuilder parameters = new StringBuilder(""); + // óâåëè÷èâàåì îòñòóï òåëà áëîêà ïåðåä âõîäîì â áëîê + + // òåëî ôóíêöèè + if (value.var_definition_nodes.Length != 0) + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyIncrement(); + foreach (ILocalVariableNode nodeVariable in value.var_definition_nodes) + { + nodeVariable.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + bodyBlock.Append(";"); + bodyBlock.Append(System.Environment.NewLine); + //bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + } + // åñëè áëîê íå ïóñò - óìåíüøàåì îòñòóï + if (bodyBlock.ToString() != "") + { + //ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyDecrement(); + } + + value.function_code.visit(this); + // íà ñòåêå ëåæèò òåëî ôóíêöèè + // + string funcbody = ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack(); + bodyBlock.Append(funcbody); + if (funcbody == "") + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack("%empty%"); + else + { + funcbody += System.Environment.NewLine; + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(funcbody); + } + + foreach (IParameterNode nodeParameter in value.parameters) + { + nodeParameter.visit(this); + parameters.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.parameters[value.parameters.Length-1] != nodeParameter) + parameters.Append(", "); + } + // êëàäåì íà ñòåê òåëî ôóíêöèè + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + // êëàäåì íà ñòåê ïàðàìåòðû ô-öèè + if (parameters.Length == 0) + parameters.Append("%empty%"); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(parameters.ToString()); + + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeFunction("function", value)); + } + + public void visit(ICommonNestedInFunctionFunctionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonMethodNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledMethodNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IIfNode value) + { + if (value.else_body != null) + value.else_body.visit(this); + value.then_body.visit(this); + value.condition.visit(this); + if (value.else_body == null) + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeIf("if", value)); + else + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeIfElse("if_else", value)); + } + + public void visit(IWhileNode value) + { + value.body.visit(this); + value.condition.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeWhile("while", value)); + } + + public void visit(IRepeatNode value) + { + value.body.visit(this); + value.condition.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeRepeat("repeat", value)); + } + + public void visit(IForNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + StringBuilder parameters = new StringBuilder(""); + value.body.visit(this); + if (value.initialization_statement != null) + { + value.initialization_statement.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + } + bodyBlock.Append(";"); + //bodyBlock.Append(" "); + if (value.while_expr != null) + { + value.while_expr.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + } + bodyBlock.Append(";"); + //bodyBlock.Append(" "); + if (value.increment_statement != null) + { + value.increment_statement.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + } + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeFor("for", value)); + } + + public void visit(IStatementsListNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + NumNestedStatement++; + // óâåëè÷èâàåì îòñòóï òåëà áëîêà ïåðåä âõîäîì â áëîê + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyIncrement(); + foreach (ILocalBlockVariableNode nodeVar in value.LocalVariables) + { + nodeVar.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + bodyBlock.Append(";"); + //if (value.LocalVariables[value.LocalVariables.Length - 1] != nodeVar) + bodyBlock.Append(System.Environment.NewLine); + } + + foreach (IStatementNode nodeStatement in value.statements) + { + nodeStatement.visit(this); + string snode = ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack(); + // if (snode != "") + { + if (snode != "") + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(snode); + if (!(nodeStatement is IStatementsListNode)) + if (snode != "") + bodyBlock.Append(";"); + if (value.statements[value.statements.Length - 1] != nodeStatement) + bodyBlock.Append(System.Environment.NewLine); + } + //else + //ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack("%empty%"); + } + + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + // óìåíüøàåì îòñòóï òåëà áëîêà ïåðåä âûõîäîì èç áëîêà + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyDecrement(); + if (NumNestedStatement > 1) + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeStatementsNested("statements_nested", value)); + else + { + string snode = ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack(); + if (snode == "") + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack("%empty%"); + else + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(snode); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeStatements("statements", value)); + } + NumNestedStatement--; + } + + public void visit(INamespaceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonNamespaceNode value) + { + //value.Location.document.file_name + StringBuilder bodyBlock = new StringBuilder(""); + // óâåëè÷èâàåì îòñòóï òåëà áëîêà ïåðåä âõîäîì â áëîê + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyIncrement(); + //bodyBlock.Append(SemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + + // åñëè íàõîäèìñÿ â ãëàâíîì namespace ïðîãðàììû, äîáâàëÿåì main â body + if (mainNamespace == value) + { + bodyBlock.Append(System.Environment.NewLine); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(mainFunction); + //SemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(mainFunctionNode); + } + foreach (ICommonNamespaceNode nodeNamespace in value.nested_namespaces) + { + nodeNamespace.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + //if (value.nested_namespaces[value.nested_namespaces.Length - 1] != nodeNamespace) + bodyBlock.Append(System.Environment.NewLine); + } + // + foreach (ICommonTypeNode types in value.types) + { + types.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + //if (value.types[value.types.Length - 1] != types) + bodyBlock.Append(System.Environment.NewLine); + + } + foreach (ICommonNamespaceVariableNode var in value.variables) + { + var.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + bodyBlock.Append(";"); + //if (value.variables[value.variables.Length - 1] != var) + bodyBlock.Append(System.Environment.NewLine); + } + foreach (ICommonNamespaceFunctionNode functions in value.functions) + { + functions.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + //bodyBlock.Append(";"); + bodyBlock.Append(System.Environment.NewLine); + } + foreach (INamespaceConstantDefinitionNode constants in value.constants) + { + constants.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + bodyBlock.Append(";"); + bodyBlock.Append(System.Environment.NewLine); + } + + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + // óìåíüøàåì îòñòóï òåëà áëîêà ïåðåä âûõîäîì èç áëîêà + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyDecrement(); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeNamespace("namespace", value)); + + } + + public void visit(ICompiledNamespaceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IDllNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IProgramNode value) + { + StringBuilder bodyBlock = new StringBuilder(""); + string currNamespace = ""; + + // îáíóëÿåì îòñòóï òåëà áëîêàame + ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyDecrement(); + + if (value.main_function != null) + value.main_function.visit(this); + mainFunction = ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody + ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack(); + + // ïåðåä âõîäîì â áëîê óâ. îòñòóï + //SemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBodyIncrement(); + mainNamespace = value.main_function.comprehensive_namespace; + string outdir = System.IO.Path.GetDirectoryName(mainNamespace.Location.document.file_name); + foreach (ICommonNamespaceNode nodeNamespace in value.namespaces) + { + nodeNamespace.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.TextFormatter.Indents.BlockBody); + currNamespace = ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack(); + bodyBlock.Append(currNamespace); + if (value.namespaces[value.namespaces.Length-1] != nodeNamespace) + bodyBlock.Append(System.Environment.NewLine); + string name = nodeNamespace.namespace_name.Replace('$', 'S'); + if (name == "") + name = System.IO.Path.GetFileNameWithoutExtension(mainNamespace.Location.document.file_name); + SaveTextInFile(outdir + "\\" +name+".cs", currNamespace, false); + nmspaceFiles.Add(outdir + "\\" + name + ".cs"); + } + //bodyBlock.Append(mainFunctionNode); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeProgram("program", value)); + } + + public void visit(IAddressedExpressionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ILocalVariableReferenceNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeLocVariableReference("locvariable_reference", value)); + } + + public void visit(INamespaceVariableReferenceNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeVariableReference("variable_reference", value)); + } + + public void visit(ICommonClassFieldReferenceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IStaticCommonClassFieldReferenceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledFieldReferenceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IStaticCompiledFieldReferenceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonParameterReferenceNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeParameterReference("parameter_reference", value)); + } + + + public void visit(IConstantNode value) + { + // abstract + } + + public void visit(IBoolConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeBoolConstant("bool_constant", value)); + } + + public void visit(IByteConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeByteConstant("byte_constant", value)); + } + + public void visit(IIntConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeIntConstant("int_constant", value)); + } + + public void visit(ISByteConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeSByteConstant("sbyte_constant", value)); + } + + public void visit(IShortConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeShortConstant("short_constant", value)); + } + + public void visit(IUShortConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeUShortConstant("ushort_constant", value)); + } + + public void visit(IUIntConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeUIntConstant("uint_constant", value)); + } + + public void visit(IULongConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeULongConstant("ulong_constant", value)); + } + + public void visit(ILongConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeLongConstant("long_constant", value)); + } + + public void visit(IDoubleConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeDoubleConstant("double_constant", value)); + } + + public void visit(IFloatConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeFloatConstant("float_constant", value)); + } + + public void visit(ICharConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeCharConstant("char_constant", value)); + } + + public void visit(IStringConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeStringConstant("string_constant", value)); + } + + + public void visit(IVAriableDefinitionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ILocalVariableNode value) + { + StringBuilder bodyBlock = new StringBuilder(); + + if (value.inital_value == null) + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeVariable("var", value)); + else + { + // êëàäåì íà ñòåê ñãåíåðèðîâàííîå â íîâûé òåêñò çíà÷åíèå ïåðåìåííîé + value.inital_value.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeVariable("var_init", value)); + } + } + + public void visit(ICommonNamespaceVariableNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeNamespaceVariable("namespace_var", value)); + } + + public void visit(ICommonClassFieldNode value) + { + + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledClassFieldNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IParameterNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonParameterNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeParameter("parameter", value)); + } + + public void visit(IBasicParameterNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledParameterNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IConstantDefinitionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IClassConstantDefinitionNode value) + { + + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledClassConstantDefinitionNode value) + { + + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(INamespaceConstantDefinitionNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeNamespaceConst("const", value)); + } + + public void visit(ICommonFunctionConstantDefinitionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IPropertyNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonPropertyNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IBasicPropertyNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledPropertyNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IThisNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IReturnNode value) + { + value.return_value.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeReturn("return", value)); + } + + public void visit(ICommonConstructorCall value) + { + StringBuilder bodyBlock = new StringBuilder(""); + foreach (IExpressionNode nodeParameter in value.real_parameters) + { + nodeParameter.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.real_parameters[value.real_parameters.Length - 1] != nodeParameter) + bodyBlock.Append(", "); + } + if (bodyBlock.Length == 0) + bodyBlock.Append("%empty%"); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeConstructorCall("constructor_call", value)); + } + + public void visit(ICompiledConstructorCall value) + { + StringBuilder bodyBlock = new StringBuilder(""); + foreach (IExpressionNode nodeParameter in value.real_parameters) + { + nodeParameter.visit(this); + bodyBlock.Append(ISemanticNodeConverter.SourceTextBuilder.GetNodeFromStack()); + if (value.real_parameters[value.real_parameters.Length - 1] != nodeParameter) + bodyBlock.Append(", "); + } + if (bodyBlock.Length == 0) + bodyBlock.Append("%empty%"); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(bodyBlock.ToString()); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeConstructorCall("constructor_call", value)); + } + + public void visit(IWhileBreakNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IRepeatBreakNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IForBreakNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IWhileContinueNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IRepeatContinueNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IForContinueNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledConstructorNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ISimpleArrayNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ISimpleArrayIndexingNode value) + { + value.index.visit(this); + value.array.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeSimpleArrInd("array_indexing", value)); + } + + public void visit(IExternalStatementNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IRefTypeNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IGetAddrNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IDereferenceNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IThrowNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ISwitchNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICaseVariantNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICaseRangeNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(INullConstantNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeNullConst("const_null", value)); + } + + public void visit(IUnsizedArray value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IRuntimeManagedMethodBody value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IAsNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IIsNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ISizeOfOperator value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ITypeOfOperator value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeTypeOf("type_of", value)); + } + + public void visit(IExitProcedure value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ITryBlockNode value) + { + + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IExceptionFilterBlockNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IArrayConstantNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IStatementsExpressionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IQuestionColonExpressionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IRecordConstantNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ILabelNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ILabeledStatementNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IGotoStatementNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledStaticMethodCallNodeAsConstant value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonNamespaceFunctionCallNodeAsConstant value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IEnumConstNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IForeachNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + //prepare_node(value.Body, "IForeachNode.Body"); ? + //prepare_node(value.InWhatExpr, "IForeachnode.InWhatExpr"); ? + //prepare_node(value.VarIdent, "IForeachNode.VarIdent"); ? + } + + public void visit(ILockStatement value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + //prepare_node(value.Body, "ILockStatement.Body"); ? + //prepare_node(value.LockObject, "ILockStatement.LockObject"); ? + } + + public void visit(ILocalBlockVariableNode value) + { + StringBuilder bodyBlock = new StringBuilder(); + + if (value.inital_value == null) + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeVariable("var", value)); + else + { + // êëàäåì íà ñòåê ñãåíåðèðîâàííîå â íîâûé òåêñò çíà÷åíèå ïåðåìåííîé + value.inital_value.visit(this); + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeVariable("var_init", value)); + } + } + + public void visit(ILocalBlockVariableReferenceNode value) + { + ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(ISemanticNodeConverter.ConvertPABCNETNodeLocalBlockVariable("var_locblock", value)); + } + public void visit(ICompiledConstructorCallAsConstant value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + public void visit(IRethrowStatement value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IForeachBreakNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IForeachContinueNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + public void visit(INamespaceConstantReference value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IFunctionConstantReference value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonConstructorCallAsConstant value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IArrayInitializer value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICommonEventNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IEventNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(ICompiledEventNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IStaticEventReference value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(INonStaticEventReference value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public void visit(IRecordInitializer value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(IDefaultOperatorNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(IAttributeNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(IPInvokeStatementNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(IBasicFunctionCallNodeAsConstant value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(ICompiledStaticFieldReferenceNodeAsConstant value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(ILambdaFunctionNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + + public virtual void visit(ILambdaFunctionCallNode value) + { + throw new System.NotSupportedException(value.GetType().ToString()); + } + public virtual void visit(ICommonNamespaceEventNode value) + { + } + } +} diff --git a/VisualPlugins/LanguageConverter/icon.png b/VisualPlugins/LanguageConverter/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a4fa2e8d6990f48450f8af6f3362a9abbc808513 GIT binary patch literal 820 zcmV-41Izr0P)Px#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy7j#8fbW?9;ba!ELWdKlNX>N2bPDNB8b~7$8%`aC*0007yNkl4_y;f98X9HhIUX?-joa&bbLNZAiENrh#HnB&BStU*L$B9;O{Xeyp11G-;N zu*ig-RiJSbvTK4MMqPKQaC=Y0){cOA{~CrRQ-hk zignJjfR>&y7I`l&i$z?a2}Y(PXlz|VeWMqSkr?d#VVLXvFjjnrMm-L_-gTUWYkKKC zaHZ#sP}eYZ4Mqe!e(FbW&o9{R+o-OZ#qHcK=t^u1kgXiTwW}JIgtOQj$Bnv9zk=rZ zD&9vITI~!29Q}=4ed{p7w9CP59vfQ;tc7?4f(a^K zgwfz)vsU|x_Mji7#$l*bZU#7la5c?u@jJr9zp@GM;yOIu0H!_5P-M3vBcl@cwJzMb zHwtB*6T0FB2FNe4ogAUcItZ2F5ps34P!?4~Rn`ElsR`wEZLrz~kdax3!u%nmrx)X9 yRx_K=T&DB4>-=+ejup2Q2X~;R;XQ+#-t!lrco<&w!TNjv0000 + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {8F44EF8C-C487-4D23-B028-55935466DC36} + Library + Properties + SCharpLanguageConverter + SCharpLanguageConverter + + + 4.0 + + + v4.0 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + true + full + false + ..\..\bin\ + DEBUG;TRACE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + ..\..\bin\ + TRACE + prompt + 4 + AllRules.ruleset + + + + False + ..\..\bin\SemanticTree.dll + + + + + + + + + + + + False + КлиентÑ�кий профиль .NET Framework 3.5 SP1 + false + + + False + .NET Framework 3.5 SP1 + true + + + False + УÑ�тановщик Windows 3.1 + true + + + + + {43879684-ADBE-470A-AAC6-2ACA36603971} + LanguageConverter + + + + + \ No newline at end of file diff --git a/VisualPlugins/SCharpLanguageConverter/SemanticNodeConverter.cs b/VisualPlugins/SCharpLanguageConverter/SemanticNodeConverter.cs new file mode 100644 index 000000000..f9f8a9aba --- /dev/null +++ b/VisualPlugins/SCharpLanguageConverter/SemanticNodeConverter.cs @@ -0,0 +1,398 @@ +using System; +using System.Collections.Generic; +using System.Text; +using PascalABCCompiler.SemanticTree; + +namespace Converter +{ + public class CSharpSemanticNodeConverter : ISemanticNodeConverter + { + private SourceTextBilder sourceTextBuilder; + public SourceTextBilder SourceTextBuilder + { + set + { + sourceTextBuilder = value; + } + get + { + return sourceTextBuilder; + } + } + + public CSharpSemanticNodeConverter() + { + SourceTextBuilder = new SourceTextBilder(); + } + + public CSharpSemanticNodeConverter(ListSyntRules _listSyntRules, TextFormatter _textFormatter) + { + SourceTextBuilder = new SourceTextBilder(_listSyntRules, _textFormatter); + } + + public string GetConvertedText() + { + return SourceTextBuilder.GetNodeFromStack(); + } + + public virtual string ConvertPABCNETNodeProgram(string _nodeName, object _node) + { + // IProgramNode - îñíîâíîé óçåë, ñîäåðæèò âåñü òåêñò ïðîãðàììû, + // îáðàáàòûâàåòñÿ âèçèòîðîì ïîñëåäíèì. + return SourceTextBuilder.GetNodeFromStack(); + } + + public virtual string ConvertPABCNETNodeClass(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeNamespace(string _nodeName, object _node) + { + //SourceTextBuilder.TextFormatter.Indents.BlockBodyIncrement(); + string nodeContext = SourceTextBuilder.ConvertNode(_nodeName, _node); + //SourceTextBuilder.TextFormatter.Indents.BlockBodyDecrement(); + return nodeContext; + } + + public virtual string ConvertPABCNETNodeBlock(string _nodeName, object _node) + { + return ""; + } + + public virtual string ConvertPABCNETNodeType(string _nodeName, object _node) + { + if ((_node as ICommonTypeNode).is_value_type) + return SourceTextBuilder.ConvertNode("struct", _node); + else // ñäåëàòü äëÿ øàáëîíîâ, ïàðàìåòðèçîâàííûõ ùàáëîíîâ, êëàññîâ. + return SourceTextBuilder.ConvertNode("class", _node); + + } + + public virtual string ConvertPABCNETNodeFunction(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeVariable(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeStatementsNested(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeStatements(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeAssign(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeVariableReference(string _nodeName, object _node) + { + // âîçâðàùàåì èìÿ ïåðåìåííîé + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeParameterReference(string _nodeName, object _node) + { + // âîçâðàùàåì èìÿ ïåðåìåííîé + return (_node as ICommonParameterReferenceNode).parameter.name; + } + + public virtual string ConvertPABCNETNodeBoolConstant(string _nodeName, object _node) + { + // âîçâðàùàåì èìÿ ïåðåìåííîé + return (_node as IBoolConstantNode).constant_value.ToString(); + } + + public virtual string ConvertPABCNETNodeFunctionCall(string _nodeName, object _node) + { + // âîçâðàùàåì èìÿ ïåðåìåííîé + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeParameter(string _nodeName, object _node) + { + string type = ""; + // âîçâðàùàåì èìÿ è òèï ïåðåìåííîé + if ((_node as ICommonParameterNode).type is ICompiledTypeNode) + type = ((_node as ICommonParameterNode).type as ICompiledTypeNode).compiled_type.ToString(); + if ((_node as ICommonParameterNode).type is ICommonTypeNode) + type = ((_node as ICommonParameterNode).type as ICommonTypeNode).name; + return type + " " + (_node as ICommonParameterNode).name; + } + + public virtual string ConvertPABCNETNodeNamespaceVariable(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeNamespaceConst(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeIf(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeLocalBlockVariable(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeStaticMethodCall(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeTypeOf(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeIntConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IIntConstantNode).constant_value.ToString(); + } + + public virtual string ConvertPABCNETNodeByteConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IByteConstantNode).constant_value.ToString(); + } + public virtual string ConvertPABCNETNodeSByteConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as ISByteConstantNode).constant_value.ToString(); + } + public virtual string ConvertPABCNETNodeShortConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IShortConstantNode).constant_value.ToString(); + } + public virtual string ConvertPABCNETNodeUShortConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IUShortConstantNode).constant_value.ToString(); + } + public virtual string ConvertPABCNETNodeUIntConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IUIntConstantNode).constant_value.ToString(); + } + public virtual string ConvertPABCNETNodeULongConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IULongConstantNode).constant_value.ToString(); + } + + public virtual string ConvertPABCNETNodeLongConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as ILongConstantNode).constant_value.ToString(); + } + + public virtual string ConvertPABCNETNodeDoubleConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IDoubleConstantNode).constant_value.ToString(); + } + + public virtual string ConvertPABCNETNodeFloatConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return (_node as IFloatConstantNode).constant_value.ToString(); + } + + public virtual string ConvertPABCNETNodeCharConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return "'" + (_node as ICharConstantNode).constant_value.ToString() + "'"; + } + + public virtual string ConvertPABCNETNodeStringConstant(string _nodeName, object _node) + { + // âîçâðàùàåì ÷èñëî integer + return "\"" + (_node as IStringConstantNode).constant_value.ToString() + "\""; + } + + public virtual string ConvertPABCNETNodeWhile(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeRepeat(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeFor(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeSimpleArrInd(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeAdd(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeSubtract(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeMult(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeDiv(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeMod(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeInc(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeDec(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeBinNot(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeUnNot(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeShr(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeShl(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeReturn(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeEq(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeNotEq(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeGr(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeGrEq(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeSm(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeSmEq(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeAnd(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeOr(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeXor(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeUnMin(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeLocVariableReference(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeNullConst(string _nodeName, object _node) + { + return "null"; + } + + public virtual string ConvertPABCNETNodeConstructorCall(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeCompMethodCall(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeIfElse(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeUnInc(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + + public virtual string ConvertPABCNETNodeUnDec(string _nodeName, object _node) + { + return SourceTextBuilder.ConvertNode(_nodeName, _node); + } + public override string ToString() + { + return "C#"; + } + } +}