Skip to content

Commit

Permalink
bug fix: can not override virtual methods of abstract class
Browse files Browse the repository at this point in the history
performance improvements
  • Loading branch information
ibond84 committed Oct 18, 2015
1 parent 248da67 commit a404833
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
18 changes: 18 additions & 0 deletions TestSuite/abstract1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ procedure Test3; override;
end;
end;

TClass7 = abstract class
a: integer;
procedure Test; virtual;
begin
a := 5;
end;
end;

TClass8 = class(TClass7)
procedure Test; override;
begin
a := 3;
end;
end;

var t : TClass;
t2 : TClass3;
t3 : TClass5;
Expand All @@ -55,4 +70,7 @@ procedure Test3; override;
t2.Test2(2.3);
t3 := new TClass6;
t3.Test3;
var t4 := new TClass8;
t4.Test;
assert(t4.a=3);
end.
15 changes: 7 additions & 8 deletions TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void AddError(Errors.Error err)

private T AddError<T>(Errors.Error err)
{
syntax_tree_visitor.AddError(err);
syntax_tree_visitor.AddError(err, true);
return default(T);
}

Expand Down Expand Up @@ -1789,7 +1789,7 @@ public function_node select_function(expressions_list parameters, SymbolInfo fun

if (set_of_possible_functions.Count==0 && indefinits.Count == 0)
{
AddError(new NoFunctionWithSameParametresNum(loc, is_alone_method_defined, first_function));
return AddError<function_node>(new NoFunctionWithSameParametresNum(loc, is_alone_method_defined, first_function));
}

//(ssyy) Инициализируем is_alone_defined
Expand Down Expand Up @@ -1866,10 +1866,10 @@ public function_node select_function(expressions_list parameters, SymbolInfo fun
if (set_of_possible_functions.Count==0 && indefinits.Count == 0)
{
if (_is_assigment && parameters.Count == 2)
AddError(new CanNotConvertTypes(parameters[1], parameters[1].type, parameters[0].type, parameters[1].location));
return AddError<function_node>(new CanNotConvertTypes(parameters[1], parameters[1].type, parameters[0].type, parameters[1].location));
if (_tmp_bfn != null && parameters.Count == 2)
AddError(new OperatorCanNotBeAppliedToThisTypes(_tmp_bfn.name, parameters[0], parameters[1],loc));
AddError(new NoFunctionWithSameArguments(loc,is_alone_method_defined));
return AddError<function_node>(new OperatorCanNotBeAppliedToThisTypes(_tmp_bfn.name, parameters[0], parameters[1],loc));
return AddError<function_node>(new NoFunctionWithSameArguments(loc,is_alone_method_defined));
}

bool remove=true;
Expand Down Expand Up @@ -2001,9 +2001,8 @@ public function_node select_function(expressions_list parameters, SymbolInfo fun
indefinits.AddRange(set_of_possible_functions);
return new indefinite_functions_set(indefinits);
}

AddError(new SeveralFunctionsCanBeCalled(loc,set_of_possible_functions));
return null;

return AddError<function_node>(new SeveralFunctionsCanBeCalled(loc,set_of_possible_functions));
}

private function_node is_exist_eq_return_value_method(function_node fn, function_node_list funcs)
Expand Down
42 changes: 38 additions & 4 deletions TreeConverter/TreeConversion/syntax_tree_visitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,21 @@ public string UniqueNumStr()
return num.ToString();
}

internal void AddError(Errors.Error err)
internal Errors.Error LastError()
{
if (ThrowCompilationError || err.MustThrow)
Errors.Error err = ErrorsList[ErrorsList.Count-1];
ErrorsList.RemoveAt(ErrorsList.Count - 1);
return err;
}

internal void RemoveLastError()
{
ErrorsList.RemoveAt(ErrorsList.Count - 1);
}

internal void AddError(Errors.Error err, bool shouldReturn=false)
{
if (ThrowCompilationError || !shouldReturn /*|| err.MustThrow && !shouldReturn*/)
{
throw err;
}
Expand Down Expand Up @@ -5283,10 +5295,32 @@ internal void visit_method_call(SyntaxTree.method_call _method_call)
{
try
{
ThrowCompilationError = false;
fn = convertion_data_and_alghoritms.select_function(exprs, si, subloc, syntax_nodes_parameters);
if (fn == null && skip_first_parameter)
{
if (si.Next == null)
{
ThrowCompilationError = true;
throw LastError();
}
RemoveLastError();
skip_first_parameter = false;
si = tmp_si;
exprs.remove_at(0);
fn = convertion_data_and_alghoritms.select_function(exprs, si, subloc, syntax_nodes_parameters);
if (fn == null)
{
ThrowCompilationError = true;
throw LastError();
}
else
RemoveLastError();
}
}
catch (Exception ex)
{
ThrowCompilationError = true;
if (skip_first_parameter)
{
si = tmp_si;
Expand All @@ -5296,6 +5330,7 @@ internal void visit_method_call(SyntaxTree.method_call _method_call)
else
throw ex;
}
ThrowCompilationError = true;
}
SemanticTree.IGenericInstance igi = fn as SemanticTree.IGenericInstance;
if (igi != null)
Expand Down Expand Up @@ -11616,14 +11651,13 @@ public override void visit(SyntaxTree.procedure_attributes_list _procedure_attri
{
AddError(get_location(_procedure_attributes_list.proc_attributes[i]), "USING_MODIFIERS{0}_{1}_TOGETHER_NOT_ALLOWED", cmn,_procedure_attributes_list.proc_attributes[i].name,override_proc_attr);
}
if (!context.converted_type.IsAbstract)
if (!context.converted_type.IsAbstract || true)
{
is_virtual = true;
virtual_proc_attr = _procedure_attributes_list.proc_attributes[i].name;
if (!is_abstract)
context.set_virtual(cmn);
}

break;
}
case SyntaxTree.proc_attribute.attr_override:
Expand Down

0 comments on commit a404833

Please sign in to comment.