From 3f520df65ee32ff02be5cce6ef4800cfbeb7c9af 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: Tue, 3 Oct 2017 20:18:37 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D1=81=D1=82=D0=B2=20=D0=B8=D0=BC=D0=B5=D0=BD=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=D1=85=20=D0=92=D0=BE=D0=B7?= =?UTF-8?q?=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=88=D0=B8=D1=80=D1=8F=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D1=81=D1=82=D0=B2=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=20.NET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Compiler/Compiler.cs | 21 +- TreeConverter/NetWrappers/NetHelper.cs | 2 +- TreeConverter/SymbolTable/DSST/SymbolTable.cs | 4 +- .../TreeConversion/syntax_tree_visitor.cs | 159 +++++-------- TreeConverter/TreeRealization/namespaces.cs | 36 ++- TreeConverter/TreeRealization/units.cs | 1 + .../Projects/NewFileForm.Designer.cs | 208 +++++++++--------- VisualPascalABCNET/Projects/NewFileForm.cs | 13 +- VisualPascalABCNET/Projects/NewFileForm.resx | 2 +- VisualPascalABCNET/Projects/ProjectHelper.cs | 172 +++++++++------ VisualPascalABCNET/Projects/ProjectTasks.cs | 28 ++- bin/Lng/Eng/SemanticErrors_ib.dat | 1 + bin/Lng/Eng/VisualPascalABCNET.dat | 1 + bin/Lng/Rus/SemanticErrors_ib.dat | 1 + bin/Lng/Rus/VisualPascalABCNET.dat | 1 + 15 files changed, 344 insertions(+), 306 deletions(-) diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index bcd9f42ea..105d619e2 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -1807,7 +1807,7 @@ namespace PascalABCCompiler //Console.WriteLine("Compile Implementation "+UnitName);//DEBUG //TODO: Избавиться от преобразования типа. - AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true); + AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true, null); #if DEBUG if (InternalDebug.SemanticAnalysis) @@ -2704,7 +2704,7 @@ namespace PascalABCCompiler return false; } - private void IncludeNamespaces(CompilationUnit Unit) + private Dictionary IncludeNamespaces(CompilationUnit Unit) { if (HasIncludeNamespacesDirective(Unit) && Unit.SyntaxTree is SyntaxTree.unit_module && (Unit.SyntaxTree as SyntaxTree.unit_module).unit_name.HeaderKeyword != SyntaxTree.UnitHeaderKeyword.Library) throw new IncludeNamespaceInUnit(CurrentCompilationUnit.SyntaxTree.file_name, CurrentCompilationUnit.SyntaxTree.source_context); @@ -2810,6 +2810,7 @@ namespace PascalABCCompiler main_library.interface_part.uses_modules = main_uses; else main_program.used_units = main_uses; + return namespaces; } private SyntaxTree.compilation_unit GetNamespaceSyntaxTree(string FileName) @@ -2917,9 +2918,9 @@ namespace PascalABCCompiler return new TreeRealization.using_namespace(SyntaxTree.Utils.IdentListToString(_name_space.name.idents, ".")); } - private TreeRealization.using_namespace GetNamespace(TreeRealization.using_namespace_list using_list, string full_namespace_name, SyntaxTree.unit_or_namespace _name_space, bool possible_is_unit) + private TreeRealization.using_namespace GetNamespace(TreeRealization.using_namespace_list using_list, string full_namespace_name, SyntaxTree.unit_or_namespace _name_space, bool possible_is_unit, Dictionary pabc_namespaces) { - if (!NetHelper.NetHelper.NamespaceExists(full_namespace_name)) + if (!NetHelper.NetHelper.NamespaceExists(full_namespace_name) && !(pabc_namespaces != null && pabc_namespaces.ContainsKey(full_namespace_name))) { if (possible_is_unit) if (!full_namespace_name.Contains(".")) @@ -2929,16 +2930,16 @@ namespace PascalABCCompiler return new TreeRealization.using_namespace(full_namespace_name); } - public void AddNamespaces(TreeRealization.using_namespace_list using_list, List namespaces, bool possible_is_units) + public void AddNamespaces(TreeRealization.using_namespace_list using_list, List namespaces, bool possible_is_units, Dictionary pabc_namespaces) { foreach (SyntaxTree.unit_or_namespace ns in namespaces) - using_list.AddElement(GetNamespace(using_list, SyntaxTree.Utils.IdentListToString(ns.name.idents, "."), ns, possible_is_units)); + using_list.AddElement(GetNamespace(using_list, SyntaxTree.Utils.IdentListToString(ns.name.idents, "."), ns, possible_is_units, pabc_namespaces)); } public void AddNamespaces(TreeRealization.using_namespace_list using_list, SyntaxTree.using_list ul) { if (ul != null) - AddNamespaces(using_list, ul.namespaces, false); + AddNamespaces(using_list, ul.namespaces, false, null); } public SyntaxTree.using_list GetInterfaceSyntaxUsingList(SyntaxTree.compilation_unit cu) @@ -3195,7 +3196,7 @@ namespace PascalABCCompiler } } TreeRealization.unit_node_list References = GetReferences(CurrentUnit); - IncludeNamespaces(CurrentUnit); + var namespaces = IncludeNamespaces(CurrentUnit); if (SyntaxUsesList != null) { @@ -3240,7 +3241,7 @@ namespace PascalABCCompiler CurrentUnit.InterfaceUsedUnits.AddRange(References); - AddNamespaces(CurrentUnit.InterfaceUsingNamespaceList, CurrentUnit.PossibleNamespaces, true); + AddNamespaces(CurrentUnit.InterfaceUsingNamespaceList, CurrentUnit.PossibleNamespaces, true, namespaces); AddNamespaces(CurrentUnit.InterfaceUsingNamespaceList, GetInterfaceSyntaxUsingList(CurrentUnit.SyntaxTree)); //Console.WriteLine("Compile Interface "+UnitName);//DEBUG @@ -3305,7 +3306,7 @@ namespace PascalABCCompiler CurrentCompilationUnit = CurrentUnit; - AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true); + AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true, namespaces); AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, GetImplementationSyntaxUsingList(CurrentUnit.SyntaxTree)); if (!interfcompile) diff --git a/TreeConverter/NetWrappers/NetHelper.cs b/TreeConverter/NetWrappers/NetHelper.cs index a1a4d8486..a00a40f22 100644 --- a/TreeConverter/NetWrappers/NetHelper.cs +++ b/TreeConverter/NetWrappers/NetHelper.cs @@ -142,7 +142,7 @@ namespace PascalABCCompiler.NetHelper string full_ns = null; if (NetHelper.IsNetNamespace(name, _unar, out full_ns) == true) { - compiled_namespace_node cnn = new compiled_namespace_node(full_ns, _tcst); + compiled_namespace_node cnn = compiled_namespace_node.get_compiled_namespace(full_ns, _tcst);//new compiled_namespace_node(full_ns, _tcst); si = new SymbolInfoList(new SymbolInfoUnit(cnn)); } else diff --git a/TreeConverter/SymbolTable/DSST/SymbolTable.cs b/TreeConverter/SymbolTable/DSST/SymbolTable.cs index 0ea6b82a1..243ba5681 100644 --- a/TreeConverter/SymbolTable/DSST/SymbolTable.cs +++ b/TreeConverter/SymbolTable/DSST/SymbolTable.cs @@ -242,7 +242,8 @@ namespace SymbolTable public class DotNETScope:Scope { - public DotNETScope(DSSymbolTable vSymbolTable):base(vSymbolTable,null,false) + public NamespaceScope AdditionalNamespaceScope; + public DotNETScope(DSSymbolTable vSymbolTable):base(vSymbolTable,null,false) { } @@ -259,6 +260,7 @@ namespace SymbolTable } public class UnitInterfaceScope:UnitPartScope { + public UnitInterfaceScope(DSSymbolTable vSymbolTable,Scope TopScope,Scope[] vTopScopeArray): base(vSymbolTable,TopScope,vTopScopeArray) { diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index cb53ec293..f2e34d671 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -2730,6 +2730,7 @@ namespace PascalABCCompiler.TreeConverter { if (referenced_units[i] is namespace_unit_node) { + namespace_unit_node nun = referenced_units[i] as namespace_unit_node; for (int j = 0; j < assembly_references.Length; j++) { using_namespace_list unl = new using_namespace_list(); @@ -2739,6 +2740,8 @@ namespace PascalABCCompiler.TreeConverter } if (_compiled_unit != null) _compiled_unit.used_namespaces.Add((referenced_units[i] as namespace_unit_node).namespace_name.namespace_name); + if (nun.scope != null) + used_units.Add(nun.scope); } else { @@ -10050,15 +10053,59 @@ namespace PascalABCCompiler.TreeConverter parent_scope.AddSymbol(names[i], new SymbolInfoUnit(cmn)); scope.AddSymbol(names[i], new SymbolInfoUnit(cmn)); if (i == names.Length - 1) + { dict.Add(_syntax_namespace_node, cmn); + var unit_scope = context.converted_namespace.scope as SymTable.UnitInterfaceScope; + if (unit_scope.TopScopeArray != null) + for (int j = 0; j < unit_scope.TopScopeArray.Length; j++) + { + if (unit_scope.TopScopeArray[j] is NetHelper.NetScope) + { + NetHelper.NetScope netScope = unit_scope.TopScopeArray[j] as NetHelper.NetScope; + if (netScope.used_namespaces.Count > 0 && string.Compare(netScope.used_namespaces[0].namespace_name, _syntax_namespace_node.name, true) == 0) + { + unit_scope.TopScopeArray[j] = scope; + } + } + } + } + } else { foreach (SymbolInfoUnit si in si_list.InfoUnitList) if (si.sym_info is common_namespace_node) { - scope = (si.sym_info as common_namespace_node).scope; + common_namespace_node cmn = si.sym_info as common_namespace_node; + scope = cmn.scope; + if (!(scope is SymTable.NamespaceScope)) + { + if (i == names.Length - 1) + dict.Add(_syntax_namespace_node, cmn); + } + break; } + else if (si.sym_info is compiled_namespace_node) + { + List top_scopes = new List(); + top_scopes.AddRange(build_referenced_units(_syntax_namespace_node.referenced_units, false)); + if (parent_scope != context.CurrentScope) + top_scopes.Add(parent_scope); + compiled_namespace_node cnn = si.sym_info as compiled_namespace_node; + if (cnn.common_namespace == null) + { + scope = convertion_data_and_alghoritms.symbol_table.CreateNamespaceScope(top_scopes.ToArray(), parent_scope); + common_namespace_node cmn = new common_namespace_node(null, _compiled_unit, names[i], scope, null); + cnn.common_namespace = cmn; + } + else + scope = cnn.common_namespace.scope; + if (i == names.Length - 1 && !dict.ContainsKey(_syntax_namespace_node)) + dict.Add(_syntax_namespace_node, cnn.common_namespace); + } + + if (scope == null) + AddError(get_location(_syntax_namespace_node), "NAMESPACE_REDECLARATION"); } parent_scope = scope; } @@ -10105,7 +10152,7 @@ namespace PascalABCCompiler.TreeConverter { var cmn = dict[_syntax_namespace_node]; List scopes = new List(); - SymTable.NamespaceScope ns_scope = cmn.scope as SymTable.NamespaceScope; + SymTable.UnitInterfaceScope ns_scope = cmn.scope as SymTable.UnitInterfaceScope; if (ns_scope.TopScopeArray != null) scopes.AddRange(ns_scope.TopScopeArray); foreach (unit_node un in _syntax_namespace_node.referenced_units) @@ -19082,113 +19129,7 @@ namespace PascalABCCompiler.TreeConverter } body_exists = false; } - public void lambda_body_visit(SyntaxTree.block _block) - { - //weak_node_test_and_visit(_block.defs); - - //ssyy добавил генерацию вызова конструктора предка без параметров - if (context.converting_block() == block_type.function_block) - { - common_method_node cmn = context.top_function as common_method_node; - if (cmn != null && cmn.is_constructor && !(cmn.polymorphic_state == SemanticTree.polymorphic_state.ps_static)) - { - context.allow_inherited_ctor_call = true; - if (_block.program_code != null && _block.program_code.subnodes != null) - { - //(ssyy) Для записей конструктор предка не вызываем. - bool should_ctor_add = context.converted_type.is_class; - if (should_ctor_add) - { - if (_block.program_code.subnodes.Count > 0) - { - SyntaxTree.procedure_call pc = _block.program_code.subnodes[0] as SyntaxTree.procedure_call; - if (pc != null || _block.program_code.subnodes[0] is SyntaxTree.inherited_message) - { - //SyntaxTree.inherited_ident ii = pc.func_name as SyntaxTree.inherited_ident; - //SyntaxTree.method_call mc = pc.func_name as SyntaxTree.method_call; - //SyntaxTree.ident id = pc.func_name as SyntaxTree.ident; - //if (/*ii != null*/id != null || mc != null /*&& mc.dereferencing_value is SyntaxTree.inherited_ident*/) - { - //(ssyy) Не уверен, что следующий оператор необходим. - convertion_data_and_alghoritms.check_node_parser_error(_block.program_code); - - statement_node inh = convert_strong(_block.program_code.subnodes[0]); - - compiled_constructor_call c1 = inh as compiled_constructor_call; - if (c1 != null && !c1._new_obj_awaited) - { - should_ctor_add = false; - } - else - { - common_constructor_call c2 = inh as common_constructor_call; - if (c2 != null && !c2._new_obj_awaited) - { - should_ctor_add = false; - } - } - } - } - } - } - if (should_ctor_add) - { - //Пытаемся добавить вызов .ctor() предка... - //Для начала проверим, есть ли у предка таковой. - bool not_found = true; - SymbolInfoList sym = context.converted_type.base_type.find_in_type(compiler_string_consts.default_constructor_name, context.CurrentScope); - if (sym != null) - { - foreach (SymbolInfoUnit sym_unit in sym.InfoUnitList) - { - if (!not_found) - break; - compiled_constructor_node ccn = sym_unit.sym_info as compiled_constructor_node; - if (ccn != null && ccn.parameters.Count == 0) - { - not_found = false; - } - else - { - common_method_node cnode = sym_unit.sym_info as common_method_node; - if (cnode != null && cnode.is_constructor && (cnode.parameters.Count == 0 || cnode.parameters[0].default_value != null)) - { - not_found = false; - } - } - } - } - if (not_found) - { - //У предка нет конструктора по умолчанию - AddError(get_location(_block.program_code), "INHERITED_CONSTRUCTOR_CALL_EXPECTED"); - } - else - { - //Генерируем вызов .ctor() предка - SyntaxTree.inherited_ident ii = new SyntaxTree.inherited_ident(); - ii.name = compiler_string_consts.default_constructor_name; - _block.program_code.subnodes.Insert(0, new SyntaxTree.procedure_call(ii)); - //context.allow_inherited_ctor_call = false; - } - } - } - } - } - //\ssyy - - //ssyy - if (context.converting_block() == block_type.namespace_block) - { - context.check_predefinition_defined(); - } - - context.enter_code_block_with_bind(); - statement_node sn = convert_strong(_block.program_code); - context.leave_code_block(); - - context.code = sn; - } + public override void visit(SyntaxTree.lambda_inferred_type lit) //lroman// { diff --git a/TreeConverter/TreeRealization/namespaces.cs b/TreeConverter/TreeRealization/namespaces.cs index 4a6bf3781..03e2fa70d 100644 --- a/TreeConverter/TreeRealization/namespaces.cs +++ b/TreeConverter/TreeRealization/namespaces.cs @@ -585,6 +585,7 @@ namespace PascalABCCompiler.TreeRealization /// Имя (полное) пространства имен. /// private string _name; + private common_namespace_node _common_namespace; private SymbolTable.TreeConverterSymbolTable _tcst; @@ -613,6 +614,19 @@ namespace PascalABCCompiler.TreeRealization return new string(_name.ToCharArray(last_dot_ind,_name.Length-last_dot_ind)); } + private static Dictionary compiled_namespaces = new Dictionary(); + public static compiled_namespace_node get_compiled_namespace(string full_name, SymbolTable.TreeConverterSymbolTable tcst) + { + compiled_namespace_node cnn = null; + if (!compiled_namespaces.TryGetValue(full_name, out cnn)) + { + cnn = new compiled_namespace_node(full_name, tcst); + compiled_namespaces.Add(full_name, cnn); + } + cnn._tcst = tcst; + return cnn; + } + /// /// Имя пространства имен (не полное). /// @@ -635,6 +649,18 @@ namespace PascalABCCompiler.TreeRealization } } + public common_namespace_node common_namespace + { + get + { + return _common_namespace; + } + set + { + _common_namespace = value; + } + } + /// /// Поиск символа в пространстве имен. /// @@ -644,15 +670,21 @@ namespace PascalABCCompiler.TreeRealization { bool is_ns = NetHelper.NetHelper.IsNetNamespace(_name + "." + name); SymbolInfoList si = null; - if (is_ns == true) + if (is_ns) { - compiled_namespace_node cnn = new compiled_namespace_node(_name + "." + name,_tcst); + compiled_namespace_node cnn = compiled_namespace_node.get_compiled_namespace(_name + "." + name, _tcst); si = new SymbolInfoList(new SymbolInfoUnit(cnn)); } else { //Kolay changed next string. throwOnError=false ignoreCase=true, . //Type t = Type.GetType(_name+"."+name,false,true); + if (common_namespace != null) + { + si = common_namespace.scope.FindOnlyInScope(name); + if (si != null) + return si; + } Type t = NetHelper.NetHelper.FindType(_name + "." + name); if (t != null) { diff --git a/TreeConverter/TreeRealization/units.cs b/TreeConverter/TreeRealization/units.cs index 3b8a8e86e..d279787e7 100644 --- a/TreeConverter/TreeRealization/units.cs +++ b/TreeConverter/TreeRealization/units.cs @@ -24,6 +24,7 @@ namespace PascalABCCompiler.TreeRealization public class namespace_unit_node : unit_node { public using_namespace namespace_name; + public SymbolTable.Scope scope; public namespace_unit_node(using_namespace namespace_name) { this.namespace_name = namespace_name; diff --git a/VisualPascalABCNET/Projects/NewFileForm.Designer.cs b/VisualPascalABCNET/Projects/NewFileForm.Designer.cs index 290440ca6..3c161796e 100644 --- a/VisualPascalABCNET/Projects/NewFileForm.Designer.cs +++ b/VisualPascalABCNET/Projects/NewFileForm.Designer.cs @@ -29,108 +29,112 @@ namespace VisualPascalABC /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("PRJ_UNIT", 0); - System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("PRJ_FORM", 1); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NewFileForm)); - this.lvTemplates = new System.Windows.Forms.ListView(); - this.imageList1 = new System.Windows.Forms.ImageList(this.components); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.tbFileName = new System.Windows.Forms.TextBox(); - this.btnAdd = new System.Windows.Forms.Button(); - this.btnCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // lvTemplates - // - this.lvTemplates.HideSelection = false; - this.lvTemplates.HoverSelection = true; - listViewItem1.Tag = "0"; - listViewItem2.Tag = "1"; - this.lvTemplates.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem1, - listViewItem2}); - this.lvTemplates.LargeImageList = this.imageList1; - this.lvTemplates.Location = new System.Drawing.Point(1, 30); - this.lvTemplates.Name = "lvTemplates"; - this.lvTemplates.Size = new System.Drawing.Size(372, 196); - this.lvTemplates.TabIndex = 0; - this.lvTemplates.UseCompatibleStateImageBehavior = false; - // - // imageList1 - // - this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); - this.imageList1.TransparentColor = System.Drawing.Color.Transparent; - this.imageList1.Images.SetKeyName(0, "Icons.32x32.Unit.png"); - this.imageList1.Images.SetKeyName(1, "Icons.32x32.Form.png"); - // - // label1 - // - this.label1.Location = new System.Drawing.Point(1, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(100, 23); - this.label1.TabIndex = 1; - this.label1.Text = "PRJ_TEMPLATES"; - // - // label2 - // - this.label2.Location = new System.Drawing.Point(1, 241); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(100, 23); - this.label2.TabIndex = 2; - this.label2.Text = "PRJ_FILE_NAME"; - // - // tbFileName - // - this.tbFileName.Location = new System.Drawing.Point(86, 241); - this.tbFileName.Name = "tbFileName"; - this.tbFileName.Size = new System.Drawing.Size(287, 20); - this.tbFileName.TabIndex = 3; - // - // btnAdd - // - this.btnAdd.DialogResult = System.Windows.Forms.DialogResult.OK; - this.btnAdd.Location = new System.Drawing.Point(183, 280); - this.btnAdd.Name = "btnAdd"; - this.btnAdd.Size = new System.Drawing.Size(95, 23); - this.btnAdd.TabIndex = 4; - this.btnAdd.Text = "RF_OK"; - this.btnAdd.UseVisualStyleBackColor = true; - // - // btnCancel - // - this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnCancel.Location = new System.Drawing.Point(292, 280); - this.btnCancel.Name = "btnCancel"; - this.btnCancel.Size = new System.Drawing.Size(81, 23); - this.btnCancel.TabIndex = 5; - this.btnCancel.Text = "RF_CANCEL"; - this.btnCancel.UseVisualStyleBackColor = true; - // - // NewFileForm - // - this.AcceptButton = this.btnAdd; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.btnCancel; - this.ClientSize = new System.Drawing.Size(385, 315); - this.Controls.Add(this.btnCancel); - this.Controls.Add(this.btnAdd); - this.Controls.Add(this.tbFileName); - this.Controls.Add(this.lvTemplates); - this.Controls.Add(this.label1); - this.Controls.Add(this.label2); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "NewFileForm"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "PRJ_NEW_FILE"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewFileFormFormClosing); - this.ResumeLayout(false); - this.PerformLayout(); + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("PRJ_UNIT", 0); + System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("PRJ_FORM", 1); + System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("PRJ_NAMESPACE", 0); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NewFileForm)); + this.lvTemplates = new System.Windows.Forms.ListView(); + this.imageList1 = new System.Windows.Forms.ImageList(this.components); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.tbFileName = new System.Windows.Forms.TextBox(); + this.btnAdd = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lvTemplates + // + this.lvTemplates.HideSelection = false; + this.lvTemplates.HoverSelection = true; + listViewItem1.Tag = "0"; + listViewItem2.Tag = "1"; + listViewItem3.Tag = "2"; + this.lvTemplates.Items.AddRange(new System.Windows.Forms.ListViewItem[] { + listViewItem1, + listViewItem2, + listViewItem3}); + this.lvTemplates.LargeImageList = this.imageList1; + this.lvTemplates.Location = new System.Drawing.Point(1, 30); + this.lvTemplates.Name = "lvTemplates"; + this.lvTemplates.Size = new System.Drawing.Size(372, 196); + this.lvTemplates.TabIndex = 0; + this.lvTemplates.UseCompatibleStateImageBehavior = false; + // + // imageList1 + // + this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); + this.imageList1.TransparentColor = System.Drawing.Color.Transparent; + this.imageList1.Images.SetKeyName(0, "Icons.32x32.Unit.png"); + this.imageList1.Images.SetKeyName(1, "Icons.32x32.Form.png"); + // + // label1 + // + this.label1.Location = new System.Drawing.Point(1, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(100, 23); + this.label1.TabIndex = 1; + this.label1.Text = "PRJ_TEMPLATES"; + // + // label2 + // + this.label2.Location = new System.Drawing.Point(1, 241); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(100, 23); + this.label2.TabIndex = 2; + this.label2.Text = "PRJ_FILE_NAME"; + // + // tbFileName + // + this.tbFileName.Location = new System.Drawing.Point(86, 241); + this.tbFileName.Name = "tbFileName"; + this.tbFileName.Size = new System.Drawing.Size(287, 20); + this.tbFileName.TabIndex = 3; + // + // btnAdd + // + this.btnAdd.DialogResult = System.Windows.Forms.DialogResult.OK; + this.btnAdd.Location = new System.Drawing.Point(183, 280); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(95, 23); + this.btnAdd.TabIndex = 4; + this.btnAdd.Text = "RF_OK"; + this.btnAdd.UseVisualStyleBackColor = true; + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(292, 280); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(81, 23); + this.btnCancel.TabIndex = 5; + this.btnCancel.Text = "RF_CANCEL"; + this.btnCancel.UseVisualStyleBackColor = true; + // + // NewFileForm + // + this.AcceptButton = this.btnAdd; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btnCancel; + this.ClientSize = new System.Drawing.Size(385, 315); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnAdd); + this.Controls.Add(this.tbFileName); + this.Controls.Add(this.lvTemplates); + this.Controls.Add(this.label1); + this.Controls.Add(this.label2); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "NewFileForm"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "PRJ_NEW_FILE"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewFileFormFormClosing); + this.ResumeLayout(false); + this.PerformLayout(); + } private System.Windows.Forms.ListView lvTemplates; private System.Windows.Forms.ImageList imageList1; diff --git a/VisualPascalABCNET/Projects/NewFileForm.cs b/VisualPascalABCNET/Projects/NewFileForm.cs index baccce1ce..5578a05a0 100644 --- a/VisualPascalABCNET/Projects/NewFileForm.cs +++ b/VisualPascalABCNET/Projects/NewFileForm.cs @@ -9,6 +9,8 @@ using System.Windows.Forms; namespace VisualPascalABC { + public enum FileType { Unit, Namespace, Form} + /// /// Description of NewFileForm. /// @@ -23,7 +25,7 @@ namespace VisualPascalABC foreach (ListViewItem li in lvTemplates.Items) { - if ((string)li.Tag == "0") + if ((string)li.Tag == "0" || (string)li.Tag == "2") source_items.Add(li); else forms_items.Add(li); @@ -107,6 +109,15 @@ namespace VisualPascalABC lvTemplates.Items[0].Selected = true; } + public FileType GetFileFilter() + { + if ((string)lvTemplates.SelectedItems[0].Tag == "0") + return FileType.Unit; + else if ((string)lvTemplates.SelectedItems[0].Tag == "2") + return FileType.Namespace; + return FileType.Form; + } + public Button CancelButtonCommon { get diff --git a/VisualPascalABCNET/Projects/NewFileForm.resx b/VisualPascalABCNET/Projects/NewFileForm.resx index d072ee31a..280f50551 100644 --- a/VisualPascalABCNET/Projects/NewFileForm.resx +++ b/VisualPascalABCNET/Projects/NewFileForm.resx @@ -125,7 +125,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACm - DAAAAk1TRnQBSQFMAgEBAgEAAQQBAAEEAQABIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + DAAAAk1TRnQBSQFMAgEBAgEAARQBAAEUAQABIAEAASABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABgAMAASADAAEBAQABCAYAARAYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/VisualPascalABCNET/Projects/ProjectHelper.cs b/VisualPascalABCNET/Projects/ProjectHelper.cs index caaa7c451..7306aa7ee 100644 --- a/VisualPascalABCNET/Projects/ProjectHelper.cs +++ b/VisualPascalABCNET/Projects/ProjectHelper.cs @@ -49,26 +49,26 @@ namespace VisualPascalABC return Path.GetDirectoryName(currentProject.Path); } } - - public PascalABCCompiler.IProjectInfo CreateProject(string projectName, string projectFileName, PascalABCCompiler.ProjectType projectType) - { - currentProject = new PascalABCCompiler.ProjectInfo(); - currentProject.name = projectName; - currentProject.path = projectFileName; - string dir = Path.GetDirectoryName(projectFileName); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - currentProject.include_debug_info = true; - - currentProject.project_type = projectType; - currentProject.source_files.Add(new PascalABCCompiler.SourceCodeFileInfo(projectName+".pas",Path.Combine(dir,projectName+".pas"))); - currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System","System.dll")); - if (projectType == PascalABCCompiler.ProjectType.WindowsApp) - { - currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Windows.Forms","System.Windows.Forms.dll")); - currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Drawing","System.Drawing.dll")); + + public PascalABCCompiler.IProjectInfo CreateProject(string projectName, string projectFileName, PascalABCCompiler.ProjectType projectType) + { + currentProject = new PascalABCCompiler.ProjectInfo(); + currentProject.name = projectName; + currentProject.path = projectFileName; + string dir = Path.GetDirectoryName(projectFileName); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + currentProject.include_debug_info = true; + + currentProject.project_type = projectType; + currentProject.source_files.Add(new PascalABCCompiler.SourceCodeFileInfo(projectName + ".pas", Path.Combine(dir, projectName + ".pas"))); + currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System", "System.dll")); + if (projectType == PascalABCCompiler.ProjectType.WindowsApp) + { + currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Windows.Forms", "System.Windows.Forms.dll")); + currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Drawing", "System.Drawing.dll")); //roman// currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Core", "System.Core.dll")); currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Data", "System.Data.dll")); @@ -76,42 +76,42 @@ namespace VisualPascalABC currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Xml", "System.Xml.dll")); currentProject.references.Add(new PascalABCCompiler.ReferenceInfo("System.Xml.Linq", "System.Xml.Linq.dll")); //roman// - } - currentProject.main_file = Path.Combine(dir,projectName+".pas"); - currentProject.generate_xml_doc = false; + } + currentProject.main_file = Path.Combine(dir, projectName + ".pas"); + currentProject.generate_xml_doc = false; currentProject.delete_exe = true; currentProject.delete_pdb = true; currentProject.major_version = 0; currentProject.minor_version = 0; currentProject.build_version = 0; currentProject.revision_version = 0; - currentProject.output_directory = dir; - StreamWriter sw = File.CreateText(Path.Combine(dir,projectName+".pas")); - currentProject.output_file_name = projectName + ".exe"; - if (projectType == PascalABCCompiler.ProjectType.ConsoleApp) - { - //sw.WriteLine("program "+projectName+";"); - //sw.WriteLine(); - //sw.WriteLine("uses System;"); - //sw.WriteLine(); - sw.WriteLine("begin"); - sw.WriteLine(); - sw.WriteLine("end."); - } - else if (projectType == PascalABCCompiler.ProjectType.Library) - { - sw.WriteLine("library "+projectName+";"); - sw.WriteLine(); - //sw.WriteLine("uses System;"); - //sw.WriteLine(); - sw.WriteLine("end."); - currentProject.output_file_name = projectName + ".dll"; - } - sw.Close(); - currentProject.Save(); - //VisualPABCSingleton.MainForm.OpenFile(Path.Combine(dir,projectName+".pas")); - return currentProject; - } + currentProject.output_directory = dir; + StreamWriter sw = File.CreateText(Path.Combine(dir, projectName + ".pas")); + currentProject.output_file_name = projectName + ".exe"; + if (projectType == PascalABCCompiler.ProjectType.ConsoleApp) + { + //sw.WriteLine("program "+projectName+";"); + //sw.WriteLine(); + //sw.WriteLine("uses System;"); + //sw.WriteLine(); + sw.WriteLine("begin"); + sw.WriteLine(); + sw.Write("end."); + } + else if (projectType == PascalABCCompiler.ProjectType.Library) + { + sw.WriteLine("library " + projectName + ";"); + sw.WriteLine(); + //sw.WriteLine("uses System;"); + //sw.WriteLine(); + sw.Write("end."); + currentProject.output_file_name = projectName + ".dll"; + } + sw.Close(); + currentProject.Save(); + //VisualPABCSingleton.MainForm.OpenFile(Path.Combine(dir,projectName+".pas")); + return currentProject; + } public PascalABCCompiler.IProjectInfo OpenProject(string projectFileName) { @@ -150,22 +150,52 @@ namespace VisualPascalABC } } } - - public PascalABCCompiler.IFileInfo AddSourceFile(string file_name) - { - PascalABCCompiler.SourceCodeFileInfo fi = new PascalABCCompiler.SourceCodeFileInfo(file_name,Path.Combine(Path.GetDirectoryName(currentProject.Path),file_name)); - currentProject.source_files.Add(fi); - Dirty = true; - return fi; - } - - public PascalABCCompiler.IReferenceInfo AddReference(string s) - { - PascalABCCompiler.ReferenceInfo ri = new PascalABCCompiler.ReferenceInfo(s,s+".dll"); - currentProject.references.Add(ri); - Dirty = true; - return ri; - } + + public PascalABCCompiler.IFileInfo AddSourceFile(string fileName) + { + PascalABCCompiler.SourceCodeFileInfo fi = new PascalABCCompiler.SourceCodeFileInfo(fileName, Path.Combine(Path.GetDirectoryName(currentProject.Path), fileName)); + currentProject.source_files.Add(fi); + Dirty = true; + return fi; + } + + public void AddNamespaceFileReference(string fileName) + { + var text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(currentProject.main_file, PascalABCCompiler.SourceFileOperation.GetText) as string; + text = "{$includenamespace " + Path.GetFileName(fileName) + "}"+Environment.NewLine + text; + var doc = WorkbenchServiceFactory.DocumentService.GetDocument(currentProject.main_file); + if (doc != null) + { + doc.TextEditor.Text = text; + } + else + { + File.WriteAllText(currentProject.main_file, text); + } + } + + public void RemoveNamespaceFileReference(string fileName) + { + var text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(currentProject.main_file, PascalABCCompiler.SourceFileOperation.GetText) as string; + text = text.Replace("{$includenamespace " + Path.GetFileName(fileName) + "}"+Environment.NewLine,""); + var doc = WorkbenchServiceFactory.DocumentService.GetDocument(currentProject.main_file); + if (doc != null) + { + doc.TextEditor.Text = text; + } + else + { + File.WriteAllText(currentProject.main_file, text); + } + } + + public PascalABCCompiler.IReferenceInfo AddReference(string s) + { + PascalABCCompiler.ReferenceInfo ri = new PascalABCCompiler.ReferenceInfo(s, s + ".dll"); + currentProject.references.Add(ri); + Dirty = true; + return ri; + } public void RemoveReference(PascalABCCompiler.IReferenceInfo ri) { @@ -189,11 +219,11 @@ namespace VisualPascalABC { return "Unit"+uid++ + ".pas"; } - - public string GetFullUnitFileName() - { - return Path.Combine(Path.GetDirectoryName(currentProject.path),GetUnitFileName()); - } + + public string GetFullUnitFileName() + { + return Path.Combine(Path.GetDirectoryName(currentProject.path), GetUnitFileName()); + } public void SaveProject() { diff --git a/VisualPascalABCNET/Projects/ProjectTasks.cs b/VisualPascalABCNET/Projects/ProjectTasks.cs index 7819c7cd0..14b310da7 100644 --- a/VisualPascalABCNET/Projects/ProjectTasks.cs +++ b/VisualPascalABCNET/Projects/ProjectTasks.cs @@ -99,14 +99,25 @@ namespace VisualPascalABC PascalABCCompiler.IFileInfo fi = ProjectFactory.Instance.AddSourceFile(frm.FileName); ProjectExplorerWindow.AddSourceFile(fi,false); string full_file_name = Path.Combine(Path.GetDirectoryName(ProjectFactory.Instance.CurrentProject.Path),frm.FileName); - StreamWriter sw = File.CreateText(full_file_name); - sw.WriteLine("unit "+Path.GetFileNameWithoutExtension(frm.FileName)+";"); - sw.WriteLine(); - sw.WriteLine("interface"); - sw.WriteLine(); - sw.WriteLine("implementation"); - sw.WriteLine(); - sw.WriteLine("end."); + StreamWriter sw = File.CreateText(full_file_name); + if (frm.GetFileFilter() == FileType.Unit) + { + sw.WriteLine("unit " + Path.GetFileNameWithoutExtension(frm.FileName) + ";"); + sw.WriteLine(); + sw.WriteLine("interface"); + sw.WriteLine(); + sw.WriteLine("implementation"); + sw.WriteLine(); + sw.Write("end."); + } + else + { + sw.WriteLine("namespace "+ProjectFactory.Instance.CurrentProject.Name+";"); + sw.WriteLine(); + sw.Write("end."); + ProjectFactory.Instance.AddNamespaceFileReference(full_file_name); + } + sw.Close(); WorkbenchServiceFactory.FileService.OpenFile(full_file_name, null); } @@ -199,6 +210,7 @@ namespace VisualPascalABC public static void ExcludeFile(PascalABCCompiler.IFileInfo fi) { ProjectFactory.Instance.ExcludeFile(fi); + ProjectFactory.Instance.RemoveNamespaceFileReference(fi.Path); } private static TypeLibConverter type_conv = new TypeLibConverter(); diff --git a/bin/Lng/Eng/SemanticErrors_ib.dat b/bin/Lng/Eng/SemanticErrors_ib.dat index e1a3377e2..103f2be80 100644 --- a/bin/Lng/Eng/SemanticErrors_ib.dat +++ b/bin/Lng/Eng/SemanticErrors_ib.dat @@ -130,6 +130,7 @@ GOTO_AND_LAMBDAS_NOT_ALLOWED=Cannot use 'goto' and lambdas in the same function NO_PROPERTY_TO_OVERRIDE=No property to override TYPE_PREDEFINITION_NOT_ALLOWED=Type predefinition in namespaces NAMESPACE_SHOULD_CONTAINS_ONLY_TYPES=class, record, enumeration type or functional type expected +NAMESPACE_REDECLARATION=Namespaces cannot be the same as the names of units or .NET namespaces %PREFIX%=COMPILATIONERROR_ UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Unit expected, library found ASSEMBLY_{0}_READING_ERROR=Error by reading assembly '{0}' diff --git a/bin/Lng/Eng/VisualPascalABCNET.dat b/bin/Lng/Eng/VisualPascalABCNET.dat index d49114214..f9b4b88e2 100644 --- a/bin/Lng/Eng/VisualPascalABCNET.dat +++ b/bin/Lng/Eng/VisualPascalABCNET.dat @@ -333,6 +333,7 @@ PRJ_TRADEMARK=Trademark PRJ_COPYRIGHT=Copyright PRJ_GENERATE_XML_DOC=Generate XML doc PRJ_NUGET=NuGet +PRJ_NAMESPACE=Namespace NUGET_PACKAGE=Package Id NUGET_INSTALL=Install package NUGET_LOG=Log diff --git a/bin/Lng/Rus/SemanticErrors_ib.dat b/bin/Lng/Rus/SemanticErrors_ib.dat index 864f8fbd6..61835994c 100644 --- a/bin/Lng/Rus/SemanticErrors_ib.dat +++ b/bin/Lng/Rus/SemanticErrors_ib.dat @@ -125,6 +125,7 @@ GOTO_AND_LAMBDAS_NOT_ALLOWED=Недопустимо совместное исп NO_PROPERTY_TO_OVERRIDE=Нет свойства для переопределения TYPE_PREDEFINITION_NOT_ALLOWED=Предописание типов в пространствах имен недопустимо NAMESPACE_SHOULD_CONTAINS_ONLY_TYPES=В пространство имен можно описывать только классы, записи, перечислимые и процедурные типы +NAMESPACE_REDECLARATION=Пространства имен не должны совпадать с именами модулей и пространств .NET %PREFIX%=COMPILATIONERROR_ UNIT_MODULE_EXPECTED_LIBRARY_FOUND=Ожидался модуль, а встречена библиотека ASSEMBLY_{0}_READING_ERROR=Ошибка при чтении сборки '{0}' diff --git a/bin/Lng/Rus/VisualPascalABCNET.dat b/bin/Lng/Rus/VisualPascalABCNET.dat index 2f9c106fa..518cf53db 100644 --- a/bin/Lng/Rus/VisualPascalABCNET.dat +++ b/bin/Lng/Rus/VisualPascalABCNET.dat @@ -333,6 +333,7 @@ PRJ_TRADEMARK=Торговая марка PRJ_COPYRIGHT=Copyright PRJ_GENERATE_XML_DOC=Генерировать XML документацию PRJ_NUGET=NuGet +PRJ_NAMESPACE=Пространство имен NUGET_PACKAGE=Идентификатор пакета NUGET_INSTALL=Установить пакет NUGET_LOG=Лог