Esempio n. 1
0
        public ProjectionDefinition <T, T> Compile <T>(FieldSpec fieldSpec)
        {
            var sb = new StringBuilder();

            sb.Append("{ ");

            for (int i = 0; i < fieldSpec.Fields.Length; i++)
            {
                var    field = fieldSpec.Fields[i];
                string name  = MongoNameFixer.Field(field.Name);

                if (String.CompareOrdinal(name, "textScore") == 0)
                {
                    sb.AppendFormat("{0} : {{ $meta : \"textScore\" }}", name);
                }
                else if (field.Presence == FieldSpecPresence.Included)
                {
                    sb.AppendFormat("{0} : 1", name);
                }
                else
                {
                    sb.AppendFormat("{0} : 0", name);
                }

                if (i < fieldSpec.Fields.Length - 1)
                {
                    sb.Append(", ");
                }
            }

            sb.Append(" }");

            return(new BsonDocumentProjectionDefinition <T, T>(BsonSerializer.Deserialize <BsonDocument>(sb.ToString())));
        }
Esempio n. 2
0
 public Join(Expr outer, Expr inner, FieldSpec <T> outerFieldSpec, FieldSpec <T> innerFieldSpec)
 {
     Outer          = outer;
     Inner          = inner;
     OuterFieldSpec = outerFieldSpec;
     InnerFieldSpec = innerFieldSpec;
 }
Esempio n. 3
0
        public MixInstruction GetInstruction(byte opcode, FieldSpec fieldSpec)
        {
            if (!mOpcodeInstructionMap.TryGetValue(opcode, out List <MixInstruction> instructions))
            {
                return(null);
            }

            int            startIndex         = 0;
            MixInstruction defaultInstruction = null;

            if (instructions[0].FieldSpec == null)
            {
                defaultInstruction = instructions[0];
                startIndex         = 1;
            }

            for (int index = startIndex; index < instructions.Count; index++)
            {
                if (instructions[index].FieldSpec == fieldSpec)
                {
                    return(instructions[index]);
                }
            }

            return(defaultInstruction);
        }
Esempio n. 4
0
        private static UpversionType AnalyzeFields(IList <FieldSpec> oldFields, IList <FieldSpec> newFields)
        {
            foreach (FieldSpec oldField in oldFields)
            {
                FieldSpec newField = newFields
                                     .FirstOrDefault(field => field.Name.Name.Equals(oldField.Name.Name, StringComparison.InvariantCulture));
                if (newField == null)
                {
                    return(UpversionType.Major);
                }

                // Verify types are equal. This will false-positive on string/String conversions, but that's a minor issue for later consideration.
                if (!oldField.Type.Equals(newField.Type, StringComparison.InvariantCulture))
                {
                    return(UpversionType.Major);
                }

                // Validate modifiers.
                if ((oldField.IsUserModifiable && !newField.IsUserModifiable) ||
                    (oldField.IsStatic != newField.IsStatic))
                {
                    return(UpversionType.Major);
                }
            }

            if (newFields.Count != oldFields.Count)
            {
                return(UpversionType.Minor);
            }

            return(UpversionType.Patch);
        }
        private static FieldSpecList ReadTextSchema(IEnumerable <string> enumerator)
        {
            var result = new FieldSpecList();

            foreach (var item in enumerator)
            {
                string line = RemoveComments(item).ToLower().Trim(' ', '\t');
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                var len = FieldSpecList.ReadRecordLength(line);
                if (len.HasValue)
                {
                    result.RecordLength = len.Value;
                    continue;
                }

                var spec = FieldSpec.ToFieldSpec(line);
                result.Add(spec);
            }

            return(result);
        }
Esempio n. 6
0
        public static WordField LoadFromRegister(FieldSpec fieldSpec, Register register)
        {
            int fieldSpecByteCount = fieldSpec.ByteCount;

            if (fieldSpecByteCount > register.ByteCountWithPadding)
            {
                throw new ArgumentOutOfRangeException("fieldSpec", fieldSpec, "bytecount too large for this register");
            }

            WordField field = new WordField(fieldSpec, fieldSpecByteCount);
            int       fromRegisterStartIndex = register.ByteCountWithPadding - fieldSpecByteCount;

            fieldSpecByteCount--;

            while (fieldSpecByteCount >= 0)
            {
                field[fieldSpecByteCount] = register.GetByteWithPadding(fromRegisterStartIndex + fieldSpecByteCount);
                fieldSpecByteCount--;
            }

            if (fieldSpec.IncludesSign)
            {
                field.Sign = register.Sign;
            }

            return(field);
        }
Esempio n. 7
0
        public void Test_gt4_snapshot_3()
        {
            var fsa = new FieldSpec <int>("a");
            var fsb = new FieldSpec <int>("b");

            var store1 = TableStore.Create(fsa, fsb);

            var students = Table.Create(store1);

            var fa = store1.GetField(fsa);
            var fb = store1.GetField(fsb);

            var r1 = store1.Insert();

            r1.SetValue(fa, 0);
            r1.SetValue(fb, 5);

            var r2 = store1.Insert();

            r2.SetValue(fa, 1);
            r2.SetValue(fb, 6);

            var r3 = store1.Insert();

            r3.SetValue(fa, 2);
            r3.SetValue(fb, 5);

            var fsc = new FieldSpec <int>("c");
            var fsd = new FieldSpec <int>("d");

            var store2 = TableStore.Create(fsc, fsd);

            var r4 = store2.Insert();

            var fc = store2.GetField(fsc);
            var fd = store2.GetField(fsd);

            r4.SetValue(fc, 5);
            r4.SetValue(fd, 2);

            var r5 = store2.Insert();

            r5.SetValue(fc, 7);
            r5.SetValue(fd, 3);

            var(_, snapshot, test) = Table.Join(Table.Create(store1), Table.Create(store2), fsb, fsc);

            Assert.Equal(new Array8[] { new Array8(2)
                                        {
                                            [0] = 0, [1] = 0
                                        }, new Array8(2)
                                        {
                                            [0] = 2, [1] = 0
                                        } }, snapshot());
        }
