public override bool Equals(object o)
 {
     if (o is VariantClosure)
     {
         VariantClosure vc = (VariantClosure)o;
         return(mObject == vc.mObject && mObjThis == vc.mObjThis);
     }
     else
     {
         return(false);
     }
 }
Example #2
0
        /// <exception cref="VariantException"></exception>
        public static string VariantToReadableString(Variant val, int maxlen)
        {
            string ret = null;

            if (val == null || val.IsVoid())
            {
                ret = "(void)";
            }
            else
            {
                if (val.IsInteger())
                {
                    ret = "(int)" + val.AsString();
                }
                else
                {
                    if (val.IsReal())
                    {
                        ret = "(real)" + val.AsString();
                    }
                    else
                    {
                        if (val.IsString())
                        {
                            ret = "(string)\"" + LexBase.EscapeC(val.AsString()) + "\"";
                        }
                        else
                        {
                            if (val.IsOctet())
                            {
                                ret = "(octet)<% " + Variant.OctetToListString(val.AsOctet()) + " %>";
                            }
                            else
                            {
                                if (val.IsObject())
                                {
                                    VariantClosure c   = (VariantClosure)val.AsObjectClosure();
                                    StringBuilder  str = new StringBuilder(128);
                                    str.Append("(object)");
                                    str.Append('(');
                                    if (c.mObject != null)
                                    {
                                        str.Append('[');
                                        if (c.mObject is NativeClass)
                                        {
                                            str.Append(((NativeClass)c.mObject).GetClassName());
                                        }
                                        else
                                        {
                                            if (c.mObject is InterCodeObject)
                                            {
                                                str.Append(((InterCodeObject)c.mObject).GetName());
                                            }
                                            else
                                            {
                                                if (c.mObject is CustomObject)
                                                {
                                                    string name = ((CustomObject)c.mObject).GetClassNames();
                                                    if (name != null)
                                                    {
                                                        str.Append(name);
                                                    }
                                                    else
                                                    {
                                                        str.Append(c.mObject.GetType().FullName);
                                                    }
                                                }
                                                else
                                                {
                                                    str.Append(c.mObject.GetType().FullName);
                                                }
                                            }
                                        }
                                        str.Append(']');
                                    }
                                    else
                                    {
                                        str.Append("0x00000000");
                                    }
                                    if (c.mObjThis != null)
                                    {
                                        str.Append('[');
                                        if (c.mObjThis is NativeClass)
                                        {
                                            str.Append(((NativeClass)c.mObjThis).GetClassName());
                                        }
                                        else
                                        {
                                            if (c.mObjThis is InterCodeObject)
                                            {
                                                str.Append(((InterCodeObject)c.mObjThis).GetName());
                                            }
                                            else
                                            {
                                                if (c.mObjThis is CustomObject)
                                                {
                                                    string name = ((CustomObject)c.mObjThis).GetClassNames();
                                                    if (name != null)
                                                    {
                                                        str.Append(name);
                                                    }
                                                    else
                                                    {
                                                        str.Append(c.mObjThis.GetType().FullName);
                                                    }
                                                }
                                                else
                                                {
                                                    str.Append(c.mObjThis.GetType().FullName);
                                                }
                                            }
                                        }
                                        str.Append(']');
                                    }
                                    else
                                    {
                                        str.Append(":0x00000000");
                                    }
                                    str.Append(')');
                                    ret = str.ToString();
                                }
                                else
                                {
                                    // native object ?
                                    ret = "(octet) [" + val.GetType().FullName + "]";
                                }
                            }
                        }
                    }
                }
            }
            if (ret != null)
            {
                if (ret.Length > maxlen)
                {
                    return(Sharpen.Runtime.Substring(ret, 0, maxlen));
                }
                else
                {
                    return(ret);
                }
            }
            return(string.Empty);
        }
        public int PutVariant(Variant v, Compiler block)
        {
            object o    = v.ToJavaObject();
            int    type = GetType(v);

            switch (type)
            {
            case TYPE_VOID:
            {
                return(0);
            }

            case TYPE_OBJECT:
            {
                // 常に0
                VariantClosure clo = (VariantClosure)o;
                if (clo.mObject == null && clo.mObjThis == null)
                {
                    return(0);
                }
                else
                {
                    // null の VariantClosure は受け入れる
                    return(-1);
                }
            }

            case TYPE_INTER_OBJECT:
            {
                // その他は入れない。Dictionary と Array は保存できるようにした方がいいが……
                VariantClosure clo = (VariantClosure)o;
                Dispatch2      dsp = clo.mObject;
                return(block.GetObjectIndex((InterCodeObject)dsp));
            }

            case TYPE_STRING:
            {
                return(PutString(((string)o)));
            }

            case TYPE_OCTET:
            {
                return(PutByteBuffer((ByteBuffer)o));
            }

            case TYPE_REAL:
            {
                return(PutDouble(((Number)o)));
            }

            case TYPE_BYTE:
            {
                if (o is Number n)
                {
                    return(PutByte(n));
                }

                if (o is int i)
                {
                    return(PutByte((byte)i));
                }
                return(PutByte((byte)o));
            }

            case TYPE_SHORT:
            {
                return(PutShort(((Number)o)));
            }

            case TYPE_INTEGER:
            {
                return(PutInteger(((Number)o)));
            }

            case TYPE_LONG:
            {
                return(PutLong(((Number)o)));
            }

            case TYPE_INTER_GENERATOR:
            {
                return(block.GetCodeIndex((InterCodeGenerator)o));
            }

            case TYPE_UNKNOWN:
            {
                return(-1);
            }
            }
            return(-1);
        }
 public virtual void Set(VariantClosure clo)
 {
     mObject  = clo.mObject;
     mObjThis = clo.mObjThis;
 }
        public byte GetType(Variant v)
        {
            object o = v.ToJavaObject();

            if (o == null)
            {
                return(TYPE_VOID);
            }
            else
            {
                if (o is string)
                {
                    return(TYPE_STRING);
                }
                else
                {
                    if (o is int)
                    {
                        int val = ((int)o);
                        if (val >= byte.MinValue && val <= byte.MaxValue)
                        {
                            return(TYPE_BYTE);
                        }
                        else
                        {
                            if (val >= short.MinValue && val <= short.MaxValue)
                            {
                                return(TYPE_SHORT);
                            }
                            else
                            {
                                return(TYPE_INTEGER);
                            }
                        }
                    }
                    else
                    {
                        if (o is double)
                        {
                            return(TYPE_REAL);
                        }
                        else
                        {
                            if (o is VariantClosure)
                            {
                                VariantClosure clo = (VariantClosure)o;
                                Dispatch2      dsp = clo.mObject;
                                if (dsp is InterCodeObject)
                                {
                                    return(TYPE_INTER_OBJECT);
                                }
                                else
                                {
                                    return(TYPE_OBJECT);
                                }
                            }
                            else
                            {
                                if (o is InterCodeGenerator)
                                {
                                    return(TYPE_INTER_GENERATOR);
                                }
                                else
                                {
                                    if (o is ByteBuffer)
                                    {
                                        return(TYPE_OCTET);
                                    }
                                    else
                                    {
                                        if (o is long)
                                        {
                                            long val = ((long)o);
                                            if (val >= byte.MinValue && val <= byte.MaxValue)
                                            {
                                                return(TYPE_BYTE);
                                            }
                                            else
                                            {
                                                if (val >= short.MinValue && val <= short.MaxValue)
                                                {
                                                    return(TYPE_SHORT);
                                                }
                                                else
                                                {
                                                    if (val >= int.MinValue && val <= int.MaxValue)
                                                    {
                                                        return(TYPE_INTEGER);
                                                    }
                                                    else
                                                    {
                                                        return(TYPE_LONG);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(TYPE_UNKNOWN);
        }