Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
miks1965 committed Jan 10, 2017
2 parents 1557775 + 3663833 commit 67b9159
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
25 changes: 20 additions & 5 deletions NETGenerator/NETGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class ILConverter : AbstractVisitor
protected CompilerOptions comp_opt = new CompilerOptions();//опции компилятора
protected Dictionary<string, ISymbolDocumentWriter> sym_docs = new Dictionary<string, ISymbolDocumentWriter>();//таблица отладочных документов
protected bool is_constructor = false;//флаг, переводим ли мы конструктор
protected bool init_call_awaited = false;
protected bool save_debug_info = false;
protected bool add_special_debug_variables = false;
protected bool make_next_spoint = true;
Expand Down Expand Up @@ -5782,15 +5783,17 @@ private void ConvertConstructorBody(SemanticTree.ICommonMethodNode value)
ConvertCommonFunctionConstantDefinitions(value.constants);
ConvertLocalVariables(value.var_definition_nodes);
//вызываем метод $Init$ для инициализации массивов и проч.
if (value.polymorphic_state != polymorphic_state.ps_static && value.common_comprehensive_type.base_type is ICompiledTypeNode && (value.common_comprehensive_type.base_type as ICompiledTypeNode).compiled_type == TypeFactory.ObjectType)
/*if (value.polymorphic_state != polymorphic_state.ps_static && value.common_comprehensive_type.base_type is ICompiledTypeNode && (value.common_comprehensive_type.base_type as ICompiledTypeNode).compiled_type == TypeFactory.ObjectType)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, TypeFactory.ObjectType.GetConstructor(Type.EmptyTypes));
}
}*/
if (value.polymorphic_state != polymorphic_state.ps_static)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, cur_ti.init_meth);
init_call_awaited = true;

//il.Emit(OpCodes.Ldarg_0);
//il.Emit(OpCodes.Call, cur_ti.init_meth);
}
//переводим тело
is_constructor = true;
Expand Down Expand Up @@ -9182,6 +9185,12 @@ public override void visit(SemanticTree.ICommonConstructorCall value)
{
is_dot_expr = false;
}
if (init_call_awaited && !value.new_obj_awaited())
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, cur_ti.init_meth);
init_call_awaited = false;
}
}

//вызов откомпилированного конструктора
Expand Down Expand Up @@ -9263,7 +9272,13 @@ public override void visit(SemanticTree.ICompiledConstructorCall value)
{
is_dot_expr = false;
}
//\ssyy
//\ssyy
if (init_call_awaited && !value.new_obj_awaited())
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, cur_ti.init_meth);
init_call_awaited = false;
}
}

private bool TypeNeedToFix(ITypeNode type)
Expand Down
5 changes: 5 additions & 0 deletions TestSuite/extensionmethods19.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin
var a := Arr(1,3,5,4,3);
var b := a.Println.ToArray;
assert(b[2] = 5);
end.
24 changes: 24 additions & 0 deletions TreeConverter/TreeConversion/syntax_tree_visitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8975,6 +8975,30 @@ private expression_node expression_value_reciving(SyntaxTree.ident id_right, Sym
{
return new indefinite_reference(dn as indefinite_definition_node, get_location(id_right));
}
if (expected_delegate && en != null)
{
SymbolInfo tmp_si = si;
function_node tmp_fn = null;
bool has_empty_methods = false;
bool only_extension_methods = true;
while (tmp_si != null)
{
tmp_fn = tmp_si.sym_info as function_node;
if (tmp_fn != null)
{
if (!tmp_fn.is_extension_method)
only_extension_methods = false;
else
{
if (tmp_fn.parameters.Count == 1 || tmp_fn.parameters.Count == 2 && (tmp_fn.parameters[1].is_params || tmp_fn.parameters[1].default_value != null))
has_empty_methods = true;
}
}
tmp_si = tmp_si.Next;
}
if (has_empty_methods && only_extension_methods)
expected_delegate = false;
}
if (expected_delegate)
return make_delegate_wrapper(en, si, get_location(id_right), false);
else
Expand Down

0 comments on commit 67b9159

Please sign in to comment.