Esempio n. 8
0
        public void AddFieldToList(SPOList spoList, FieldSpec fs)
        {
            List   spList      = context.Web.Lists.GetById(spoList.Id);
            string fieldSchema =
                "<Field ID='" + Guid.NewGuid() + "' " +
                "Type='" + fs.Type + "' " +
                "Name='" + fs.Name + "' " +
                "StaticName='" + fs.Name + "' " +
                "DisplayName='" + fs.Name + "' />";
            Field field = spList.Fields.AddFieldAsXml(fieldSchema, true, AddFieldOptions.AddToDefaultContentType);

            context.ExecuteQuery();
        }
Esempio n. 9
0
        public void Test_gt4_test_3()
        {
            var fsa = new FieldSpec <int>("a");
            var fsb = new FieldSpec <int>("b");

            var store1 = TableStore.Create(fsa, fsb);

            var fa = store1.GetField(fsa);
            var fb = store1.GetField(fsb);


            var r1 = store1.Insert();

            r1.SetValue(fa, 0);
            r1.SetValue(fb, 5);

            var r2 = store1.Insert();

            r2.SetValue(fa, 1);
            r2.SetValue(fb, 6);

            var r3 = store1.Insert();

            r3.SetValue(fa, 2);
            r3.SetValue(fb, 5);

            var fsc = new FieldSpec <int>("c");
            var fsd = new FieldSpec <int>("d");

            var store2 = TableStore.Create(fsc, fsd);

            var fc = store2.GetField(fsc);
            var fd = store2.GetField(fsd);

            var r4 = store2.Insert();

            r4.SetValue(fc, 5);
            r4.SetValue(fd, 2);

            var r5 = store2.Insert();

            r5.SetValue(fc, 7);
            r5.SetValue(fd, 3);

            var(_, snapshot, test) = Table.Join(Table.Create(store1), Table.Create(store2), fsb, fsc);

            Assert.Empty(test(store2[1]));
        }
Esempio n. 10
0
        public void FieldAndClassTest()
        {
            ClassSpec classSpec = NapackFileAnalyzer.Analyze("Test", "unused", SampleStrings.LargeSampleClass).Classes.First();

            Assert.AreEqual(1, classSpec.PublicFields.Count);

            FieldSpec field = classSpec.PublicFields.First();

            Assert.IsNotNull(field.Name);
            Assert.IsNotNull(field.Name.Name);
            Assert.IsNotNull(field.Name.Documentation);
            Assert.IsNotNull(field.Type);
            Assert.IsTrue(field.IsConst);
            Assert.IsFalse(field.IsStatic);
            Assert.IsFalse(field.IsReadonly);
        }
Esempio n. 11
0
        MixInstruction(byte opcode, FieldSpec fieldSpec, MetaFieldSpec metaFieldSpec, string mnemonic, int tickCount, Executor executor, Validator validator)
            : base(mnemonic)
        {
            // if the MetaFieldSpec Presence is Forbidden then an instruction fieldspec must be specified. Likewise, if an instruction fieldspec is provided, the MetaFieldSpec Presence must be Forbidden.
            if ((fieldSpec == null && metaFieldSpec.Presence == Instruction.MetaFieldSpec.Presences.Forbidden) || (metaFieldSpec.Presence != Instruction.MetaFieldSpec.Presences.Forbidden && fieldSpec != null))
            {
                throw new ArgumentException("forbidden fieldspec presence makes instruction fieldspec mandatory and vice versa");
            }

            Opcode        = opcode;
            FieldSpec     = fieldSpec;
            MetaFieldSpec = metaFieldSpec;
            TickCount     = tickCount;
            mExecutor     = executor ?? throw new ArgumentNullException(nameof(executor));
            mValidator    = validator;
        }
Esempio n. 12
0
        public void Test_b_gt_5()
        {
            var fsa = new FieldSpec <int>("a");
            var fsb = new FieldSpec <int>("b");

            var store1 = TableStore.Create(fsa, fsb);

            var fa = store1.GetField(fsa);
            var fb = store1.GetField(fsb);

            var expr = new Gt <int>(fsb, 5);

            var(_, snapshot, test) = Table.Filter(Table.Create(store1), expr);

            var r1 = store1.Insert();

            r1.SetValue(fa, 0);
            r1.SetValue(fb, 5);

            var r2 = store1.Insert();

            r2.SetValue(fa, 1);
            r2.SetValue(fb, 6);

            var r3 = store1.Insert();

            r3.SetValue(fa, 2);
            r3.SetValue(fb, 7);

            Assert.Equal(new Array8[] { new Array8(1)
                                        {
                                            [0] = 1
                                        }, new Array8(1)
                                        {
                                            [0] = 2
                                        } }, snapshot());
            Assert.Empty(test(store1[0]));
            Assert.Equal(new Array8[] { new Array8(1)
                                        {
                                            [0] = 1
                                        } }, test(store1[1]));
            Assert.Equal(new Array8[] { new Array8(1)
                                        {
                                            [0] = 2
                                        } }, test(store1[2]));
        }
Esempio n. 13
0
        public static WordField LoadFromFullWord(FieldSpec fieldSpec, FullWord word)
        {
            int fieldSpecByteCount = fieldSpec.ByteCount;

            WordField field             = new WordField(fieldSpec, fieldSpecByteCount);
            int       lowBoundByteIndex = fieldSpec.LowBoundByteIndex;

            for (int i = 0; i < fieldSpecByteCount; i++)
            {
                field[i] = word[lowBoundByteIndex + i];
            }

            if (fieldSpec.IncludesSign)
            {
                field.Sign = word.Sign;
            }

            return(field);
        }
Esempio n. 14
0
        public void Test_gt5_snapshot()
        {
            var fsa = new FieldSpec <int>("a");
            var fsb = new FieldSpec <int>("b");

            var store = TableStore.Create(fsa, fsb);

            var fa = store.GetField(fsa);
            var fb = store.GetField(fsb);

            var students = Table.Create(store);

            var(_, snapshot, test) = Table.Gt(students, fsb, 5);

            var r1 = store.Insert();

            r1.SetValue(fa, 0);
            r1.SetValue(fb, 5);

            Assert.Empty(snapshot());
        }
