Example #1
0
        public static OperatorFunctions LoadOperatorFunctions(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            OperatorFunctions operatorFunctions = new OperatorFunctions(); serizlized.Add(key, operatorFunctions);

            for (int i = 0; i < operatorFunctions.operFunctions.Length; i++)
            {
                var dict  = operatorFunctions.operFunctions[i];
                int count = reader.ReadInt32();
                for (int j = 0; j < count; j++)
                {
                    RunTimeDataType v1 = reader.ReadInt32();
                    RunTimeDataType v2 = reader.ReadInt32();

                    OperatorFunctionKey operatorFunctionKey = new OperatorFunctionKey(v1, v2);

                    rtti.FunctionDefine define   = serizlizer.DeserializeObject <rtti.FunctionDefine>(reader, rtti.FunctionDefine.LoadFunctionDefine);
                    rtData.rtFunction   function = serizlizer.DeserializeObject <rtData.rtFunction>(reader, RunTimeValueBase.LoadRunTimeValueBase);

                    DefineAndFunc defineAndFunc = new DefineAndFunc();
                    defineAndFunc.define = define;
                    defineAndFunc.func   = function;

                    dict.Add(operatorFunctionKey, defineAndFunc);
                }
            }

            return(operatorFunctions);
        }
        public static SourceToken LoadToken(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            int    line = reader.ReadInt32();
            int    ptr  = reader.ReadInt32();
            string srcfile;
            var    tag = serizlizer.ReadTag(reader);

            if (tag == CSWCSerizlizer.TagType.NULLINSTANCE)
            {
                srcfile = null;
            }
            else if (tag == CSWCSerizlizer.TagType.INSTANCEATCACHE)
            {
                int idx = reader.ReadInt32();
                srcfile = serizlizer.stringpool[idx];
            }
            else if (tag == CSWCSerizlizer.TagType.WRITEINSTANCEANDCACHEIT)
            {
                int idx = reader.ReadInt32();
                srcfile = reader.ReadString();
                serizlizer.stringpool.Add(idx, srcfile);
            }
            else
            {
                throw new IOException("文件错误");
            }

            SourceToken token = new SourceToken(line, ptr, srcfile);

            serizlized.Add(key, token);

            return(token);
        }
        public void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
        {
            writer.Write(line);
            writer.Write(ptr);

            if (sourceFile == null)
            {
                serizlizer.WriteTag(writer, CSWCSerizlizer.TagType.NULLINSTANCE);
                return;
            }

            foreach (var item in serizlizer.stringpool)
            {
                if (string.Equals(item.Value, sourceFile))
                {
                    serizlizer.WriteTag(writer, CSWCSerizlizer.TagType.INSTANCEATCACHE);
                    writer.Write(item.Key);
                    return;
                }
            }
            int index = serizlizer.stringpool.Count;

            serizlizer.stringpool.Add(index, sourceFile);

            serizlizer.WriteTag(writer, CSWCSerizlizer.TagType.WRITEINSTANCEANDCACHEIT);
            writer.Write(index);
            writer.Write(sourceFile);
        }
        public static Variable LoadVariable(BinaryReader reader,CSWCSerizlizer serizlizer,IDictionary <int,object> serizlized,int key)
        {
            //	private string _name;
            string _name = reader.ReadString();
            //protected int _indexOfMembers;
            int _indexOfMembers = reader.ReadInt32();
            //protected readonly int refblockid;
            int refblockid = reader.ReadInt32();

            ///// <summary>
            ///// 赋值是否忽略编译期类型检查
            ///// </summary>
            //public readonly bool ignoreImplicitCast;
            bool ignoreImplicitCast = reader.ReadBoolean();
            ///// <summary>
            ///// 是否不可赋值
            ///// </summary>
            //public readonly bool isConst;
            bool isConst = reader.ReadBoolean();

            RunTimeDataType valuetype = reader.ReadInt32();

            Variable variable = new Variable(_name,_indexOfMembers,ignoreImplicitCast,refblockid,isConst);

            variable.valueType = valuetype;
            serizlized.Add(key,variable);
            return(variable);
        }
