This commit is contained in:
Ivan Bondarev 2021-10-12 20:39:29 +02:00
parent 05f94b9dde
commit 1e51c553fb
5 changed files with 75 additions and 3 deletions

View file

@ -0,0 +1,15 @@
type
t0 = partial abstract class
end;
t1 = sealed class(t0)
end;
t0 = partial abstract class
procedure p1; abstract;
end;
begin
new t1;
end.

View file

@ -0,0 +1,16 @@
unit err0429;
type
t0 = partial abstract class
end;
t1 = sealed class(t0)
end;
t0 = partial abstract class
procedure p1; abstract;
end;
begin
new t1;
end.

View file

@ -0,0 +1,19 @@
unit err0430;
interface
type
t0 = partial abstract class
end;
t1 = sealed class(t0)
end;
t0 = partial abstract class
procedure p1; abstract;
end;
implementation
begin
new t1;
end.

View file

@ -2932,7 +2932,7 @@ namespace PascalABCCompiler.TreeConverter
}
//Проверка типа на соответствие заявленным интерфейсам
private void check_implement_interfaces()//common_type_node cnode)
public void check_implement_interfaces()//common_type_node cnode)
{
//Переводим контекст в состояние разбора класса cnode
//_ctn = cnode;
@ -3116,6 +3116,22 @@ namespace PascalABCCompiler.TreeConverter
}
}
public void check_abstracts_implemented(List<common_type_node> types)
{
foreach (common_type_node ctn in types)
{
_ctn = ctn;
check_implement_interfaces();
_ctn = null;
if (ctn.IsSealed && ctn.IsAbstract && !ctn.IsStatic)
if (ctn.AbstractReason == null)
AddError(ctn.loc, "ABSTRACT_CLASS_CANNOT_BE_SEALED");
else
AddError(ctn.loc, ctn.AbstractReason.Explanation, ctn.name, ctn.AbstractReason.ObjName);
}
}
//ssyy
public void check_labels(List<label_node> lab_list)
{

View file

@ -70,7 +70,7 @@ namespace PascalABCCompiler.TreeConverter
public compilation_context context;
private bool var_def_statement_converting;
private List<common_type_node> inherited_from_partials_list = new List<common_type_node>();
public ContextChanger contextChanger;
internal using_namespace_list using_list = new using_namespace_list();
@ -202,6 +202,7 @@ namespace PascalABCCompiler.TreeConverter
generic_param_abilities.Clear();
current_converted_method_not_in_class_defined = false;
assign_is_converting = false;
inherited_from_partials_list.Clear();
motivation_keeper.reset();
SystemLibrary.SystemLibInitializer.NeedsToRestore.Clear();
type_section_converting = false;
@ -3036,6 +3037,7 @@ namespace PascalABCCompiler.TreeConverter
statement_node init_statements = convert_weak(_unit_module.initialization_part);
context.leave_code_block();
common_namespace_function_node initialization_function = null;
context.check_abstracts_implemented(inherited_from_partials_list);
if (init_statements != null)
{
context.check_labels(context.converted_namespace.labels);
@ -3056,6 +3058,7 @@ namespace PascalABCCompiler.TreeConverter
if (final_statements != null)
{
context.check_labels(context.converted_namespace.labels);
finalization_function = new common_namespace_function_node(compiler_string_consts.finalization_function_name,
null, final_statements.location, context.converted_namespace, convertion_data_and_alghoritms.symbol_table.CreateScope(context.converted_namespace.scope));
finalization_function.function_code = final_statements;
@ -3758,6 +3761,8 @@ namespace PascalABCCompiler.TreeConverter
AddError(get_location(_class_definition.class_parents.types[0]), "CAN_NOT_INHERIT_FROM_DELEGATE_TYPE");
}
Hashtable used_interfs = new Hashtable();
if (tn is common_type_node && (tn as common_type_node).IsPartial)
inherited_from_partials_list.Add(context.converted_type);
//Если tn - это интерфейс
if (tn.IsInterface)
{
@ -11111,7 +11116,7 @@ namespace PascalABCCompiler.TreeConverter
UpdateUnitDefinitionItemForUnit(_compiled_unit);
hard_node_test_and_visit(_program_module.program_block);
context.check_labels(context.converted_namespace.labels);
context.check_abstracts_implemented(inherited_from_partials_list);
// frninja 28/04/16 - режем мусорные методы хелперы yield
{
var toRemove = cnsn.functions.Where(m => m.is_yield_helper).ToArray();
@ -11122,6 +11127,7 @@ namespace PascalABCCompiler.TreeConverter
}
// end frninja
common_namespace_function_node main_function = new common_namespace_function_node(compiler_string_consts.temp_main_function_name,
null, null, cnsn, null);
main_function.function_code = context.code;