public override AstNode Visit(AsExpression node) { // Begin the node. builder.BeginNode(node); // Get the target type and value. //Expression target = node.GetTarget(); Expression value = node.GetValue(); // Visit them. //target.Accept(this); value.Accept(this); // Get their types. IChelaType targetType = node.GetNodeType(); IChelaType valueType = value.GetNodeType(); if(targetType != valueType) Cast(node, value.GetNodeValue(), valueType, targetType, false); return builder.EndNode(); }
public override AstNode Visit(AsExpression node) { // Get the target type and value. Expression target = node.GetTarget(); Expression value = node.GetValue(); // Visit them. target.Accept(this); value.Accept(this); // The value must be a reference. IChelaType valueType = value.GetNodeType(); node.SetCoercionType(valueType); if(!valueType.IsReference()) Error(node, "expected reference value."); // De-ref the value. valueType = DeReferenceType(valueType); if(valueType.IsReference()) node.SetCoercionType(valueType); // De-ref again. valueType = DeReferenceType(valueType); if(!valueType.IsPassedByReference()) Error(node, "expeceted a reference value."); // Get the target type. IChelaType targetType = target.GetNodeType(); targetType = ExtractActualType(target, targetType); if(!targetType.IsPassedByReference()) Error(node, "as operator only can be used with reference types."); targetType = ReferenceType.Create(targetType); // TODO: Check if it is possible to perform the cast. // Set the node type. node.SetNodeType(targetType); return node; }