Example #5
0
        public void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
        {
            writer.Write(id);
            writer.Write(name);
            writer.Write(define_class_id);
            writer.Write(isoutclass);
            writer.Write(hasTryStmt);
            writer.Write((ushort)totalStackSlots);

            serizlizer.SerializeObject(writer, (scopes.ScopeBase)scope);

            //writer.Write(opSteps.Count);
            //for (int i = 0; i < opSteps.Count; i++)
            //{
            //	var step = opSteps[i];
            //	serizlizer.SerializeObject(writer, step);
            //}

            writer.Write((ushort)instructions.Length);
            for (int i = 0; i < instructions.Length; i++)
            {
                var step = instructions[i];
                serizlizer.SerializeObject(writer, step);
            }

            writer.Write((ushort)regConvFromVar.Length);
            for (int i = 0; i < regConvFromVar.Length; i++)
            {
                StackSlotAccessor conv = regConvFromVar[i];
                //conv.Serialize(writer, serizlizer);
                serizlizer.SerializeObject(writer, conv);
            }
        }
Example #6
0
        public static ClassMethodGetter LoadClassMethodGetter(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            //protected int indexofMember;
            int indexofMember = reader.ReadInt32();
            //private readonly string _name;
            string _name = reader.ReadString();
            //public readonly int refdefinedinblockid;
            int refdefinedinblockid = reader.ReadInt32();
            //protected int functionid;
            int functionid = reader.ReadInt32();

            ///// <summary>
            ///// 比如说,私有方法就肯定不是虚方法
            ///// </summary>
            //protected bool isNotReadVirtual = false;
            bool isNotReadVirtual = reader.ReadBoolean();

            RunTimeDataType datetype = reader.ReadInt32();

            ClassMethodGetter cg = new ClassMethodGetter(_name, null, indexofMember, refdefinedinblockid);

            serizlized.Add(key, cg);

            //protected readonly ASBinCode.rtti.Class _class;
            ASBinCode.rtti.Class _class = serizlizer.DeserializeObject <rtti.Class>(reader, rtti.Class.LoadClass);

            cg._class = _class;


            cg.functionid       = functionid;
            cg.isNotReadVirtual = isNotReadVirtual;
            cg.valueType        = datetype;

            return(cg);
        }
 public byte[] toBytes()
 {
     byte[] bin;
     {
         CSWCSerizlizer serizlizer = new CSWCSerizlizer();
         bin = serizlizer.Serialize(this);
     }
     return(bin);
 }
Example #8
0
        public override void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
        {
            writer.Write(9);
            base.Serialize(writer, serizlizer);

            serizlizer.SerializeObject(writer, superClass);
            serizlizer.SerializeObject(writer, thisClass);

            //throw new NotImplementedException();
        }
        public static ThisPointer LoadThisPointer(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            RunTimeDataType type  = reader.ReadInt32();
            SourceToken     token = serizlizer.DeserializeObject <SourceToken>(reader, SourceToken.LoadToken);

            ThisPointer pointer = new ThisPointer(null, token); serizlized.Add(key, pointer);

            pointer.valueType = type;

            return(pointer);
        }
Example #10
0
        public static MemRegister_UInt LoadRegister(BinaryReader reader,CSWCSerizlizer serizlizer,IDictionary <int,object> serizlized,int key)
        {
            RunTimeDataType valuetype = reader.ReadInt32();
            int             id        = reader.ReadInt32();

            MemRegister_UInt register = new MemRegister_UInt(id);

            serizlized.Add(key,register);

            serizlizer.loadingSwc.MemRegList.Add(register);

            return(register);
        }
Example #11
0
        public static SuperPointer LoadSuperPointer(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            RunTimeDataType valuetype = reader.ReadInt32();

            rtti.Class superClass = serizlizer.DeserializeObject <rtti.Class>(reader, rtti.Class.LoadClass);
            rtti.Class thisClass  = serizlizer.DeserializeObject <rtti.Class>(reader, rtti.Class.LoadClass);

            SuperPointer sp = new SuperPointer(superClass, thisClass); serizlized.Add(key, sp);

            sp.valueType = valuetype;

            return(sp);
        }
