예제 #1
0
 public MemoryTier this[Fld fld]
 {
     get
     {
         return(this[fld.AssertNotNull().Field]);
     }
 }
예제 #2
0
 public void clear()
 {
     try
     {
         if (namedGroups != null)
         {
             foreach (Grp g in namedGroups.Values)
             {
                 g.indexedItems.Clear();
                 g.namedItems.Clear();
                 g.indexedItems = null;
                 g.namedItems   = null;
             }
             namedGroups.Clear();
         }
         if (stack != null)
         {
             stack.Clear();
             stack = null;
         }
         if (scannedField != null)
         {
             scannedField.clear();
             scannedField = null;
         }
     }
     catch (Exception e)
     {
     }
 }
예제 #3
0
 public MemoryTier this[Fld fld]
 {
     get
     {
         return this[fld.AssertNotNull().Field];
     }
 }
        /// <summary>
        /// Resolves the links.
        /// </summary>
        /// <param name="Twin">The twin.</param>
        public void ResolveLinks(Table NewParent)
        {
            m_Parent = NewParent;

            foreach (TableField Fld in m_Fields)
            {
                Fld.ResolveLinks(NewParent);
            }
        }
예제 #5
0
        protected override void TraverseFld(Fld fld)
        {
            var is_static     = fld.Field.IsStatic();
            var is_kernel_fld = _kernel.DeclaringType.Hierarchy().Contains(fld.Field.DeclaringType);

            if (!is_static && !is_kernel_fld)
            {
                _ptx.ld(fld.This);
            }
            _ptx.fld(fld);
        }
예제 #6
0
        public FieldCollection Clone()
        {
            FieldCollection Res = new FieldCollection();

            foreach (Field Fld in this)
            {
                Res.Add(Fld.Clone());
            }

            return(Res);
        }
예제 #7
0
        protected internal override void TraverseFld(Fld fld)
        {
            var ass = fld.Parent as Assign;

            (ass != null && ass.Lhs == fld).AssertFalse();

            if (fld.This != null)
            {
                Traverse(fld.This);
            }
            il.ldfld(fld.Field);
        }
예제 #8
0
 public virtual Row Clone()
 {
     Lfx.Data.Row Res = new Lfx.Data.Row();
     Res.DataTable = this.DataTable;
     foreach (Lazaro.Orm.Data.ColumnValue Fld in this.Fields)
     {
         Res.Fields.Add(Fld.Clone());
     }
     Res.IsModified = this.IsModified;
     Res.IsNew      = this.IsNew;
     return(Res);
 }
예제 #9
0
        protected internal override void TraverseFld(Fld fld)
        {
            if (fld.Member.IsStatic())
            {
                fld.This.AssertNull();
                _writer.Write(fld.Member.DeclaringType.GetCSharpRef(ToCSharpOptions.Informative));
            }
            else
            {
                Traverse(fld.This);
            }

            var t_this = fld.This.Type();
            var is_ptr = t_this != null && t_this.IsPointer;

            _writer.Write(is_ptr ? "->" : ".");

            _writer.Write(fld.Member.Name);
        }
예제 #10
0
        /// <summary>
        /// Retrieve a tuple of (Field, 2DAColumnAttribute) for each public
        /// instance field that is .2DA serializable in the generic type T.
        /// If the type has no .2DA serializable fields, then an
        /// InvalidOperationException is raised.
        /// </summary>
        /// <param name="T">Supplies the type to retrieve the data for.</param>
        /// <returns>A map of fields to .2DA serialization data.</returns>
        public static IEnumerable <ColumnFieldInfo> GetColumnFieldInfo(Type T)
        {
            var ColumnFields = T.GetMembers(BindingFlags.Public | BindingFlags.Instance)
                               .Select(Fld => new ColumnFieldInfo {
                Field = Fld, Column = (TwoDAColumnAttribute)(Fld.GetCustomAttributes(typeof(TwoDAColumnAttribute), false).FirstOrDefault())
            })
                               .Where(ColFld => ColFld.Column != null && ColFld.ValueType != null);

            //
            // The type should have at least one serializable field.
            //

            if (ColumnFields.Any() == false)
            {
                throw new InvalidOperationException("Type " + T.ToString() + " is not .2DA serializable.");
            }

            return(ColumnFields);
        }
