This commit is contained in:
Бондарев Иван 2020-01-26 12:33:06 +01:00
parent 66ed13f94e
commit 4e235e906e
6 changed files with 66 additions and 9 deletions

View file

@ -313,7 +313,7 @@ namespace CodeCompletion
meths = entry_scope.GetExtensionMethods(name, tright);
foreach (ProcScope meth in meths)
lst.Add(meth);
ProcScope ps = select_method(lst.ToArray(), tleft, tright, null, false, _bin_expr.left, _bin_expr.right);
ProcScope ps = select_method(lst.ToArray(), tleft, tright, null, false, null, _bin_expr.left, _bin_expr.right);
if (ps != null)
returned_scope = ps.return_type;
else
@ -3174,13 +3174,19 @@ namespace CodeCompletion
private SymScope[] selected_methods = null;
private bool disable_lambda_compilation = false;
private ProcScope select_method(SymScope[] meths, TypeScope tleft, TypeScope tright, TypeScope obj, bool obj_instanced, params expression[] args)
private ProcScope select_method(SymScope[] meths, TypeScope tleft, TypeScope tright, TypeScope obj, bool obj_instanced, List<SymScope> arg_types, params expression[] args)
{
List<SymScope> arg_types = new List<SymScope>();
if (arg_types == null)
arg_types = new List<SymScope>();
List<TypeScope> arg_types2 = new List<TypeScope>();
SymScope[] saved_selected_methods = selected_methods;
selected_methods = meths;
if (tleft != null || tright != null)
if (arg_types.Count > 0)
{
foreach (TypeScope ts in arg_types)
arg_types2.Add(ts);
}
else if (tleft != null || tright != null)
{
if (tleft != null)
{
@ -3309,8 +3315,11 @@ namespace CodeCompletion
{
parameters.AddRange(_method_call.parameters.expressions);
}
List<TypeScope> lambda_types = new List<TypeScope>();
ProcScope ps = select_method(names, null, null, obj, obj_instanced, parameters.ToArray());
List<TypeScope> lambda_types = new List<TypeScope>();
List<SymScope> param_types = new List<SymScope>();
ProcScope ps = select_method(names, null, null, obj, obj_instanced, param_types, parameters.ToArray());
bool has_lambda = false;
if (_method_call.parameters != null && ps != null)
for (int i = 0; i < _method_call.parameters.expressions.Count; i++)
{
@ -3325,8 +3334,12 @@ namespace CodeCompletion
e.visit(this);
disable_lambda_compilation = tmp_disable_lambda_compilation;
awaitedProcType = tmp_awaitedProcType;
has_lambda = true;
param_types[obj == null ? i : i + 1] = returned_scope;
}
}
if (has_lambda)
ps = select_method(names, null, null, obj, obj_instanced, param_types, parameters.ToArray());
returned_scopes.Clear();
if (ps != null)
@ -5367,6 +5380,7 @@ namespace CodeCompletion
}
SymScope tmp = cur_scope;
cur_scope = ps;
TypeScope saved_return_type = ps.return_type;
if (!disable_lambda_compilation)
{
if (awaitedProcType != null)
@ -5380,7 +5394,10 @@ namespace CodeCompletion
statement_list sl = _function_lambda_definition.proc_body as statement_list;
if (sl != null && sl.list.Count == 1 && sl.list[0] is assign && (sl.list[0] as assign).to is ident
&& ((sl.list[0] as assign).to as ident).name.ToLower() == "result")
{
(sl.list[0] as assign).from.visit(this);
ps.return_type = returned_scope as TypeScope;
}
else
_function_lambda_definition.proc_body.visit(this);
}
@ -5388,7 +5405,7 @@ namespace CodeCompletion
cur_scope = tmp;
if (_function_lambda_definition.usedkeyword == 2)
ps.return_type = null;
else
else if (saved_return_type == ps.return_type)
ps.return_type = new UnknownScope(new SymInfo("",SymbolKind.Class,""));// returned_scope as TypeScope;
returned_scope = new ProcType(ps);
}
@ -5545,6 +5562,16 @@ namespace CodeCompletion
else
visit(ttr.name);
}
public override void visit(diapason_expr_new _diapason_expr_new)
{
_diapason_expr_new.left.visit(this);
TypeScope ts = TypeTable.get_compiled_type(new SymInfo("IEnumerable`1", SymbolKind.Type, "System.Collections.Generic.IEnumerable`1"), typeof(IEnumerable<>));
TypeScope elem_ts = returned_scope as TypeScope;
if (elem_ts != null)
ts = ts.GetInstance(new List<TypeScope>() { elem_ts });
returned_scope = ts;
}
}
}

View file

@ -1994,5 +1994,17 @@ namespace CodeCompletion
mc.dereferencing_value = new dot_node(new ident("Tuple"), new ident("Create"));
mc.visit(this);
}
public override void visit(diapason_expr_new _diapason_expr_new)
{
_diapason_expr_new.left.visit(this);
TypeScope ts = TypeTable.get_compiled_type(new SymInfo("IEnumerable`1", SymbolKind.Type, "System.Collections.Generic.IEnumerable`1"), typeof(IEnumerable<>));
TypeScope elem_ts = null;
if (returned_scope is ElementScope)
elem_ts = (returned_scope as ElementScope).sc as TypeScope;
if (elem_ts != null)
ts = ts.GetInstance(new List<TypeScope>() { elem_ts });
returned_scope = new ElementScope(ts);
}
}
}

View file

@ -2331,6 +2331,17 @@ namespace CodeCompletion
if (this.template_parameters.Contains(inst_ts.name))
{
exact = false;
if (ts.IsDelegate)
{
for (int j=0; j<gen_args.Count; j++)
{
TypeScope gen_ts = gen_args[j];
if (gen_ts is ProcType)
{
gen_args[j] = (gen_ts as ProcType).InvokeMethod.return_type;
}
}
}
break;
}
}

View file

@ -567,7 +567,10 @@ namespace CodeCompletion
s = parser.LanguageInformation.FindExpression(off, test_str, line, col, out keyw);
assert(s.Trim('\n', ' ', '\t') == "");
test_str = "(2..4)";
off = test_str.Length;
s = parser.LanguageInformation.FindExpression(off, test_str, line, col, out keyw);
assert(s.Trim('\n', ' ', '\t') == test_str);

View file

@ -2812,7 +2812,7 @@ namespace PascalABCCompiler.Parsers
}
else if (ch == '.' || ch == '^' || ch == '&' || ch == '?' && IsPunctuation(Text, i + 1))
{
if (ch == '.' && i >= 1 && Text[i - 1] == '.')
if (ch == '.' && i >= 1 && Text[i - 1] == '.' && tokens.Count == 0)
end = true;
else if (ch == '?' && i + 1 < Text.Length && Text[i + 1] != '.')
end = true;

View file

@ -0,0 +1,4 @@
begin
var s{@var s: sequence of integer;@} := 1..4;
var s2{@var s2: sequence of char;@} := '1'..'4';
end.