Example #12
0
        public static StackSlotAccessor LoadRegister(BinaryReader reader,CSWCSerizlizer serizlizer,IDictionary <int,object> serizlized,int key)
        {
            RunTimeDataType valuetype = reader.ReadInt32();

            //public readonly int Id;
            int id = reader.ReadInt32();
            //public int _index;
            int _index = reader.ReadInt32();
            //public readonly int stmtid;
            int stmtid = reader.ReadInt32();


            StackSlotAccessor register = new StackSlotAccessor(id,stmtid); serizlized.Add(key,register);

            register._index = _index;

            ///// <summary>
            ///// 指示是否delete目标
            ///// </summary>
            //public bool _isdeletetarget;
            register._isdeletetarget = reader.ReadBoolean();
            ///// <summary>
            ///// 指示是否对其有=赋值操作
            ///// </summary>
            //public bool _isassigntarget;
            register._isassigntarget = reader.ReadBoolean();
            ///// <summary>
            ///// 指示是否对其有++,--,delete操作
            ///// </summary>
            //public bool _hasUnaryOrShuffixOrDelete;
            register._hasUnaryOrShuffixOrDelete = reader.ReadBoolean();
            ///// <summary>
            ///// 指示是否对其有++,--
            ///// </summary>
            //public bool _hasUnaryOrShuffix;
            register._hasUnaryOrShuffix = reader.ReadBoolean();
            ///// <summary>
            ///// 只是是否. [] 操作的目标
            ///// </summary>
            //public bool _isDotAccessTarget;
            register._isDotAccessTarget = reader.ReadBoolean();

            //public bool isFindByPath;
            register.isFindByPath = reader.ReadBoolean();
            //public bool isFuncResult;
            register.isFuncResult = reader.ReadBoolean();
            //public bool isConvertFromVariable;
            register.isConvertFromVariable = reader.ReadBoolean();

            return(register);
        }
Example #13
0
        public void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
        {
            writer.Write(MetaName == null);
            if (MetaName != null)
            {
                writer.Write(MetaName);
            }

            writer.Write(MetaData == null);
            if (MetaData != null)
            {
                writer.Write(MetaData);
            }
        }
Example #14
0
        public static FieldMeta LoadFieldMeta(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            FieldMeta fieldMeta = new FieldMeta(); serizlized.Add(key, fieldMeta);

            if (!reader.ReadBoolean())
            {
                fieldMeta.MetaName = reader.ReadString();
            }
            if (!reader.ReadBoolean())
            {
                fieldMeta.MetaData = reader.ReadString();
            }

            return(fieldMeta);
        }
        public override void Serialize(BinaryWriter writer,CSWCSerizlizer serizlizer)
        {
            writer.Write(2);

            //private readonly int indexofMember;
            writer.Write(indexofMember);
            //private readonly string _name;
            writer.Write(_name);

            //public readonly ASBinCode.rtti.Class _class;
            serizlizer.SerializeObject(writer,_class);
            //public MethodGetterBase getter;
            serizlizer.SerializeObject(writer,getter);
            //public MethodGetterBase setter;
            serizlizer.SerializeObject(writer,setter);
        }
Example #16
0
        public void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
        {
            for (int i = 0; i < operFunctions.Length; i++)
            {
                var dict = operFunctions[i];
                writer.Write(dict.Count);
                foreach (var item in dict)
                {
                    writer.Write(item.Key.v1);
                    writer.Write(item.Key.v2);

                    serizlizer.SerializeObject(writer, item.Value.define);
                    serizlizer.SerializeObject(writer, item.Value.func);
                }
            }
        }
Example #17
0
        public override void Serialize(BinaryWriter writer,CSWCSerizlizer serizlizer)
        {
            writer.Write(5);
            base.Serialize(writer,serizlizer);

            //public readonly int Id;
            writer.Write(Id);
            //public int _index;
            writer.Write(_index);
            //public readonly int stmtid;
            writer.Write(stmtid);

            ///// <summary>
            ///// 指示是否delete目标
            ///// </summary>
            //public bool _isdeletetarget;
            writer.Write(_isdeletetarget);
            ///// <summary>
            ///// 指示是否对其有=赋值操作
            ///// </summary>
            //public bool _isassigntarget;
            writer.Write(_isassigntarget);
            ///// <summary>
            ///// 指示是否对其有++,--,delete操作
            ///// </summary>
            //public bool _hasUnaryOrShuffixOrDelete;
            writer.Write(_hasUnaryOrShuffixOrDelete);
            ///// <summary>
            ///// 指示是否对其有++,--
            ///// </summary>
            //public bool _hasUnaryOrShuffix;
            writer.Write(_hasUnaryOrShuffix);
            ///// <summary>
            ///// 只是是否. [] 操作的目标
            ///// </summary>
            //public bool _isDotAccessTarget;
            writer.Write(_isDotAccessTarget);

            //public bool isFindByPath;
            writer.Write(isFindByPath);
            //public bool isFuncResult;
            writer.Write(isFuncResult);
            //public bool isConvertFromVariable;
            writer.Write(isConvertFromVariable);
        }
