diff --git a/Compiler/PCU/PCUReader.cs b/Compiler/PCU/PCUReader.cs index cd2dffea4..787bc550e 100644 --- a/Compiler/PCU/PCUReader.cs +++ b/Compiler/PCU/PCUReader.cs @@ -3498,6 +3498,11 @@ namespace PascalABCCompiler.PCU return new default_operator_node_as_constant(CreateDefaultOperator(), null); } + private sizeof_operator_as_constant CreateSizeOfOperatorAsConstant() + { + return new sizeof_operator_as_constant(CreateSizeOfOperator(), null); + } + private expression_node CreateExpression(semantic_node_type snt) { //location loc = ReadDebugInfo(); @@ -3528,6 +3533,8 @@ namespace PascalABCCompiler.PCU return CreateCompiledConstructorCallAsConstant(); case semantic_node_type.default_operator_node_as_constant: return CreateDefaultOperatorAsConstant(); + case semantic_node_type.sizeof_operator_as_constant: + return CreateSizeOfOperatorAsConstant(); case semantic_node_type.array_const: return CreateArrayConst(); case semantic_node_type.record_const: diff --git a/Compiler/PCU/PCUWriter.cs b/Compiler/PCU/PCUWriter.cs index 9fbc9bba5..61aafa897 100644 --- a/Compiler/PCU/PCUWriter.cs +++ b/Compiler/PCU/PCUWriter.cs @@ -3728,6 +3728,11 @@ namespace PascalABCCompiler.PCU VisitCompiledConstructorCall(node.method_call); } + private void VisitSizeOfOperatorAsConstant(sizeof_operator_as_constant node) + { + VisitSizeOfOperator(node.sizeof_operator); + } + private void VisitCommonNamespaceFunctionCallNodeAsConstant(common_namespace_function_call_as_constant node) { VisitCommonNamespaceFunctionCall(node.method_call); @@ -3762,7 +3767,9 @@ namespace PascalABCCompiler.PCU 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: - VisitCompiledConstructorCallAsConstant((compiled_constructor_call_as_constant)en); break; + VisitCompiledConstructorCallAsConstant((compiled_constructor_call_as_constant)en); break; + case semantic_node_type.sizeof_operator_as_constant: + VisitSizeOfOperatorAsConstant((sizeof_operator_as_constant)en); break; case semantic_node_type.array_const: VisitArrayConst((array_const)en); break; case semantic_node_type.record_const: diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 7b988b0bc..857519918 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -11753,6 +11753,11 @@ namespace PascalABCCompiler.NETGenerator value.DefaultOperator.visit(this); } + public override void visit(ISizeOfOperatorAsConstant value) + { + value.SizeOfOperator.visit(this); + } + public override void visit(ITypeOfOperatorAsConstant value) { value.TypeOfOperator.visit(this); diff --git a/SemanticTree/AbstractVisitor.cs b/SemanticTree/AbstractVisitor.cs index 99d0aa76b..59ac764c8 100644 --- a/SemanticTree/AbstractVisitor.cs +++ b/SemanticTree/AbstractVisitor.cs @@ -661,6 +661,12 @@ namespace PascalABCCompiler.SemanticTree { } - } + + public virtual void visit(ISizeOfOperatorAsConstant value) + { + + } + + } } diff --git a/SemanticTree/IVisitor.cs b/SemanticTree/IVisitor.cs index c0d8a61de..fab340e8d 100644 --- a/SemanticTree/IVisitor.cs +++ b/SemanticTree/IVisitor.cs @@ -102,25 +102,25 @@ namespace PascalABCCompiler.SemanticTree void visit(IBoolConstantNode value); - void visit(IByteConstantNode value); + void visit(IByteConstantNode value); - void visit(IIntConstantNode value); + void visit(IIntConstantNode value); - void visit(ISByteConstantNode value); + void visit(ISByteConstantNode value); - void visit(IShortConstantNode value); + void visit(IShortConstantNode value); - void visit(IUShortConstantNode value); + void visit(IUShortConstantNode value); - void visit(IUIntConstantNode value); + void visit(IUIntConstantNode value); - void visit(IULongConstantNode value); + void visit(IULongConstantNode value); - void visit(ILongConstantNode value); + void visit(ILongConstantNode value); void visit(IDoubleConstantNode value); - void visit(IFloatConstantNode value); + void visit(IFloatConstantNode value); void visit(ICharConstantNode value); @@ -148,13 +148,13 @@ namespace PascalABCCompiler.SemanticTree void visit(IConstantDefinitionNode value); - void visit(IClassConstantDefinitionNode value); + void visit(IClassConstantDefinitionNode value); - void visit(ICompiledClassConstantDefinitionNode value); + void visit(ICompiledClassConstantDefinitionNode value); - void visit(INamespaceConstantDefinitionNode value); + void visit(INamespaceConstantDefinitionNode value); - void visit(ICommonFunctionConstantDefinitionNode value); + void visit(ICommonFunctionConstantDefinitionNode value); void visit(IPropertyNode value); @@ -189,122 +189,123 @@ namespace PascalABCCompiler.SemanticTree void visit(ISimpleArrayNode value); void visit(ISimpleArrayIndexingNode value); - + void visit(IExternalStatementNode value); - + void visit(IRefTypeNode value); - + void visit(IGetAddrNode value); - + void visit(IDereferenceNode value); - void visit(IThrowNode value); + void visit(IThrowNode value); - void visit(ISwitchNode value); + void visit(ISwitchNode value); - void visit(ICaseVariantNode value); + void visit(ICaseVariantNode value); - void visit(ICaseRangeNode value); + void visit(ICaseRangeNode value); - void visit(INullConstantNode value); + void visit(INullConstantNode value); - void visit(IUnsizedArray value); + void visit(IUnsizedArray value); - void visit(IRuntimeManagedMethodBody value); + void visit(IRuntimeManagedMethodBody value); - void visit(IAsNode value); + void visit(IAsNode value); - void visit(IIsNode value); + void visit(IIsNode value); - void visit(ISizeOfOperator value); + void visit(ISizeOfOperator value); - void visit(ITypeOfOperator value); + void visit(ITypeOfOperator value); - void visit(IExitProcedure value); + void visit(IExitProcedure value); - void visit(ITryBlockNode value); + void visit(ITryBlockNode value); - void visit(IExceptionFilterBlockNode value); + void visit(IExceptionFilterBlockNode value); - void visit(IArrayConstantNode value); + void visit(IArrayConstantNode value); - void visit(IStatementsExpressionNode value); + void visit(IStatementsExpressionNode value); - void visit(IQuestionColonExpressionNode value); - - void visit(IRecordConstantNode value); + void visit(IQuestionColonExpressionNode value); - void visit(ILabelNode value); + void visit(IRecordConstantNode value); - void visit(ILabeledStatementNode value); + void visit(ILabelNode value); - void visit(IGotoStatementNode value); + void visit(ILabeledStatementNode value); - void visit(ICompiledStaticMethodCallNodeAsConstant value); + void visit(IGotoStatementNode value); - void visit(ICompiledConstructorCallAsConstant value); + void visit(ICompiledStaticMethodCallNodeAsConstant value); - void visit(ICommonNamespaceFunctionCallNodeAsConstant value); - - void visit(IEnumConstNode value); + void visit(ICompiledConstructorCallAsConstant value); - void visit(IForeachNode value); + void visit(ICommonNamespaceFunctionCallNodeAsConstant value); - void visit(ILockStatement value); + void visit(IEnumConstNode value); - void visit(ILocalBlockVariableNode value); - - void visit(ILocalBlockVariableReferenceNode value); - - void visit(IRethrowStatement value); - - void visit(IForeachBreakNode value); - - void visit(IForeachContinueNode value); - - void visit(INamespaceConstantReference value); - - void visit(IFunctionConstantReference value); - - void visit(ICommonConstructorCallAsConstant value); - - void visit(IArrayInitializer value); - - void visit(ICommonEventNode value); - - void visit(IEventNode value); - - void visit(ICompiledEventNode value); - - void visit(IStaticEventReference value); - - void visit(INonStaticEventReference value); - - void visit(IRecordInitializer value); + void visit(IForeachNode value); - void visit(IDefaultOperatorNode value); - - void visit(IAttributeNode value); - - void visit(IPInvokeStatementNode value); - - void visit(IBasicFunctionCallNodeAsConstant value); + void visit(ILockStatement value); - void visit(ICompiledStaticFieldReferenceNodeAsConstant value); + void visit(ILocalBlockVariableNode value); - void visit(ILambdaFunctionNode value); + void visit(ILocalBlockVariableReferenceNode value); - void visit(ILambdaFunctionCallNode value); + void visit(IRethrowStatement value); - void visit(ICommonNamespaceEventNode value); + void visit(IForeachBreakNode value); - void visit(IDefaultOperatorNodeAsConstant value); + void visit(IForeachContinueNode value); + + void visit(INamespaceConstantReference value); + + void visit(IFunctionConstantReference value); + + void visit(ICommonConstructorCallAsConstant value); + + void visit(IArrayInitializer value); + + void visit(ICommonEventNode value); + + void visit(IEventNode value); + + void visit(ICompiledEventNode value); + + void visit(IStaticEventReference value); + + void visit(INonStaticEventReference value); + + void visit(IRecordInitializer value); + + void visit(IDefaultOperatorNode value); + + void visit(IAttributeNode value); + + void visit(IPInvokeStatementNode value); + + void visit(IBasicFunctionCallNodeAsConstant value); + + void visit(ICompiledStaticFieldReferenceNodeAsConstant value); + + void visit(ILambdaFunctionNode value); + + void visit(ILambdaFunctionCallNode value); + + void visit(ICommonNamespaceEventNode value); + + void visit(IDefaultOperatorNodeAsConstant value); void visit(IDoubleQuestionColonExpressionNode value); void visit(ITypeOfOperatorAsConstant value); void visit(ICommonStaticMethodCallNodeAsConstant value); - } + void visit(ISizeOfOperatorAsConstant value); + } } diff --git a/SemanticTree/SemanticTree.cs b/SemanticTree/SemanticTree.cs index ea9f20024..29dcd0b91 100644 --- a/SemanticTree/SemanticTree.cs +++ b/SemanticTree/SemanticTree.cs @@ -1897,6 +1897,14 @@ namespace PascalABCCompiler.SemanticTree } } + public interface ISizeOfOperatorAsConstant : IConstantNode + { + ISizeOfOperator SizeOfOperator + { + get; + } + } + public interface ICompiledConstructorCallAsConstant : IConstantNode { ICompiledConstructorCall MethodCall diff --git a/TestSuite/sizeof2.pas b/TestSuite/sizeof2.pas new file mode 100644 index 000000000..e422a1cfb --- /dev/null +++ b/TestSuite/sizeof2.pas @@ -0,0 +1,26 @@ +type TRec = record +a: integer; +b: real; +c: char; +end; + +type + t1 = class + o: t1; + end; + +const + isize = sizeof(integer); + rsize = sizeof(real); + csize = sizeof(char); + psize = sizeof(pointer); + recsize = sizeof(TRec); + classsize = sizeof(t1); +begin + assert(isize=4); + assert(rsize=8); + assert(csize=2); + assert(psize=System.Runtime.InteropServices.Marshal.SizeOf(typeof(pointer))); + assert(recsize=System.Runtime.InteropServices.Marshal.SizeOf(typeof(TRec))); + assert(classsize > 0); +end. \ No newline at end of file diff --git a/TestSuite/units/u_sizeof2.pas b/TestSuite/units/u_sizeof2.pas new file mode 100644 index 000000000..79297c30e --- /dev/null +++ b/TestSuite/units/u_sizeof2.pas @@ -0,0 +1,27 @@ +unit u_sizeof2; +type TRec = record +a: integer; +b: real; +c: char; +end; + +type + t1 = class + o: t1; + end; + +const + isize = sizeof(integer); + rsize = sizeof(real); + csize = sizeof(char); + psize = sizeof(pointer); + recsize = sizeof(TRec); + classsize = sizeof(t1); +begin + assert(isize=4); + assert(rsize=8); + assert(csize=2); + assert(psize=System.Runtime.InteropServices.Marshal.SizeOf(typeof(pointer))); + assert(recsize=System.Runtime.InteropServices.Marshal.SizeOf(typeof(TRec))); + assert(classsize > 0); +end. \ No newline at end of file diff --git a/TestSuite/usesunits/use_sizeof2.pas b/TestSuite/usesunits/use_sizeof2.pas new file mode 100644 index 000000000..c0aa95df7 --- /dev/null +++ b/TestSuite/usesunits/use_sizeof2.pas @@ -0,0 +1 @@ +uses u_sizeof2; begin end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 044260d17..062073acc 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -15107,9 +15107,9 @@ namespace PascalABCCompiler.TreeConverter { AddError(loc, "CONSTANT_EXPRESSION_EXPECTED"); } - else if (expr is common_namespace_function_call) + else if (expr is common_namespace_function_call) { - common_namespace_function_call cnfc=expr as common_namespace_function_call; + common_namespace_function_call cnfc = expr as common_namespace_function_call; foreach (expression_node el in cnfc.parameters) convert_strong_to_constant_node(el, el.type, false, false, cnfc.location); //if (cnfc.function_node.namespace_node == context.converted_namespace) @@ -15119,7 +15119,7 @@ namespace PascalABCCompiler.TreeConverter } else if (expr is basic_function_call) { - basic_function_call cnfc=expr as basic_function_call; + basic_function_call cnfc = expr as basic_function_call; //if (cnfc.function_node.namespace_node == context.converted_namespace) // throw new ConstantExpressionExpected(loc); foreach (expression_node el in cnfc.parameters) @@ -15128,69 +15128,69 @@ namespace PascalABCCompiler.TreeConverter } else if (expr is typed_expression) { - expr = convertion_data_and_alghoritms.convert_type(expr, tn); - if (expr is common_constructor_call) - { - constant = new common_constructor_call_as_constant(expr as common_constructor_call, null); - } - else - if (expr is typed_expression) - { - if (const_def_type != null) - { - expr = convertion_data_and_alghoritms.convert_type(expr, const_def_type); - tn = const_def_type; - constant = new common_constructor_call_as_constant(expr as common_constructor_call, null); - } - else - { - base_function_call bfc = ((expr as typed_expression).type as delegated_methods).proper_methods[0]; - common_type_node del = - convertion_data_and_alghoritms.type_constructor.create_delegate(context.get_delegate_type_name(), bfc.simple_function_node.return_value_type, bfc.simple_function_node.parameters, context.converted_namespace, null); - context.converted_namespace.types.AddElement(del); - tn = del; - expr = convertion_data_and_alghoritms.explicit_convert_type(expr, del); - expr.type = tn; - constant = new common_constructor_call_as_constant(expr as common_constructor_call, loc); - } - } + expr = convertion_data_and_alghoritms.convert_type(expr, tn); + if (expr is common_constructor_call) + { + constant = new common_constructor_call_as_constant(expr as common_constructor_call, null); + } + else + if (expr is typed_expression) + { + if (const_def_type != null) + { + expr = convertion_data_and_alghoritms.convert_type(expr, const_def_type); + tn = const_def_type; + constant = new common_constructor_call_as_constant(expr as common_constructor_call, null); + } + else + { + base_function_call bfc = ((expr as typed_expression).type as delegated_methods).proper_methods[0]; + common_type_node del = + convertion_data_and_alghoritms.type_constructor.create_delegate(context.get_delegate_type_name(), bfc.simple_function_node.return_value_type, bfc.simple_function_node.parameters, context.converted_namespace, null); + context.converted_namespace.types.AddElement(del); + tn = del; + expr = convertion_data_and_alghoritms.explicit_convert_type(expr, del); + expr.type = tn; + constant = new common_constructor_call_as_constant(expr as common_constructor_call, loc); + } + } } - + else if (expr is namespace_constant_reference) { - constant = (expr as namespace_constant_reference).constant.const_value; - convertion_data_and_alghoritms.check_convert_type(constant,tn,expr.location); - if ((tn.type_special_kind == SemanticTree.type_special_kind.set_type || tn.type_special_kind == SemanticTree.type_special_kind.base_set_type) && tn.element_type != null) + constant = (expr as namespace_constant_reference).constant.const_value; + convertion_data_and_alghoritms.check_convert_type(constant, tn, expr.location); + if ((tn.type_special_kind == SemanticTree.type_special_kind.set_type || tn.type_special_kind == SemanticTree.type_special_kind.base_set_type) && tn.element_type != null) { ordinal_type_interface oti = tn.element_type.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; if (oti != null) { - common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as common_namespace_function_node,null); - cmc.parameters.AddElement(expr); - cmc.parameters.AddElement(oti.lower_value.get_constant_copy(null)); - cmc.parameters.AddElement(oti.upper_value.get_constant_copy(null)); - cmc.ret_type = tn; - constant = new common_namespace_function_call_as_constant(cmc,null); + common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as common_namespace_function_node, null); + cmc.parameters.AddElement(expr); + cmc.parameters.AddElement(oti.lower_value.get_constant_copy(null)); + cmc.parameters.AddElement(oti.upper_value.get_constant_copy(null)); + cmc.ret_type = tn; + constant = new common_namespace_function_call_as_constant(cmc, null); } else if (tn.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { - common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as common_namespace_function_node,null); - cmc.parameters.AddElement(expr); - cmc.parameters.AddElement(new int_const_node((tn.element_type as short_string_type_node).Length,null)); - cmc.ret_type = tn; - constant = new common_namespace_function_call_as_constant(cmc,null); + common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as common_namespace_function_node, null); + cmc.parameters.AddElement(expr); + cmc.parameters.AddElement(new int_const_node((tn.element_type as short_string_type_node).Length, null)); + cmc.ret_type = tn; + constant = new common_namespace_function_call_as_constant(cmc, null); } - } - else - if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) - { - /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); + } + else + if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) + { + /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); cmc.parameters.AddElement(expr); cmc.parameters.AddElement(new int_const_node((tn as short_string_type_node).Length,null));*/ - expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(expr,SystemLibrary.SystemLibrary.string_type),new int_const_node((tn as short_string_type_node).Length,null)); - constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call,null); - } - /*expression_node e = convertion_data_and_alghoritms.convert_type(constant.get_constant_copy(expr.location), tn); + expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(expr, SystemLibrary.SystemLibrary.string_type), new int_const_node((tn as short_string_type_node).Length, null)); + constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call, null); + } + /*expression_node e = convertion_data_and_alghoritms.convert_type(constant.get_constant_copy(expr.location), tn); switch (e.semantic_node_type) { case semantic_node_type.compiled_constructor_call: @@ -15200,7 +15200,7 @@ namespace PascalABCCompiler.TreeConverter constant = e as constant_node; break; }*/ - /*if (constant.get_object_value() != null) + /*if (constant.get_object_value() != null) { //if (const_def_type != null) { @@ -15232,43 +15232,43 @@ namespace PascalABCCompiler.TreeConverter } } }*/ - return constant; + return constant; } else if (expr is function_constant_reference) { - constant = (expr as function_constant_reference).constant.const_value; - convertion_data_and_alghoritms.check_convert_type(constant,tn,expr.location); - if ((tn.type_special_kind == SemanticTree.type_special_kind.set_type || tn.type_special_kind == SemanticTree.type_special_kind.base_set_type) && tn.element_type != null) + constant = (expr as function_constant_reference).constant.const_value; + convertion_data_and_alghoritms.check_convert_type(constant, tn, expr.location); + if ((tn.type_special_kind == SemanticTree.type_special_kind.set_type || tn.type_special_kind == SemanticTree.type_special_kind.base_set_type) && tn.element_type != null) { ordinal_type_interface oti = tn.element_type.get_internal_interface(internal_interface_kind.ordinal_interface) as ordinal_type_interface; if (oti != null) { - common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as common_namespace_function_node,null); - cmc.parameters.AddElement(expr); - cmc.parameters.AddElement(oti.lower_value.get_constant_copy(null)); - cmc.parameters.AddElement(oti.upper_value.get_constant_copy(null)); - cmc.ret_type = tn; - constant = new common_namespace_function_call_as_constant(cmc,null); + common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipFunction.sym_info as common_namespace_function_node, null); + cmc.parameters.AddElement(expr); + cmc.parameters.AddElement(oti.lower_value.get_constant_copy(null)); + cmc.parameters.AddElement(oti.upper_value.get_constant_copy(null)); + cmc.ret_type = tn; + constant = new common_namespace_function_call_as_constant(cmc, null); } else if (tn.element_type.type_special_kind == SemanticTree.type_special_kind.short_string) { - common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as common_namespace_function_node,null); - cmc.parameters.AddElement(expr); - cmc.parameters.AddElement(new int_const_node((tn.element_type as short_string_type_node).Length,null)); - cmc.ret_type = tn; - constant = new common_namespace_function_call_as_constant(cmc,null); + common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringInSetFunction.sym_info as common_namespace_function_node, null); + cmc.parameters.AddElement(expr); + cmc.parameters.AddElement(new int_const_node((tn.element_type as short_string_type_node).Length, null)); + cmc.ret_type = tn; + constant = new common_namespace_function_call_as_constant(cmc, null); } - } - else - if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) - { - /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); + } + else + if (tn.type_special_kind == SemanticTree.type_special_kind.short_string) + { + /*common_namespace_function_call cmc = new common_namespace_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as common_namespace_function_node,null); cmc.parameters.AddElement(expr); cmc.parameters.AddElement(new int_const_node((tn as short_string_type_node).Length,null));*/ - expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node,null,convertion_data_and_alghoritms.convert_type(expr,SystemLibrary.SystemLibrary.string_type),new int_const_node((tn as short_string_type_node).Length,null)); - constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call,null); - } - return constant; + expression_node cmc = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.ClipShortStringProcedure.sym_info as function_node, null, convertion_data_and_alghoritms.convert_type(expr, SystemLibrary.SystemLibrary.string_type), new int_const_node((tn as short_string_type_node).Length, null)); + constant = new common_namespace_function_call_as_constant(cmc as common_namespace_function_call, null); + } + return constant; } else if (expr is static_compiled_variable_reference && !(expr as static_compiled_variable_reference).var.IsLiteral) { @@ -15277,6 +15277,8 @@ namespace PascalABCCompiler.TreeConverter } else if (expr is default_operator_node) constant = new default_operator_node_as_constant(expr as default_operator_node, null); + else if (expr is sizeof_operator) + constant = new sizeof_operator_as_constant(expr as sizeof_operator, 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) @@ -15289,7 +15291,7 @@ namespace PascalABCCompiler.TreeConverter constant = new common_static_method_call_as_constant(csmc, null); break; } - + } else { diff --git a/TreeConverter/TreeRealization/base_nodes.cs b/TreeConverter/TreeRealization/base_nodes.cs index 717ba5f98..c62fb1ced 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, common_static_method_call_node_as_constant + typeof_operator_as_constant, common_static_method_call_node_as_constant, sizeof_operator_as_constant }; /// diff --git a/TreeConverter/TreeRealization/constants.cs b/TreeConverter/TreeRealization/constants.cs index d1da442c9..c82efa795 100644 --- a/TreeConverter/TreeRealization/constants.cs +++ b/TreeConverter/TreeRealization/constants.cs @@ -1292,6 +1292,59 @@ namespace PascalABCCompiler.TreeRealization } } + public class sizeof_operator_as_constant : constant_node, SemanticTree.ISizeOfOperatorAsConstant + { + private sizeof_operator _sizeof_operator; + + public sizeof_operator sizeof_operator + { + get + { + return _sizeof_operator; + } + set + { + _sizeof_operator = value; + } + } + + public sizeof_operator_as_constant(sizeof_operator sizeof_operator, location loc) + : + base(sizeof_operator.type, loc) + { + _sizeof_operator = sizeof_operator; + } + + SemanticTree.ISizeOfOperator SemanticTree.ISizeOfOperatorAsConstant.SizeOfOperator + { + get + { + return _sizeof_operator; + } + } + + + /// + /// Метод для обхода дерева посетителем. + /// + /// Класс - посетитель дерева. + public override void visit(SemanticTree.ISemanticVisitor visitor) + { + visitor.visit(this); + } + + /// + /// Тип узла. + /// + public override semantic_node_type semantic_node_type + { + get + { + return semantic_node_type.sizeof_operator_as_constant; + } + } + } + public class compiled_constructor_call_as_constant : constant_node, SemanticTree.ICompiledConstructorCallAsConstant { private compiled_constructor_call _method_call; diff --git a/VisualPascalABCNETLinux/IB/Debugger/Debugger.cs b/VisualPascalABCNETLinux/IB/Debugger/Debugger.cs index db7736ab6..39ef408ca 100644 --- a/VisualPascalABCNETLinux/IB/Debugger/Debugger.cs +++ b/VisualPascalABCNETLinux/IB/Debugger/Debugger.cs @@ -566,7 +566,6 @@ namespace VisualPascalABC return null; } - private delegate void EndDebuggerSessionDelegate(); private void EndDebuggerSessionSafe() diff --git a/VisualPlugins/LanguageConverter/Source/Visitor.cs b/VisualPlugins/LanguageConverter/Source/Visitor.cs index 47b8de3f8..e0e757770 100644 --- a/VisualPlugins/LanguageConverter/Source/Visitor.cs +++ b/VisualPlugins/LanguageConverter/Source/Visitor.cs @@ -1569,5 +1569,10 @@ namespace VisualPascalABCPlugins { throw new System.NotImplementedException(); } + + public void visit(ISizeOfOperatorAsConstant value) + { + throw new System.NotImplementedException(); + } } }