Esempio n. 15
0
        public void Test()
        {
            var fsa         = new FieldSpec <int>("a");
            var fsb         = new FieldSpec <int>("b");
            var store       = TableStore.Create(fsa, fsb);
            var fa          = store.GetField(fsa);
            var fb          = store.GetField(fsb);
            var sourceTable = Table.Create(store);
            var subManager  = new SubscriptionManager(sourceTable);

            subManager.Subscribe(">,b,4i", (r, changeType, n) =>
            {
                Console.WriteLine("hello");
            });

            subManager.Insert(store, r =>
            {
                r.SetValue(fa, 0);
                r.SetValue(fb, 5);
            });
        }
Esempio n. 16
0
        public void Test_gt4_notify_2()
        {
            var fsa = new FieldSpec <int>("a");
            var fsb = new FieldSpec <int>("b");

            var store = TableStore.Create(fsa, fsb);

            var fa = store.GetField(fsa);
            var fb = store.GetField(fsb);

            var students = Table.Create(store);

            var(_, snapshot, test) = Table.Gt(students, fsb, 4);

            var r1 = store.Insert();

            r1.SetValue(fa, 0);
            r1.SetValue(fb, 5);

            var r2 = store.Insert();

            r2.SetValue(fa, 1);
            r2.SetValue(fb, 6);

            var r3 = store.Insert();

            r3.SetValue(fa, 2);
            r3.SetValue(fb, 4);

            Assert.Equal(new Array8[] { new Array8(1)
                                        {
                                            [0] = 0
                                        } }, test(store[0]));
            Assert.Equal(new Array8[] { new Array8(1)
                                        {
                                            [0] = 1
                                        } }, test(store[1]));
            Assert.Empty(test(store[2]));
        }
Esempio n. 17
0
        public void Test_gt4_snapshot()
        {
            var fsa = new FieldSpec <int>("a");
            var fsb = new FieldSpec <int>("b");

            var store = TableStore.Create(fsa, fsb);

            var fa = store.GetField(fsa);
            var fb = store.GetField(fsb);

            var students = Table.Create(store);

            var(_, snapshot, test) = Table.Gt(students, fsb, 4);

            var r1 = store.Insert();

            r1.SetValue(fa, 0);
            r1.SetValue(fb, 5);

            Assert.Equal(new Array8[] { new Array8(1)
                                        {
                                            [0] = 0
                                        } }, snapshot());
        }
Esempio n. 18
0
 void AddInstruction(string mnemonic, byte opcode, FieldSpec fieldSpec, int tickCount, MixInstruction.Executor executor, MixInstruction.Validator validator) =>
 AddInstruction(mnemonic, new MixInstruction(opcode, fieldSpec, mnemonic, tickCount, executor, validator));
