private void CheckRecordCompatibility(HeronValue record) { if (!(record is RecordValue)) { if (!(record is ListValue)) { throw new Exception(record.ToString() + " is not a valid list or record type"); } ListValue list = record as ListValue; if (layout.IsCompatible(list)) { return; } throw new Exception("The list value is not compatible"); } else { RecordValue rec = record as RecordValue; if (rec.GetLayout() == layout) { return; } // Check then that there are the same exposedFields in "record" that we require. if (layout.IsCompatible(rec)) { return; } throw new Exception("The record layout " + layout.ToString() + " does not contain a super-set of the accepted fields"); } }
public override HeronValue Eval(VM vm) { RecordLayout layout = ComputeRecordLayout(); TableValue r = new TableValue(layout); foreach (ExpressionList row in rows) { List <HeronValue> vals = new List <HeronValue>(); for (int i = 0; i < row.Count; ++i) { vals.Add(vm.Eval(row[i])); } RecordValue rv = new RecordValue(layout, vals); r.Add(rv); } return(r); }
public bool IsCompatible(RecordValue x) { for (int i = 0; i < names.Count; ++i) { string name = names[i]; HeronType type = types[i]; int n = x.GetFieldIndex(name); if (n < 0) { return(false); } HeronValue val = x.GetValue(n); HeronValue test = val.As(type); if (test == null) { return(false); } } return(true); }
public void Add(HeronValue record) { CheckRecordCompatibility(record); if (record is RecordValue) { RecordValue rec = record as RecordValue; int n = GetIndexValue(rec).GetHashCode(); values.Add(n, rec); } else { ListValue list = record as ListValue; if (list == null) { throw new Exception("Can only add lists or records to a table"); } RecordValue rec = new RecordValue(layout, list.InternalList()); int n = GetIndexValue(rec).GetHashCode(); values.Add(n, rec); } }
public bool IsCompatible(RecordValue x) { for (int i = 0; i < names.Count; ++i) { string name = names[i]; HeronType type = types[i]; int n = x.GetFieldIndex(name); if (n < 0) return false; HeronValue val = x.GetValue(n); HeronValue test = val.As(type); if (test == null) return false; } return true; }
public void Add(HeronValue record) { CheckRecordCompatibility(record); if (record is RecordValue) { RecordValue rec = record as RecordValue; int n = GetIndexValue(rec).GetHashCode(); values.Add(n, rec); } else { ListValue list = record as ListValue; if (list == null) throw new Exception("Can only add lists or records to a table"); RecordValue rec = new RecordValue(layout, list.InternalList()); int n = GetIndexValue(rec).GetHashCode(); values.Add(n, rec); } }
public HeronValue GetIndexValue(RecordValue rec) { return rec.GetValue(GetIndexField()); }
public HeronValue GetIndexValue(RecordValue rec) { return(rec.GetValue(GetIndexField())); }