Exemplo n.º 1
0
 internal override MSA.Expression /*!*/ TransformRead(AstGenerator /*!*/ gen)
 {
     return(Methods.MatchString.OpCall(
                AstUtils.LightDynamic(ConvertToStrAction.Make(gen.Context), typeof(MutableString), _expression.Transform(gen)),
                _regex.Transform(gen),
                gen.CurrentScopeVariable
                ));
 }
Exemplo n.º 2
0
        private Expression /*!*/ MarshalArgument(MetaObjectBuilder /*!*/ metaBuilder, DynamicMetaObject /*!*/ arg, ArgType parameterType)
        {
            object value = arg.Value;

            if (value == null)
            {
                metaBuilder.AddRestriction(Ast.Equal(arg.Expression, AstUtils.Constant(null)));
            }
            else
            {
                metaBuilder.AddTypeRestriction(value.GetType(), arg.Expression);
            }

            switch (parameterType)
            {
            case ArgType.Buffer:
                if (value == null)
                {
                    return(AstUtils.Constant(null, typeof(byte[])));
                }

                if (value is int && (int)value == 0)
                {
                    metaBuilder.AddRestriction(Ast.Equal(AstUtils.Convert(arg.Expression, typeof(int)), AstUtils.Constant(0)));
                    return(AstUtils.Constant(null, typeof(byte[])));
                }

                if (value.GetType() == typeof(MutableString))
                {
                    return(Methods.GetMutableStringBytes.OpCall(
                               AstUtils.Convert(arg.Expression, typeof(MutableString))
                               ));
                }

                return(Methods.GetMutableStringBytes.OpCall(
                           AstUtils.LightDynamic(ConvertToStrAction.Make(_context), typeof(MutableString), arg.Expression)
                           ));

            case ArgType.Int32:
                if (value is int)
                {
                    return(AstUtils.Convert(arg.Expression, typeof(int)));
                }

                return(Ast.Convert(
                           Ast.Call(
                               AstUtils.LightDynamic(ConvertToIntAction.Make(_context), typeof(IntegerValue), arg.Expression),
                               Methods.IntegerValue_ToUInt32Unchecked
                               ),
                           typeof(int)
                           ));
            }
            throw Assert.Unreachable;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts an object to string using to_str protocol (<see cref="ConvertToStrAction"/>).
        /// </summary>
        public static MutableString /*!*/ CastToString(ConversionStorage <MutableString> /*!*/ stringCast, object obj)
        {
            var site   = stringCast.GetSite(ConvertToStrAction.Make(stringCast.Context));
            var result = site.Target(site, obj);

            if (result == null)
            {
                throw RubyExceptions.CreateTypeConversionError("nil", "String");
            }
            return(result);
        }
Exemplo n.º 4
0
        internal string[] /*!*/ GetLoadPathStrings()
        {
            var loadPaths = GetLoadPaths();
            var result    = new string[loadPaths.Length];
            var toStr     = _toStrStorage.GetSite(ConvertToStrAction.Make(_context));

            for (int i = 0; i < loadPaths.Length; i++)
            {
                if (loadPaths[i] == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                result[i] = toStr.Target(toStr, loadPaths[i]).ConvertToString();
            }

            return(result);
        }
Exemplo n.º 5
0
        private bool IsFileLoaded(MutableString /*!*/ path)
        {
            var toStr = _toStrStorage.GetSite(ConvertToStrAction.Make(_context));

            foreach (object file in GetLoadedFiles())
            {
                if (file == null)
                {
                    throw RubyExceptions.CreateTypeConversionError("nil", "String");
                }

                // case sensitive comparison:
                if (path.Equals(toStr.Target(toStr, file)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Converts an object to string using to_str protocol (<see cref="ConvertToStrAction"/>).
 /// </summary>
 public static MutableString /*!*/ CastToString(ConversionStorage <MutableString> /*!*/ stringCast, object obj)
 {
     return(CastToString(stringCast.GetSite(ConvertToStrAction.Make(stringCast.Context)), obj));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Converts an object to string using to_str protocol (<see cref="ConvertToStrAction"/>).
        /// </summary>
        public static MutableString /*!*/ CastToString(ConversionStorage <MutableString> /*!*/ stringCast, object obj)
        {
            var site = stringCast.GetSite(ConvertToStrAction.Make(stringCast.Context));

            return(site.Target(site, obj));
        }