Esempio n. 19
0
        public InstructionSet()
        {
            var fullWordMetaSpec = new MetaFieldSpec(true, FullWordRegister.DefaultFieldSpec);
            var indexMetaSpec    = new MetaFieldSpec(true, IndexRegister.DefaultFieldSpec);

            FieldSpec[] rangeSpecs = new FieldSpec[8];
            for (int i = 0; i < rangeSpecs.Length; i++)
            {
                rangeSpecs[i] = new FieldSpec(i);
            }

            MixInstruction.Executor  executor  = LoadInstructions.Load;
            MixInstruction.Validator validator = InstructionHelpers.ValidateIndexAndFieldSpec;
            AddInstruction("LDA", 8, fullWordMetaSpec, 2, executor, validator);
            AddInstruction("LD1", 9, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD2", 10, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD3", 11, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD4", 12, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD5", 13, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD6", 14, indexMetaSpec, 2, executor, validator);
            AddInstruction("LDX", 15, fullWordMetaSpec, 2, executor, validator);

            executor = LoadInstructions.LoadNegative;
            AddInstruction("LDAN", 16, fullWordMetaSpec, 2, executor, validator);
            AddInstruction("LD1N", 17, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD2N", 18, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD3N", 19, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD4N", 20, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD5N", 21, indexMetaSpec, 2, executor, validator);
            AddInstruction("LD6N", 22, indexMetaSpec, 2, executor, validator);
            AddInstruction("LDXN", 23, fullWordMetaSpec, 2, executor, validator);

            executor = StoreInstructions.StoreRegister;
            AddInstruction("STA", 24, fullWordMetaSpec, 2, executor, validator);
            AddInstruction("ST1", 25, indexMetaSpec, 2, executor, validator);
            AddInstruction("ST2", 26, indexMetaSpec, 2, executor, validator);
            AddInstruction("ST3", 27, indexMetaSpec, 2, executor, validator);
            AddInstruction("ST4", 28, indexMetaSpec, 2, executor, validator);
            AddInstruction("ST5", 29, indexMetaSpec, 2, executor, validator);
            AddInstruction("ST6", 30, indexMetaSpec, 2, executor, validator);
            AddInstruction("STX", 31, fullWordMetaSpec, 2, executor, validator);
            AddInstruction("STJ", 32, new MetaFieldSpec(true, AddressRegister.DefaultFieldSpec), 2, executor, validator);

            executor = StoreInstructions.StoreZero;
            AddInstruction("STZ", 33, new MetaFieldSpec(true, Memory.DefaultFieldSpec), 2, executor, validator);

            executor = ArithmaticInstructions.AddSubstract;
            AddInstruction("ADD", 1, fullWordMetaSpec, 2, executor, validator);
            AddInstruction("SUB", 2, fullWordMetaSpec, 2, executor, validator);

            executor = ArithmaticInstructions.Multiply;
            AddInstruction("MUL", 3, fullWordMetaSpec, 10, executor, validator);

            executor = ArithmaticInstructions.Divide;
            AddInstruction("DIV", 4, fullWordMetaSpec, 12, executor, validator);

            executor = ComparisonInstructions.Compare;
            AddInstruction("CMPA", 56, fullWordMetaSpec, 2, executor, validator);
            AddInstruction("CMP1", 57, indexMetaSpec, 2, executor, validator);
            AddInstruction("CMP2", 58, indexMetaSpec, 2, executor, validator);
            AddInstruction("CMP3", 59, indexMetaSpec, 2, executor, validator);
            AddInstruction("CMP4", 60, indexMetaSpec, 2, executor, validator);
            AddInstruction("CMP5", 61, indexMetaSpec, 2, executor, validator);
            AddInstruction("CMP6", 62, indexMetaSpec, 2, executor, validator);
            AddInstruction("CMPX", 63, fullWordMetaSpec, 2, executor, validator);

            executor  = AddressTransferInstructions.Increase;
            validator = InstructionHelpers.ValidateIndex;
            AddInstruction("INCA", 48, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INC1", 49, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INC2", 50, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INC3", 51, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INC4", 52, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INC5", 53, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INC6", 54, rangeSpecs[0], 1, executor, validator);
            AddInstruction("INCX", 55, rangeSpecs[0], 1, executor, validator);

            executor = AddressTransferInstructions.Decrease;
            AddInstruction("DECA", 48, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DEC1", 49, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DEC2", 50, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DEC3", 51, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DEC4", 52, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DEC5", 53, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DEC6", 54, rangeSpecs[1], 1, executor, validator);
            AddInstruction("DECX", 55, rangeSpecs[1], 1, executor, validator);

            executor = AddressTransferInstructions.Enter;
            AddInstruction("ENTA", 48, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENT1", 49, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENT2", 50, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENT3", 51, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENT4", 52, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENT5", 53, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENT6", 54, rangeSpecs[2], 1, executor, validator);
            AddInstruction("ENTX", 55, rangeSpecs[2], 1, executor, validator);

            executor = AddressTransferInstructions.EnterNegative;
            AddInstruction("ENNA", 48, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENN1", 49, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENN2", 50, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENN3", 51, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENN4", 52, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENN5", 53, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENN6", 54, rangeSpecs[3], 1, executor, validator);
            AddInstruction("ENNX", 55, rangeSpecs[3], 1, executor, validator);

            executor = JumpInstructions.NonRegJump;
            AddInstruction("JMP", 39, rangeSpecs[0], 1, executor, validator);
            AddInstruction("JSJ", 39, rangeSpecs[1], 1, executor, validator);
            AddInstruction("JOV", 39, rangeSpecs[2], 1, executor, validator);
            AddInstruction("JNOV", 39, rangeSpecs[3], 1, executor, validator);
            AddInstruction("JL", 39, rangeSpecs[4], 1, executor, validator);
            AddInstruction("JE", 39, rangeSpecs[5], 1, executor, validator);
            AddInstruction("JG", 39, rangeSpecs[6], 1, executor, validator);
            AddInstruction("JGE", 39, rangeSpecs[7], 1, executor, validator);
            AddInstruction("JNE", 39, new FieldSpec(8), 1, executor, validator);
            AddInstruction("JLE", 39, new FieldSpec(9), 1, executor, validator);

            executor = JumpInstructions.RegJump;
            AddInstruction("JAN", 40, rangeSpecs[0], 1, executor, validator);
            AddInstruction("JAZ", 40, rangeSpecs[1], 1, executor, validator);
            AddInstruction("JAP", 40, rangeSpecs[2], 1, executor, validator);
            AddInstruction("JANN", 40, rangeSpecs[3], 1, executor, validator);
            AddInstruction("JANZ", 40, rangeSpecs[4], 1, executor, validator);
            AddInstruction("JANP", 40, rangeSpecs[5], 1, executor, validator);
            AddInstruction("JAE", 40, rangeSpecs[6], 1, executor, validator);
            AddInstruction("JAO", 40, rangeSpecs[7], 1, executor, validator);

            AddInstruction("J1N", 41, rangeSpecs[0], 1, executor, validator);
            AddInstruction("J1Z", 41, rangeSpecs[1], 1, executor, validator);
            AddInstruction("J1P", 41, rangeSpecs[2], 1, executor, validator);
            AddInstruction("J1NN", 41, rangeSpecs[3], 1, executor, validator);
            AddInstruction("J1NZ", 41, rangeSpecs[4], 1, executor, validator);
            AddInstruction("J1NP", 41, rangeSpecs[5], 1, executor, validator);

            AddInstruction("J2N", 42, rangeSpecs[0], 1, executor, validator);
            AddInstruction("J2Z", 42, rangeSpecs[1], 1, executor, validator);
            AddInstruction("J2P", 42, rangeSpecs[2], 1, executor, validator);
            AddInstruction("J2NN", 42, rangeSpecs[3], 1, executor, validator);
            AddInstruction("J2NZ", 42, rangeSpecs[4], 1, executor, validator);
            AddInstruction("J2NP", 42, rangeSpecs[5], 1, executor, validator);

            AddInstruction("J3N", 43, rangeSpecs[0], 1, executor, validator);
            AddInstruction("J3Z", 43, rangeSpecs[1], 1, executor, validator);
            AddInstruction("J3P", 43, rangeSpecs[2], 1, executor, validator);
            AddInstruction("J3NN", 43, rangeSpecs[3], 1, executor, validator);
            AddInstruction("J3NZ", 43, rangeSpecs[4], 1, executor, validator);
            AddInstruction("J3NP", 43, rangeSpecs[5], 1, executor, validator);

            AddInstruction("J4N", 44, rangeSpecs[0], 1, executor, validator);
            AddInstruction("J4Z", 44, rangeSpecs[1], 1, executor, validator);
            AddInstruction("J4P", 44, rangeSpecs[2], 1, executor, validator);
            AddInstruction("J4NN", 44, rangeSpecs[3], 1, executor, validator);
            AddInstruction("J4NZ", 44, rangeSpecs[4], 1, executor, validator);
            AddInstruction("J4NP", 44, rangeSpecs[5], 1, executor, validator);

            AddInstruction("J5N", 45, rangeSpecs[0], 1, executor, validator);
            AddInstruction("J5Z", 45, rangeSpecs[1], 1, executor, validator);
            AddInstruction("J5P", 45, rangeSpecs[2], 1, executor, validator);
            AddInstruction("J5NN", 45, rangeSpecs[3], 1, executor, validator);
            AddInstruction("J5NZ", 45, rangeSpecs[4], 1, executor, validator);
            AddInstruction("J5NP", 45, rangeSpecs[5], 1, executor, validator);

            AddInstruction("J6N", 46, rangeSpecs[0], 1, executor, validator);
            AddInstruction("J6Z", 46, rangeSpecs[1], 1, executor, validator);
            AddInstruction("J6P", 46, rangeSpecs[2], 1, executor, validator);
            AddInstruction("J6NN", 46, rangeSpecs[3], 1, executor, validator);
            AddInstruction("J6NZ", 46, rangeSpecs[4], 1, executor, validator);
            AddInstruction("J6NP", 46, rangeSpecs[5], 1, executor, validator);

            AddInstruction("JXN", 47, rangeSpecs[0], 1, executor, validator);
            AddInstruction("JXZ", 47, rangeSpecs[1], 1, executor, validator);
            AddInstruction("JXP", 47, rangeSpecs[2], 1, executor, validator);
            AddInstruction("JXNN", 47, rangeSpecs[3], 1, executor, validator);
            AddInstruction("JXNZ", 47, rangeSpecs[4], 1, executor, validator);
            AddInstruction("JXNP", 47, rangeSpecs[5], 1, executor, validator);
            AddInstruction("JXE", 47, rangeSpecs[6], 1, executor, validator);
            AddInstruction("JXO", 47, rangeSpecs[7], 1, executor, validator);

            executor = FloatingPointInstructions.DoFloatingPoint;
            AddInstruction("FADD", 1, rangeSpecs[6], 4, executor, validator);
            AddInstruction("FSUB", 2, rangeSpecs[6], 4, executor, validator);
            AddInstruction("FMUL", 3, rangeSpecs[6], 9, executor, validator);
            AddInstruction("FDIV", 4, rangeSpecs[6], 11, executor, validator);
            AddInstruction("FLOT", 5, rangeSpecs[6], 3, executor, validator);
            AddInstruction("FIX", 5, rangeSpecs[7], 3, executor, validator);
            AddInstruction(FloatingPointInstructions.FcmpMnemonic, 56, rangeSpecs[6], 4, executor, validator);

            executor = MiscInstructions.Move;
            AddInstruction("MOVE", 7, new MetaFieldSpec(false, rangeSpecs[1]), 1, executor, validator);

            var ioMetaSpec = new MetaFieldSpec(MetaFieldSpec.Presences.Mandatory, false);

            executor  = IOInstructions.JumpIfBusy;
            validator = IOInstructions.InstanceValid;
            AddInstruction("JBUS", 34, ioMetaSpec, 1, executor, validator);

            executor = IOInstructions.IOControl;
            AddInstruction("IOC", 35, ioMetaSpec, 1, executor, validator);

            executor = IOInstructions.Input;
            AddInstruction("IN", IOInstructions.INOpCode, ioMetaSpec, 1, executor, validator);

            executor = IOInstructions.Output;
            AddInstruction("OUT", 37, ioMetaSpec, 1, executor, validator);

            executor = IOInstructions.JumpIfReady;
            AddInstruction("JRED", 38, ioMetaSpec, 1, executor, validator);

            executor = ShiftInstructions.ShiftA;
            AddInstruction("SLA", 6, rangeSpecs[0], 2, executor, null);
            AddInstruction("SRA", 6, rangeSpecs[1], 2, executor, null);

            executor = ShiftInstructions.ShiftAX;
            AddInstruction("SLAX", 6, rangeSpecs[2], 2, executor, null);
            AddInstruction("SRAX", 6, rangeSpecs[3], 2, executor, null);
            AddInstruction("SLC", 6, rangeSpecs[4], 2, executor, null);
            AddInstruction("SRC", 6, rangeSpecs[5], 2, executor, null);

            executor = ShiftInstructions.ShiftAXBinary;
            AddInstruction("SLB", 6, rangeSpecs[6], 2, executor, null);
            AddInstruction("SRB", 6, rangeSpecs[7], 2, executor, null);

            executor = MiscInstructions.Noop;
            AddInstruction("NOP", 0, new MetaFieldSpec(false, rangeSpecs[0]), 1, executor, null);

            executor = MiscInstructions.ConvertToNumeric;
            AddInstruction("NUM", 5, rangeSpecs[0], 10, executor, null);

            executor = MiscInstructions.ConvertToChar;
            AddInstruction("CHAR", 5, rangeSpecs[1], 10, executor, null);

            executor = MiscInstructions.Halt;
            AddInstruction("HLT", 5, rangeSpecs[2], 10, executor, null);

            executor = MiscInstructions.ForceInterrupt;
            AddInstruction("INT", 5, new FieldSpec(9), 2, executor, null);
        }
Esempio n. 20
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            // split the text to parse in its W-value components
            var textParts    = text.Split(new char[] { ',' });
            int currentIndex = 0;

            var register = new FullWordRegister();
            var word     = new FullWord(0);

            // parse and apply each component to the word that contains the result
            foreach (string part in textParts)
            {
                // parse the address part...
                var braceIndex = part.IndexOf('(');
                var address    = ExpressionValue.ParseValue((braceIndex == -1) ? part : part.Substring(0, braceIndex), sectionCharIndex + currentIndex, status);
                if (address == null)
                {
                    return(null);
                }

                // ... and check if it is valid
                var addressSign      = address.GetSign(status.LocationCounter);
                var addressMagnitude = address.GetMagnitude(status.LocationCounter);
                if (addressMagnitude > register.MaxMagnitude)
                {
                    status.ReportParsingError(sectionCharIndex + currentIndex, (braceIndex == -1) ? part.Length : braceIndex, "W-value field value invalid");
                    return(null);
                }

                register.MagnitudeLongValue = addressMagnitude;
                register.Sign = addressSign;
                int fieldValue = FullWord.ByteCount;

                // if a fieldspec part is present...
                if (braceIndex >= 0)
                {
                    // ... parse its value...
                    var field = FPartValue.ParseValue(part.Substring(braceIndex), (sectionCharIndex + currentIndex) + braceIndex, status);
                    if (field == null)
                    {
                        return(null);
                    }

                    // ... and check if it is valid
                    if (field.GetValue(status.LocationCounter) != FPartValue.Default)
                    {
                        fieldValue = (int)field.GetValue(status.LocationCounter);
                    }
                }

                // use the fieldspec value to create and check an actual fieldspec
                var fieldSpec = new FieldSpec(fieldValue);
                if (!fieldSpec.IsValid)
                {
                    status.ReportParsingError((sectionCharIndex + currentIndex) + braceIndex, part.Length - braceIndex, "field must be a fieldspec");
                    return(null);
                }

                // apply the component to the word that will contain the end result
                WordField.LoadFromRegister(fieldSpec, register).ApplyToFullWord(word);
                currentIndex += part.Length + 1;
            }

            return(new NumberValue(word.Sign, word.MagnitudeLongValue));
        }