예제 #11
0
        public Emitter fld(Fld fld)
        {
            var fi = fld.Field;

            if (fi.DeclaringType.IsCudaVector())
            {
                var target = pop_expr();
                var mod    = typeof(Mod).GetFields(BF.PublicStatic).AssertSingle(p => p.Name == fi.Name).GetValue(null).AssertCast <Mod>();
                var modded = target.mod(mod);
                push(modded);
            }
            else if (Kernel.DeclaringType.Hierarchy().Contains(fi.DeclaringType))
            {
                var layout = _alloc[fld];
                push(layout);
            }
            else
            {
                throw AssertionHelper.Fail();
            }

            return(this);
        }
 protected internal override Node TransformFld(Fld fld)
 {
     return Dispatch(fld);
 }
 protected internal override void TraverseFld(Fld fld)
 {
     Dispatch(fld);
 }
예제 #14
0
        public Layout this[Fld fld]
        {
            get
            {
                fld.AssertNotNull();

                var fi = fld.Field;
                fi.AssertNotNull();
                _kernel.DeclaringType.Hierarchy().Contains(fi.DeclaringType).AssertTrue();

                return _fi_cache.GetOrCreate(fi, () =>
                {
                    var t = fi.FieldType;
                    if (_scheme[fi] == MemoryTier.Private)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Shared)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Global)
                    {
                        if (fi.FieldType.IsArray)
                        {
                            var p_raw = new Var{Space = space.param, Name = "parm_" + fi.Name, Type = typeof(uint)};
                            var raw = new Reg{Type = typeof(uint), Name = fi.Name};
                            _ptx.Add(new ld{ss = space.param, type = typeof(uint), d = raw, a = p_raw});

                            var p_height = new Var{Space = space.param, Name = "parm_" + fi.Name + "_height", Type = typeof(int)};
                            var height = new Reg{Type = typeof(int), Name = fi.Name + "_height"};
                            _ptx.Add(new ld{ss = space.param, type = typeof(int), d = height, a = p_height});

                            var p_width = new Var{Space = space.param, Name = "parm_" + fi.Name + "_width", Type = typeof(int)};
                            var width = new Reg{Type = typeof(int), Name = fi.Name + "_width"};
                            _ptx.Add(new ld{ss = space.param, type = typeof(int), d = width, a = p_width});

                            _params.AddElements(p_raw, p_height, p_width);
                            return new ArrayLayout(fld, space.global, raw, new []{height, width}.ToReadOnly());
                        }
                        else
                        {
                            (t.IsCudaPrimitive() || t.IsCudaVector()).AssertTrue();

                            var p_value = new Var{Space = space.param, Name = "parm_" + fi.Name, Type = t};
                            var value = new Reg{Type = t, Name = fi.Name};
                            _ptx.Add(new ld{ss = space.param, type = t, d = value, a = p_value});

                            _params.Add(p_value);
                            return new SlotLayout(fld, value);
                        }
                    }
                    else
                    {
                        throw AssertionHelper.Fail();
                    }
                });
            }
        }
예제 #15
0
 protected internal override Node TransformFld(Fld fld)
 {
     return(Dispatch(fld));
 }
