void Visitor.Visit(TypeMap type) { if (id < 0) { throw new Exception("invalid variable.id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + "case (Zeze.ByteBuffer.MAP | " + id + " << Zeze.ByteBuffer.TAG_SHIFT):"); sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " var _state_ = _os_.BeginReadSegment();"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip key typetag"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip value typetag"); sw.WriteLine(prefix + " " + varname + ".clear();"); sw.WriteLine(prefix + " for (var size = _os_.ReadInt(); size > 0; --size)"); sw.WriteLine(prefix + " {"); string vartmpkey = Program.GenUniqVarName(); string vartmpvalue = Program.GenUniqVarName(); keytype.Accept(new Define(vartmpkey, sw, prefix + " ")); keytype.Accept(new Decode(vartmpkey, -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Define(vartmpvalue, sw, prefix + " ")); valuetype.Accept(new Decode(vartmpvalue, -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".set(" + vartmpkey + ", " + vartmpvalue + ");"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " break;"); }
void Visitor.Visit(TypeMap type) { if (id < 0) { throw new Exception("invalid variable.id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + "case (ByteBuffer.MAP | " + id + " << ByteBuffer.TAG_SHIFT):"); sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " _os_.BeginReadSegment(out var _state_);"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip key typetag"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip value typetag"); sw.WriteLine(prefix + " " + varname + ".Clear();"); sw.WriteLine(prefix + " for (int size = _os_.ReadInt(); size > 0; --size)"); sw.WriteLine(prefix + " {"); keytype.Accept(new Define("_k_", sw, prefix + " ")); keytype.Accept(new Decode("_k_", -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Define("_v_", sw, prefix + " ")); valuetype.Accept(new Decode("_v_", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".Add(_k_, _v_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " break;"); }
void Visitor.Visit(TypeSet type) { if (id < 0) { throw new Exception("invalid variable.id"); } sw.WriteLine(prefix + "case (Zeze.ByteBuffer.SET | " + id + " << Zeze.ByteBuffer.TAG_SHIFT):"); Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " var _state_ = _os_.BeginReadSegment();"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip collection.value typetag"); sw.WriteLine(prefix + " " + varname + ".clear();"); sw.WriteLine(prefix + " for (var _size_ = _os_.ReadInt(); _size_ > 0; --_size_)"); sw.WriteLine(prefix + " {"); string vartmpname = Program.GenUniqVarName(); valuetype.Accept(new Define(vartmpname, sw, prefix + " ")); valuetype.Accept(new Decode(vartmpname, -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".add(" + vartmpname + ");"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " break;"); }
public void Visit(TypeMap type) { if (id < 0) { throw new Exception("invalie Variable.Id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + bufname + ".WriteInt(Zeze.ByteBuffer.MAP | " + id + " << Zeze.ByteBuffer.TAG_SHIFT);"); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " var _state_ = _os_.BeginWriteSegment();"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(keytype) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(valuetype) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + varname + ".size);"); string tmpvarname = Program.GenUniqVarName(); sw.WriteLine(prefix + " for (let " + tmpvarname + " of " + varname + ".entries())"); sw.WriteLine(prefix + " {"); keytype.Accept(new Encode("" + tmpvarname + "[0]", -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Encode("" + tmpvarname + "[1]", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndWriteSegment(_state_); "); sw.WriteLine(prefix + "}"); }
public static TypeMeta Get(Types.Variable var, Types.Type type) { TypeMeta v = new TypeMeta(var); type.Accept(v); return(v); }
public static string GetName(Types.Type type) { TypeTagName v = new TypeTagName(); type.Accept(v); return(v.Name); }
public string nameCollectionImplement; // 容器内部类型。其他情况下为 null。 public static string GetName(Types.Type type) { var visitor = new TypeName(); type.Accept(visitor); return(visitor.name); }
private void DecodeCollection(TypeCollection type) { Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + " {"); sw.WriteLine(prefix + " _os_.BeginReadSegment(out var _state_);"); sw.WriteLine(prefix + " _os_.ReadInt(); // skip collection.value typetag"); sw.WriteLine(prefix + " " + varname + ".Clear();"); sw.WriteLine(prefix + " for (int _size_ = _os_.ReadInt(); _size_ > 0; --_size_)"); sw.WriteLine(prefix + " {"); valuetype.Accept(new Define("_v_", sw, prefix + " ")); valuetype.Accept(new Decode("_v_", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " " + varname + ".Add(_v_);"); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndReadSegment(_state_);"); sw.WriteLine(prefix + " }"); }
private void EncodeCollection(TypeCollection type) { Types.Type vt = type.ValueType; sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " _os_.BeginWriteSegment(out var _state_);"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(vt) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + varname + ".Count);"); sw.WriteLine(prefix + " foreach (var _v_ in " + varname + ")"); sw.WriteLine(prefix + " {"); vt.Accept(new Encode("_v_", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndWriteSegment(_state_); "); sw.WriteLine(prefix + "}"); }
private void WriteCollectionLog(Types.Type type) { var tn = new TypeName(); type.Accept(tn); sw.WriteLine(prefix + "private sealed class Log_" + var.NamePrivate + " : " + tn.name + ".LogV"); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " public Log_" + var.NamePrivate + "(" + bean.Name + " host, " + tn.nameCollectionImplement + " value) : base(host, value) { }"); sw.WriteLine(prefix + " public override long LogKey => Bean.ObjectId + " + var.Id + ";"); sw.WriteLine(prefix + " public " + bean.Name + " BeanTyped => (" + bean.Name + ")Bean;"); sw.WriteLine(prefix + " public override void Commit() { Commit(BeanTyped." + var.NamePrivate + "); }"); sw.WriteLine(prefix + "}"); }
public void Visit(TypeSet type) { if (id < 0) { throw new Exception("invalie Variable.Id"); } sw.WriteLine(prefix + bufname + ".WriteInt(Zeze.ByteBuffer.SET | " + id + " << Zeze.ByteBuffer.TAG_SHIFT);"); Types.Type vt = type.ValueType; sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " var _state_ = _os_.BeginWriteSegment();"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(vt) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + varname + ".size);"); string tmpvarname = Program.GenUniqVarName(); sw.WriteLine(prefix + " for (let " + tmpvarname + " of " + varname + ")"); sw.WriteLine(prefix + " {"); vt.Accept(new Encode(tmpvarname, -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndWriteSegment(_state_); "); sw.WriteLine(prefix + "}"); }
public void Visit(TypeMap type) { if (id < 0) { throw new Exception("invalie Variable.Id"); } Types.Type keytype = type.KeyType; Types.Type valuetype = type.ValueType; sw.WriteLine(prefix + bufname + ".WriteInt(ByteBuffer.MAP | " + id + " << ByteBuffer.TAG_SHIFT);"); sw.WriteLine(prefix + "{"); sw.WriteLine(prefix + " _os_.BeginWriteSegment(out var _state_);"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(keytype) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + TypeTagName.GetName(valuetype) + ");"); sw.WriteLine(prefix + " _os_.WriteInt(" + varname + ".Count);"); sw.WriteLine(prefix + " foreach (var _e_ in " + varname + ")"); sw.WriteLine(prefix + " {"); keytype.Accept(new Encode("_e_.Key", -1, "_os_", sw, prefix + " ")); valuetype.Accept(new Encode("_e_.Value", -1, "_os_", sw, prefix + " ")); sw.WriteLine(prefix + " }"); sw.WriteLine(prefix + " _os_.EndWriteSegment(_state_); "); sw.WriteLine(prefix + "}"); }