Esempio n. 21
0
        internal static ClassSpec AnalyzeClassSyntaxTree(string napackName, string filename, ClassDeclarationSyntax classNode)
        {
            ClassSpec classSpec = new ClassSpec();

            classSpec.Name       = DocumentedElement.LoadFromSyntaxNode(classNode);
            classSpec.IsAbstract = classNode.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.AbstractKeyword));
            classSpec.IsStatic   = classNode.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.StaticKeyword));
            classSpec.IsSealed   = classSpec.IsStatic || classNode.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.SealedKeyword));

            // Parse classes recursively
            foreach (ClassDeclarationSyntax node in classNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.ClassDeclaration)))
            {
                if (node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.PublicKeyword)) ||
                    (classSpec.ProtectedItemsConsideredPublic && node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ProtectedKeyword))))
                {
                    // This recursion will exit because we aren't *compiling* the code, but merely parsing it.
                    classSpec.PublicClasses.Add(AnalyzeClassSyntaxTree(napackName, filename, node));
                }
            }

            // Parse methods
            foreach (MethodDeclarationSyntax node in classNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.MethodDeclaration)))
            {
                if (node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.PublicKeyword)) ||
                    (classSpec.ProtectedItemsConsideredPublic && node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ProtectedKeyword))))
                {
                    classSpec.PublicMethods.Add(MethodSpec.LoadFromSyntaxNode(node));
                }
            }

            // Parse constructors
            foreach (ConstructorDeclarationSyntax node in classNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.ConstructorDeclaration)))
            {
                if (node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.PublicKeyword)) ||
                    (classSpec.ProtectedItemsConsideredPublic && node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ProtectedKeyword))))
                {
                    classSpec.PublicConstructors.Add(ConstructorSpec.LoadFromSyntaxNode(node));
                }
            }

            // Parse fields
            foreach (FieldDeclarationSyntax node in classNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.FieldDeclaration)))
            {
                if (node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.PublicKeyword)) ||
                    (classSpec.ProtectedItemsConsideredPublic && node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ProtectedKeyword))))
                {
                    classSpec.PublicFields.Add(FieldSpec.LoadFromSyntaxNode(node));
                }
            }

            // Parse properties
            foreach (PropertyDeclarationSyntax node in classNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.PropertyDeclaration)))
            {
                if (node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.PublicKeyword)) ||
                    (classSpec.ProtectedItemsConsideredPublic && node.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.ProtectedKeyword))))
                {
                    classSpec.PublicProperties.Add(PropertySpec.LoadFromSyntaxNode(node));
                }
            }

            return(classSpec);
        }