예제 #16
0
      public void ReadCriteria(ref string Criteria, ref string CritFormula, DataTable dtObject)
      {
          int    i, Sort;
          string Fld, Op, Link, T;

          string[] Crit;
          int      Typ, Idx;
          string   Value;
          DateTime Vdate = new DateTime();

          if ((_RepCriteria != ""))
          {
              Crit = Regex.Split(_RepCriteria, ";");
              //Crit = _RepCriteria.Split(';');
              for (i = 0; i <= (Crit.Length - 1); i++)
              {
                  if ((Crit[i].ToString().Trim() == ""))
                  {
                      // TODO: Continue For... Warning!!! not translated
                  }

                  Fld   = DataTools.GetStrPart(Crit[i].ToString(), 0, "^^^");
                  Op    = DataTools.GetStrPart(Crit[i].ToString(), 1, "^^^");
                  Value = DataTools.GetStrPart(Crit[i].ToString(), 2, "^^^");
                  Sort  = (DataTools.GetStrPart(Crit[i].ToString(), 3, "^^^") == "" ? 0: Int32.Parse(DataTools.GetStrPart(Crit[i].ToString(), 3, "^^^")));
                  Link  = DataTools.GetStrPart(Crit[i].ToString(), 4, "^^^");
                  Idx   = DataTools.GetStrSerial(DataTools.ReadField(dtObject.Rows[0]["CriteriaFields"]), Fld);
                  T     = DataTools.GetStrPart(DataTools.ReadField(dtObject.Rows[0]["CriteriaFieldsTables"]), Idx);
                  //Val(GenericMethods.GetStrPart(GenericMethods.ReadField(dtObject.Rows(0)("CriteriaFieldsTypes")), Idx))
                  Typ = (DataTools.GetStrPart(DataTools.ReadField(dtObject.Rows[0]["CriteriaFieldsTypes"]), Idx) == ""?0: Int32.Parse(DataTools.GetStrPart(DataTools.ReadField(dtObject.Rows[0]["CriteriaFieldsTypes"]), Idx)));
                  if ((Typ == 7))
                  {
                      Value = Value.Replace("-", "/").Replace(" ", "/").Replace("\\", "/");
                      Vdate = new DateTime(Int32.Parse(Value.Split('/')[2]), Int32.Parse(Value.Split('/')[1]), Int32.Parse(Value.Split('/')[0]));
                  }

                  //if ((Sort != 0))//later
                  //{
                  //    rpt.DataDefinition.SortFields.Item[rpt.DataDefinition.SortFields.Count].SortDirection = ((Sort == 1) ? SortDirection.AscendingOrder : SortDirection.DescendingOrder);
                  //    if ((T.Substring(0, 1) == "@"))
                  //    {
                  //        rpt.DataDefinition.SortFields.Item[rpt.DataDefinition.SortFields.Count].Field = rpt.DataDefinition.FormulaFields[Fld];
                  //    }
                  //    else
                  //    {
                  //        rpt.DataDefinition.SortFields.Item[rpt.DataDefinition.SortFields.Count].Field = rpt.Database.Tables[dtObject.Rows[0]["Source"].ToString()].Fields[Fld];
                  //    }

                  //}

                  if ((T == "@@"))
                  {
                      if ((Typ == 7))
                      {
                          rpt.DataDefinition.FormulaFields[Fld].Text = ("Date (" + (Vdate.Year + ("," + (Vdate.Month + ("," + (Vdate.Day + ")"))))));
                      }
                      else if ((Typ == 3))
                      {
                          rpt.DataDefinition.FormulaFields[Fld].Text = Value;
                      }
                      else
                      {
                          rpt.DataDefinition.FormulaFields[Fld].Text = ("\'" + (Value + "\'"));
                      }
                  }
                  else if ((T.Substring(0, 1) == "@"))
                  {
                      if ((T == "@"))
                      {
                          T = ("@" + dtObject.Rows[0]["Source"]);
                      }

                      T = T.Substring(1);
                      if ((Value == "NULL"))
                      {
                          CritFormula = (CritFormula + ("(IsNull({" + (((Fld.Substring(0, 1) == "@") ? Fld : (T + ("." + Fld))) + ("})= " + ((Op == "<>") ? "FALSE" : "TRUE")))));
                      }
                      else
                      {
                          CritFormula = (CritFormula + ("({" + (((Fld.Substring(0, 1) == "@") ? Fld : (T + ("." + Fld))) + "} ")));
                          if ((Typ == 7))
                          {
                              CritFormula = (CritFormula + (Op + (" Date (" + (Vdate.Year + ("," + (Vdate.Month + ("," + (Vdate.Day + ")"))))))));
                          }
                          else if ((Typ == 3))
                          {
                              CritFormula = (CritFormula + (Op + (" " + Value)));
                          }
                          else
                          {
                              CritFormula = (CritFormula + (Op + (" \'" + (Value + "\'"))));
                          }
                      }

                      CritFormula = (CritFormula + (") " + (Link + " ")));
                  }
                  else
                  {
                      Value = Value.Replace("*", "%");
                      if ((Value == "NULL"))
                      {
                          Criteria = (Criteria + (((Op == "<>") ? " NOT" : "") + ("(" + (((T == "") ? Fld : (T + ("." + Fld))) + " IS Null"))));
                      }
                      else
                      {
                          Value    = (((Typ == 3) ? "" : "\'") + (((Typ == 7) ? string.Format("MM/dd/yyyy", Vdate) : Value) + ((Typ == 3) ? "" : "\'")));
                          Criteria = (Criteria + ("(" + (((T == "") ? "" : (T + ".")) + (Fld + (" " + (Op + (" " + Value)))))));
                      }

                      Criteria = (Criteria + (") " + (Link + " ")));
                  }
              }
          }

          if ((CritFormula != ""))
          {
              CritFormula = ("(" + (CritFormula.Substring(0, (CritFormula.Length - 4)) + ")"));
              CritFormula = CritFormula.Replace(" AND ", ") AND (");
          }

          if ((DataTools.ReadField(dtObject.Rows[0]["FilterOnFormula"]) != ""))
          {
              CritFormula = (CritFormula + (((CritFormula == "") ? "" : " AND ") + ("(" + (DataTools.ReadField(dtObject.Rows[0]["FilterOnFormula"]) + ")"))));
          }

          if ((Criteria != ""))
          {
              Criteria = ("(" + (Criteria.Substring(0, (Criteria.Length - 4)) + ")"));
              Criteria = Criteria.Replace(") AND (", ")) AND ((");
          }

          if ((DataTools.ReadField(dtObject.Rows[0]["FilterOn"]) != ""))
          {
              Criteria = (Criteria + (((Criteria == "") ? "" : " AND ") + ("(" + (DataTools.ReadField(dtObject.Rows[0]["FilterOn"]) + ")"))));
          }

          Fld = ApplyBranchPermissions(dtObject);
          if ((Fld != ""))
          {
              if ((Fld.IndexOf("{")) == 0)
              {
                  CritFormula = (CritFormula + (((CritFormula == "") ? "" : " AND ") + ("(" + (Fld + ")"))));
              }
              else
              {
                  Criteria = (Criteria + (((Criteria == "") ? "" : " AND ") + ("(" + (Fld + ")"))));
              }
          }

          Fld = ApplySalesmanPermissions(dtObject);
          if ((Fld != ""))
          {
              if ((Fld.IndexOf("{")) == 0)
              {
                  CritFormula = (CritFormula + (((CritFormula == "") ? "" : " AND ") + ("(" + (Fld + ")"))));
              }
              else
              {
                  Criteria = (Criteria + (((Criteria == "") ? "" : " AND ") + ("(" + (Fld + ")"))));
              }
          }
      }
