public void AsEnumNegativeTest() { AltType defaultValue = AltType.Altitude; string value = "Magnitude"; AltType actual = StringExtensions.AsEnum <AltType>(value, defaultValue); Assert.AreEqual(defaultValue, actual); }
public void AsEnumTest() { AltType defaultValue = AltType.Altitude; AltType expected = AltType.Depth; string value = Convert.ToString(expected, CultureInfo.InvariantCulture); AltType actual = StringExtensions.AsEnum <AltType>(value, defaultValue); Assert.AreEqual(expected, actual); }
public void AltTypeTest() { Layer target = new Layer(); AltType expected = AltType.Depth; target.AltType = expected; AltType actual = target.AltType; Assert.AreEqual(expected, actual); }
public AltType(VList <LNode> classAttrs, LNode typeName, VList <LNode> baseTypes, AltType parentType) { _classAttrs = classAttrs; TypeName = typeName; BaseTypes = baseTypes; ParentType = parentType; { LNode stem; VList <LNode> a = default(VList <LNode>); if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new VList <LNode>(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null) { _typeNameStem = stem; _genericArgs = a.ToWList(); } else { _genericArgs = new WList <LNode>(); } } if (ParentType != null) { BaseTypes.Insert(0, ParentType.TypeNameWithoutAttrs); bool changed = false; for (int i = 0; i < _genericArgs.Count; i++) { var arg = _genericArgs[i]; var parentArg = ParentType._genericArgs.FirstOrDefault(a => a.IsIdNamed(arg.Name)); if (parentArg != null) { var wheres = new HashSet <LNode>(WhereTypes(arg)); int oldCount = wheres.Count; var parentWheres = WhereTypes(parentArg); foreach (var where in parentWheres) { wheres.Add(where); } if (wheres.Count > oldCount) { arg = arg.WithAttrs(arg.Attrs.Where(a => !a.Calls(S.Where)).Add(LNode.Call(S.Where, LNode.List(wheres)))); _genericArgs[i] = arg; changed = true; } } } if (changed) { TypeName = LNode.Call(CodeSymbols.Of, LNode.List().Add(_typeNameStem).AddRange(_genericArgs)); } } TypeNameWithoutAttrs = TypeName.Select(n => n.WithoutAttrs()); }
public AltType(VList<LNode> classAttrs, LNode typeName, VList<LNode> baseTypes, AltType parentType) { _classAttrs = classAttrs; TypeName = typeName; BaseTypes = baseTypes; ParentType = parentType; //matchCode (TypeName) { // case $stem<$(..a)>, $stem: // _typeNameStem = stem; // _genericArgs = a; // default: // _genericArgs = new WList<LNode>(); //} { // Above matchCode expanded: LNode stem; VList<LNode> a = default(VList<LNode>); if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new VList<LNode>(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null) { _typeNameStem = stem; _genericArgs = a.ToWList(); } else { _genericArgs = new WList<LNode>(); } } if (ParentType != null) { BaseTypes.Insert(0, ParentType.TypeNameWithoutAttrs); // Search for all 'where' clauses on the ParentType and make sure OUR generic args have them too. bool changed = false; for (int i = 0; i < _genericArgs.Count; i++) { var arg = _genericArgs[i]; var parentArg = ParentType._genericArgs.FirstOrDefault(a => a.IsIdNamed(arg.Name)); if (parentArg != null) { var wheres = new HashSet<LNode>(WhereTypes(arg)); int oldCount = wheres.Count; var parentWheres = WhereTypes(parentArg); foreach (var where in parentWheres) wheres.Add(where); if (wheres.Count > oldCount) { arg = arg.WithAttrs(arg.Attrs.SmartWhere(a => !a.Calls(S.Where)) .Add(LNode.Call(S.Where, LNode.List(wheres)))); _genericArgs[i] = arg; changed = true; } } } if (changed) TypeName = LNode.Call(CodeSymbols.Of, LNode.List().Add(_typeNameStem).AddRange(_genericArgs)).SetStyle(NodeStyle.Operator); } TypeNameWithoutAttrs = TypeName.Select(n => n.WithoutAttrs()); }
public AltType(RVList<LNode> typeAttrs, LNode typeName, RVList<LNode> baseTypes, AltType parentType) { _typeAttrs = typeAttrs; TypeName = typeName; BaseTypes = baseTypes; ParentType = parentType; if (ParentType != null) BaseTypes.Add(ParentType.TypeName); { LNode stem; RVList<LNode> a = default(RVList<LNode>); if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new RVList<LNode>(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null) { _typeNameStem = stem; _genericArgs = a; } } }
internal void ScanClassBody(LNodeList body) { foreach (var stmt in body) { int?i; { LNode altName; LNodeList attrs, childBody = default(LNodeList), parts, rest; if ((attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 3) && stmt.Args[0].IsIdNamed((Symbol)"alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true || (attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 4) && stmt.Args[0].IsIdNamed((Symbol)"alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true && stmt.Args[3].Calls(CodeSymbols.Braces) && (childBody = stmt.Args[3].Args).IsEmpty | true) { LNode genericAltName = altName; if (altName.CallsMin(CodeSymbols.Of, 1)) { } else { if (_genericArgs.Count > 0) { genericAltName = LNode.Call(CodeSymbols.Of, LNode.List().Add(altName).AddRange(_genericArgs.ToVList())).SetStyle(NodeStyle.Operator); } } var child = new AltType(attrs, genericAltName, LNode.List(), this); child.AddParts(parts); child.ScanClassBody(childBody); _children.Add(child); } else if ((attrs = stmt.Attrs).IsEmpty | true && (i = attrs.FirstIndexWhere(a => a.IsIdNamed(__alt))) != null && stmt.CallsMin(CodeSymbols.Constructor, 3) && stmt.Args[1].IsIdNamed((Symbol)"#this") && stmt.Args[2].Calls(CodeSymbols.AltList) && (rest = new LNodeList(stmt.Args.Slice(3))).IsEmpty | true && rest.Count <= 1) { parts = stmt.Args[2].Args; attrs.RemoveAt(i.Value); _constructorAttrs.AddRange(attrs); if (rest.Count > 0 && rest[0].Calls(S.Braces)) { _extraConstrLogic.AddRange(rest[0].Args); } AddParts(parts); } else { _classBody.Add(stmt); } } } }
public AdtParam(LNode originalDecl, AltType containingType) { OriginalDecl = originalDecl; ContainingType = containingType; if (!OriginalDecl.Calls(S.Var, 2)) { throw new LogException(OriginalDecl, "alt: Expected a variable declaration"); } Type = OriginalDecl.Args[0]; NameId = OriginalDecl.Args[1]; if (NameId.Calls(S.Assign, 2)) { NameId = NameId.Args[0]; } if (!NameId.IsId) { throw new LogException(NameId, "alt: Expected a simple variable name"); } }
public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList<LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList<LNode>(); adt.GenerateOutput(ref output); return LNode.Call(CodeSymbols.Splice, LNode.List(output)); } } return null; }
[LexicalMacro("e.g. alt class Pair<A,B> { alt this(A Item1, B Item2); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class. " + "All data members are read-only, and for each member (e.g. Item1 and Item2 above), " + "a With() method is generated to let users create modified versions.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList<LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList<LNode>(); adt.GenerateOutput(ref output); return LNode.Call(CodeSymbols.Splice, LNode.List(output)); } } return null; }
[LexicalMacro("e.g. alt class Tree<T> { alt Node(Tree<T> Left, Tree<T> Right); alt Leaf(T Value); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; RVList<LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new RVList<LNode>(); adt.GenerateOutput(ref output); return LNode.Call(CodeSymbols.Splice, new RVList<LNode>(output)); } } return null; }
public override void WriteLayerProperties(System.Xml.XmlTextWriter xmlWriter) { xmlWriter.WriteAttributeString("TimeSeries", TimeSeries.ToString()); xmlWriter.WriteAttributeString("BeginRange", BeginRange.ToString()); xmlWriter.WriteAttributeString("EndRange", EndRange.ToString()); xmlWriter.WriteAttributeString("Decay", Decay.ToString()); xmlWriter.WriteAttributeString("CoordinatesType", CoordinatesType.ToString()); xmlWriter.WriteAttributeString("LatColumn", LatColumn.ToString()); xmlWriter.WriteAttributeString("LngColumn", LngColumn.ToString()); xmlWriter.WriteAttributeString("GeometryColumn", GeometryColumn.ToString()); xmlWriter.WriteAttributeString("AltType", AltType.ToString()); xmlWriter.WriteAttributeString("MarkerMix", MarkerMix.ToString()); xmlWriter.WriteAttributeString("ColorMap", ColorMap.ToString()); xmlWriter.WriteAttributeString("MarkerColumn", MarkerColumn.ToString()); xmlWriter.WriteAttributeString("ColorMapColumn", ColorMapColumn.ToString()); xmlWriter.WriteAttributeString("PlotType", PlotType.ToString()); xmlWriter.WriteAttributeString("MarkerIndex", MarkerIndex.ToString()); xmlWriter.WriteAttributeString("MarkerScale", MarkerScale.ToString()); xmlWriter.WriteAttributeString("AltUnit", AltUnit.ToString()); xmlWriter.WriteAttributeString("AltColumn", AltColumn.ToString()); xmlWriter.WriteAttributeString("StartDateColumn", StartDateColumn.ToString()); xmlWriter.WriteAttributeString("EndDateColumn", EndDateColumn.ToString()); xmlWriter.WriteAttributeString("SizeColumn", SizeColumn.ToString()); xmlWriter.WriteAttributeString("HyperlinkFormat", HyperlinkFormat.ToString()); xmlWriter.WriteAttributeString("HyperlinkColumn", HyperlinkColumn.ToString()); xmlWriter.WriteAttributeString("ScaleFactor", ScaleFactor.ToString()); xmlWriter.WriteAttributeString("PointScaleType", PointScaleType.ToString()); xmlWriter.WriteAttributeString("ShowFarSide", ShowFarSide.ToString()); xmlWriter.WriteAttributeString("RaUnits", RaUnits.ToString()); xmlWriter.WriteAttributeString("HoverTextColumn", NameColumn.ToString()); xmlWriter.WriteAttributeString("XAxisColumn", XAxisColumn.ToString()); xmlWriter.WriteAttributeString("XAxisReverse", XAxisReverse.ToString()); xmlWriter.WriteAttributeString("YAxisColumn", YAxisColumn.ToString()); xmlWriter.WriteAttributeString("YAxisReverse", YAxisReverse.ToString()); xmlWriter.WriteAttributeString("ZAxisColumn", ZAxisColumn.ToString()); xmlWriter.WriteAttributeString("ZAxisReverse", ZAxisReverse.ToString()); xmlWriter.WriteAttributeString("CartesianScale", CartesianScale.ToString()); xmlWriter.WriteAttributeString("CartesianCustomScale", CartesianCustomScale.ToString()); xmlWriter.WriteAttributeString("DynamicData", DynamicData.ToString()); xmlWriter.WriteAttributeString("AutoUpdate", AutoUpdate.ToString()); xmlWriter.WriteAttributeString("DataSourceUrl", DataSourceUrl.ToString()); }
public AltType(RVList <LNode> typeAttrs, LNode typeName, RVList <LNode> baseTypes, AltType parentType) { _typeAttrs = typeAttrs; TypeName = typeName; BaseTypes = baseTypes; ParentType = parentType; if (ParentType != null) { BaseTypes.Add(ParentType.TypeName); } { LNode stem; RVList <LNode> a = default(RVList <LNode>); if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new RVList <LNode>(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null) { _typeNameStem = stem; _genericArgs = a; } } }
public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList <LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList <LNode>(); adt.GenerateOutput(ref output); return(LNode.Call(CodeSymbols.Splice, LNode.List(output))); } } return(null); }
[LexicalMacro("e.g. alt class Pair<A,B> { alt this(A Item1, B Item2); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class. " + "All data members are read-only, and for each member (e.g. Item1 and Item2 above), " + "a With() method is generated to let users create modified versions.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList <LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList <LNode>(); adt.GenerateOutput(ref output); return(LNode.Call(CodeSymbols.Splice, LNode.List(output))); } } return(null); }
[LexicalMacro("e.g. alt class Tree<T> { alt Node(Tree<T> Left, Tree<T> Right); alt Leaf(T Value); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; RVList <LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new RVList <LNode>(); adt.GenerateOutput(ref output); return(LNode.Call(CodeSymbols.Splice, new RVList <LNode>(output))); } } return(null); }
public AltType(VList<LNode> classAttrs, LNode typeName, VList<LNode> baseTypes, AltType parentType) { _classAttrs = classAttrs; TypeName = typeName; BaseTypes = baseTypes; ParentType = parentType; { LNode stem; VList<LNode> a = default(VList<LNode>); if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new VList<LNode>(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null) { _typeNameStem = stem; _genericArgs = a.ToWList(); } else { _genericArgs = new WList<LNode>(); } } if (ParentType != null) { BaseTypes.Insert(0, ParentType.TypeNameWithoutAttrs); bool changed = false; for (int i = 0; i < _genericArgs.Count; i++) { var arg = _genericArgs[i]; var parentArg = ParentType._genericArgs.FirstOrDefault(a => a.IsIdNamed(arg.Name)); if (parentArg != null) { var wheres = new HashSet<LNode>(WhereTypes(arg)); int oldCount = wheres.Count; var parentWheres = WhereTypes(parentArg); foreach (var where in parentWheres) wheres.Add(where); if (wheres.Count > oldCount) { arg = arg.WithAttrs(arg.Attrs.Where(a => !a.Calls(S.Where)).Add(LNode.Call(S.Where, LNode.List(wheres)))); _genericArgs[i] = arg; changed = true; } } } if (changed) TypeName = LNode.Call(CodeSymbols.Of, LNode.List().Add(_typeNameStem).AddRange(_genericArgs)); } TypeNameWithoutAttrs = TypeName.Select(n => n.WithoutAttrs()); }
object DeserializeObject(Type type = null) { UInt16 valueNr = Reader.ReadByte(); if (valueNr == 0) { object value; AltType altType; List <FieldInfo> fields; if (type == null) { type = DeserializeType(); } //var constructor = type.GetConstructor(Type.EmptyTypes); //if (constructor != null) // value = constructor.Invoke(null); //else value = FormatterServices.GetSafeUninitializedObject(type); valueList.Add(value); altType = AltType.GetAltType(AltTypes, type, value); altType.DeserializeValueFields(value, this); fields = altType.AllRefFields; if (fields.Count == 0) { return(value); } #if USE_NULL_MAP int bitNr = 0; byte bitInByte; var nullMap = new byte[1 + (fields.Count - 1) / 8]; Reader.Read(nullMap, 0, 1 + (fields.Count - 1) / 8); #endif object fieldValue; for (int i = 0; i < fields.Count; i++) { Type itemType = null; #if USE_NULL_MAP bitInByte = (byte)(0x1 << (bitNr % 8)); if ((nullMap[bitNr++ / 8] & bitInByte) == 0) { continue; } if (ALL_SEALED || fields[i].FieldType.IsSealed) { itemType = fields[i].FieldType; } #endif #if TRACE field = fields[i]; #endif fieldValue = Deserialize(itemType); fields[i].SetValue(value, fieldValue); } return(value); } else { valueNr |= (ushort)(Reader.ReadByte() << 8); return(valueList[valueNr - 1]); } }
public void ScanClassBody(RVList<LNode> body) { foreach (var stmt in body) { int i; { LNode altName; RVList<LNode> attrs, childBody = default(RVList<LNode>), parts, rest; if ((attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 3) && stmt.Args[0].IsIdNamed((Symbol) "alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true || (attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 4) && stmt.Args[0].IsIdNamed((Symbol) "alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true && stmt.Args[3].Calls(CodeSymbols.Braces) && (childBody = stmt.Args[3].Args).IsEmpty | true) { LNode genericAltName = altName; if (altName.CallsMin(CodeSymbols.Of, 1)) { } else if (_genericArgs.Count > 0) genericAltName = LNode.Call(CodeSymbols.Of, new RVList<LNode>().Add(altName).AddRange(_genericArgs)); var child = new AltType(attrs, genericAltName, LNode.List(), this); child.AddParts(parts); child.ScanClassBody(childBody); _children.Add(child); } else if ((attrs = stmt.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && stmt.CallsMin(CodeSymbols.Cons, 3) && stmt.Args[1].IsIdNamed((Symbol) "#this") && stmt.Args[2].Calls(CodeSymbols.AltList) && (rest = new RVList<LNode>(stmt.Args.Slice(3))).IsEmpty | true && rest.Count <= 1) { parts = stmt.Args[2].Args; attrs.RemoveAt(i); _constructorAttrs.AddRange(attrs); if (rest.Count > 0 && rest[0].Calls(S.Braces)) _extraConstrLogic.AddRange(rest[0].Args); AddParts(parts); } else _classBody.Add(stmt); } } }
void SerializeObject(object value, Type type = null) { ushort valueNr; if (!values.TryGetValue(value, out valueNr)) { AltType altType; List <FieldInfo> fields; Writer.Write((byte)0); values.Add(value, (UInt16)(values.Count + 1)); if (type == null) { type = value.GetType(); SerializeType(type); } altType = AltType.GetAltType(AltTypes, type, value); altType.SerializeValueFields(value, this); fields = altType.AllRefFields; if (fields.Count == 0) { return; } #if USE_NULL_MAP // Prepare null map int bitNr = 0; byte bitInByte; object[] fieldValues = altType.AllRefValues.Take(); for (int i = 0; i < fields.Count; i++) { fieldValue = fields[i].GetValue(value); fieldValues[i] = fieldValue; bitInByte = (byte)(0x1 << (bitNr % 8)); if (fieldValue != null) { nullMap[bitNr / 8] |= bitInByte; } else { nullMap[bitNr / 8] &= (byte)(0xFF ^ bitInByte); } bitNr++; } Writer.Write(nullMap, 0, 1 + (fields.Count - 1) / 8); bitNr = 0; #endif // write non null reference values for (int i = 0; i < fields.Count; i++) { Type itemType = null; #if USE_NULL_MAP fieldValue = fieldValues[i]; if (fieldValue == null) { continue; } if (ALL_SEALED || fields[i].FieldType.IsSealed) { itemType = fields[i].FieldType; } #else fieldValue = fields[i].GetValue(value); #endif #if TRACE field = fields[i]; #endif Serialize(fieldValue, itemType); } #if USE_NULL_MAP altType.AllRefValues.Return(fieldValues); #endif } else { Writer.Write((byte)(valueNr & 0xFF)); Writer.Write((byte)(valueNr >> 8)); } }
public AdtParam(LNode originalDecl, AltType containingType) { OriginalDecl = originalDecl; ContainingType = containingType; if (!OriginalDecl.Calls(S.Var, 2)) throw new LogException(OriginalDecl, "alt: Expected a variable declaration"); Type = OriginalDecl.Args[0]; NameId = OriginalDecl.Args[1]; if (NameId.Calls(S.Assign, 2)) NameId = NameId.Args[0]; if (!NameId.IsId) throw new LogException(NameId, "alt: Expected a simple variable name"); }
public AltType(VList <LNode> classAttrs, LNode typeName, VList <LNode> baseTypes, AltType parentType) { _classAttrs = classAttrs; TypeName = typeName; BaseTypes = baseTypes; ParentType = parentType; //matchCode (TypeName) { // case $stem<$(..a)>, $stem: // _typeNameStem = stem; // _genericArgs = a; // default: // _genericArgs = new WList<LNode>(); //} { // Above matchCode expanded: LNode stem; VList <LNode> a = default(VList <LNode>); if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new VList <LNode>(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null) { _typeNameStem = stem; _genericArgs = a.ToWList(); } else { _genericArgs = new WList <LNode>(); } } if (ParentType != null) { BaseTypes.Insert(0, ParentType.TypeNameWithoutAttrs); // Search for all 'where' clauses on the ParentType and make sure OUR generic args have them too. bool changed = false; for (int i = 0; i < _genericArgs.Count; i++) { var arg = _genericArgs[i]; var parentArg = ParentType._genericArgs.FirstOrDefault(a => a.IsIdNamed(arg.Name)); if (parentArg != null) { var wheres = new HashSet <LNode>(WhereTypes(arg)); int oldCount = wheres.Count; var parentWheres = WhereTypes(parentArg); foreach (var where in parentWheres) { wheres.Add(where); } if (wheres.Count > oldCount) { arg = arg.WithAttrs(arg.Attrs.SmartWhere(a => !a.Calls(S.Where)) .Add(LNode.Call(S.Where, LNode.List(wheres)))); _genericArgs[i] = arg; changed = true; } } } if (changed) { TypeName = LNode.Call(CodeSymbols.Of, LNode.List().Add(_typeNameStem).AddRange(_genericArgs)).SetStyle(NodeStyle.Operator); } } TypeNameWithoutAttrs = TypeName.Select(n => n.WithoutAttrs()); }
public AltManager(AltType type) { m_type = type; }