private void VisitAsNode(as_node node)
 {
     VisitExpression(node.left);
     WriteTypeReference(node.right);
 }
Exemple #2
0
 private void VisitAsNode(as_node en)
 {
     VisitExpression(en.left);
 }
        public override void visit(SyntaxTree.typecast_node node)
        {

            expression_node en = convert_strong(node.expr);
            location loc = get_location(node);
            type_node tp = convert_strong(node.type_def);
            //ssyy
            if (en.type.semantic_node_type == semantic_node_type.delegated_method)
            {
                try_convert_typed_expression_to_function_call(ref en);
            }
            //\ssyy
            if (!SemanticRules.IsAsForPointers && (tp.IsPointer || en.type.IsPointer))
            {
                if (node.cast_op == PascalABCCompiler.SyntaxTree.op_typecast.is_op)
                    AddError(loc, "OPERATOR_{0}_CAN_NOT_BE_APPLIED_TO_POINTER_TYPE", compiler_string_consts.is_name);
                else
                    AddError(loc, "OPERATOR_{0}_CAN_NOT_BE_APPLIED_TO_POINTER_TYPE", compiler_string_consts.as_name);
            }
            else
            	if (!(type_table.is_derived(en.type, tp) || type_table.is_derived(tp, en.type) || en.type == tp || en.type == SystemLibrary.SystemLibrary.object_type
            	      || en.type.IsInterface || tp.IsInterface))
                {
                    AddError(loc, "EXPECTED_DERIVED_CLASSES");
                }
            if (en.type.IsSealed && tp.IsInterface && !en.type.ImplementingInterfaces.Contains(tp))
            {
                AddError(loc, "CAN_NOT_CONVERT_TYPE_{0}_TO_INTERFACE_{1}", en.type.PrintableName, tp.PrintableName);
            }
            if (node.cast_op == PascalABCCompiler.SyntaxTree.op_typecast.is_op)
            {
                is_node isn = new is_node(en, tp, loc);
                return_value(isn);
            }
            else
            {
                if (tp.is_generic_parameter && !tp.is_class)
                    AddError(get_location(node.type_def), "OPERATOR_AS_CAN_NOT_BE_USED_WITH_GENERIC_PARAMETER_{0}_WITHOUT_CLASS_CONSTRAINT", tp.name);
                if (tp.is_value_type)
                    AddError(get_location(node.type_def), "OPERATOR_AS_MUST_BE_USED_WITCH_A_REFERENCE_TYPE_VALUETYPE{0}", tp.PrintableName);
                as_node asn = new as_node(en, tp, loc);
                return_value(asn);
            }
        }