예제 #17
0
 protected internal virtual Node TransformFld(Fld fld)
 {
     return(fld.AcceptTransformer(this, true));
 }
        protected internal override void TraverseFld(Fld fld)
        {
            if (fld.Member.IsStatic())
            {
                fld.This.AssertNull();
                _writer.Write(fld.Member.DeclaringType.GetCSharpRef(ToCSharpOptions.Informative));
            }
            else
            {
                Traverse(fld.This);
            }

            var t_this = fld.This.Type();
            var is_ptr = t_this != null && t_this.IsPointer;
            _writer.Write(is_ptr ? "->" : ".");

            _writer.Write(fld.Member.Name);
        }
 protected internal override void TraverseFld(Fld fld)
 {
     Traverse(fld.This);
     Types.Add(fld, fld.Field == null ? null : fld.Field.FieldType);
 }
 protected internal override void TraverseFld(Fld fld)
 {
     Traverse(fld.This);
     Types.Add(fld, fld.Field == null ? null : fld.Field.FieldType);
 }
예제 #21
0
        protected override void TraverseFld(Fld fld)
        {
            var ass = fld.Parent as Assign;
            (ass != null && ass.Lhs == fld).AssertFalse();

            if (fld.This != null) Traverse(fld.This);
            il.ldfld(fld.Field);
        }
예제 #22
0
 protected override void TraverseFld(Fld fld)
 {
     var is_static = fld.Field.IsStatic();
     var is_kernel_fld = _kernel.DeclaringType.Hierarchy().Contains(fld.Field.DeclaringType);
     if (!is_static && !is_kernel_fld) _ptx.ld(fld.This);
     _ptx.fld(fld);
 }
 protected internal override void TraverseFld(Fld fld)
 {
     Dispatch(fld);
 }
 protected internal virtual void TraverseFld(Fld fld)
 {
     fld.Unsupported();
 }
