Merge branch 'master' of https://github.com/pascalabcnet/pascalabcnet
This commit is contained in:
commit
3a98c40f47
|
|
@ -490,7 +490,7 @@ namespace CodeFormatters
|
|||
if (s.Length > 0 && !char.IsWhiteSpace(s[0]) && s[0] != '{' && !s.StartsWith("//") && !s.StartsWith("(*") && s[0] != ';' && !char.IsWhiteSpace(s[0]) && (sb.Length == 0 || !char.IsWhiteSpace(sb[sb.Length-1])))
|
||||
sb.Append(' ');
|
||||
}
|
||||
else
|
||||
else if (s.IndexOf("//") == -1)
|
||||
s = s.TrimStart(' ', '\t');
|
||||
sb.Append(s);
|
||||
if (add_space_after)
|
||||
|
|
@ -908,6 +908,7 @@ namespace CodeFormatters
|
|||
add_newline_before = true;
|
||||
}*/
|
||||
visit_node(_statement_list.left_logical_bracket);
|
||||
//add_space_before = true;
|
||||
}
|
||||
|
||||
if (!in_one_row(_statement_list) && _statement_list.left_logical_bracket != null && _statement_list.subnodes.Count > 0 && _statement_list.subnodes[0].source_context != null && _statement_list.left_logical_bracket.source_context.end_position.line_num == _statement_list.subnodes[0].source_context.begin_position.line_num
|
||||
|
|
|
|||
|
|
@ -2921,6 +2921,13 @@ namespace CodeCompletion
|
|||
}
|
||||
|
||||
}
|
||||
else if (returned_scope is ProcScope)
|
||||
{
|
||||
method_call mc = new method_call(_dot_node, new expression_list());
|
||||
search_all = true;
|
||||
mc.visit(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (returned_scope != null && returned_scope is ProcScope && (returned_scope as ProcScope).return_type != null)
|
||||
|
|
|
|||
|
|
@ -902,6 +902,12 @@ namespace CodeCompletion
|
|||
return;
|
||||
}
|
||||
}
|
||||
else if (ps != null)
|
||||
{
|
||||
method_call mc = new method_call(_dot_node, new expression_list());
|
||||
mc.visit(this);
|
||||
return;
|
||||
}
|
||||
if (tmp_tn is ElementScope && stv != null)
|
||||
{
|
||||
List<ProcScope> procs = stv.entry_scope.GetExtensionMethods((_dot_node.right as ident).name, (tmp_tn as ElementScope).sc as TypeScope);
|
||||
|
|
|
|||
|
|
@ -2588,7 +2588,10 @@ namespace CodeCompletion
|
|||
if (this.parameters[i].param_kind != ps.parameters[i].param_kind)
|
||||
return false;
|
||||
if (!this.parameters[i].sc.IsEqual(ps.parameters[i].sc))
|
||||
return false;
|
||||
if (this.parameters[i].sc is UnknownScope)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if (this.return_type == null)
|
||||
if (ps.return_type != null)
|
||||
|
|
@ -4355,8 +4358,25 @@ namespace CodeCompletion
|
|||
ts.loc = this.loc;
|
||||
for (int i = 0; i < gen_args.Count; i++)
|
||||
{
|
||||
ts.AddGenericInstanceParameter(gen_args[i].si.name);
|
||||
ts.AddGenericInstanciation(gen_args[i]);
|
||||
TypeScope gen_arg = gen_args[i];
|
||||
if (gen_arg.instances != null && gen_arg.original_type != null)
|
||||
{
|
||||
if (gen_arg.original_type.generic_params != null && this.generic_params != null)
|
||||
for (int j = 0; j < gen_arg.original_type.generic_params.Count; j++)
|
||||
{
|
||||
if (string.Compare(gen_arg.original_type.generic_params[j], this.generic_params[j], true) == 0)
|
||||
{
|
||||
ts.AddGenericInstanceParameter(gen_arg.instances[j].si.name);
|
||||
ts.AddGenericInstanciation(gen_arg.instances[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ts.AddGenericInstanceParameter(gen_args[i].si.name);
|
||||
ts.AddGenericInstanciation(gen_args[i]);
|
||||
}
|
||||
|
||||
}
|
||||
ts.si.name = this.si.name;
|
||||
ts.documentation = this.documentation;
|
||||
|
|
@ -5587,6 +5607,11 @@ namespace CodeCompletion
|
|||
}
|
||||
}
|
||||
|
||||
protected override TypeScope simpleGetInstance(List<TypeScope> gen_args)
|
||||
{
|
||||
return this.GetInstance(gen_args);
|
||||
}
|
||||
|
||||
public override TypeScope GetInstance(List<TypeScope> gen_args, bool exact = false)
|
||||
{
|
||||
Type t = this.ctn;
|
||||
|
|
|
|||
|
|
@ -2618,7 +2618,6 @@ namespace PascalABCCompiler
|
|||
{
|
||||
if (FileName.IndexOf(Path.DirectorySeparatorChar) != -1)
|
||||
{
|
||||
|
||||
File.Copy(Path.Combine(Environment.CurrentDirectory, FileName), Path.Combine(Environment.CurrentDirectory, Path.GetFileName(FileName)), true);
|
||||
if (CompilerOptions.useOutputDirectory)
|
||||
File.Copy(Path.Combine(Environment.CurrentDirectory, FileName), Path.Combine(CompilerOptions.OutputDirectory, Path.GetFileName(FileName)), true);
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ namespace Debugger
|
|||
case CorElementType.U8: return typeof(System.UInt64);
|
||||
case CorElementType.R4: return typeof(System.Single);
|
||||
case CorElementType.R8: return typeof(System.Double);
|
||||
case CorElementType.I: return typeof(int);
|
||||
case CorElementType.U: return typeof(uint);
|
||||
case CorElementType.I: return typeof(IntPtr);
|
||||
case CorElementType.U: return typeof(UIntPtr);//return System.Environment.Is64BitProcess?typeof(ulong):typeof(uint);
|
||||
case CorElementType.SZARRAY:
|
||||
case CorElementType.ARRAY: return typeof(System.Array);
|
||||
case CorElementType.OBJECT: return typeof(System.Object);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -2951,7 +2951,11 @@ namespace PascalABCCompiler.NETGenerator
|
|||
il.Emit(OpCodes.Stloc, lb);
|
||||
}
|
||||
in_var_init = true;
|
||||
GenerateInitCode(var, il);
|
||||
|
||||
if (!(var.type.is_value_type && var.inital_value is IDefaultOperatorNode))
|
||||
{
|
||||
GenerateInitCode(var, il);
|
||||
}
|
||||
in_var_init = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ namespace PascalABCCompiler.Parsers
|
|||
keywords.Add("overload", "overload"); keys.Add("overload");
|
||||
keywords.Add("internal", "internal"); keys.Add("internal");
|
||||
//keywords.Add("template", "template"); keys.Add("template");
|
||||
keywords.Add("partial", "partial"); keys.Add("partial");
|
||||
keywords.Add("namespace", "namespace"); keys.Add("namespace");
|
||||
keywords.Add("exit", "exit"); keys.Add("exit");
|
||||
keywords.Add("event", "event"); keys.Add("event");
|
||||
|
|
@ -1627,8 +1628,17 @@ namespace PascalABCCompiler.Parsers
|
|||
Type t = (scope.Type as ICompiledTypeScope).CompiledType;
|
||||
inst_type = get_type_instance(t,scope.GenericArgs);
|
||||
}
|
||||
sb.Append("property "+ GetShortTypeName(scope.CompiledProperty.DeclaringType) +"."+ scope.CompiledProperty.Name + get_indexer_for_prop(scope)+ ": "+(inst_type != null?inst_type:GetSimpleDescription(scope.Type)));
|
||||
if (acc != null)
|
||||
sb.Append("property "+ GetShortTypeName(scope.CompiledProperty.DeclaringType) +"."+ scope.CompiledProperty.Name + get_indexer_for_prop(scope));
|
||||
if (inst_type == null)
|
||||
{
|
||||
if (scope.Type is ICompiledTypeScope)
|
||||
sb.Append(": " + GetFullTypeName((scope.Type as ICompiledTypeScope).CompiledType, false));
|
||||
else
|
||||
sb.Append(": " + GetSimpleDescription(scope.Type));
|
||||
}
|
||||
else
|
||||
sb.Append(": " + inst_type);
|
||||
if (acc != null)
|
||||
//if (acc.IsStatic) sb.Append("; static");
|
||||
if (acc.IsVirtual) sb.Append("; virtual");
|
||||
else if (acc.IsAbstract) sb.Append("; abstract");
|
||||
|
|
|
|||
|
|
@ -12362,12 +12362,10 @@ begin
|
|||
Result := Self.Split(delim, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
end;
|
||||
|
||||
const SpaceDelimiters = ' '+#9#10#13;
|
||||
|
||||
/// Преобразует строку в массив слов, используя в качестве разделителей символы из строки delim
|
||||
function ToWords(Self: string; delim: string := SpaceDelimiters): array of string; extensionmethod;
|
||||
/// Преобразует строку в массив слов, используя в качестве разделителей символы из строки delims
|
||||
function ToWords(Self: string; delims: string := ' '): array of string; extensionmethod;
|
||||
begin
|
||||
Result := Self.Split(delim.ToCharArray, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
Result := Self.Split(delims.ToCharArray, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
end;
|
||||
|
||||
procedure PassSpaces(var s: string; var from: integer);
|
||||
|
|
|
|||
23
TestSuite/errors/err0390.pas
Normal file
23
TestSuite/errors/err0390.pas
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
type
|
||||
t0 = abstract class end;
|
||||
|
||||
t1<T> = class
|
||||
where T: t0;
|
||||
|
||||
procedure p1(x: byte);
|
||||
begin
|
||||
var p: Action0 := ()->
|
||||
begin
|
||||
|
||||
|
||||
Writeln(x);
|
||||
|
||||
Writeln(new T);
|
||||
|
||||
end;
|
||||
p();
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
begin end.
|
||||
13
TestSuite/errors/err0391.pas
Normal file
13
TestSuite/errors/err0391.pas
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type
|
||||
|
||||
c1<T> = class where T: c1<T>;
|
||||
|
||||
end;
|
||||
|
||||
c2 = class(c1<List<integer>>)
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
new c2;
|
||||
end.
|
||||
9
TestSuite/extensionoperators4.pas
Normal file
9
TestSuite/extensionoperators4.pas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function operator=<T>(a,b: array of T): boolean; extensionmethod :=
|
||||
(a.Length=b.Length) and a.SequenceEqual(b);
|
||||
|
||||
begin
|
||||
var a := Arr(1,2,3);
|
||||
var b := Arr(1,2,3);
|
||||
Assert(not object.ReferenceEquals(a,b));
|
||||
Assert(a = b);
|
||||
end.
|
||||
3
TestSuite/formatter_tests/input/comment1.pas
Normal file
3
TestSuite/formatter_tests/input/comment1.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
begin //dsdsd
|
||||
if true then;
|
||||
end.
|
||||
4
TestSuite/formatter_tests/input/comment2.pas
Normal file
4
TestSuite/formatter_tests/input/comment2.pas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
begin
|
||||
//dsdsd
|
||||
if true then;
|
||||
end.
|
||||
3
TestSuite/formatter_tests/should/comment1.pas
Normal file
3
TestSuite/formatter_tests/should/comment1.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
begin //dsdsd
|
||||
if true then;
|
||||
end.
|
||||
4
TestSuite/formatter_tests/should/comment2.pas
Normal file
4
TestSuite/formatter_tests/should/comment2.pas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
begin
|
||||
//dsdsd
|
||||
if true then;
|
||||
end.
|
||||
28
TestSuite/generics43.pas
Normal file
28
TestSuite/generics43.pas
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
var i: integer;
|
||||
procedure p1<T>(a: array of T);
|
||||
begin
|
||||
i := 1;
|
||||
end;
|
||||
procedure p1<T>(a: T);
|
||||
begin
|
||||
i := 2;
|
||||
end;
|
||||
|
||||
procedure p2<T>(a: array[,] of T);
|
||||
begin
|
||||
i := 1;
|
||||
end;
|
||||
procedure p2<T>(a: T);
|
||||
begin
|
||||
i := 2;
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
var a := new byte[5];
|
||||
p1(a);
|
||||
assert(i = 1);
|
||||
i := 0;
|
||||
p2(a);
|
||||
assert(i = 2);
|
||||
end.
|
||||
|
|
@ -67,6 +67,9 @@ const
|
|||
/// Константа перехода на новую строку
|
||||
/// !! The newline string defined for this environment.
|
||||
NewLine = System.Environment.NewLine;
|
||||
/// Константа - символы-разделители слов
|
||||
/// !! symbols - word delimiters
|
||||
AllDelimiters = ' <>=^`|~$№§!"#%&''()*,+-./:;?@[\]_{}«·»'#9#10#13;
|
||||
//{{{--doc: Конец секции стандартных констант для документации }}}
|
||||
|
||||
|
||||
|
|
@ -253,6 +256,9 @@ type
|
|||
/// Предоставляет методы для точного измерения затраченного времени
|
||||
Stopwatch = System.Diagnostics.Stopwatch;
|
||||
|
||||
/// Указывает на возможность сериализации класса
|
||||
Serializable = System.SerializableAttribute;
|
||||
|
||||
/// Представляет тип короткой строки фиксированной длины 255 символов
|
||||
ShortString = string[255];
|
||||
|
||||
|
|
@ -492,6 +498,7 @@ type
|
|||
function ToString: string; override;
|
||||
class function operator implicit<T>(s: TypedSet): HashSet<T>;
|
||||
class function operator implicit<T>(s: HashSet<T>): TypedSet;
|
||||
//class function operator implicit<T>(a: array of T): TypedSet;
|
||||
function Count: integer := ht.Count;
|
||||
procedure Print(delim: string := ' ');
|
||||
procedure Println(delim: string := ' ');
|
||||
|
|
@ -585,6 +592,10 @@ type
|
|||
function ReadReal: real;
|
||||
/// Считывает строку из бестипового файла
|
||||
function ReadString: string;
|
||||
/// Сериализует объект в файл (объект должен иметь атрибут [Serializable])
|
||||
procedure Serialize(obj: object);
|
||||
/// Десериализует объект из файла
|
||||
function Deserialize: object;
|
||||
end;
|
||||
|
||||
type
|
||||
|
|
@ -627,7 +638,7 @@ type
|
|||
Result := (l = r2.l) and (h = r2.h);
|
||||
end;
|
||||
function GetHashCode: integer; override := l.GetHashCode xor h.GetHashCode;
|
||||
function ToArray: array of integer;
|
||||
{function ToArray: array of integer;
|
||||
begin
|
||||
Result := new integer[Count];
|
||||
var x := l;
|
||||
|
|
@ -639,14 +650,14 @@ type
|
|||
end;
|
||||
function ToList: List<integer>;
|
||||
begin
|
||||
Result := new List<integer>;
|
||||
Result := new List<integer>(Count);
|
||||
var x := l;
|
||||
loop Count do
|
||||
begin
|
||||
Result.Add(x);
|
||||
x += 1;
|
||||
end;
|
||||
end;
|
||||
end;}
|
||||
function ToLinkedList: LinkedList<integer>;
|
||||
begin
|
||||
Result := new LinkedList<integer>(System.Linq.Enumerable.Range(l,Count));
|
||||
|
|
@ -700,7 +711,7 @@ type
|
|||
end;
|
||||
function GetHashCode: integer; override := l.GetHashCode xor h.GetHashCode;
|
||||
|
||||
function ToArray: array of char;
|
||||
{function ToArray: array of char;
|
||||
begin
|
||||
Result := new char[Count];
|
||||
var x := l;
|
||||
|
|
@ -719,7 +730,7 @@ type
|
|||
Result.Add(x);
|
||||
x := char(integer(x) + 1);
|
||||
end;
|
||||
end;
|
||||
end;}
|
||||
function ToLinkedList: LinkedList<char>;
|
||||
begin
|
||||
Result := new LinkedList<char>(System.Linq.Enumerable.Range(integer(l),Count).Select(i -> char(i)));
|
||||
|
|
@ -1182,6 +1193,12 @@ procedure Println(params args: array of object);
|
|||
/// Выводит значения a,b,... в текстовый файл f, после каждого значения выводит пробел и переходит на новую строку
|
||||
procedure Println(f: Text; params args: array of object);
|
||||
|
||||
/// Сериализует объект в файл (объект должен иметь атрибут [Serializable])
|
||||
procedure Serialize(filename: string; obj: object);
|
||||
/// Десериализует объект из файла
|
||||
function Deserialize(filename: string): object;
|
||||
|
||||
|
||||
// -----------------------------------------------------
|
||||
//>> Общие подпрограммы для работы с файлами # Common subroutines for files
|
||||
// -----------------------------------------------------
|
||||
|
|
@ -2130,6 +2147,9 @@ function MatrEqual<T>(a, b: array [,] of T): boolean;
|
|||
/// Перемешивает список случайным образом
|
||||
procedure Shuffle<T>(l: List<T>);
|
||||
|
||||
/// Возвращает следующую перестановку в массиве
|
||||
function NextPermutation(a: array of integer): boolean;
|
||||
|
||||
|
||||
// -----------------------------------------------------
|
||||
//>> Подпрограммы для генерации последовательностей # Subroutines for sequence generation
|
||||
|
|
@ -2138,6 +2158,10 @@ procedure Shuffle<T>(l: List<T>);
|
|||
function Range(a, b: integer): sequence of integer;
|
||||
/// Возвращает последовательность целых от a до b с шагом step
|
||||
function Range(a, b, step: integer): sequence of integer;
|
||||
/// Возвращает последовательность длинных целых от a до b
|
||||
function Range(a, b: BigInteger): sequence of BigInteger;
|
||||
/// Возвращает последовательность длинных целых от a до b с шагом step
|
||||
function Range(a, b, step: BigInteger): sequence of BigInteger;
|
||||
/// Возвращает последовательность символов от c1 до c2
|
||||
function Range(c1, c2: char): sequence of char;
|
||||
/// Возвращает последовательность символов от c1 до c2 с шагом step
|
||||
|
|
@ -2810,6 +2834,9 @@ function WINAPI_AllocConsole: longword; external 'kernel32.dll' name 'AllocConso
|
|||
|
||||
var
|
||||
console_alloc: boolean := false;
|
||||
|
||||
type
|
||||
BinaryFormatter = System.Runtime.Serialization.Formatters.Binary.BinaryFormatter;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Internal functions
|
||||
|
|
@ -3366,6 +3393,17 @@ begin
|
|||
Result := ts;
|
||||
end;
|
||||
|
||||
///--
|
||||
{class function TypedSet.operator implicit<T>(a: array of T): TypedSet;
|
||||
begin
|
||||
var ts := new TypedSet();
|
||||
foreach key: T in a do
|
||||
begin
|
||||
ts.ht[key] := key;
|
||||
end;
|
||||
Result := ts;
|
||||
end;}
|
||||
|
||||
///--
|
||||
function TypedSet.ToString: string;
|
||||
var
|
||||
|
|
@ -4029,20 +4067,25 @@ function CharRange.Reverse: sequence of char := Range(l,h).Reverse;
|
|||
//------------------------------------------------------------------------------
|
||||
// Операции для string и char
|
||||
//------------------------------------------------------------------------------
|
||||
///--
|
||||
procedure string.operator+=(var left: string; right: string);
|
||||
begin
|
||||
left := left + right;
|
||||
end;
|
||||
|
||||
///--
|
||||
function string.operator<(left, right: string) := string.CompareOrdinal(left, right) < 0;
|
||||
|
||||
///--
|
||||
function string.operator<=(left, right: string) := string.CompareOrdinal(left, right) <= 0;
|
||||
|
||||
///--
|
||||
function string.operator>(left, right: string) := string.CompareOrdinal(left, right) > 0;
|
||||
|
||||
///--
|
||||
function string.operator>=(left, right: string) := string.CompareOrdinal(left, right) >= 0;
|
||||
|
||||
/// Повторяет строку str n раз
|
||||
///--
|
||||
function string.operator*(str: string; n: integer): string;
|
||||
begin
|
||||
var sb := new StringBuilder;
|
||||
|
|
@ -4051,7 +4094,7 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
/// Повторяет строку str n раз
|
||||
///--
|
||||
function string.operator*(n: integer; str: string): string;
|
||||
begin
|
||||
var sb := new StringBuilder;
|
||||
|
|
@ -4060,7 +4103,7 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
/// Повторяет символ c n раз
|
||||
///--
|
||||
function char.operator*(c: char; n: integer): string;
|
||||
begin
|
||||
if n <= 0 then
|
||||
|
|
@ -4074,7 +4117,7 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
/// Повторяет символ c n раз
|
||||
///--
|
||||
function char.operator*(n: integer; c: char): string;
|
||||
begin
|
||||
if n <= 0 then
|
||||
|
|
@ -4088,18 +4131,23 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
/// Добавляет к строке str строковое представление числа n
|
||||
// Добавляет к строке str строковое представление числа n
|
||||
///--
|
||||
function string.operator+(str: string; n: integer) := str + n.ToString;
|
||||
|
||||
/// Добавляет к строке str строковое представление числа n
|
||||
// Добавляет к строке str строковое представление числа n
|
||||
///--
|
||||
function string.operator+(n: integer; str: string) := n.ToString + str;
|
||||
|
||||
/// Добавляет к строке str строковое представление числа r
|
||||
// Добавляет к строке str строковое представление числа r
|
||||
///--
|
||||
function string.operator+(str: string; r: real) := str + r.ToString(nfi);
|
||||
|
||||
/// Добавляет к строке str строковое представление числа r
|
||||
// Добавляет к строке str строковое представление числа r
|
||||
///--
|
||||
function string.operator+(r: real; str: string) := r.ToString(nfi) + str;
|
||||
|
||||
///--
|
||||
procedure string.operator+=(var left: string; right: integer);
|
||||
begin
|
||||
left := left + right.ToString;
|
||||
|
|
@ -4542,7 +4590,7 @@ begin
|
|||
else Result := System.Linq.Enumerable.Range(a, b - a + 1);
|
||||
end;
|
||||
|
||||
function Range(a, b: real; n: integer): sequence of real;
|
||||
function PartitionPoints(a, b: real; n: integer): sequence of real;
|
||||
begin
|
||||
if n = 0 then
|
||||
raise new System.ArgumentException('Range: n=0');
|
||||
|
|
@ -4567,11 +4615,26 @@ begin
|
|||
Result := Range(integer(c1), integer(c2), step).Select(x -> Chr(x));
|
||||
end;
|
||||
|
||||
function PartitionPoints(a, b: real; n: integer): sequence of real;
|
||||
function Range(a, b, step: BigInteger): sequence of BigInteger;
|
||||
begin
|
||||
Result := Range(a, b, n)
|
||||
if step = 0 then
|
||||
raise new System.ArgumentException('step=0');
|
||||
if step > 0 then
|
||||
while a<=b do
|
||||
begin
|
||||
yield a;
|
||||
a += step;
|
||||
end
|
||||
else
|
||||
while a>=b do
|
||||
begin
|
||||
yield a;
|
||||
a += step;
|
||||
end
|
||||
end;
|
||||
|
||||
function Range(a, b: BigInteger): sequence of BigInteger := Range(a,b,1);
|
||||
|
||||
type
|
||||
ArithmSeq = auto class
|
||||
a, step: integer;
|
||||
|
|
@ -5190,33 +5253,6 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;}
|
||||
|
||||
function ReadLexem(f: Text): string;
|
||||
begin
|
||||
if f.fi = nil then
|
||||
raise new System.IO.IOException(GetTranslation(FILE_NOT_ASSIGNED));
|
||||
if f.sr = nil then
|
||||
raise new System.IO.IOException(GetTranslation(FILE_NOT_OPENED_FOR_READING));
|
||||
var i: integer;
|
||||
repeat
|
||||
i := f.sr.Read();
|
||||
until not char.IsWhiteSpace(char(i)); // pass spaces
|
||||
if i=-1 then
|
||||
raise new System.IO.IOException(GetTranslation(READ_LEXEM_AFTER_END_OF_TEXT_FILE));
|
||||
var c := char(i);
|
||||
var sb := System.Text.StringBuilder.Create;
|
||||
repeat
|
||||
sb.Append(c);
|
||||
i := f.sr.Peek();
|
||||
if i = -1 then
|
||||
break;
|
||||
c := char(i);
|
||||
if char.IsWhiteSpace(c) then
|
||||
break;
|
||||
f.sr.Read();
|
||||
until False; // accumulate nonspaces
|
||||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// IOStandardSystem: implementation
|
||||
// -----------------------------------------------------
|
||||
|
|
@ -6444,6 +6480,34 @@ begin
|
|||
Result := ReadBoolean(f);
|
||||
Readln(f);
|
||||
end;
|
||||
|
||||
function ReadLexem(f: Text): string;
|
||||
begin
|
||||
if f.fi = nil then
|
||||
raise new System.IO.IOException(GetTranslation(FILE_NOT_ASSIGNED));
|
||||
if f.sr = nil then
|
||||
raise new System.IO.IOException(GetTranslation(FILE_NOT_OPENED_FOR_READING));
|
||||
var i: integer;
|
||||
repeat
|
||||
i := f.sr.Read();
|
||||
until not char.IsWhiteSpace(char(i)); // pass spaces
|
||||
if i=-1 then
|
||||
raise new System.IO.IOException(GetTranslation(READ_LEXEM_AFTER_END_OF_TEXT_FILE));
|
||||
var c := char(i);
|
||||
var sb := System.Text.StringBuilder.Create;
|
||||
repeat
|
||||
sb.Append(c);
|
||||
i := f.sr.Peek();
|
||||
if i = -1 then
|
||||
break;
|
||||
c := char(i);
|
||||
if char.IsWhiteSpace(c) then
|
||||
break;
|
||||
f.sr.Read();
|
||||
until False; // accumulate nonspaces
|
||||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// TextFile methods
|
||||
// -----------------------------------------------------
|
||||
|
|
@ -6642,6 +6706,18 @@ begin
|
|||
Result := Self.br.ReadString;
|
||||
end;
|
||||
|
||||
procedure BinaryFile.Serialize(obj: object);
|
||||
begin
|
||||
var formatter := new BinaryFormatter;
|
||||
formatter.Serialize(fs,obj);
|
||||
end;
|
||||
|
||||
function BinaryFile.Deserialize: object;
|
||||
begin
|
||||
var formatter := new BinaryFormatter;
|
||||
Result := formatter.Deserialize(fs);
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Eoln - Eof
|
||||
// -----------------------------------------------------
|
||||
|
|
@ -6962,6 +7038,23 @@ begin
|
|||
Print(f, args);
|
||||
Writeln(f);
|
||||
end;
|
||||
|
||||
procedure Serialize(filename: string; obj: object);
|
||||
begin
|
||||
var fs := new System.IO.FileStream(filename,System.IO.FileMode.Create);
|
||||
var formatter := new BinaryFormatter;
|
||||
formatter.Serialize(fs,obj);
|
||||
fs.Close;
|
||||
end;
|
||||
|
||||
function Deserialize(filename: string): object;
|
||||
begin
|
||||
var fs := new System.IO.FileStream(filename,System.IO.FileMode.Open);
|
||||
var formatter := new BinaryFormatter;
|
||||
Result := formatter.Deserialize(fs);
|
||||
fs.Close;
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Text files
|
||||
// -----------------------------------------------------
|
||||
|
|
@ -6979,6 +7072,7 @@ begin
|
|||
begin
|
||||
f.sr := new StreamReader(f.fi.FullName, DefaultEncoding);
|
||||
(CurrentIOSystem as IOStandardSystem).tr := f.sr;
|
||||
(CurrentIOSystem as IOStandardSystem).realbuflen := -1;
|
||||
_IsPipedRedirected := True;
|
||||
_IsPipedRedirectedQuery := True;
|
||||
end;
|
||||
|
|
@ -7029,6 +7123,11 @@ begin
|
|||
f.sr.BaseStream.Position := 0;
|
||||
f.sr.DiscardBufferedData;
|
||||
end;
|
||||
if f = input then
|
||||
begin
|
||||
(CurrentIOSystem as IOStandardSystem).tr := f.sr;
|
||||
(CurrentIOSystem as IOStandardSystem).realbuflen := -1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Reset(f: Text; name: string) := Reset(f, name, DefaultEncoding);
|
||||
|
|
@ -9723,6 +9822,39 @@ begin
|
|||
Result += f(x);
|
||||
end;}
|
||||
|
||||
// SSM 23/11/2020 - Sum Average Product for sequence of BigInteger
|
||||
|
||||
/// Возвращает сумму элементов последовательности
|
||||
function Sum(Self: sequence of BigInteger): BigInteger; extensionmethod;
|
||||
begin
|
||||
Result := 0bi;
|
||||
foreach var a in Self do
|
||||
Result += a
|
||||
end;
|
||||
|
||||
/// Возвращает среднее элементов последовательности
|
||||
function Average(Self: sequence of BigInteger): real; extensionmethod;
|
||||
begin
|
||||
var cnt := 0;
|
||||
var sum := 0bi;
|
||||
foreach var a in Self do
|
||||
begin
|
||||
sum += a;
|
||||
cnt += 1;
|
||||
end;
|
||||
if cnt <> 0 then
|
||||
Result := sum/cnt
|
||||
else Result := 0
|
||||
end;
|
||||
|
||||
/// Возвращает произведение элементов последовательности
|
||||
function Product(Self: sequence of BigInteger): BigInteger; extensionmethod;
|
||||
begin
|
||||
Result := 1bi;
|
||||
foreach var a in Self do
|
||||
Result *= a
|
||||
end;
|
||||
|
||||
|
||||
/// Возвращает отсортированную по возрастанию последовательность
|
||||
function Sorted<T>(Self: sequence of T): sequence of T; extensionmethod;
|
||||
|
|
@ -10239,6 +10371,15 @@ end;
|
|||
|
||||
// ToDo Сделать AdjacentGroup с функцией сравнения
|
||||
|
||||
/// Возвращает количество элементов, равных указанному значению
|
||||
function CountOf<T>(Self: sequence of T; x: T): integer; extensionmethod;
|
||||
begin
|
||||
Result := 0;
|
||||
foreach var y in Self do
|
||||
if y = x then
|
||||
Result += 1;
|
||||
end;
|
||||
|
||||
// -----------------------------------------------------
|
||||
//>> Методы расширения списков # Extension methods for List T
|
||||
// -----------------------------------------------------
|
||||
|
|
@ -11696,7 +11837,7 @@ begin
|
|||
repeat
|
||||
for var i:=0 to n-1 do
|
||||
res[i] := a[ind[i]];
|
||||
yield res;
|
||||
yield Arr(res);
|
||||
until not NextPermutation(ind);
|
||||
end;
|
||||
|
||||
|
|
@ -12221,6 +12362,12 @@ begin
|
|||
Result := Self.Split(delim, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
end;
|
||||
|
||||
/// Преобразует строку в массив слов, используя в качестве разделителей символы из строки delims
|
||||
function ToWords(Self: string; delims: string := ' '): array of string; extensionmethod;
|
||||
begin
|
||||
Result := Self.Split(delims.ToCharArray, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
end;
|
||||
|
||||
procedure PassSpaces(var s: string; var from: integer);
|
||||
begin
|
||||
while (from <= s.Length) and (s[from]=' ') do
|
||||
|
|
@ -12723,59 +12870,59 @@ function operator>=<T1,T2,T3,T4,T5,T6,T7>(Self: (T1, T2, T3, T4,T5,T6,T7); v: (T
|
|||
// -------------------------------------------
|
||||
// Дополнения февраль 2016
|
||||
|
||||
// Добавляет поле к кортежу
|
||||
/// Добавляет поле к кортежу
|
||||
function Add<T1, T2, T3>(Self: (T1, T2); v: T3): (T1, T2, T3); extensionmethod;
|
||||
begin
|
||||
Result := (Self[0], Self[1], v);
|
||||
end;
|
||||
|
||||
// Добавляет поле к кортежу
|
||||
/// Добавляет поле к кортежу
|
||||
function Add<T1, T2, T3, T4>(Self: (T1, T2, T3); v: T4): (T1, T2, T3, T4); extensionmethod;
|
||||
begin
|
||||
Result := (Self[0], Self[1], Self[2], v);
|
||||
end;
|
||||
|
||||
// Добавляет поле к кортежу
|
||||
/// Добавляет поле к кортежу
|
||||
function Add<T1, T2, T3, T4, T5>(Self: (T1, T2, T3, T4); v: T5): (T1, T2, T3, T4, T5); extensionmethod;
|
||||
begin
|
||||
Result := (Self[0], Self[1], Self[2], Self[3], v);
|
||||
end;
|
||||
|
||||
// Добавляет поле к кортежу
|
||||
/// Добавляет поле к кортежу
|
||||
function Add<T1, T2, T3, T4, T5, T6>(Self: (T1, T2, T3, T4, T5); v: T6): (T1, T2, T3, T4, T5, T6); extensionmethod;
|
||||
begin
|
||||
Result := (Self[0], Self[1], Self[2], Self[3], Self[4], v);
|
||||
end;
|
||||
|
||||
// Добавляет поле к кортежу
|
||||
/// Добавляет поле к кортежу
|
||||
function Add<T1, T2, T3, T4, T5, T6, T7>(Self: (T1, T2, T3, T4, T5, T6); v: T7): (T1, T2, T3, T4, T5, T6, T7); extensionmethod;
|
||||
begin
|
||||
Result := (Self[0], Self[1], Self[2], Self[3], Self[4], Self[5], v);
|
||||
end;
|
||||
|
||||
// Выводит кортеж
|
||||
/// Выводит кортеж
|
||||
procedure Print<T1, T2>(Self: (T1, T2)); extensionmethod := Print(Self);
|
||||
// Выводит кортеж
|
||||
/// Выводит кортеж
|
||||
procedure Print<T1, T2, T3>(Self: (T1, T2, T3)); extensionmethod := Print(Self);
|
||||
// Выводит кортеж
|
||||
/// Выводит кортеж
|
||||
procedure Print<T1, T2, T3, T4>(Self: (T1, T2, T3, T4)); extensionmethod := Print(Self);
|
||||
// Выводит кортеж
|
||||
/// Выводит кортеж
|
||||
procedure Print<T1, T2, T3, T4, T5>(Self: (T1, T2, T3, T4, T5)); extensionmethod := Print(Self);
|
||||
// Выводит кортеж
|
||||
/// Выводит кортеж
|
||||
procedure Print<T1, T2, T3, T4, T5, T6>(Self: (T1, T2, T3, T4, T5, T6)); extensionmethod := Print(Self);
|
||||
// Выводит кортеж
|
||||
/// Выводит кортеж
|
||||
procedure Print<T1, T2, T3, T4, T5, T6, T7>(Self: (T1, T2, T3, T4, T5, T6, T7)); extensionmethod := Print(Self);
|
||||
// Выводит кортеж и переходит на новую строку
|
||||
/// Выводит кортеж и переходит на новую строку
|
||||
procedure Println<T1, T2>(Self: (T1, T2)); extensionmethod := Println(Self);
|
||||
// Выводит кортеж и переходит на новую строку
|
||||
/// Выводит кортеж и переходит на новую строку
|
||||
procedure Println<T1, T2, T3>(Self: (T1, T2, T3)); extensionmethod := Println(Self);
|
||||
// Выводит кортеж и переходит на новую строку
|
||||
/// Выводит кортеж и переходит на новую строку
|
||||
procedure Println<T1, T2, T3, T4>(Self: (T1, T2, T3, T4)); extensionmethod := Println(Self);
|
||||
// Выводит кортеж и переходит на новую строку
|
||||
/// Выводит кортеж и переходит на новую строку
|
||||
procedure Println<T1, T2, T3, T4, T5>(Self: (T1, T2, T3, T4, T5)); extensionmethod := Println(Self);
|
||||
// Выводит кортеж и переходит на новую строку
|
||||
/// Выводит кортеж и переходит на новую строку
|
||||
procedure Println<T1, T2, T3, T4, T5, T6>(Self: (T1, T2, T3, T4, T5, T6)); extensionmethod := Println(Self);
|
||||
// Выводит кортеж и переходит на новую строку
|
||||
/// Выводит кортеж и переходит на новую строку
|
||||
procedure Println<T1, T2, T3, T4, T5, T6, T7>(Self: (T1, T2, T3, T4, T5, T6, T7)); extensionmethod := Println(Self);
|
||||
|
||||
|
||||
|
|
@ -13385,7 +13532,11 @@ end;
|
|||
|
||||
procedure __InitModule;
|
||||
begin
|
||||
DefaultEncoding := Encoding.GetEncoding(1251);
|
||||
try
|
||||
DefaultEncoding := Encoding.GetEncoding(1251);
|
||||
except
|
||||
DefaultEncoding := Encoding.UTF8;
|
||||
end;
|
||||
rnd := new System.Random;
|
||||
|
||||
CurrentIOSystem := new IOStandardSystem;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
procedure Test(a: integer);
|
||||
procedure Test(a: integer);
|
||||
begin
|
||||
|
||||
end;
|
||||
begin
|
||||
var p{@var p: procedure(a: integer);@} := Test+Test;
|
||||
|
||||
end.
|
||||
3
TestSuite/intellisense_tests/extensionmethods12.pas
Normal file
3
TestSuite/intellisense_tests/extensionmethods12.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
begin
|
||||
var a{@var a: sequence of integer;@} := ArrRandom(7, 10, 99).Reverse.Println();
|
||||
end.
|
||||
17
TestSuite/intellisense_tests/generics22.pas
Normal file
17
TestSuite/intellisense_tests/generics22.pas
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
type
|
||||
t0<T> = class
|
||||
|
||||
l: List<(T, byte)>;
|
||||
|
||||
end;
|
||||
|
||||
t1 = class(t0<word>)
|
||||
|
||||
public procedure p1;
|
||||
begin
|
||||
l{@var t0<>.l: List<Tuple<word, byte>>;@} := l;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
begin end.
|
||||
12
TestSuite/intellisense_tests/lambdas11.pas
Normal file
12
TestSuite/intellisense_tests/lambdas11.pas
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
procedure p1(p: procedure(pp: Action0)) := exit;
|
||||
|
||||
procedure p2(f: real->real) := exit;
|
||||
|
||||
begin
|
||||
p1(p->
|
||||
begin
|
||||
var a: real;
|
||||
p2(x->x*x{@parameter x: real;@});
|
||||
a{@var a: real;@} := 2;
|
||||
end);
|
||||
end.
|
||||
12
TestSuite/intellisense_tests/property6.pas
Normal file
12
TestSuite/intellisense_tests/property6.pas
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
uses System.Windows.Media.Animation;
|
||||
|
||||
{$reference PresentationFramework.dll}
|
||||
{$reference PresentationCore.dll}
|
||||
{$reference WindowsBase.dll}
|
||||
|
||||
{$apptype windows}
|
||||
|
||||
begin
|
||||
var ac: AnimationClock;
|
||||
ac.CurrentTime{@property Clock.CurrentTime: System.Nullable<TimeSpan>; readonly;@};
|
||||
end.
|
||||
26
TestSuite/lambdas_generics8.pas
Normal file
26
TestSuite/lambdas_generics8.pas
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
type
|
||||
t0 = abstract class
|
||||
end;
|
||||
|
||||
t2 = class(t0)
|
||||
end;
|
||||
|
||||
t1<T> = class
|
||||
where T: t0, constructor;
|
||||
public obj: T;
|
||||
procedure p1;
|
||||
begin
|
||||
var p: Action0 := ()->
|
||||
begin
|
||||
obj := new T;
|
||||
end;
|
||||
p();
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
var o := new t1<t2>;
|
||||
o.p1;
|
||||
assert((o.obj <> nil) and (o.obj.GetType = typeof(t2)));
|
||||
end.
|
||||
25
TestSuite/lambdas_generics9.pas
Normal file
25
TestSuite/lambdas_generics9.pas
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
type
|
||||
t0 = abstract class end;
|
||||
|
||||
t1<T> = class
|
||||
where T: t0, constructor;
|
||||
i: byte;
|
||||
function MakeT := new T;
|
||||
|
||||
function f1(x: byte): ()->T := ()->
|
||||
begin
|
||||
|
||||
i := x;
|
||||
|
||||
Result := MakeT;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
t2 = class(t0) end;
|
||||
|
||||
begin
|
||||
var a := new t1<t2>;
|
||||
var obj := a.f1(5)();
|
||||
assert(a.i = 5);
|
||||
end.
|
||||
24
TestSuite/records15.pas
Normal file
24
TestSuite/records15.pas
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
var i: integer;
|
||||
|
||||
type
|
||||
r1 = record
|
||||
public function InitI1:integer;
|
||||
begin
|
||||
Result := 1;
|
||||
Inc(i);
|
||||
end;
|
||||
|
||||
public i1: integer := InitI1;
|
||||
end;
|
||||
|
||||
procedure test;
|
||||
var a := new r1;
|
||||
begin
|
||||
|
||||
end;
|
||||
begin
|
||||
var a := new r1;
|
||||
assert(i = 1);
|
||||
test;
|
||||
assert(i = 2);
|
||||
end.
|
||||
24
TestSuite/records16.pas
Normal file
24
TestSuite/records16.pas
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
type
|
||||
t0=class
|
||||
static i := 0;
|
||||
|
||||
constructor :=
|
||||
i += 1;
|
||||
end;
|
||||
r1=record
|
||||
ni := t0.i;
|
||||
end;
|
||||
|
||||
t1=class(t0)
|
||||
|
||||
constructor;
|
||||
begin
|
||||
var a: r1;
|
||||
assert(a.ni = 1);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
new t1;
|
||||
end.
|
||||
27
TestSuite/records17.pas
Normal file
27
TestSuite/records17.pas
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
type
|
||||
r1 = record
|
||||
i := 1;
|
||||
static function f(a: r1): boolean;
|
||||
begin
|
||||
Result := a = a;
|
||||
end;
|
||||
static function f2(a: r1): boolean;
|
||||
begin
|
||||
Result := a <> a;
|
||||
end;
|
||||
|
||||
{static function operator=(a, b: r1): boolean;
|
||||
begin
|
||||
Result := a.i = b.i;
|
||||
end;
|
||||
|
||||
static function operator<>(a, b: r1): boolean;
|
||||
begin
|
||||
Result := a.i <> b.i;
|
||||
end;}
|
||||
end;
|
||||
|
||||
begin
|
||||
assert(r1.f(new r1));
|
||||
assert(not r1.f2(new r1));
|
||||
end.
|
||||
34
TestSuite/records18.pas
Normal file
34
TestSuite/records18.pas
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
var flag: boolean;
|
||||
|
||||
type
|
||||
r1 = record
|
||||
i := 1;
|
||||
static function f(a: r1): boolean;
|
||||
begin
|
||||
Result := a = a;
|
||||
end;
|
||||
static function f2(a: r1): boolean;
|
||||
begin
|
||||
Result := a <> a;
|
||||
end;
|
||||
|
||||
static function operator=(a, b: r1): boolean;
|
||||
begin
|
||||
flag := true;
|
||||
Result := a.i = b.i;
|
||||
end;
|
||||
|
||||
static function operator<>(a, b: r1): boolean;
|
||||
begin
|
||||
flag := true;
|
||||
Result := a.i <> b.i;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
assert(r1.f(new r1));
|
||||
assert(flag);
|
||||
flag := false;
|
||||
assert(not r1.f2(new r1));
|
||||
assert(flag);
|
||||
end.
|
||||
13
TestSuite/where13.pas
Normal file
13
TestSuite/where13.pas
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type
|
||||
|
||||
c1<T> = class where T: c1<T>;
|
||||
|
||||
end;
|
||||
|
||||
c2 = class(c1<c2>)
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
new c2;
|
||||
end.
|
||||
|
|
@ -1113,7 +1113,12 @@ namespace TreeConverter.LambdaExpressions.Closure
|
|||
|
||||
if (_visitor.context._ctn != null && _visitor.context._ctn.generic_params != null)
|
||||
{
|
||||
genericParameterEliminations.AddRange(generic_parameter_eliminations.make_eliminations_common(_visitor.context._ctn.generic_params));
|
||||
List<generic_parameter_eliminations> lst = generic_parameter_eliminations.make_eliminations_common(_visitor.context._ctn.generic_params);
|
||||
for (int i = 0; i < lst.Count; i++)
|
||||
if (!lst[i].has_default_ctor && _visitor.context._ctn.generic_params[i] is common_type_node)
|
||||
lst[i].has_default_ctor = (_visitor.context._ctn.generic_params[i] as common_type_node).has_default_constructor;
|
||||
genericParameterEliminations.AddRange(lst);
|
||||
|
||||
}
|
||||
|
||||
if (_visitor.context.top_function != null && _visitor.context.top_function.generic_params != null)
|
||||
|
|
|
|||
|
|
@ -1017,22 +1017,42 @@ namespace PascalABCCompiler.TreeConverter
|
|||
|
||||
private readonly System.Collections.Generic.Stack<common_type_node> type_stack = new System.Collections.Generic.Stack<common_type_node>();
|
||||
|
||||
private void add_notequal_operator_if_need()
|
||||
internal void add_notequal_operator_if_need(bool not_add_body= false)
|
||||
{
|
||||
List<SymbolInfo> si_list = _ctn.find_in_type(compiler_string_consts.noteq_name);
|
||||
common_method_node cmn = null;
|
||||
common_parameter prm1 = null;
|
||||
common_parameter prm2 = null;
|
||||
foreach (SymbolInfo si2 in si_list)
|
||||
if (si2.sym_info is common_method_node)
|
||||
return;
|
||||
{
|
||||
cmn = si2.sym_info as common_method_node;
|
||||
if (cmn.function_code != null)
|
||||
return;
|
||||
}
|
||||
SymbolInfo si = si_list[0];
|
||||
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope(_ctn.scope, _cmn.scope, null, si.ToString());
|
||||
common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.noteq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn,
|
||||
SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope);
|
||||
cmn.IsOperator = true;
|
||||
common_parameter prm1 = new common_parameter("a",_ctn,SemanticTree.parameter_type.value,cmn,concrete_parameter_type.cpt_none,null,null);
|
||||
common_parameter prm2 = new common_parameter("b",_ctn,SemanticTree.parameter_type.value,cmn,concrete_parameter_type.cpt_none,null,null);
|
||||
cmn.parameters.AddElement(prm1);
|
||||
cmn.parameters.AddElement(prm2);
|
||||
statements_list body = new statements_list(null);
|
||||
if (cmn == null)
|
||||
{
|
||||
cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.noteq_name), SystemLibrary.SystemLibrary.bool_type, null, _ctn,
|
||||
SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, scope);
|
||||
cmn.IsOperator = true;
|
||||
prm1 = new common_parameter("a", _ctn, SemanticTree.parameter_type.value, cmn, concrete_parameter_type.cpt_none, null, null);
|
||||
prm2 = new common_parameter("b", _ctn, SemanticTree.parameter_type.value, cmn, concrete_parameter_type.cpt_none, null, null);
|
||||
cmn.parameters.AddElement(prm1);
|
||||
cmn.parameters.AddElement(prm2);
|
||||
cmn.is_overload = true;
|
||||
_ctn.methods.AddElement(cmn);
|
||||
_ctn.Scope.AddSymbol(compiler_string_consts.noteq_name, new SymbolInfo(cmn));
|
||||
}
|
||||
else
|
||||
{
|
||||
prm1 = cmn.parameters[0] as common_parameter;
|
||||
prm2 = cmn.parameters[1] as common_parameter;
|
||||
}
|
||||
if (not_add_body)
|
||||
return;
|
||||
statements_list body = new statements_list(null);
|
||||
foreach (class_field cf in _ctn.fields)
|
||||
{
|
||||
if (cf.polymorphic_state == SemanticTree.polymorphic_state.ps_static)
|
||||
|
|
@ -1048,26 +1068,45 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
body.statements.AddElement(new return_node(new bool_const_node(false,null),null));
|
||||
cmn.function_code = body;
|
||||
cmn.is_overload = true;
|
||||
_ctn.methods.AddElement(cmn);
|
||||
_ctn.Scope.AddSymbol(compiler_string_consts.noteq_name,new SymbolInfo(cmn));
|
||||
|
||||
}
|
||||
|
||||
private void add_equal_operator_if_need()
|
||||
internal void add_equal_operator_if_need(bool not_add_body=false)
|
||||
{
|
||||
List<SymbolInfo> si_list = _ctn.find_in_type(compiler_string_consts.eq_name);
|
||||
common_method_node cmn = null;
|
||||
common_parameter prm1 = null;
|
||||
common_parameter prm2 = null;
|
||||
foreach (SymbolInfo si2 in si_list)
|
||||
if (si2.sym_info is common_method_node)
|
||||
return;
|
||||
{
|
||||
cmn = si2.sym_info as common_method_node;
|
||||
if (cmn.function_code != null)
|
||||
return;
|
||||
}
|
||||
|
||||
SymbolInfo si = si_list[0];
|
||||
SymbolTable.ClassMethodScope scope = convertion_data_and_alghoritms.symbol_table.CreateClassMethodScope( _ctn.scope, _cmn.scope, null, si.ToString());
|
||||
common_method_node cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.eq_name),SystemLibrary.SystemLibrary.bool_type,null,_ctn,
|
||||
SemanticTree.polymorphic_state.ps_static,SemanticTree.field_access_level.fal_public,scope);
|
||||
cmn.IsOperator = true;
|
||||
common_parameter prm1 = new common_parameter("a",_ctn,SemanticTree.parameter_type.value,cmn,concrete_parameter_type.cpt_none,null,null);
|
||||
common_parameter prm2 = new common_parameter("b",_ctn,SemanticTree.parameter_type.value,cmn,concrete_parameter_type.cpt_none,null,null);
|
||||
cmn.parameters.AddElement(prm1);
|
||||
cmn.parameters.AddElement(prm2);
|
||||
if (cmn == null)
|
||||
{
|
||||
cmn = new common_method_node(compiler_string_consts.GetNETOperName(compiler_string_consts.eq_name), SystemLibrary.SystemLibrary.bool_type, null, _ctn,
|
||||
SemanticTree.polymorphic_state.ps_static, SemanticTree.field_access_level.fal_public, scope);
|
||||
cmn.IsOperator = true;
|
||||
prm1 = new common_parameter("a", _ctn, SemanticTree.parameter_type.value, cmn, concrete_parameter_type.cpt_none, null, null);
|
||||
prm2 = new common_parameter("b", _ctn, SemanticTree.parameter_type.value, cmn, concrete_parameter_type.cpt_none, null, null);
|
||||
cmn.parameters.AddElement(prm1);
|
||||
cmn.parameters.AddElement(prm2);
|
||||
cmn.is_overload = true;
|
||||
_ctn.methods.AddElement(cmn);
|
||||
_ctn.Scope.AddSymbol(compiler_string_consts.eq_name, new SymbolInfo(cmn));
|
||||
}
|
||||
else
|
||||
{
|
||||
prm1 = cmn.parameters[0] as common_parameter;
|
||||
prm2 = cmn.parameters[1] as common_parameter;
|
||||
}
|
||||
if (not_add_body)
|
||||
return;
|
||||
statements_list body = new statements_list(null);
|
||||
foreach (class_field cf in _ctn.fields)
|
||||
{
|
||||
|
|
@ -1084,9 +1123,7 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
body.statements.AddElement(new return_node(new bool_const_node(true,null),null));
|
||||
cmn.function_code = body;
|
||||
cmn.is_overload = true;
|
||||
_ctn.methods.AddElement(cmn);
|
||||
_ctn.Scope.AddSymbol(compiler_string_consts.eq_name,new SymbolInfo(cmn));
|
||||
|
||||
}
|
||||
|
||||
public void leave_record()
|
||||
|
|
@ -1094,8 +1131,8 @@ namespace PascalABCCompiler.TreeConverter
|
|||
check_implement_interfaces();
|
||||
if (!_ctn.IsEnum)
|
||||
{
|
||||
add_equal_operator_if_need();
|
||||
add_notequal_operator_if_need();
|
||||
//add_equal_operator_if_need();
|
||||
//add_notequal_operator_if_need();
|
||||
}
|
||||
if (type_stack.Count != 0)
|
||||
{
|
||||
|
|
@ -2047,6 +2084,18 @@ namespace PascalABCCompiler.TreeConverter
|
|||
|
||||
internal expression_node GetInitalValueForVariable(var_definition_node vdn, expression_node userInitalValue)
|
||||
{
|
||||
if (userInitalValue == null && CurrentStatementList != null && vdn.type.is_value_type && vdn.type is common_type_node)
|
||||
{
|
||||
common_type_node ctn = vdn.type as common_type_node;
|
||||
foreach (var meth in ctn.methods)
|
||||
{
|
||||
if (meth.is_constructor && meth.parameters.Count == 0)
|
||||
{
|
||||
userInitalValue = new common_constructor_call(meth, vdn.location);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userInitalValue != null)
|
||||
{
|
||||
if (CurrentStatementList != null)
|
||||
|
|
@ -2055,31 +2104,35 @@ namespace PascalABCCompiler.TreeConverter
|
|||
location lid = ((local_block_variable)vdn).loc;
|
||||
local_block_variable_reference lbvr = new local_block_variable_reference((local_block_variable)vdn, lid);
|
||||
if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type)
|
||||
{
|
||||
userInitalValue = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn,userInitalValue);
|
||||
//userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node;
|
||||
}
|
||||
{
|
||||
userInitalValue = syntax_tree_visitor.get_init_call_for_set_as_constr(vdn, userInitalValue);
|
||||
//userInitalValue.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node;
|
||||
}
|
||||
else if (vdn.type.type_special_kind == SemanticTree.type_special_kind.short_string)
|
||||
{
|
||||
userInitalValue = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(userInitalValue, SystemLibrary.SystemLibrary.string_type), new int_const_node((vdn.type as short_string_type_node).Length, null));
|
||||
}
|
||||
else if (userInitalValue is array_initializer)
|
||||
{
|
||||
array_initializer arr = userInitalValue as array_initializer;
|
||||
if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string)
|
||||
{
|
||||
for (int i=0; i<arr.element_values.Count; i++)
|
||||
{
|
||||
//arr.element_values[i] = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, arr.element_values[i], null);
|
||||
arr.element_values[i] = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(arr.element_values[i],SystemLibrary.SystemLibrary.string_type),new int_const_node((vdn.type.element_type as short_string_type_node).Length,null));
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
array_initializer arr = userInitalValue as array_initializer;
|
||||
if (vdn.type.element_type.type_special_kind == SemanticTree.type_special_kind.short_string)
|
||||
{
|
||||
for (int i = 0; i < arr.element_values.Count; i++)
|
||||
{
|
||||
//arr.element_values[i] = syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, varref2, arr.element_values[i], null);
|
||||
arr.element_values[i] = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(arr.element_values[i], SystemLibrary.SystemLibrary.string_type), new int_const_node((vdn.type.element_type as short_string_type_node).Length, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
CurrentStatementList.statements.AddElement(syntax_tree_visitor.find_operator(compiler_string_consts.assign_name, lbvr, userInitalValue, lid));
|
||||
if (vdn.type.type_special_kind == SemanticTree.type_special_kind.set_type)
|
||||
{
|
||||
lbvr.type = SystemLibrary.SystemLibInitializer.TypedSetType.sym_info as type_node;
|
||||
}
|
||||
if (vdn.type.is_value_type && userInitalValue is common_constructor_call)
|
||||
{
|
||||
return new default_operator_node(vdn.type, lid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (userInitalValue is constant_node)
|
||||
|
|
|
|||
|
|
@ -2602,7 +2602,25 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
List<function_node> to_remove = new List<function_node>();
|
||||
foreach (function_node fn in funcs)
|
||||
{
|
||||
if (fn.is_generic_function_instance)
|
||||
foreach (parameter p in fn.original_function.parameters)
|
||||
{
|
||||
if (p.type.is_generic_parameter)
|
||||
{
|
||||
to_remove.Add(fn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (set_of_possible_functions.Count - to_remove.Count == 1)
|
||||
{
|
||||
foreach (function_node fn in to_remove)
|
||||
set_of_possible_functions.Remove(fn);
|
||||
return set_of_possible_functions[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3705,7 +3705,9 @@ namespace PascalABCCompiler.TreeConverter
|
|||
{
|
||||
if (context.converted_type.IsStatic)
|
||||
AddError(get_location(_class_definition), "STATIC_CLASS_CANNOT_HAVE_PARENT");
|
||||
context.skip_check_where_sections = true;
|
||||
type_node tn = ret.visit(_class_definition.class_parents.types[0]);
|
||||
context.skip_check_where_sections = false;
|
||||
//if (tn == context.converted_type)
|
||||
if (type_table.original_types_equals(tn, context.converted_type))
|
||||
AddError(new UndefinedNameReference(tn.name, get_location(_class_definition.class_parents.types[0])));
|
||||
|
|
@ -3737,6 +3739,8 @@ namespace PascalABCCompiler.TreeConverter
|
|||
//Добавляем интерфейс
|
||||
used_interfs.Add(tn, tn);
|
||||
type_table.AddInterface(context.converted_type, tn, get_location(_class_definition.class_parents.types[0]));
|
||||
if (tn.is_generic_type_instance)
|
||||
ret.visit(_class_definition.class_parents.types[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -3749,6 +3753,8 @@ namespace PascalABCCompiler.TreeConverter
|
|||
AddError(get_location(_class_definition.class_parents.types[0]), "CAN_NOT_INHERIT_FROM_GENERIC_PARAMETER");
|
||||
}
|
||||
context.converted_type.SetBaseType(tn);
|
||||
if (tn.is_generic_type_instance)
|
||||
ret.visit(_class_definition.class_parents.types[0]);
|
||||
var type_instances = generic_convertions.get_type_instances(context.converted_type);
|
||||
if (type_instances != null)
|
||||
foreach (generic_type_instance_info gti in type_instances)
|
||||
|
|
@ -3912,6 +3918,7 @@ namespace PascalABCCompiler.TreeConverter
|
|||
record_type_name = null;
|
||||
record_is_generic = false;
|
||||
context.converted_type.internal_is_value = true;
|
||||
|
||||
if (_class_definition.body == null &&
|
||||
(_class_definition.class_parents == null || _class_definition.class_parents.types.Count == 0))
|
||||
{
|
||||
|
|
@ -3924,6 +3931,7 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
context.converted_type.ForwardDeclarationOnly = false;
|
||||
weak_node_test_and_visit(_class_definition.body);
|
||||
|
||||
|
|
@ -4045,7 +4053,13 @@ namespace PascalABCCompiler.TreeConverter
|
|||
|
||||
private void visit_class_member_realizations(SyntaxTree.class_body_list _class_body)
|
||||
{
|
||||
foreach (SyntaxTree.class_members clmem in _class_body.class_def_blocks)
|
||||
if (context.converted_type.internal_is_value)
|
||||
{
|
||||
context.add_equal_operator_if_need();
|
||||
context.add_notequal_operator_if_need();
|
||||
}
|
||||
|
||||
foreach (SyntaxTree.class_members clmem in _class_body.class_def_blocks)
|
||||
{
|
||||
foreach (SyntaxTree.declaration sd in clmem.members)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3456,7 +3456,7 @@ namespace PascalABCCompiler.TreeRealization
|
|||
List<SymbolInfo> sil2 = find_in_additional_names(name);
|
||||
List<SymbolInfo> sil3 = compiled_find(name);
|
||||
bool clone = false;
|
||||
if (!no_search_in_extension_methods || this._compiled_type.IsGenericType)
|
||||
if (!no_search_in_extension_methods || this._compiled_type.IsGenericType || this.type_special_kind == SemanticTree.type_special_kind.array_kind)
|
||||
{
|
||||
|
||||
if (this.type_special_kind == SemanticTree.type_special_kind.array_kind && this.base_type.Scope != null)
|
||||
|
|
|
|||
|
|
@ -233,8 +233,8 @@ namespace VisualPascalABCPlugins
|
|||
{
|
||||
CodeCompletion.CodeCompletionTester.Test();
|
||||
|
||||
CodeCompletion.CodeCompletionTester.TestIntellisense(Path.Combine(@"c:\Work\Miks\_PABCNETGitHub\TestSuite", "intellisense_tests"));
|
||||
CodeCompletion.CodeCompletionTester.TestRename(@"c:\Work\Miks\_PABCNETGitHub\TestSuite\refactoring_tests\rename_tests");
|
||||
CodeCompletion.CodeCompletionTester.TestIntellisense(Path.Combine(@"c:\Work\Miks\_PABCNETGitHub\pascalabcnet\TestSuite", "intellisense_tests"));
|
||||
CodeCompletion.CodeCompletionTester.TestRename(@"c:\Work\Miks\_PABCNETGitHub\pascalabcnet\TestSuite\refactoring_tests\rename_tests");
|
||||
MessageBox.Show("Done");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue