Example #1
0
        public override Expression DoResolve(ParseContext parseContext)
        {
            if (ExpressionClass != ExpressionClass.Invalid)
            {
                return(this);
            }

            _destinationType = _destinationType.ResolveAsTypeStep(parseContext, false);

            Type = _destinationType.Type;

            if (Type == null)
            {
                return(null);
            }

            var childLambda = _child as LambdaExpression;

            if (childLambda != null)
            {
                childLambda.ImplicitStandardConversionExists(parseContext, Type);
            }

            _child = _child.Resolve(parseContext);

            ExpressionClass = ExpressionClass.Value;

            return(this);
        }
Example #2
0
        public override Expression DoResolve(ParseContext parseContext)
        {
            _operand    = _operand.Resolve(parseContext);
            _targetType = _targetType.ResolveAsTypeStep(parseContext, false);

            Type = _targetType.Type;

            return(this);
        }
Example #3
0
        public override Expression DoResolve(ParseContext rc)
        {
            if (Kind == LiteralKind.Null)
            {
                return(new DefaultValueExpression(typeof(object)));
            }

            var literalText = Text;

            if (literalText == null)
            {
                rc.Compiler.Errors.Add(
                    rc.Compiler.SourceUnit,
                    "Literal expression cannot have null text value.",
                    Span,
                    -1,
                    Severity.Error);

                return(null);
            }

            _literalType = _literalType.ResolveAsTypeStep(rc, false);

            if ((_literalType == null) || (_literalType.Type == null))
            {
                return(null);
            }

            if (Kind == LiteralKind.Text)
            {
                return(new InterpolatedStringExpression(this).Resolve(rc));
            }

            var builtinType = TypeManager.GetBuiltinTypeFromClrType(_literalType.Type);

            if (!builtinType.HasValue)
            {
                rc.ReportError(
                    CompilerErrors.LiteralValueMustBeBuiltinType,
                    Span,
                    TypeManager.GetCSharpName(_literalType.Type));

                return(null);
            }

            Type type;

            if (TypeManager.TryParseLiteral(
                    builtinType.Value,
                    literalText,
                    out _value,
                    out type))
            {
                Type = type;

                return(ConstantExpression.Create(
                           Type,
                           _value,
                           Span));
            }

            rc.ReportError(
                CompilerErrors.InvalidLiteralValue,
                Span,
                literalText,
                TypeManager.GetCSharpName(_literalType.Type));

            return(null);
        }