This commit is contained in:
Бондарев Иван 2019-06-30 14:22:24 +02:00
parent da613b74f4
commit 818bd7acd6
10 changed files with 103 additions and 48 deletions

View file

@ -1815,6 +1815,8 @@ namespace PascalABCCompiler
//Console.WriteLine("ERROR! interface not compiled "+GetUnitFileName(CurrentUnit.SyntaxUnitName));//DEBUG
System.Collections.Generic.List<SyntaxTree.unit_or_namespace> 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<string> files = new List<string>();
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
{

View file

@ -0,0 +1,4 @@
{$includenamespace namespaces/err0326.pas}
begin
end.

View file

@ -0,0 +1,5 @@
{$includenamespace namespaces/err0328.pas}
begin
end.

View file

@ -0,0 +1,7 @@
namespace NS1;
uses NS2;
type
T1 = class end;
end.

View file

@ -0,0 +1,8 @@
namespace NS1.SubNS1;
uses NS1.SubNS2;
type
T1 = class end;
end.

View file

@ -1,4 +1,5 @@
{$includenamespace 'namespaces/nstypedef1.pas'}
//nopabcrtl
{$includenamespace 'namespaces/nstypedef1.pas'}
{$includenamespace 'namespaces/nstypedef2.pas'}
uses nstypedef;

View file

@ -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];

View file

@ -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<TreeConverter.SymbolInfo> 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

Binary file not shown.

View file

@ -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';