Esempio n. 22
0
 /// <summary>
 /// Create a MIX instruction with the specified opcode, fieldspec, mnemonic, tickCount, executor and validator.
 /// The instruction's MetaFieldSpec will indicate that for this instruction, fieldspecs are forbidden in the MIXAL code.
 /// </summary>
 public MixInstruction(byte opcode, FieldSpec fieldSpec, string mnemonic, int tickCount, Executor executor, Validator validator)
     : this(opcode, fieldSpec, new MetaFieldSpec(), mnemonic, tickCount, executor, validator)
 {
 }
Esempio n. 23
0
 private WordField(FieldSpec fieldSpec, int byteCount)
     : base(byteCount)
 {
     mFieldSpec = fieldSpec;
 }
Esempio n. 24
0
        static void Main(string[] args)
        {
            var srcPath   = "C:/Users/v-chph/Downloads/DatCon-master/DatCon/src/DatConRecs/";
            var fileNames = Directory.GetFiles(srcPath, "*.java", SearchOption.AllDirectories);

            var typeLookup = new Dictionary <string, string>
            {
                { ".getByte(", "byte" },
                { ".getUnsignedByte(", "byte" },
                { ".getUnsignedInt(", "UInt32" },
                { ".getUnsignedShort(", "UInt16" },
                { ".getFloat(", "float" },
                { ".getShort(", "short" },
                { ".getInt(", "int" },
                { ".getDouble(", "double" },
                { ".getString(", "string" },
                { ".getCleanString(", "string" }
            };
            var specString = "new RecClassSpec(";

            var recSpecs = new Dictionary <string, RecordSpec>();

            foreach (var fn in fileNames)
            {
                var lines = File.ReadAllLines(fn);
                foreach (var l in lines)
                {
                    if (l.Contains(specString))
                    {
                        if (l.Trim().StartsWith("//"))
                        {
                            continue;
                        }
                        var ia = l.IndexOf(specString) + specString.Length;
                        var ib = l.IndexOf(".class");
                        if (ib < 0)
                        {
                            continue;
                        }

                        var name  = l.Substring(ia, ib - ia);
                        var parts = l.Substring(ib).Split(new char[] { ',', ')' });
                        if (parts.Length < 3)
                        {
                            continue;
                        }
                        var id  = parts[1].Trim();
                        var len = parts[2].Trim();
                        Console.WriteLine("{0},{1},{2}", name, id, len);
                        var cleanName = name.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_' });
                        var dirName   = Path.GetFileName(Directory.GetParent(fn).ToString());
                        recSpecs[name] = new RecordSpec {
                            name      = cleanName, id = id, len = len,
                            definedIn = dirName
                        };
                    }
                }
            }

            var allLines     = new List <string>();
            var validLines   = new List <string>();
            var invalidLines = new List <string>();

            validLines.Add("definedIn,groupName,groupId,groupLen,name,offset,type,validParse,sourceLine");
            foreach (var fn in fileNames)
            {
                var lines = File.ReadAllLines(fn);
                foreach (var l in lines)
                {
                    foreach (var key in typeLookup.Keys)
                    {
                        if (l.Trim().StartsWith("//"))
                        {
                            continue;
                        }
                        if (l.Contains(key))
                        {
                            var name   = l.Split('=')[0].Trim();
                            var ia     = l.IndexOf(key) + key.Length;
                            var ib     = l.IndexOf(')', ia);
                            var offStr = l.Substring(ia, ib - ia);

                            var valid = true;
                            int off;
                            if (typeLookup[key] == "string")
                            {
                                off = 0;
                            }
                            else if (!int.TryParse(offStr, out off))
                            {
                                valid = false;
                            }
                            var groupName = Path.GetFileNameWithoutExtension(fn);
                            var recSpec   = new RecordSpec {
                                name = "unk", id = "0", len = "0"
                            };

                            if (recSpecs.Keys.Contains(groupName))
                            {
                                recSpec = recSpecs[groupName];
                            }
                            else
                            {
                                valid = false;
                            }

                            if (name.StartsWith("double "))//special case for a few lines that are defined like this.
                            {
                                name = name.Substring("double ".Length);
                            }

                            //groupName = groupName.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_' });

                            var outLine = String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", Path.GetFileName(Directory.GetParent(fn).ToString()), recSpec.name, recSpec.id, recSpec.len, name, off, typeLookup[key], valid, l.Trim());

                            if (recSpec.id == "65533")
                            {
                            }

                            if (valid)
                            {
                                var field = new FieldSpec()
                                {
                                    name = name, offset = off, type = typeLookup[key]
                                };
                                recSpec.fields.Add(field);

                                validLines.Add(outLine);
                            }
                            else
                            {
                                invalidLines.Add(outLine);
                            }
                        }
                    }
                }
            }
            var destPath = "../../../TelloLib/";

            File.WriteAllLines(destPath + "parsedRecSpecs.csv", validLines.Concat(invalidLines).ToArray());

            string json = JsonConvert.SerializeObject(recSpecs.Values.ToArray(), Formatting.Indented);

            File.WriteAllText(destPath + "parsedRecSpecs.json", json);

            //var xx = JsonConvert.DeserializeObject(json);
        }