Example #18
0
        public static Field LoadField(BinaryReader reader,CSWCSerizlizer serizlizer,IDictionary <int,object> serizlized,int key)
        {
            //	private string _name;
            string _name = reader.ReadString();
            //protected int _indexOfMembers;
            int _indexOfMembers = reader.ReadInt32();
            //protected readonly int refblockid;
            int refblockid = reader.ReadInt32();

            ///// <summary>
            ///// 赋值是否忽略编译期类型检查
            ///// </summary>
            //public readonly bool ignoreImplicitCast;
            bool ignoreImplicitCast = reader.ReadBoolean();
            ///// <summary>
            ///// 是否不可赋值
            ///// </summary>
            //public readonly bool isConst;
            bool isConst = reader.ReadBoolean();

            RunTimeDataType valuetype = reader.ReadInt32();

            Field field = new Field(_name,_indexOfMembers,refblockid,isConst);

            field.valueType = valuetype;

            serizlized.Add(key,field);



            field.isPublic    = reader.ReadBoolean();
            field.isInternal  = reader.ReadBoolean();
            field.isPrivate   = reader.ReadBoolean();
            field.isProtected = reader.ReadBoolean();
            field.isStatic    = reader.ReadBoolean();

            int metas = reader.ReadInt32();

            for (int i = 0; i < metas; i++)
            {
                field.metas.Add(serizlizer.DeserializeObject <FieldMeta>(reader,FieldMeta.LoadFieldMeta));
            }

            return(field);
        }
        public override void Serialize(BinaryWriter writer,CSWCSerizlizer serizlizer)
        {
            //protected int indexofMember;
            writer.Write(indexofMember);
            //private readonly string _name;
            writer.Write(_name);
            //public readonly int refdefinedinblockid;
            writer.Write(refdefinedinblockid);
            //protected int functionid;
            writer.Write(functionid);

            ///// <summary>
            ///// 比如说,私有方法就肯定不是虚方法
            ///// </summary>
            //protected bool isNotReadVirtual = false;
            writer.Write(isNotReadVirtual);

            base.Serialize(writer,serizlizer);

            //protected readonly ASBinCode.rtti.Class _class;
            serizlizer.SerializeObject(writer,_class);
        }
Example #20
0
        public override void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
        {
            //	private string _name;
            writer.Write(_name);
            //protected int _indexOfMembers;
            writer.Write(_indexOfMembers);
            //protected readonly int refblockid;
            writer.Write(refblockid);

            ///// <summary>
            ///// 赋值是否忽略编译期类型检查
            ///// </summary>
            //public readonly bool ignoreImplicitCast;
            writer.Write(ignoreImplicitCast);
            ///// <summary>
            ///// 是否不可赋值
            ///// </summary>
            //public readonly bool isConst;
            writer.Write(isConst);

            base.Serialize(writer, serizlizer);
        }
Example #21
0
        public override void Serialize(BinaryWriter writer,CSWCSerizlizer serizlizer)
        {
            writer.Write(4);
            base.Serialize(writer,serizlizer);

            //public bool isPublic;
            writer.Write(isPublic);
            //public bool isInternal;
            writer.Write(isInternal);
            //public bool isPrivate;
            writer.Write(isPrivate);
            //public bool isProtected;
            writer.Write(isProtected);
            //public bool isStatic;
            writer.Write(isStatic);
            //public List<FieldMeta> metas;

            writer.Write(metas.Count);
            for (int i = 0; i < metas.Count; i++)
            {
                serizlizer.SerializeObject(writer,metas[i]);
            }
        }
