diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 7fb508a60..64a37b3d7 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -1815,6 +1815,8 @@ namespace PascalABCCompiler //Console.WriteLine("ERROR! interface not compiled "+GetUnitFileName(CurrentUnit.SyntaxUnitName));//DEBUG System.Collections.Generic.List SyntaxUsesList = GetSyntaxImplementationUsesList(CurrentUnit.SyntaxTree); CurrentUnit.PossibleNamespaces.Clear(); + if (HasIncludeNamespacesDirective(CurrentUnit)) + compilerOptions.UseDllForSystemUnits = false; if (SyntaxUsesList != null) { for (int i = SyntaxUsesList.Count - 1; i >= 0; i--) @@ -2771,7 +2773,6 @@ namespace PascalABCCompiler SyntaxTree.unit_module main_library = Unit.SyntaxTree as SyntaxTree.unit_module; SyntaxTree.program_module main_program = Unit.SyntaxTree as SyntaxTree.program_module; List files = new List(); - foreach (TreeRealization.compiler_directive cd in directives) { if (cd.name.ToLower() == TreeConverter.compiler_string_consts.include_namespace_directive) @@ -2838,7 +2839,7 @@ namespace PascalABCCompiler { if (IsPossibleNamespace(name_space, false)) { - ns.referenced_units.AddElement(new TreeRealization.namespace_unit_node(GetNamespace(name_space))); + ns.referenced_units.AddElement(new TreeRealization.namespace_unit_node(GetNamespace(name_space), get_location_from_treenode(name_space, tree.file_name))); } else { diff --git a/TestSuite/errors/err0326.pas b/TestSuite/errors/err0326.pas new file mode 100644 index 000000000..a61169060 --- /dev/null +++ b/TestSuite/errors/err0326.pas @@ -0,0 +1,4 @@ +{$includenamespace namespaces/err0326.pas} +begin + +end. \ No newline at end of file diff --git a/TestSuite/errors/err0328.pas b/TestSuite/errors/err0328.pas new file mode 100644 index 000000000..a54eb58e4 --- /dev/null +++ b/TestSuite/errors/err0328.pas @@ -0,0 +1,5 @@ +{$includenamespace namespaces/err0328.pas} + +begin + +end. \ No newline at end of file diff --git a/TestSuite/errors/namespaces/err0327.pas b/TestSuite/errors/namespaces/err0327.pas new file mode 100644 index 000000000..40ba1393b --- /dev/null +++ b/TestSuite/errors/namespaces/err0327.pas @@ -0,0 +1,7 @@ +namespace NS1; + +uses NS2; +type + T1 = class end; + +end. \ No newline at end of file diff --git a/TestSuite/errors/namespaces/err0328.pas b/TestSuite/errors/namespaces/err0328.pas new file mode 100644 index 000000000..e42bbf1b0 --- /dev/null +++ b/TestSuite/errors/namespaces/err0328.pas @@ -0,0 +1,8 @@ +namespace NS1.SubNS1; + +uses NS1.SubNS2; + +type + T1 = class end; + +end. \ No newline at end of file diff --git a/TestSuite/use_ns_typedef.pas b/TestSuite/use_ns_typedef.pas index 0cb86eebe..52192bcb3 100644 --- a/TestSuite/use_ns_typedef.pas +++ b/TestSuite/use_ns_typedef.pas @@ -1,4 +1,5 @@ -{$includenamespace 'namespaces/nstypedef1.pas'} +//nopabcrtl +{$includenamespace 'namespaces/nstypedef1.pas'} {$includenamespace 'namespaces/nstypedef2.pas'} uses nstypedef; diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index b599fb994..47583a399 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -10874,51 +10874,8 @@ namespace PascalABCCompiler.TreeConverter } parent_scope = scope; } - - context.enter_scope(scope); - foreach (declaration decl in _syntax_namespace_node.defs) - { - if (decl is type_declarations) - { - type_declarations type_decls = decl as type_declarations; - foreach (type_declaration td in type_decls.types_decl) - { - if (td.type_def is class_definition) - { - class_definition cl_def = td.type_def as class_definition; - if (cl_def.body == null) - AddError(get_location(cl_def), "TYPE_PREDEFINITION_NOT_ALLOWED"); - common_type_node ctn = null; - if (td.type_name is template_type_name) - ctn = context.advanced_create_type(td.type_name.name+"`"+(td.type_name as template_type_name).template_args.Count, get_location(td.type_name), (td.type_def as class_definition).keyword == class_keyword.Interface, false); - else - ctn = context.advanced_create_type(td.type_name.name, get_location(td.type_name), (td.type_def as class_definition).keyword == class_keyword.Interface, false); - ctn.ForwardDeclarationOnly = true; - if ((td.type_def as class_definition).keyword == class_keyword.Interface) - ctn.IsInterface = true; - context.converted_type = null; - context.add_type_header(td, ctn); - } - else if (td.type_def is procedure_header || td.type_def is function_header || td.type_def is named_type_reference) - { - - } - else if (td.type_def is enum_type_definition) - { - hard_node_test_and_visit(td); - } - else - AddError(get_location(decl), "NAMESPACE_SHOULD_CONTAINS_ONLY_TYPES"); - } - - } - else - AddError(get_location(decl), "NAMESPACE_SHOULD_CONTAINS_ONLY_TYPES"); - } - - context.leave_scope(); - } + foreach (syntax_namespace_node _syntax_namespace_node in namespaces) { var cmn = dict[_syntax_namespace_node]; @@ -10939,14 +10896,70 @@ namespace PascalABCCompiler.TreeConverter for (int i = 1; i < names.Length; i++) { si_list = ns_scope2.Find(names[i]); - ns_scope2 = (si_list.FirstOrDefault().sym_info as common_namespace_node).scope; + if (si_list != null && si_list.FirstOrDefault().sym_info is common_namespace_node) + ns_scope2 = (si_list.FirstOrDefault().sym_info as common_namespace_node).scope; + else + AddError(new NamespaceNotFound(nun.namespace_name.namespace_name, un.location)); } scopes.Add(ns_scope2); } + else + AddError(new NamespaceNotFound(nun.namespace_name.namespace_name, un.location)); } } ns_scope.TopScopeArray = scopes.ToArray(); } + + //convert type predefinitions + foreach (syntax_namespace_node _syntax_namespace_node in namespaces) + { + var cmn = dict[_syntax_namespace_node]; + var scope = cmn.scope; + context.enter_scope(scope); + foreach (declaration decl in _syntax_namespace_node.defs) + { + if (decl is type_declarations) + { + type_declarations type_decls = decl as type_declarations; + foreach (type_declaration td in type_decls.types_decl) + { + if (td.type_def is class_definition) + { + class_definition cl_def = td.type_def as class_definition; + if (cl_def.body == null) + AddError(get_location(cl_def), "TYPE_PREDEFINITION_NOT_ALLOWED"); + common_type_node ctn = null; + if (td.type_name is template_type_name) + ctn = context.advanced_create_type(td.type_name.name + "`" + (td.type_name as template_type_name).template_args.Count, get_location(td.type_name), (td.type_def as class_definition).keyword == class_keyword.Interface, false); + else + ctn = context.advanced_create_type(td.type_name.name, get_location(td.type_name), (td.type_def as class_definition).keyword == class_keyword.Interface, false); + ctn.ForwardDeclarationOnly = true; + if ((td.type_def as class_definition).keyword == class_keyword.Interface) + ctn.IsInterface = true; + context.converted_type = null; + context.add_type_header(td, ctn); + } + else if (td.type_def is procedure_header || td.type_def is function_header || td.type_def is named_type_reference) + { + + } + else if (td.type_def is enum_type_definition) + { + hard_node_test_and_visit(td); + } + else + AddError(get_location(decl), "NAMESPACE_SHOULD_CONTAINS_ONLY_TYPES"); + } + + } + else + AddError(get_location(decl), "NAMESPACE_SHOULD_CONTAINS_ONLY_TYPES"); + } + + context.leave_scope(); + } + + foreach (syntax_namespace_node _syntax_namespace_node in namespaces) { common_namespace_node cmn = dict[_syntax_namespace_node]; diff --git a/TreeConverter/TreeRealization/units.cs b/TreeConverter/TreeRealization/units.cs index 9b986bf6d..042d45569 100644 --- a/TreeConverter/TreeRealization/units.cs +++ b/TreeConverter/TreeRealization/units.cs @@ -25,14 +25,27 @@ namespace PascalABCCompiler.TreeRealization { public using_namespace namespace_name; public SymbolTable.Scope scope; + public location loc; public namespace_unit_node(using_namespace namespace_name) { this.namespace_name = namespace_name; } + public namespace_unit_node(using_namespace namespace_name, location loc) + { + this.namespace_name = namespace_name; + this.loc = loc; + } public override List find_only_in_namespace(string name) { throw new NotSupportedException(); } + public override location location + { + get + { + return loc; + } + } public override semantic_node_type semantic_node_type { get diff --git a/bin/TestRunner.exe b/bin/TestRunner.exe index 75e161fd8..d30904e78 100644 Binary files a/bin/TestRunner.exe and b/bin/TestRunner.exe differ diff --git a/bin/TestRunner.pas b/bin/TestRunner.pas index 081e51dd3..220a52373 100644 --- a/bin/TestRunner.pas +++ b/bin/TestRunner.pas @@ -44,6 +44,7 @@ begin var content := &File.ReadAllText(files[i]); if content.StartsWith('//winonly') and IsUnix then continue; + var co: CompilerOptions := new CompilerOptions(files[i], CompilerOptions.OutputType.ConsoleApplicaton); co.Debug := true; co.OutputDirectory := TestSuiteDir + PathSeparator + 'errors'; @@ -80,6 +81,8 @@ begin var content := &File.ReadAllText(files[i]); if content.StartsWith('//winonly') and IsUnix then continue; + if content.StartsWith('//nopabcrtl') and withdll then + continue; var co: CompilerOptions := new CompilerOptions(files[i], CompilerOptions.OutputType.ConsoleApplicaton); co.Debug := true; co.OutputDirectory := TestSuiteDir + PathSeparator + 'exe';