exit(param)
This commit is contained in:
parent
c22dee65fa
commit
4c56298bfb
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
|||
public const string Major = "3";
|
||||
public const string Minor = "10";
|
||||
public const string Build = "3";
|
||||
public const string Revision = "3617";
|
||||
public const string Revision = "3619";
|
||||
|
||||
public const string MainVersion = Major + "." + Minor;
|
||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%MINOR%=10
|
||||
%REVISION%=3617
|
||||
%REVISION%=3619
|
||||
%COREVERSION%=3
|
||||
%MAJOR%=3
|
||||
|
|
|
|||
8
InstallerSamples/WhatsNew/3_10_4/exit_param1.pas
Normal file
8
InstallerSamples/WhatsNew/3_10_4/exit_param1.pas
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
function fff: integer;
|
||||
begin
|
||||
exit(3)
|
||||
end;
|
||||
|
||||
begin
|
||||
Print(fff());
|
||||
end.
|
||||
11
InstallerSamples/WhatsNew/3_10_4/exit_param2.pas
Normal file
11
InstallerSamples/WhatsNew/3_10_4/exit_param2.pas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function IsPrime(n: integer): boolean;
|
||||
begin
|
||||
for var i:=2 to n.Sqrt.Round do
|
||||
if n.Divs(i) then
|
||||
exit(False);
|
||||
exit(True);
|
||||
end;
|
||||
|
||||
begin
|
||||
IsPrime(17).Print;
|
||||
end.
|
||||
10
InstallerSamples/WhatsNew/3_10_4/exit_param3.pas
Normal file
10
InstallerSamples/WhatsNew/3_10_4/exit_param3.pas
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
begin
|
||||
var IsPrime: integer → boolean := n → begin
|
||||
for var i:=2 to n.Sqrt.Round do
|
||||
if n.Divs(i) then
|
||||
exit(False);
|
||||
exit(True);
|
||||
end;
|
||||
|
||||
IsPrime(17).Print;
|
||||
end.
|
||||
15
InstallerSamples/WhatsNew/3_10_4/exit_param4.pas
Normal file
15
InstallerSamples/WhatsNew/3_10_4/exit_param4.pas
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function FastPower(a: real; n: integer): real;
|
||||
begin
|
||||
if n = 0 then exit(1); // a^0 = 1
|
||||
if n = 1 then exit(a); // a^1 = a
|
||||
if n < 0 then exit(1 / FastPower(a, -n)); // отрицательная степень
|
||||
|
||||
var half := FastPower(a, n div 2);
|
||||
if n mod 2 = 0 then exit(half * half); // чётная степень
|
||||
exit(half * half * a); // нечётная
|
||||
end;
|
||||
|
||||
begin
|
||||
Writeln('2^10 = ', FastPower(2, 10)); // 1024
|
||||
Writeln('3^-2 = ', FastPower(3, -2)); // 0.111...
|
||||
end.
|
||||
|
|
@ -391,5 +391,6 @@ script=
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
3.10.3.3617
|
||||
3.10.3.3619
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
!define VERSION '3.10.3.3617'
|
||||
!define VERSION '3.10.3.3619'
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace Languages.Pascal.Frontend.Converters
|
|||
{
|
||||
root.FillParentsInAllChilds();
|
||||
|
||||
ExitParamVisitor.New.ProcessNode(root);
|
||||
|
||||
var binder = new BindCollectLightSymInfo(root as compilation_unit);
|
||||
#if DEBUG
|
||||
// var stat = new ABCStatisticsVisitor();
|
||||
|
|
|
|||
79
SyntaxVisitors/SugarVisitors/ExitParamVisitor.cs
Normal file
79
SyntaxVisitors/SugarVisitors/ExitParamVisitor.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using PascalABCCompiler.SyntaxTree;
|
||||
|
||||
namespace SyntaxVisitors.SugarVisitors
|
||||
{
|
||||
public class ExitParamVisitor : BaseChangeVisitor
|
||||
{
|
||||
public static ExitParamVisitor New
|
||||
{
|
||||
get { return new ExitParamVisitor(); }
|
||||
}
|
||||
|
||||
public override void visit(procedure_call pc)
|
||||
{
|
||||
var fname = pc.func_name as method_call;
|
||||
var id = fname?.dereferencing_value as ident;
|
||||
if (id != null && id.name.ToLower() == "exit")
|
||||
{
|
||||
if (fname.parameters == null || fname.parameters.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (fname.parameters.Count > 1)
|
||||
{
|
||||
throw new SyntaxVisitorError("EXIT_PROC_CAN_HAVE_ONLY_ONE_OR_ZERO_PARAMS", pc.source_context);
|
||||
}
|
||||
// Поднимаемся по Parent до procedure_definition или nil
|
||||
var parent = pc.Parent;
|
||||
while (parent != null && !(parent is procedure_definition)
|
||||
&& !(parent is function_lambda_definition))
|
||||
parent = parent.Parent;
|
||||
if (parent == null)
|
||||
{
|
||||
throw new SyntaxVisitorError("EXIT_WITH_PARAM_MUST_BE_ONLY_IN_FUNC", pc.source_context);
|
||||
}
|
||||
if (parent is procedure_definition pd && !(pd.proc_header is function_header))
|
||||
{
|
||||
throw new SyntaxVisitorError("EXIT_WITH_PARAM_MUST_BE_ONLY_IN_FUNC", pc.source_context);
|
||||
}
|
||||
if (parent is function_lambda_definition fld /*&& fld.return_type == null*/)
|
||||
{
|
||||
fld.usedkeyword = 1;
|
||||
fld.return_type = new lambda_inferred_type();
|
||||
//throw new SyntaxVisitorError("EXIT_WITH_PARAM_CANNOT_BE_IN_LAMBDA_PROCEDURE", pc.source_context);
|
||||
}
|
||||
|
||||
var arg = fname.parameters[0] as expression;
|
||||
// Теперь сформировать 2 узла как statement_list: Result := arg; exit
|
||||
|
||||
var sl = new List<statement>();
|
||||
var exitproc = new procedure_call(new ident("exit", pc.source_context));
|
||||
var ass_Res = new assign(new ident("Result", pc.source_context), arg,
|
||||
Operators.Assignment, pc.source_context);
|
||||
sl.Add(ass_Res);
|
||||
sl.Add(exitproc);
|
||||
|
||||
ReplaceStatementUsingParent(pc, sl);
|
||||
|
||||
}
|
||||
|
||||
//mc = new method_call(
|
||||
// new dot_node(indexCreation, new ident("Reverse", ind.source_context)),
|
||||
// reverseIndexMethodParams,
|
||||
// ind.source_context);
|
||||
|
||||
//ReplaceUsingParent(ind, mc);
|
||||
//visit(mc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_DEFAULT_PARAMETERS=Functions with yield can
|
|||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_RESULT=Functions with yield cannot contain Result variable
|
||||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_LOCK=Functions with yield cannot contain lock statement
|
||||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_TRY_EXCEPT_FINALLY=Functions with yield cannot contain try..except or try..finally statements
|
||||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_NESTED_SUBROUTINES=Functions with yield cannot contain nested subrotines or be nested
|
||||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_NESTED_SUBROUTINES=Functions with yield cannot contain nested subroutines or be nested
|
||||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_LOCAL_TYPE_DEFINITIONS=Functions with yield cannot contain local type definitions
|
||||
FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_INHERITED_CALLS=Functions with yield cannot contain calls of inherited methods
|
||||
FUNCTION_WITH_YIELD_CANNOT_CONTAIN_OLDSTYLE_ARRAY_INITIALIZERS=Functions with yield cannot contain Delphi-style array initializers
|
||||
|
|
@ -23,18 +23,18 @@ ONLY_ONE_DECONSTRUCT_ALLOWED=Only one user deconstructor is allowed
|
|||
|
||||
Var_{0}_is_already_defined=Variable {0} is already defined
|
||||
|
||||
?._CANNOT_BE_IN_THIS_CONTEXT=Operator ?. cannot be in this context
|
||||
?._CANNOT_BE_IN_THIS_CONTEXT=?. operator cannot be used in this context
|
||||
|
||||
INVALID_INTERFACE_MEMBER=Interfaces cannot contain fields and method implementation
|
||||
INDEXED_AUTO_PROPERTY=Autoproperties cannot be indexed properties
|
||||
|
||||
NESTED_RECORD_CANNOT_IMPLEMENT_INTERFACE=Nested records can not implement interfaces
|
||||
NESTED_RECORD_CANNOT_CONTAIN_METHODS=Nested records can not contain methods
|
||||
NESTED_RECORD_CANNOT_CONTAIN_PROPERTIES=Nested records can not contain properties
|
||||
NESTED_RECORD_CANNOT_CONTAIN_CONSTRUCTORS=Nested records can not contain constructors
|
||||
NESTED_RECORD_CANNOT_IMPLEMENT_INTERFACE=Nested records cannot implement interfaces
|
||||
NESTED_RECORD_CANNOT_CONTAIN_METHODS=Nested records cannot contain methods
|
||||
NESTED_RECORD_CANNOT_CONTAIN_PROPERTIES=Nested records cannot contain properties
|
||||
NESTED_RECORD_CANNOT_CONTAIN_CONSTRUCTORS=Nested records cannot contain constructors
|
||||
NESTED_RECORD_CAN_CONTAIN_ONLY_ONE_PUBLIC_VISIBILITY_SECTION=Nested records can contain only one section with public visibility
|
||||
NESTED_RECORD_CANNOT_CONTAIN_SEVERAL_VISIBILITY_SECTIONS=Nested records can not contain several visibility section
|
||||
UNNAMED_RECORD_CANNOT_CATCH_NAMES_FROM_NONGLOBAL_CONTEXT=Nested records cannot catch names from nonglobal context
|
||||
NESTED_RECORD_CANNOT_CONTAIN_SEVERAL_VISIBILITY_SECTIONS=Nested records cannot contain multiple visibility sections
|
||||
UNNAMED_RECORD_CANNOT_CATCH_NAMES_FROM_NONGLOBAL_CONTEXT=Nested records cannot catch names from non-global context
|
||||
TOO_MANY_ELEMENTS_ON_LEFT_SIDE_OF_TUPLE_ASSIGNMENT=Too many elements on the left side of tuple assignment
|
||||
NESTED_LAMBDAS_MAXIMUM_10=Maximum number of nested lambdas = 10
|
||||
EMBEDDED_STATEMENT_CANNOT_BE_A_DECLARATION=Embedded statement cannot be a declaration or labeled statement
|
||||
|
|
@ -42,11 +42,14 @@ EMBEDDED_STATEMENT_CANNOT_BE_A_DECLARATION=Embedded statement cannot be a declar
|
|||
ONLY_FUNCTION_SHOULD_HAVE_CACHE_ATTRIBUTE=Only functions must have [Cache] attribute
|
||||
EXTENSION_FUNCTIONS_SHOULD_NOT_HAVE_CACHE_ATTRIBUTE=Extension methods shouldn't have [Cache] attribute
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_HAVE_PARAMETERS=Functions with [Cache] attribute must have at least 1 parameter
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_HAVE_LESSTHEN8_PARAMETERS=Functions with [Cache] attribute must have less then 8 parameters
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_HAVE_EXPLICIT_RETURN_TYPE=Functions with [Cache] attribute must have explicitely specified return type
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_NOT_HAVE_COMPOUND_NAME=Functions with [Cache] should not have compound name
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_NOT_HAVE_VAR_CONST_PARAMS_MODIFIERS=Functions with [Cache] should not have var, const or params modifier
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_HAVE_LESSTHEN8_PARAMETERS=Functions with [Cache] attribute must have fewer than 8 parameters
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_HAVE_EXPLICIT_RETURN_TYPE=Functions with [Cache] attribute must have explicitly specified return type
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_NOT_HAVE_COMPOUND_NAME=Functions with [Cache] attribute should not have compound names
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_NOT_HAVE_VAR_CONST_PARAMS_MODIFIERS=Functions with [Cache] attribute should not have var, const or params modifiers
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_BE_DEFINED_GLOBALLY=Functions with [Cache] attribute must be defined globally
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_CANNOT_HAVE_YIELD=Functions with [Cache] attribute must not contain yield statements
|
||||
FOR_LOOP_WITH_STEP_CANNOT_USE_DOWNTO=For loop with step cannot use downto
|
||||
STEP_CANNOT_BE_0=Step cannot be 0
|
||||
STEP_CANNOT_BE_0=Step cannot be 0
|
||||
EXIT_PROC_CAN_HAVE_ONLY_ONE_OR_ZERO_PARAMS = exit(param) cannot have two or more arguments
|
||||
EXIT_WITH_PARAM_MUST_BE_ONLY_IN_FUNC=exit(param) is invalid in procedures
|
||||
EXIT_WITH_PARAM_CANNOT_BE_IN_LAMBDA_PROCEDURE=exit(param)' is invalid in lambda procedures
|
||||
|
|
@ -53,4 +53,7 @@ FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_NOT_HAVE_VAR_CONST_PARAMS_MODIFIERS=Фун
|
|||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_SHOULD_BE_DEFINED_GLOBALLY=Функции с атрибутом [Cache] должны быть определены глобально
|
||||
FUNCTIONS_WITH_CACHE_ATTRIBUTE_CANNOT_HAVE_YIELD=Функции с атрибутом [Cache] не должны содержать оператор yield
|
||||
FOR_LOOP_WITH_STEP_CANNOT_USE_DOWNTO=В цикле for с шагом нельзя использовать направление downto
|
||||
STEP_CANNOT_BE_0=Шаг в цикле for не может быть равным 0
|
||||
STEP_CANNOT_BE_0=Шаг в цикле for не может быть равным 0
|
||||
EXIT_PROC_CAN_HAVE_ONLY_ONE_OR_ZERO_PARAMS=exit не может иметь 2 и более параметров
|
||||
EXIT_WITH_PARAM_MUST_BE_ONLY_IN_FUNC=exit с параметром может вызываться только в функции
|
||||
EXIT_WITH_PARAM_CANNOT_BE_IN_LAMBDA_PROCEDURE=exit с параметром не может вызываться в лямбда-процедуре
|
||||
Binary file not shown.
Loading…
Reference in a new issue