Example #22
0
        public static CodeBlock Deserialize(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            var id              = reader.ReadInt32();
            var name            = reader.ReadString();   //writer.Write(name);
            var define_class_id = reader.ReadInt32();    //writer.Write(define_class_id);
            var isoutclass      = reader.ReadBoolean();  //writer.Write(isoutclass);
            var hasTryStmt      = reader.ReadBoolean();  // writer.Write(hasTryStmt);

            CodeBlock block = new CodeBlock(id, name, define_class_id, isoutclass);

            block.hasTryStmt = hasTryStmt;
            serizlized.Add(key, block);

            block.totalStackSlots = reader.ReadUInt16();
            block.scope           = serizlizer.DeserializeObject <scopes.ScopeBase>(reader, scopes.ScopeBase.Deserialize);

            int stepscount = reader.ReadUInt16();

            block.instructions = new OpStep[stepscount]; block.opSteps = null;
            for (int i = 0; i < stepscount; i++)
            {
                OpStep step = serizlizer.DeserializeObject <OpStep>(reader, OpStep.Deserialize);
                //block.opSteps.Add(step);
                block.instructions[i] = step;
            }

            int regconvcount = reader.ReadUInt16();

            block.regConvFromVar = new StackSlotAccessor[regconvcount];
            for (int i = 0; i < regconvcount; i++)
            {
                StackSlotAccessor register = (StackSlotAccessor)serizlizer.DeserializeObject <ISWCSerializable>(reader, ISWCSerializableLoader.LoadIMember);
                block.regConvFromVar[i] = register;
            }

            return(block);
        }
Example #23
0
 public override void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
 {
     writer.Write(0);
     base.Serialize(writer, serizlizer);
 }
Example #24
0
 public override void Serialize(BinaryWriter writer,CSWCSerizlizer serizlizer)
 {
     throw new NotImplementedException();
 }
        public static ISWCSerializable LoadIMember(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            int membertype = reader.ReadInt32();

            if (membertype == 0)
            {
                return(ClassMethodGetter.LoadClassMethodGetter(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 1)
            {
                return(InterfaceMethodGetter.LoadInterfaceMethodGetter(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 2)
            {
                return(ClassPropertyGetter.LoadClassPropertyGetter(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 3)
            {
                return(Variable.LoadVariable(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 4)
            {
                return(Field.LoadField(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 5)
            {
                return(StackSlotAccessor.LoadRegister(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 6)
            {
                return(rtData.RightValue.LoadRightValue(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 7)
            {
                return(StaticClassDataGetter.LoadStaticClassDataGetter(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 8)
            {
                return(ThisPointer.LoadThisPointer(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 9)
            {
                return(SuperPointer.LoadSuperPointer(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 10)
            {
                return(MemRegister_Number.LoadRegister(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 11)
            {
                return(MemRegister_Boolean.LoadRegister(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 12)
            {
                return(MemRegister_Int.LoadRegister(reader, serizlizer, serizlized, key));
            }
            else if (membertype == 13)
            {
                return(MemRegister_UInt.LoadRegister(reader, serizlizer, serizlized, key));
            }
            //else if (membertype == 14)
            //{
            //	return MemRegister_Object.LoadRegister(reader, serizlizer, serizlized, key);
            //}
            else
            {
                throw new IOException("格式异常");
            }
        }
 public override void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
 {
     writer.Write(1);
     base.Serialize(writer, serizlizer);
     serizlizer.SerializeObject(writer, link);
 }
        public static CSWC loadFromBytes(byte[] data)
        {
            CSWCSerizlizer serizlizer = new CSWCSerizlizer();

            return(serizlizer.Deserialize(data));
        }
 public override void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
 {
     writer.Write(8);
     base.Serialize(writer, serizlizer);
     serizlizer.SerializeObject <SourceToken>(writer, token);
 }
 public virtual void Serialize(BinaryWriter writer, CSWCSerizlizer serizlizer)
 {
     writer.Write(valueType);
 }
Example #30
0
        public static StaticClassDataGetter LoadStaticClassDataGetter(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key)
        {
            RunTimeDataType type = reader.ReadInt32();

            rtti.Class _class = serizlizer.DeserializeObject <rtti.Class>(reader, rtti.Class.LoadClass);

            StaticClassDataGetter sd = new StaticClassDataGetter(_class); serizlized.Add(key, sd);

            sd.valueType = type;

            return(sd);
        }