Esempio n. 25
0
 protected static CreateFieldRequest FieldCreateRequestFromSpec(FieldSpec spec)
 {
     return(CreateFieldRequest.Builder().With((ResourceId)(int)spec.Resource, (FieldType)(int)spec.FieldType, spec.Label == null ? spec.Key.ToString() : spec.Label).Build().Content);
 }
Esempio n. 26
0
 /// <summary>
 /// Creates a MetaFieldSpec that describes an Optional fieldspec, with a specified default value.
 /// It can also specifies if the fieldspec is a range, like (0:5), or a value, like (19).
 /// </summary>
 /// <param name="fieldIsRange"></param>
 /// <param name="defaultFieldSpec"></param>
 public MetaFieldSpec(bool fieldIsRange, FieldSpec defaultFieldSpec)
     : this(Presences.Optional, fieldIsRange, defaultFieldSpec)
 {
 }
Esempio n. 27
0
        private FieldSpec UniteSubSpecsForField(OpCodeFamilyKb fkb, String fname)
        {
            // 1. Create a field spec
            var fspecs = fkb.SubSpecs.ToDictionary(kvp => kvp.Key, kvp =>
                                                   kvp.Value.Fields.Values.SingleOrDefault(f => f.Name == fname) ?? new FieldSpec {
                Name = fname
            });
            var united = new FieldSpec();

            united.Name = fname;

            // 2. Find out an unified type (it should be specified at least once and every time the same)
            var ftypes = fspecs.Values.Select(v => v.Type);
            var ftype  = ftypes.Where(v => v != null).Distinct().Single();

            united.Type = ftype;

            // 3. Normalize initializers for every opcode (replace null with default(T))
            foreach (var spec in fspecs.Values)
            {
                var init = spec.Initializer;
                if (init.IsNullOrEmpty())
                {
                    spec.Initializer = "default(" + ftype.GetCSharpRef(ToCSharpOptions.ForCodegen) + ")";
                }
            }

            // 4. Now assemble all initializers into a single language construct
            var initGroups = fspecs.Where(kvp => kvp.Value.Initializer.IsNeitherNullNorEmpty())
                             .GroupBy(kvp => kvp.Value.Initializer, kvp => kvp.Key);

            (initGroups.Count() >= 1).AssertTrue();

            // 4.1. There's only 1 possible opcode => 1 possible initializer
            // or maybe all initializers for different opcodes are the same.
            // This means that we can reuse its expression and assign the value to the field. EZ!
            if (initGroups.Count() == 1)
            {
                var initCode = initGroups.Single().Key;
                if (!initCode.EndsWith(";"))
                {
                    initCode = initCode + ";";
                }
                initCode           = fname + " = " + initCode;
                united.Initializer = (initCode + Environment.NewLine);
            }
            // 4.2. There are multiple distinct initializers
            // Thus, we're forced to implement a switch depending on the opcode.
            // Default will crash the switch since we're unprepared to it.
            else
            {
                var init = new StringBuilder();
                init.AppendLine(String.Format("switch(({0})OpSpec.OpCode.Value)",
                                              typeof(UInt16).GetCSharpRef(ToCSharpOptions.ForCodegen)));
                init.AppendLine("{");

                foreach (var initGroup in initGroups)
                {
                    foreach (var opcode in initGroup)
                    {
                        var @case = "case " + opcode.GetCSharpByteSequence() + ":";
                        @case = @case + " //" + opcode.Name;
                        init.AppendLine(@case.Indent());
                    }

                    var initCode = initGroup.Key;
                    if (!initCode.EndsWith(";"))
                    {
                        initCode = initCode + ";";
                    }
                    initCode = fname + " = " + initCode;
                    init.AppendLine(initCode.Indent().Indent());
                    init.AppendLine("break;".Indent().Indent());
                }

                init.AppendLine("default:".Indent());
                var throwOnUnknown = String.Format("throw {0}.Fail();",
                                                   typeof(AssertionHelper).GetCSharpRef(ToCSharpOptions.ForCodegen));
                init.AppendLine(throwOnUnknown.Indent().Indent());

                init.AppendLine("}");
                united.Initializer = init.ToString();
            }

            return(united);
        }
