Исправление некоторых предупреждений и комментарии в select_function

This commit is contained in:
Mikhalkovich Stanislav 2019-06-07 00:06:11 +03:00
parent d7bdc895bd
commit 357dce8e63
24 changed files with 120 additions and 115 deletions

View file

@ -897,7 +897,7 @@ namespace CodeCompletion
ss = null;
}
}
catch (Exception e)
catch (Exception)
{
}

View file

@ -2217,7 +2217,7 @@ namespace CodeCompletion
namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(assm));
unit_scope.AddReferencedAssembly(assm);
}
catch (Exception e)
catch (Exception)
{
}

View file

@ -86,7 +86,7 @@ namespace CodeCompletion
{
expr.visit(this);
}
catch (Exception e)
catch (Exception)
{
returned_scope = null;
}

View file

@ -87,7 +87,7 @@ namespace CodeCompletion
}
}
}
catch (Exception e)
catch (Exception)
{
}

View file

@ -99,10 +99,6 @@
<HintPath>..\Libraries\ICSharpCode.NRefactory.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.Dynamic, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\bin\Microsoft.Dynamic.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\Microsoft.Scripting.dll</HintPath>

View file

@ -54,7 +54,7 @@ namespace PascalABCCompiler
xtw.WriteEndElement();
xtw.Flush();
}
catch (Exception e)
catch (Exception)
{
}

View file

@ -287,7 +287,7 @@ namespace PascalABCCompiler.PCU
ChangeState(this, PCUReaderWriterState.EndReadTree, unit);
return unit;
}
catch (Exception ex)
catch (Exception)
{
CloseUnit();
throw;

View file

@ -72,7 +72,7 @@ namespace PascalABCCompiler.SemanticTreeConverters
}
}
}
catch (Exception e)
catch (Exception)
{
//ErrorList.Add(new PluginLoadingError(fi.FullName, e));
}

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "5";
public const string Build = "0";
public const string Revision = "2091";
public const string Revision = "2092";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%MINOR%=5
%REVISION%=2091
%COREVERSION%=0
%REVISION%=2092
%MINOR%=5
%MAJOR%=3

View file

@ -203,7 +203,7 @@ namespace CodeCompletionTools
return xdoc.GetDocumentation("T:" + t.FullName, false);
}
}
catch (Exception e)
catch (Exception)
{
}

View file

@ -1 +1 @@
!define VERSION '3.5.0.2091'
!define VERSION '3.5.0.2092'