예제 #25
0
        public Layout this[Fld fld]
        {
            get
            {
                fld.AssertNotNull();

                var fi = fld.Field;
                fi.AssertNotNull();
                _kernel.DeclaringType.Hierarchy().Contains(fi.DeclaringType).AssertTrue();

                return(_fi_cache.GetOrCreate(fi, () =>
                {
                    var t = fi.FieldType;
                    if (_scheme[fi] == MemoryTier.Private)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Shared)
                    {
                        if (t.IsArray)
                        {
                            throw AssertionHelper.Fail();
                        }
                        else
                        {
                            throw AssertionHelper.Fail();
                        }
                    }
                    else if (_scheme[fi] == MemoryTier.Global)
                    {
                        if (fi.FieldType.IsArray)
                        {
                            var p_raw = new Var {
                                Space = space.param, Name = "parm_" + fi.Name, Type = typeof(uint)
                            };
                            var raw = new Reg {
                                Type = typeof(uint), Name = fi.Name
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = typeof(uint), d = raw, a = p_raw
                            });

                            var p_height = new Var {
                                Space = space.param, Name = "parm_" + fi.Name + "_height", Type = typeof(int)
                            };
                            var height = new Reg {
                                Type = typeof(int), Name = fi.Name + "_height"
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = typeof(int), d = height, a = p_height
                            });

                            var p_width = new Var {
                                Space = space.param, Name = "parm_" + fi.Name + "_width", Type = typeof(int)
                            };
                            var width = new Reg {
                                Type = typeof(int), Name = fi.Name + "_width"
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = typeof(int), d = width, a = p_width
                            });

                            _params.AddElements(p_raw, p_height, p_width);
                            return new ArrayLayout(fld, space.global, raw, new [] { height, width }.ToReadOnly());
                        }
                        else
                        {
                            (t.IsCudaPrimitive() || t.IsCudaVector()).AssertTrue();

                            var p_value = new Var {
                                Space = space.param, Name = "parm_" + fi.Name, Type = t
                            };
                            var value = new Reg {
                                Type = t, Name = fi.Name
                            };
                            _ptx.Add(new ld {
                                ss = space.param, type = t, d = value, a = p_value
                            });

                            _params.Add(p_value);
                            return new SlotLayout(fld, value);
                        }
                    }
                    else
                    {
                        throw AssertionHelper.Fail();
                    }
                }));
            }
        }
 protected internal virtual Node TransformFld(Fld fld) { return fld.AcceptTransformer(this, true); }
예제 #27
0
 protected internal virtual void TraverseFld(Fld fld) { fld.Unsupported(); } 