Esempio n. 28
0
        static public RecordSpec[] Parse(byte[] data)
        {
            var records = new List <RecordSpec>();

            int pos = 0;

            //A packet can contain more than one record.
            while (pos < data.Length - 2) //-2 for CRC bytes at end of packet.
            {
                if (data[pos] != 'U')     //Check magic byte
                {
                    pos += 1;
                    //Console.WriteLine("PARSE ERROR!!!");
                    continue;
                }
                var len = data[pos + 1];
                if (data[pos + 2] != 0)//Should always be zero (so far)
                {
                    pos += 1;
                    //Console.WriteLine("SIZE OVERFLOW!!!");
                    break;
                }
                var crc = data[pos + 3];
                //todo Check crc.

                var  id       = BitConverter.ToUInt16(data, pos + 4);
                var  xorBuf   = new byte[256];
                byte xorValue = data[pos + 6];


                var recSpecId = /*len + "_" +*/ id.ToString();
                //Console.WriteLine(recSpecId);
                if (recordSpecLookup.Keys.Contains(recSpecId))
                {
                    for (var i = 0; i < len; i++)//Decrypt payload.
                    {
                        xorBuf[i] = (byte)(data[pos + i] ^ xorValue);
                    }
                    int baseOffset = 10;
                    var record     = recordSpecLookup[recSpecId];

                    var newRecord = new RecordSpec()
                    {
                        name      = record.name,
                        id        = record.id,
                        definedIn = record.definedIn,
                        len       = record.len,
                        fields    = new List <FieldSpec>()
                    };

                    var fields = record.fields;
                    foreach (var field in fields)
                    {
                        var newField = new FieldSpec()
                        {
                            name   = field.name,
                            type   = field.type,
                            offset = field.offset,
                        };
                        switch (field.type)
                        {
                        case "byte":
                            field.value = xorBuf[baseOffset + field.offset];
                            break;

                        case "short":
                            field.value = BitConverter.ToInt16(xorBuf, baseOffset + field.offset);
                            break;

                        case "UInt16":
                            field.value = BitConverter.ToUInt16(xorBuf, baseOffset + field.offset);
                            break;

                        case "int":
                            field.value = BitConverter.ToInt32(xorBuf, baseOffset + field.offset);
                            break;

                        case "UInt32":
                            field.value = BitConverter.ToUInt32(xorBuf, baseOffset + field.offset);
                            break;

                        case "float":
                            field.value = BitConverter.ToSingle(xorBuf, baseOffset + field.offset);
                            break;

                        case "double":
                            field.value = BitConverter.ToDouble(xorBuf, baseOffset + field.offset);
                            break;

                        case "string":
                            field.value = System.Text.Encoding.Default.GetString(xorBuf, baseOffset + field.offset, len - 15);
                            break;
                        }
                        newField.value = field.value;
                        newRecord.fields.Add(newField);
                    }
                    //Console.WriteLine(record.ToString());

                    records.Add(newRecord);
                }
                else
                {
                    Console.WriteLine("Not found:" + recSpecId + " len:" + len);
                }
                pos += len;
            }
            return(records.ToArray());
        }
Esempio n. 29
0
 MetaFieldSpec(Presences presence, bool fieldIsRange, FieldSpec defaultFieldSpec)
 {
     Presence         = presence;
     FieldIsRange     = fieldIsRange;
     DefaultFieldSpec = defaultFieldSpec;
 }
Esempio n. 30
0
    public SerializedObjectFields(Type t, ISerializableObjectFieldSerializerFactory factory, bool forNetwork)
    {
        if (!typeof(Actor).IsAssignableFrom(t))
        {
            throw new ObjectSerializationException("Type is not a serializable object!");
        }

        for (; t != typeof(object); t = t.BaseType)
        {
            var members = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);

            foreach (var field in members)
            {
                if (field.DeclaringType != t)
                {
                    continue;
                }

                var attributes = System.Attribute.GetCustomAttributes(field);

                if (forNetwork)
                {
                    foreach (var attr in attributes)
                    {
                        var replication = attr as Replicated;
                        if (replication != null)
                        {
                            var serializedField = new FieldSpec();
                            serializedField.field             = field;
                            serializedField.fieldID           = (ushort)++_nextFieldID;
                            serializedField.replication       = replication;
                            serializedField.isObjectReference = typeof(SerializableObject).IsAssignableFrom(field.FieldType);
                            serializedField.serializer        = factory.GetSerializerForField(serializedField);

                            if (replication.Notify != null)
                            {
                                serializedField.onRep = t.GetMethod(replication.Notify, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.ExactBinding, null, System.Type.EmptyTypes, null);
                                if (serializedField.onRep == null)
                                {
                                    throw new MissingMemberException(t.FullName + " is missing replication notification method " + serializedField.onRep + " specified by replicated field " + field.Name);
                                }
                            }

                            _serializedFields.Add(serializedField.fieldID, serializedField);
                        }
                    }
                }
                else
                {
                    bool isTransient = true;
                    foreach (var attr in attributes)
                    {
                        isTransient = !(attr is UnityEngine.SerializeField);
                        if (!isTransient)
                        {
                            break;
                        }
                    }

                    if (!isTransient)
                    {
                        var serializedField = new FieldSpec();
                        serializedField.field             = field;
                        serializedField.fieldID           = (ushort)++_nextFieldID;
                        serializedField.serializer        = factory.GetSerializerForField(serializedField);
                        serializedField.isObjectReference = typeof(SerializableObject).IsAssignableFrom(field.FieldType);
                        _serializedFields.Add(serializedField.fieldID, serializedField);
                    }
                }
            }
        }

        if (_serializedFields.Values.Count > MAX_REPLICATED_FIELDS)
        {
            throw new ObjectSerializationException("Too many replicated fields!");
        }
    }