View file

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//Все типы семантических ошибок компилятора.
using System;
using System.Collections.Generic;
using PascalABCCompiler.SemanticTree;
@ -471,9 +472,9 @@ namespace PascalABCCompiler.TreeConverter
public class SeveralFunctionsCanBeCalled : CompilationError
{
private readonly ILocation _loc;
private readonly function_node_list _possible_functions;
private readonly List<function_node> _possible_functions;
public SeveralFunctionsCanBeCalled(ILocation loc, function_node_list set_of_possible_functions)
public SeveralFunctionsCanBeCalled(ILocation loc, List<function_node> set_of_possible_functions)
{
_loc = loc;
_possible_functions = set_of_possible_functions;
@ -487,7 +488,7 @@ namespace PascalABCCompiler.TreeConverter
}
}
public function_node_list set_of_possible_functions
public List<function_node> set_of_possible_functions
{
get
{

View file

@ -1661,7 +1661,7 @@ namespace PascalABCCompiler.TreeConverter
}
private function_node find_eq_return_value_method_in_list(function_node fn, function_node_list funcs)
private function_node find_eq_return_value_method_in_list(function_node fn, List<function_node> funcs)
{
foreach (function_node f in funcs)
{
@ -1683,7 +1683,7 @@ namespace PascalABCCompiler.TreeConverter
return null;
}
public function_node find_eq_method_in_list(function_node fn,function_node_list funcs)
public function_node find_eq_method_in_list(function_node fn, List<function_node> funcs)
{
foreach(function_node f in funcs)
{
@ -1703,7 +1703,7 @@ namespace PascalABCCompiler.TreeConverter
return null;
}
public function_node is_exist_eq_method_in_list(function_node fn, function_node_list funcs)
public function_node is_exist_eq_method_in_list(function_node fn, List<function_node> funcs)
{
return find_eq_return_value_method_in_list(fn, funcs);
}
@ -1728,6 +1728,62 @@ namespace PascalABCCompiler.TreeConverter
return ctn;
}
// Эту функцию можно написать оптимальнее - без внешнего while. Например.
// Запускаем алгоритм сортировки на частичном порядке. Ищем min из оставшихся и меняем его местами с текущим.
// Потом проходимся по частично отсортированному и из пары соседних удаляем тот, что меньше
private void functions_delete_greater(List<function_node> set_of_possible_functions, possible_type_convertions_list_list tcll)
{
bool remove = true;
while (remove)
{
remove = false;
// Удаляем из всех возможных перегруженных версий функций те, которые больше какой-то. Та, которая меньше по всем параметрам, остаётся.
// По идее это надо делать для каждой дистанции отдельно - тогда баг #1970 уйдёт
var i = 0;
while (i < set_of_possible_functions.Count - 1)
{
var j = i + 1;
while (j < set_of_possible_functions.Count)
{
method_compare mc = compare_methods(set_of_possible_functions[i],
set_of_possible_functions[j], tcll[i], tcll[j]);
if (SystemLibrary.SystemLibInitializer.InSetProcedure != null)
{
if (set_of_possible_functions[j] == SystemLibrary.SystemLibInitializer.InSetProcedure.sym_info)
{
mc = method_compare.less_method;
}
else if (set_of_possible_functions[i] == SystemLibrary.SystemLibInitializer.InSetProcedure.sym_info)
{
mc = method_compare.greater_method;
}
}
if (mc == method_compare.greater_method)
{
tcll.remove_at(j);
set_of_possible_functions.RemoveAt(j);
remove = true;
}
else if (mc == method_compare.less_method)
{
tcll[i] = tcll[j];
set_of_possible_functions[i] = set_of_possible_functions[j];
tcll.remove_at(j);
set_of_possible_functions.RemoveAt(j);
remove = true;
}
else
{
j++;
}
}
i++;
}
}
}
//Первый параметр - выходной. Он содержит выражения с необходимыми преобразованиями типов.
public function_node select_function(expressions_list parameters, List<SymbolInfo> functions, location loc, List<SyntaxTree.expression> syntax_nodes_parameters = null, bool only_from_not_extensions = false)
{
@ -1736,7 +1792,7 @@ namespace PascalABCCompiler.TreeConverter
return AddError<function_node>(new NoFunctionWithThisName(loc));
}
var set_of_possible_functions = new function_node_list();
var set_of_possible_functions = new List<function_node>();
bool is_alone_method_defined = (functions.Count() == 1);
function_node first_function = functions.FirstOrDefault().sym_info as function_node;
@ -1779,13 +1835,13 @@ namespace PascalABCCompiler.TreeConverter
if (set_of_possible_functions.Count > 0)
if (set_of_possible_functions[0] is basic_function_node)
{
set_of_possible_functions.remove(set_of_possible_functions[0]);
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Remove(set_of_possible_functions[0]);
set_of_possible_functions.Add(fn);
}
continue;
}
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
}
}
else
@ -1803,7 +1859,7 @@ namespace PascalABCCompiler.TreeConverter
}
continue;
}
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
}
}
if (parameters.Count > fn.parameters.Count)
@ -1818,24 +1874,24 @@ namespace PascalABCCompiler.TreeConverter
continue;
}
//-DS
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
}
}
}
//else if ((parameters.Count == 0 && fn.parameters.Count == 1) && fn.parameters[0].is_params && !set_of_possible_functions.Contains(fn))
// SSM 6.08.18 - так просто исправить не получается - видимо, сопоставление параметров работает неверно
else if ((parameters.Count == fn.parameters.Count - 1) && fn.parameters[fn.parameters.Count-1].is_params && !set_of_possible_functions.Contains(fn))
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
else if (fn.num_of_default_parameters != 0 && parameters.Count >= fn.parameters.Count - fn.num_of_default_parameters)
{
if (!set_of_possible_functions.Contains(fn))
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
}
else if (parameters.Count == 1 && fn is common_namespace_function_node && (fn as common_namespace_function_node).ConnectedToType != null && fn.parameters.Count == 2 && fn.parameters[1].is_params)
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
else if (parameters.Count == 1 && fn is compiled_function_node && (fn as compiled_function_node).ConnectedToType != null && fn.parameters.Count == 2 && fn.parameters[1].is_params)
if (!set_of_possible_functions.Contains(fn))
set_of_possible_functions.AddElement(fn);
set_of_possible_functions.Add(fn);
}
if (set_of_possible_functions.Count == 0 && indefinits.Count == 0)
@ -1864,7 +1920,7 @@ namespace PascalABCCompiler.TreeConverter
is_alone_method_defined, syntax_tree_visitor.context, loc, syntax_nodes_parameters);
if (inst == null)
{
set_of_possible_functions.remove_at(i);
set_of_possible_functions.RemoveAt(i);
}
else
{
@ -1873,7 +1929,7 @@ namespace PascalABCCompiler.TreeConverter
}
catch (FailedWhileTryingToCompileLambdaBodyWithGivenParametersException exc) //lroman Отлавливаем последнее исключение, которое возникло при попытке скомпилировать тело лямбды с заданными типами параметров
{
set_of_possible_functions.remove_at(i);
set_of_possible_functions.RemoveAt(i);
lastFailedWhileTryingToCompileLambdaBodyWithGivenParametersException = exc;
}
catch(Errors.Error err)
@ -1937,7 +1993,7 @@ namespace PascalABCCompiler.TreeConverter
if (tcll[j] == null && set_of_possible_functions[j].node_kind != node_kind.indefinite)
{
tcll.remove_at(j);
set_of_possible_functions.remove_at(j);
set_of_possible_functions.RemoveAt(j);
}
else
{
@ -1954,63 +2010,15 @@ namespace PascalABCCompiler.TreeConverter
return AddError<function_node>(new NoFunctionWithSameArguments(loc, is_alone_method_defined));
}
bool remove = true;
while (remove)
if (set_of_possible_functions.Count == 1)
{
if (set_of_possible_functions.Count == 1)
{
check_single_possible_convertion(loc, tcll[0]);
convert_function_call_expressions(set_of_possible_functions[0], parameters, tcll[0]);
return set_of_possible_functions[0];
}
remove = false;
// Удаляем из всех возможных перегруженных версий функций те, которые больше какой-то. Та, которая меньше по всем параметрам, остаётся.
// По идее это надо делать для каждой дистанции отдельно - тогда баг #1970 уйдёт
var i = 0;
while (i < set_of_possible_functions.Count - 1)
{
j = i + 1;
while (j < set_of_possible_functions.Count)
{
method_compare mc = compare_methods(set_of_possible_functions[i],
set_of_possible_functions[j], tcll[i], tcll[j]);
if (SystemLibrary.SystemLibInitializer.InSetProcedure != null)
{
if (set_of_possible_functions[j] == SystemLibrary.SystemLibInitializer.InSetProcedure.sym_info)
{
mc = method_compare.less_method;
}
else if (set_of_possible_functions[i] == SystemLibrary.SystemLibInitializer.InSetProcedure.sym_info)
{
mc = method_compare.greater_method;
}
}
if (mc == method_compare.greater_method)
{
tcll.remove_at(j);
set_of_possible_functions.remove_at(j);
remove = true;
}
else if (mc == method_compare.less_method)
{
tcll[i] = tcll[j];
set_of_possible_functions[i] = set_of_possible_functions[j];
tcll.remove_at(j);
set_of_possible_functions.remove_at(j);
remove = true;
}
else
{
j++;
}
}
i++;
}
check_single_possible_convertion(loc, tcll[0]);
convert_function_call_expressions(set_of_possible_functions[0], parameters, tcll[0]);
return set_of_possible_functions[0];
}
functions_delete_greater(set_of_possible_functions,tcll); // SSM 06/06/19 refactoring
//Тупая заглушка для примитивных типов. иначе не работает +=, у нас лишком много неявных приведений
//в дальнейшем может вызвать странное поведение, это надо проверить
if (set_of_possible_functions.Count == 2 && indefinits.Count == 0)
@ -2042,7 +2050,6 @@ namespace PascalABCCompiler.TreeConverter
return new indefinite_functions_set(indefinits);
}
SortedDictionary<int, List<function_node>> distances = new SortedDictionary<int, List<function_node>>();
function_node best_function = null;
List<function_node> to_remove = new List<function_node>();
foreach (function_node fn in set_of_possible_functions)
@ -2079,9 +2086,10 @@ namespace PascalABCCompiler.TreeConverter
}
}
}
foreach (function_node fn in to_remove)
{
set_of_possible_functions.remove(fn);
set_of_possible_functions.Remove(fn);
}
// Формирование словаря списков функций с одинаковым значением расстояния
@ -2091,6 +2099,7 @@ namespace PascalABCCompiler.TreeConverter
// Average(IEnumerable<integer>,integer->Nullable<integer>): real
// Average(IEnumerable<integer>,integer->integer): real
// Дело в том, что на этом уровне лямбда x->x имеет тип lambda_anytype->lambda_anytype. Все подходят :)
SortedDictionary<int, List<function_node>> distances = new SortedDictionary<int, List<function_node>>();
foreach (function_node fn in set_of_possible_functions)
{
int distance = 0;
@ -2428,7 +2437,7 @@ namespace PascalABCCompiler.TreeConverter
}
private function_node is_exist_eq_return_value_method(function_node fn, function_node_list funcs)
private function_node is_exist_eq_return_value_method(function_node fn, List<function_node> funcs)
{
fn = find_eq_return_value_method_in_list(fn, funcs);
return fn;

View file

@ -1140,7 +1140,7 @@ namespace PascalABCCompiler.TreeConverter
{
//Важная проверка. Возможно один и тот же оператор с одними и теми же типами определен в двух разных классах.
//Возможно она занимает много времени, но, наверное, от нее нельзя отказаться.
function_node_list funcs = new function_node_list();
List<function_node> funcs = new List<function_node>();
foreach(SymbolInfo sic in sil)
{
if (sic.sym_info.general_node_type != general_node_type.function_node)
@ -1158,7 +1158,7 @@ namespace PascalABCCompiler.TreeConverter
if (convertion_data_and_alghoritms.is_exist_eq_method_in_list(fn, funcs) == null)
{
//break;
funcs.AddElement(fn);
funcs.Add(fn);
}
}
//TODO: Разобраться с зацикливанием.
@ -1356,7 +1356,7 @@ namespace PascalABCCompiler.TreeConverter
return false;
}
private base_function_call_list convert_functions_to_calls(expression_node obj, function_node_list fnl, location loc, bool is_static)
private base_function_call_list convert_functions_to_calls(expression_node obj, List<function_node> fnl, location loc, bool is_static)
{
base_function_call_list ret = new base_function_call_list();
foreach (function_node fnode in fnl)
@ -1529,7 +1529,7 @@ namespace PascalABCCompiler.TreeConverter
{
return new base_function_call_list();
}
function_node_list fnl = new function_node_list();
var fnl = new List<function_node>();
foreach(SymbolInfo si in sil)
{
function_node fn = si.sym_info as function_node;
@ -1548,12 +1548,12 @@ namespace PascalABCCompiler.TreeConverter
if (fn.is_extension_method)
{
if (obj != null && (fn.parameters[0].type == obj.type || type_table.compare_types(fn.parameters[0].type, obj.type) == type_compare.greater_type))
fnl.AddElementFirst(fn);
fnl.Insert(0,fn);
else
fnl.AddElement(fn);
fnl.Add(fn);
}
else
fnl.AddElement(fn);
fnl.Add(fn);
}
}
else
@ -1566,8 +1566,8 @@ namespace PascalABCCompiler.TreeConverter
private base_function_call_list create_possible_delegates_list(expression_node obj, function_node func, location loc, bool is_static)
{
function_node_list fnl = new function_node_list();
fnl.AddElement(func);
var fnl = new List<function_node>();
fnl.Add(func);
return convert_functions_to_calls(obj, fnl, loc, is_static);
}
@ -5328,7 +5328,7 @@ namespace PascalABCCompiler.TreeConverter
{
LambdaHelper.processingLambdaParametersForTypeInference++;
// SSM 21.05.14 - попытка обработать перегруженные функции с параметрами-лямбдами с различными возвращаемыми значениями
function_node_list spf = null;
List<function_node> spf = null;
try
{
ThrowCompilationError = false;
@ -5791,7 +5791,7 @@ namespace PascalABCCompiler.TreeConverter
{
LambdaHelper.processingLambdaParametersForTypeInference++;
// SSM 21.05.14 - попытка обработать перегруженные функции с параметрами-лямбдами с различными возвращаемыми значениями
function_node_list spf = null;
List<function_node> spf = null;
try
{
function_node ffn = convertion_data_and_alghoritms.select_function(exprs, sil, subloc, syntax_nodes_parameters);
@ -6086,7 +6086,7 @@ namespace PascalABCCompiler.TreeConverter
{
LambdaHelper.processingLambdaParametersForTypeInference++;
// SSM 21.05.14 - попытка обработать перегруженные функции с параметрами-лямбдами с различными возвращаемыми значениями
function_node_list spf = null;
List<function_node> spf = null;
try
{
function_node ffn = convertion_data_and_alghoritms.select_function(exprs, sil, subloc, syntax_nodes_parameters);
@ -7004,7 +7004,7 @@ namespace PascalABCCompiler.TreeConverter
{
LambdaHelper.processingLambdaParametersForTypeInference++;
// SSM 21.05.14 - попытка обработать перегруженные функции с параметрами-лямбдами с различными возвращаемыми значениями
function_node_list spf = null;
List<function_node> spf = null;
try
{
function_node fn = convertion_data_and_alghoritms.select_function(exprs, sil, subloc2, syntax_nodes_parameters);
@ -18143,7 +18143,7 @@ namespace PascalABCCompiler.TreeConverter
var syntax_nodes_parameters = lambdas_info.Item2;
// SSM 21.05.14 - попытка обработать перегруженные функции с параметрами-лямбдами с различными возвращаемыми значениями
function_node_list spf = null;
List<function_node> spf = null;
try
{
function_node fn = convertion_data_and_alghoritms.select_function(exprs, sil, loc,

View file

@ -723,7 +723,7 @@ namespace VisualPascalABC
classComboBox.Invoke(new Invoke_del(Invoke_EndUpdate));
}
}
catch (Exception ex)
catch (Exception )
{
}
}

View file

@ -38,7 +38,7 @@ namespace VisualPascalABC
WorkbenchServiceFactory.DebuggerOperationsService.AddVariable(var, true);
}
}
catch (System.Exception e)
catch (System.Exception)
{
WorkbenchServiceFactory.DebuggerOperationsService.GotoWatch();
}

View file

@ -680,7 +680,7 @@ namespace VisualPascalABC
breakpoints_conditions.Remove(breakpoints[breakpoint]);
WorkbenchServiceFactory.DebuggerManager.RemoveBreakpoint(breakpoints[breakpoint]);
}
catch (System.Exception e)
catch (System.Exception)
{
}
breakpoints.Remove(breakpoint);

View file

@ -1151,7 +1151,7 @@ namespace VisualPascalABC
continue;
list.Add(new ValueItem(v,this.DebugType));
}
catch (System.Exception e)
catch (System.Exception)
{
}
}

View file

@ -118,7 +118,7 @@ namespace VisualPascalABC
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
return bf.Deserialize(new FileStream(file_name, FileMode.Open)) as UserProjectSettings;
}
catch (Exception e)
catch (Exception)
{
}

View file

@ -392,7 +392,7 @@ namespace VisualPascalABC
if (TbPage == CurrentCodeFileDocument)
UpdateSaveButtonsEnabled();
}
catch (Exception ex)
catch (Exception)
{
MessageBox.Show(String.Format(Form1StringResources.Get("SAVE_FILE_ERROR_TEXT{0}"), FileName), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}

View file

@ -141,7 +141,7 @@ namespace VisualPascalABC
{
MessageBox.Show(Form1StringResources.Get("TOO_OLD_PROJECT_FILE_VERSION"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
catch (Exception)
{
MessageBox.Show(Form1StringResources.Get("ERROR_OPEN_PROJECT"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}

View file

@ -670,7 +670,7 @@ namespace VisualPascalABC
DebugWatchListWindow.RefreshWatch();
AdvancedDataGridView.TreeGridNode.UpdateNodesForLocalList(DebugVariablesListWindow.watchList, DebugVariablesListWindow.watchList.Nodes, items);
}
catch (System.Exception e)
catch (System.Exception)
{
}

View file

@ -10,7 +10,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using PascalABCCompiler.SemanticTree;
using System.Text.RegularExpressions;
using System.Reflection;
namespace VisualPascalABCPlugins