diff --git a/Compiler/PCU/PCUReader.cs b/Compiler/PCU/PCUReader.cs index d179a2843..9ba8c801b 100644 --- a/Compiler/PCU/PCUReader.cs +++ b/Compiler/PCU/PCUReader.cs @@ -3470,7 +3470,12 @@ namespace PascalABCCompiler.PCU { return new compiled_static_method_call_as_constant(CreateCompiledStaticMethodCall(), null); } - + + private common_static_method_call_as_constant CreateCommonStaticMethodCallNodeAsConstant() + { + return new common_static_method_call_as_constant(CreateStaticMethodCall(), null); + } + private common_namespace_function_call_as_constant CreateCommonNamespaceFunctionCallNodeAsConstant() { common_namespace_function_call_as_constant cnfcc = new common_namespace_function_call_as_constant((common_namespace_function_call)CreateCommonNamespaceFunctionCall(), null); @@ -3510,6 +3515,8 @@ namespace PascalABCCompiler.PCU return CreateAsNode(); case semantic_node_type.compiled_static_method_call_node_as_constant: return CreateCompiledStaticMethodCallNodeAsConstant(); + case semantic_node_type.common_static_method_call_node_as_constant: + return CreateCommonStaticMethodCallNodeAsConstant(); case semantic_node_type.common_namespace_function_call_node_as_constant: return CreateCommonNamespaceFunctionCallNodeAsConstant(); case semantic_node_type.compiled_constructor_call_as_constant: @@ -3734,7 +3741,7 @@ namespace PascalABCCompiler.PCU return nspr; } - private expression_node CreateStaticMethodCall() + private common_static_method_call CreateStaticMethodCall() { common_method_node meth = GetMethodByOffset(); common_static_method_call cmc = new common_static_method_call(meth,null); diff --git a/Compiler/PCU/PCUWriter.cs b/Compiler/PCU/PCUWriter.cs index e406d42af..9fbc9bba5 100644 --- a/Compiler/PCU/PCUWriter.cs +++ b/Compiler/PCU/PCUWriter.cs @@ -3717,7 +3717,12 @@ namespace PascalABCCompiler.PCU { VisitCompiledStaticMethodCall(node.method_call); } - + + private void VisitCommonStaticMethodCallNodeAsConstant(common_static_method_call_as_constant node) + { + VisitCommonStaticMethodCall(node.method_call); + } + private void VisitCompiledConstructorCallAsConstant(compiled_constructor_call_as_constant node) { VisitCompiledConstructorCall(node.method_call); @@ -3752,6 +3757,8 @@ namespace PascalABCCompiler.PCU VisitAsNode((as_node)en); break; case semantic_node_type.compiled_static_method_call_node_as_constant: VisitCompiledStaticMethodCallNodeAsConstant((compiled_static_method_call_as_constant)en); break; + case semantic_node_type.common_static_method_call_node_as_constant: + VisitCommonStaticMethodCallNodeAsConstant((common_static_method_call_as_constant)en); break; case semantic_node_type.common_namespace_function_call_node_as_constant: VisitCommonNamespaceFunctionCallNodeAsConstant((common_namespace_function_call_as_constant)en); break; case semantic_node_type.compiled_constructor_call_as_constant: diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 8fcf8c784..e89d2c333 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -11394,6 +11394,12 @@ namespace PascalABCCompiler.NETGenerator { value.MethodCall.visit(this); } + + public override void visit(ICommonStaticMethodCallNodeAsConstant value) + { + value.MethodCall.visit(this); + } + public override void visit(ICompiledConstructorCallAsConstant value) { value.MethodCall.visit(this); diff --git a/SemanticTree/AbstractVisitor.cs b/SemanticTree/AbstractVisitor.cs index 77c86c8b2..99d0aa76b 100644 --- a/SemanticTree/AbstractVisitor.cs +++ b/SemanticTree/AbstractVisitor.cs @@ -655,6 +655,11 @@ namespace PascalABCCompiler.SemanticTree public virtual void visit(ITypeOfOperatorAsConstant value) { + } + + public virtual void visit(ICommonStaticMethodCallNodeAsConstant value) + { + } } diff --git a/SemanticTree/IVisitor.cs b/SemanticTree/IVisitor.cs index c5e631224..c0d8a61de 100644 --- a/SemanticTree/IVisitor.cs +++ b/SemanticTree/IVisitor.cs @@ -303,6 +303,8 @@ namespace PascalABCCompiler.SemanticTree void visit(IDoubleQuestionColonExpressionNode value); void visit(ITypeOfOperatorAsConstant value); + + void visit(ICommonStaticMethodCallNodeAsConstant value); } } diff --git a/SemanticTree/SemanticTree.cs b/SemanticTree/SemanticTree.cs index 0979f92ee..9054b9db3 100644 --- a/SemanticTree/SemanticTree.cs +++ b/SemanticTree/SemanticTree.cs @@ -1831,7 +1831,15 @@ namespace PascalABCCompiler.SemanticTree } } - public interface ICompiledStaticMethodCallNodeAsConstant : IConstantNode + public interface ICommonStaticMethodCallNodeAsConstant : IConstantNode + { + ICommonStaticMethodCallNode MethodCall + { + get; + } + } + + public interface ICompiledStaticMethodCallNodeAsConstant : IConstantNode { ICompiledStaticMethodCallNode MethodCall { diff --git a/TestSuite/defaultparams4.pas b/TestSuite/defaultparams4.pas new file mode 100644 index 000000000..6f1167052 --- /dev/null +++ b/TestSuite/defaultparams4.pas @@ -0,0 +1,20 @@ +type TClass = class + static p: integer = 2; + static function getp: integer := p; + static property x: integer read p; + static property y: integer read getp; +end; + +function f(i: integer := TClass.x): integer; +begin + Result := i; +end; + +function f2(i: integer := TClass.y): integer; +begin + Result := i; +end; +begin + assert(f = 2); + assert(f2 = 2); +end. \ No newline at end of file diff --git a/TestSuite/units/u_defaultparams4.pas b/TestSuite/units/u_defaultparams4.pas new file mode 100644 index 000000000..5b893af47 --- /dev/null +++ b/TestSuite/units/u_defaultparams4.pas @@ -0,0 +1,22 @@ +unit u_defaultparams4; + +type TClass = class + static p: integer = 2; + static function getp: integer := p; + static property x: integer read p; + static property y: integer read getp; +end; + +function f(i: integer := TClass.x): integer; +begin + Result := i; +end; + +function f2(i: integer := TClass.y): integer; +begin + Result := i; +end; +begin + assert(f = 2); + assert(f2 = 2); +end. \ No newline at end of file diff --git a/TestSuite/usesunits/use_defaultparams4.pas b/TestSuite/usesunits/use_defaultparams4.pas new file mode 100644 index 000000000..179fc5465 --- /dev/null +++ b/TestSuite/usesunits/use_defaultparams4.pas @@ -0,0 +1,5 @@ +uses u_defaultparams4; +begin + assert(f = 2); + assert(f2 = 2); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index c3f249cb2..0a58db234 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -15266,6 +15266,18 @@ namespace PascalABCCompiler.TreeConverter constant = new default_operator_node_as_constant(expr as default_operator_node, null); else if (expr is typeof_operator && !is_const_section) constant = new typeof_operator_as_constant(expr as typeof_operator, null); + else if (expr is common_static_method_call) + { + var csmc = expr as common_static_method_call; + var properties = new List(); + foreach (common_property_node cpn in csmc.function_node.cont_type.properties) + if (cpn.get_function == csmc.function_node && cpn.set_function == null) + { + constant = new common_static_method_call_as_constant(csmc, null); + break; + } + + } else { constant = expr as constant_node; @@ -15405,6 +15417,9 @@ namespace PascalABCCompiler.TreeConverter case semantic_node_type.compiled_static_method_call: constant = new compiled_static_method_call_as_constant(exprc as compiled_static_method_call, loc); break; + case semantic_node_type.common_static_method_call: + constant = new common_static_method_call_as_constant(exprc as common_static_method_call, loc); + break; case semantic_node_type.basic_function_call: constant = new basic_function_call_as_constant(exprc as basic_function_call, loc); break; diff --git a/TreeConverter/TreeRealization/base_nodes.cs b/TreeConverter/TreeRealization/base_nodes.cs index 92645b927..717ba5f98 100644 --- a/TreeConverter/TreeRealization/base_nodes.cs +++ b/TreeConverter/TreeRealization/base_nodes.cs @@ -39,7 +39,7 @@ namespace PascalABCCompiler.TreeRealization pinvoke_node, basic_function_call_node_as_constant, compiled_static_field_reference_as_constant, common_namespace_event, indefinite_definition_node, indefinite_type, indefinite_function_call, indefinite_reference, wrapped_statement, wrapped_expression, default_operator_node_as_constant, double_question_colon_expression, - typeof_operator_as_constant + typeof_operator_as_constant, common_static_method_call_node_as_constant }; /// diff --git a/TreeConverter/TreeRealization/constants.cs b/TreeConverter/TreeRealization/constants.cs index c278397a0..d1da442c9 100644 --- a/TreeConverter/TreeRealization/constants.cs +++ b/TreeConverter/TreeRealization/constants.cs @@ -1019,6 +1019,62 @@ namespace PascalABCCompiler.TreeRealization } } + public class common_static_method_call_as_constant : constant_node, SemanticTree.ICommonStaticMethodCallNodeAsConstant + { + private common_static_method_call _method_call; + + public common_static_method_call method_call + { + get + { + return _method_call; + } + set + { + _method_call = value; + } + } + + public common_static_method_call_as_constant(common_static_method_call method_call, location loc) : + base(method_call.type, loc) + { + _method_call = method_call; + } + + SemanticTree.ICommonStaticMethodCallNode SemanticTree.ICommonStaticMethodCallNodeAsConstant.MethodCall + { + get + { + return _method_call; + } + } + + public override constant_node get_constant_copy(location loc) + { + return new common_static_method_call_as_constant(this.method_call, loc); + } + + /// + /// Метод для обхода дерева посетителем. + /// + /// Класс - посетитель дерева. + public override void visit(SemanticTree.ISemanticVisitor visitor) + { + visitor.visit(this); + } + + /// + /// Тип узла. + /// + public override semantic_node_type semantic_node_type + { + get + { + return semantic_node_type.common_static_method_call_node_as_constant; + } + } + } + public class common_namespace_function_call_as_constant : constant_node, SemanticTree.ICommonNamespaceFunctionCallNodeAsConstant { private common_namespace_function_call _method_call; diff --git a/VisualPlugins/LanguageConverter/Source/Visitor.cs b/VisualPlugins/LanguageConverter/Source/Visitor.cs index dafdeadeb..47b8de3f8 100644 --- a/VisualPlugins/LanguageConverter/Source/Visitor.cs +++ b/VisualPlugins/LanguageConverter/Source/Visitor.cs @@ -1564,5 +1564,10 @@ namespace VisualPascalABCPlugins { throw new System.NotImplementedException(); } + + public void visit(ICommonStaticMethodCallNodeAsConstant value) + { + throw new System.NotImplementedException(); + } } }