public override BoundNode VisitAsOperator(BoundAsOperator node) { BoundSpillSequenceBuilder builder = null; var operand = VisitExpression(ref builder, node.Operand); return(UpdateExpression(builder, node.Update(operand, node.TargetType, node.Conversion, node.Type))); }
public override BoundNode VisitAsOperator(BoundAsOperator node) { BoundExpression operand = (BoundExpression)this.Visit(node.Operand); BoundTypeExpression targetType = (BoundTypeExpression)this.Visit(node.TargetType); TypeSymbol type = this.VisitType(node.Type); if (operand.Kind != BoundKind.SpillSequence) { return(node.Update(operand, targetType, node.Conversion, type)); } var spill = (BoundSpillSequence)operand; var newAsOperator = node.Update(spill.Value, targetType, node.Conversion, type); return(RewriteSpillSequence(spill, newAsOperator)); }
private BoundExpression VisitAsOperator(BoundAsOperator node) { if (node.Operand.IsLiteralNull() && (object)node.Operand.Type == null) { var operand = _bound.Null(_bound.SpecialType(SpecialType.System_Object)); node = node.Update(operand, node.TargetType, node.Conversion, node.Type); } return(ExprFactory("TypeAs", Visit(node.Operand), _bound.Typeof(node.Type))); }
private BoundExpression MakeAsOperator( BoundAsOperator oldNode, SyntaxNode syntax, BoundExpression rewrittenOperand, BoundTypeExpression rewrittenTargetType, Conversion conversion, TypeSymbol rewrittenType) { // TODO: Handle dynamic operand type and target type Debug.Assert(rewrittenTargetType.Type.Equals(rewrittenType)); // target type cannot be a non-nullable value type Debug.Assert(!rewrittenType.IsValueType || rewrittenType.IsNullableType()); if (!_inExpressionLambda) { ConstantValue constantValue = Binder.GetAsOperatorConstantResult(rewrittenOperand.Type, rewrittenType, conversion.Kind, rewrittenOperand.ConstantValue); if (constantValue != null) { Debug.Assert(constantValue.IsNull); BoundExpression result = rewrittenType.IsNullableType() ? new BoundDefaultExpression(syntax, rewrittenType) : MakeLiteral(syntax, constantValue, rewrittenType); if (rewrittenOperand.ConstantValue != null) { // No need to preserve any side-effects from the operand. // We also can keep the "constant" notion of the result, which // enables some optimizations down the road. return(result); } return(new BoundSequence( syntax: syntax, locals: ImmutableArray <LocalSymbol> .Empty, sideEffects: ImmutableArray.Create <BoundExpression>(rewrittenOperand), value: result, type: rewrittenType)); } if (conversion.IsImplicit) { // Operand with bound implicit conversion to target type. // We don't need a runtime check, generate a conversion for the operand instead. return(MakeConversionNode(syntax, rewrittenOperand, conversion, rewrittenType, @checked: false)); } } return(oldNode.Update(rewrittenOperand, rewrittenTargetType, conversion, rewrittenType)); }
private BoundExpression MakeAsOperator( BoundAsOperator oldNode, CSharpSyntaxNode syntax, BoundExpression rewrittenOperand, BoundTypeExpression rewrittenTargetType, Conversion conversion, TypeSymbol rewrittenType) { // TODO: Handle dynamic operand type and target type Debug.Assert(rewrittenTargetType.Type.Equals(rewrittenType)); // target type cannot be a non-nullable value type Debug.Assert(!rewrittenType.IsValueType || rewrittenType.IsNullableType()); if (!inExpressionLambda) { ConstantValue constantValue = Binder.GetAsOperatorConstantResult(rewrittenOperand.Type, rewrittenType, conversion.Kind, rewrittenOperand.ConstantValue); Debug.Assert(constantValue == null || constantValue.IsNull); if (conversion.IsImplicit) { // Operand with bound implicit conversion to target type. // We don't need a runtime check, generate a conversion for the operand instead. return(MakeConversion(syntax, rewrittenOperand, conversion, rewrittenType, @checked: false, constantValueOpt: constantValue)); } else if (constantValue != null) { return(new BoundSequence( syntax: syntax, locals: ImmutableArray <LocalSymbol> .Empty, sideEffects: ImmutableArray.Create <BoundExpression>(rewrittenOperand), value: MakeLiteral(syntax, constantValue, rewrittenType), type: rewrittenType)); } } return(oldNode.Update(rewrittenOperand, rewrittenTargetType, conversion, rewrittenType)); }