예제 #28
0
        public Emitter fld(Fld fld)
        {
            var fi = fld.Field;
            if (fi.DeclaringType.IsCudaVector())
            {
                var target = pop_expr();
                var mod = typeof(Mod).GetFields(BF.PublicStatic).AssertSingle(p => p.Name == fi.Name).GetValue(null).AssertCast<Mod>();
                var modded = target.mod(mod);
                push(modded);
            }
            else if (Kernel.DeclaringType.Hierarchy().Contains(fi.DeclaringType))
            {
                var layout = _alloc[fld];
                push(layout);
            }
            else
            {
                throw AssertionHelper.Fail();
            }

            return this;
        }
        public bool readItem()
        {
            int wireTag;
            int wireType;
            int wireFieldNumber;
            Grp group = null;
            Itm item = null;

            if (scannedField == null)
            {
                scannedField = new Fld();
            }

            do
            {
                scannedField.clear();

                if (this.eos)
                {
                    return false;
                }

                wireTag = read_rawvarint32();
                if (wireTag == 0)
                {
                    return false;
                }
                wireType = wireTag & TAG_TYPE_MASK;
                //wireFieldNumber = wireTag >>> TAG_TYPE_BITS;
                wireFieldNumber = (int)((uint)wireTag >> TAG_TYPE_BITS);

                item = null;

                switch (wireType)
                {
                    case RAW_TYPE_END_GROUP:
                        {
                            item = stack.Pop();
                            scannedField.name = item.name;
                            scannedField.level = stack.Count;
                            scannedField.index = item.id;
                            scannedField.isa_name = item.isa.name;
                            scannedField.type_name = "end_group";
                            scannedField.is_end = true;
                        }
                        break;
                    case RAW_TYPE_FIXED32:
                        {
                            item = peekIsa(false).indexedItems[wireFieldNumber];
                            scannedField.name = item.name;
                            scannedField.level = stack.Count;
                            scannedField.index = item.id;
                            switch (item.type)
                            {
                                case ITM_TYPE_FIXED32:
                                    scannedField.type_name = "fixed32";
                                    scannedField.value = read_rawlittleendian32();
                                    break;
                                case ITM_TYPE_SINGLE:
                                    scannedField.type_name = "single";
                                    //scannedField.value = Float.intBitsToFloat(read_rawlittleendian32());
                                    scannedField.value = BitConverter.ToSingle(BitConverter.GetBytes(read_rawlittleendian32()), 0);
                                    break;
                                default:
                                    throw new Exception("bad type for fixed32");
                            }
                        }
                        break;
                    case RAW_TYPE_FIXED64:
                        {
                            item = peekIsa(false).indexedItems[wireFieldNumber];
                            scannedField.name = item.name;
                            scannedField.level = stack.Count;
                            scannedField.index = item.id;
                            switch (item.type)
                            {
                                case ITM_TYPE_FIXED64:
                                    scannedField.type_name = "fixed64";
                                    scannedField.value = read_rawlittleendian64();
                                    break;
                                case ITM_TYPE_DOUBLE:
                                    scannedField.type_name = "double";
                                    //scannedField.value = Double.longBitsToDouble(read_rawlittleendian64());
                                    scannedField.value = BitConverter.Int64BitsToDouble(read_rawlittleendian64());
                                    break;
                                default:
                                    throw new Exception("bad type for fixed64");
                            }
                        }
                        break;
                    case RAW_TYPE_LENGTH_DELIMITED:
                        {
                            item = peekIsa(false).indexedItems[wireFieldNumber];
                            scannedField.name = item.name;
                            scannedField.level = stack.Count;
                            scannedField.index = item.id;
                            switch (item.type)
                            {
                                case ITM_TYPE_STRING:
                                {
                                    scannedField.type_name = "string";
                                    scannedField.value = read_rawstring() ;
                                }
                                    break;
                                case ITM_TYPE_BYTES:
                                {
                                    scannedField.type_name = "bytes";
                                    int size = read_rawvarint32();
                                    byte[] bytes = read_rawbytes(size);
                                    scannedField.value = bytes;
                                }
                                    break;
                                default:
                                    throw new Exception("bad type for length delimited");
                            }
                        }
                        break;
                    case RAW_TYPE_SCHEMA:
                        switch (wireFieldNumber)
                        {
                            case 1:
                                {
                                    group = new Grp();
                                    group.type = (byte)read_rawbyte();
                                    group.name = read_rawstring() ;
                                    namedGroups.Add(group.name, group);
                                    if (version == null)
                                    {
                                        version = group;
                                    }
                                }
                                break;
                            case 2:
                                {
                                    item = new Itm();
                                    item.type = (byte)read_rawbyte();
                                    item.name = read_rawstring() ;
                                    group = namedGroups[read_rawstring()] ;
                                    item.id = ++group.count;
                                    group.namedItems.Add(item.name, item);
                                    group.indexedItems.Add(item.id, item);
                                }
                                break;
                            case 3:
                                {
                                    item = new Itm();
                                    item.type = (byte)read_rawbyte();
                                    item.name = read_rawstring() ;
                                    group = namedGroups[read_rawstring()] ;
                                    item.id = ++group.count;
                                    item.isa = namedGroups[read_rawstring()];
                                    group.namedItems.Add(item.name, item);
                                    group.indexedItems.Add(item.id, item);
                                }
                                break;
                            default:
                                throw new Exception("bad field number for reserved");

                        }
                        break;
                    case RAW_TYPE_START_GROUP:
                        {
                            item = peekIsa(false).indexedItems[wireFieldNumber];
                            scannedField.name = item.name;
                            scannedField.index = item.id;
                            scannedField.level = stack.Count;
                            scannedField.type_name = "start_group";
                            scannedField.is_start = true;
                            stack.Push(item);
                        }
                        break;
                    case RAW_TYPE_VARINT:
                        {
                            item = peekIsa(false).indexedItems[wireFieldNumber];
                            scannedField.name = item.name;
                            scannedField.level = stack.Count;
                            scannedField.index = item.id;
                            switch (item.type)
                            {
                                case ITM_TYPE_BOOLEAN:
                                    scannedField.type_name = "bool";
                                    scannedField.value = read_rawvarint32() != 0;
                                    break;
                                case ITM_TYPE_ENUM:
                                    scannedField.type_name = "enum";
                                    scannedField.isa_name = item.isa.name;
                                    scannedField.value = item.isa.indexedItems[read_rawvarint32()].name;
                                    break;
                                case ITM_TYPE_UINT32:
                                    scannedField.type_name = "uint32";
                                    scannedField.value = read_rawvarint32();
                                    break;
                                case ITM_TYPE_UINT64:
                                    scannedField.type_name = "uint64";
                                    scannedField.value = read_rawvarint64();
                                    break;
                                case ITM_TYPE_SINT32:
                                    scannedField.type_name = "sint32";
                                    {
                                        int n = read_rawvarint32();
                                        scannedField.value = ((int)((uint)n >> 1)) ^ -(n & 1);
                                    }
                                    break;
                                case ITM_TYPE_SINT64:
                                    scannedField.type_name = "sint64";
                                    {
                                        long n = read_rawvarint64();
                                        scannedField.value = ((long)((ulong)n >> 1)) ^ -(n & 1); 
                                    }
                                    break;
                                default:
                                    throw new Exception("bad type for readVarint");
                            }
                        }
                        break;
                    default:
                        throw new Exception("invalidwiretype");
                }
            } while (wireType == RAW_TYPE_SCHEMA);

            return true;
        }
 public void clear()
 {
     try
     {
         if (namedGroups != null)
         {
             foreach (Grp g in namedGroups.Values)
             {
                 g.indexedItems.Clear();
                 g.namedItems.Clear();
                 g.indexedItems = null;
                 g.namedItems = null;
             }
             namedGroups.Clear();
         }
         if (stack != null)
         {
             stack.Clear();
             stack = null;
         }
         if (scannedField != null)
         {
             scannedField.clear();
             scannedField = null;
         }
     }
     catch (Exception e)
     {
     }
 }
예제 #31
0
 protected internal override T ReduceFld(Fld fld)
 {
     return(Dispatch(fld));
 }
예제 #32
0
    public bool readItem()
    {
        int wireTag;
        int wireType;
        int wireFieldNumber;
        Grp group = null;
        Itm item  = null;

        if (scannedField == null)
        {
            scannedField = new Fld();
        }

        do
        {
            scannedField.clear();

            if (this.eos)
            {
                return(false);
            }

            wireTag = read_rawvarint32();
            if (wireTag == 0)
            {
                return(false);
            }
            wireType = wireTag & TAG_TYPE_MASK;
            //wireFieldNumber = wireTag >>> TAG_TYPE_BITS;
            wireFieldNumber = (int)((uint)wireTag >> TAG_TYPE_BITS);

            item = null;

            switch (wireType)
            {
            case RAW_TYPE_END_GROUP:
            {
                item = stack.Pop();
                scannedField.name      = item.name;
                scannedField.level     = stack.Count;
                scannedField.index     = item.id;
                scannedField.isa_name  = item.isa.name;
                scannedField.type_name = "end_group";
                scannedField.is_end    = true;
            }
            break;

            case RAW_TYPE_FIXED32:
            {
                item = peekIsa(false).indexedItems[wireFieldNumber];
                scannedField.name  = item.name;
                scannedField.level = stack.Count;
                scannedField.index = item.id;
                switch (item.type)
                {
                case ITM_TYPE_FIXED32:
                    scannedField.type_name = "fixed32";
                    scannedField.value     = read_rawlittleendian32();
                    break;

                case ITM_TYPE_SINGLE:
                    scannedField.type_name = "single";
                    //scannedField.value = Float.intBitsToFloat(read_rawlittleendian32());
                    scannedField.value = BitConverter.ToSingle(BitConverter.GetBytes(read_rawlittleendian32()), 0);
                    break;

                default:
                    throw new Exception("bad type for fixed32");
                }
            }
            break;

            case RAW_TYPE_FIXED64:
            {
                item = peekIsa(false).indexedItems[wireFieldNumber];
                scannedField.name  = item.name;
                scannedField.level = stack.Count;
                scannedField.index = item.id;
                switch (item.type)
                {
                case ITM_TYPE_FIXED64:
                    scannedField.type_name = "fixed64";
                    scannedField.value     = read_rawlittleendian64();
                    break;

                case ITM_TYPE_DOUBLE:
                    scannedField.type_name = "double";
                    //scannedField.value = Double.longBitsToDouble(read_rawlittleendian64());
                    scannedField.value = BitConverter.Int64BitsToDouble(read_rawlittleendian64());
                    break;

                default:
                    throw new Exception("bad type for fixed64");
                }
            }
            break;

            case RAW_TYPE_LENGTH_DELIMITED:
            {
                item = peekIsa(false).indexedItems[wireFieldNumber];
                scannedField.name  = item.name;
                scannedField.level = stack.Count;
                scannedField.index = item.id;
                switch (item.type)
                {
                case ITM_TYPE_STRING:
                {
                    scannedField.type_name = "string";
                    scannedField.value     = read_rawstring();
                }
                break;

                case ITM_TYPE_BYTES:
                {
                    scannedField.type_name = "bytes";
                    int    size  = read_rawvarint32();
                    byte[] bytes = read_rawbytes(size);
                    scannedField.value = bytes;
                }
                break;

                default:
                    throw new Exception("bad type for length delimited");
                }
            }
            break;

            case RAW_TYPE_SCHEMA:
                switch (wireFieldNumber)
                {
                case 1:
                {
                    group      = new Grp();
                    group.type = (byte)read_rawbyte();
                    group.name = read_rawstring();
                    namedGroups.Add(group.name, group);
                    if (version == null)
                    {
                        version = group;
                    }
                }
                break;

                case 2:
                {
                    item      = new Itm();
                    item.type = (byte)read_rawbyte();
                    item.name = read_rawstring();
                    group     = namedGroups[read_rawstring()];
                    item.id   = ++group.count;
                    group.namedItems.Add(item.name, item);
                    group.indexedItems.Add(item.id, item);
                }
                break;

                case 3:
                {
                    item      = new Itm();
                    item.type = (byte)read_rawbyte();
                    item.name = read_rawstring();
                    group     = namedGroups[read_rawstring()];
                    item.id   = ++group.count;
                    item.isa  = namedGroups[read_rawstring()];
                    group.namedItems.Add(item.name, item);
                    group.indexedItems.Add(item.id, item);
                }
                break;

                default:
                    throw new Exception("bad field number for reserved");
                }
                break;

            case RAW_TYPE_START_GROUP:
            {
                item = peekIsa(false).indexedItems[wireFieldNumber];
                scannedField.name      = item.name;
                scannedField.index     = item.id;
                scannedField.level     = stack.Count;
                scannedField.type_name = "start_group";
                scannedField.is_start  = true;
                stack.Push(item);
            }
            break;

            case RAW_TYPE_VARINT:
            {
                item = peekIsa(false).indexedItems[wireFieldNumber];
                scannedField.name  = item.name;
                scannedField.level = stack.Count;
                scannedField.index = item.id;
                switch (item.type)
                {
                case ITM_TYPE_BOOLEAN:
                    scannedField.type_name = "bool";
                    scannedField.value     = read_rawvarint32() != 0;
                    break;

                case ITM_TYPE_ENUM:
                    scannedField.type_name = "enum";
                    scannedField.isa_name  = item.isa.name;
                    scannedField.value     = item.isa.indexedItems[read_rawvarint32()].name;
                    break;

                case ITM_TYPE_UINT32:
                    scannedField.type_name = "uint32";
                    scannedField.value     = read_rawvarint32();
                    break;

                case ITM_TYPE_UINT64:
                    scannedField.type_name = "uint64";
                    scannedField.value     = read_rawvarint64();
                    break;

                case ITM_TYPE_SINT32:
                    scannedField.type_name = "sint32";
                    {
                        int n = read_rawvarint32();
                        scannedField.value = ((int)((uint)n >> 1)) ^ -(n & 1);
                    }
                    break;

                case ITM_TYPE_SINT64:
                    scannedField.type_name = "sint64";
                    {
                        long n = read_rawvarint64();
                        scannedField.value = ((long)((ulong)n >> 1)) ^ -(n & 1);
                    }
                    break;

                default:
                    throw new Exception("bad type for readVarint");
                }
            }
            break;

            default:
                throw new Exception("invalidwiretype");
            }
        } while (wireType == RAW_TYPE_SCHEMA);

        return(true);
    }