public PSharpSeqType(string name, PSharpType elementType) : base( name, PTypeKind.NamedTuple, $"seq<{elementType.OriginalRepresentation}>") { ElementType = elementType; }
private IList <EventDecl> GenerateEvents() { return(allEvents.Select( kv => { PSharpType payloadType = typeFactory.MakePSharpType(kv.Value.payloadType); return new EventDecl { Name = kv.Key, Assert = kv.Value.maxInstances == -1 || kv.Value.maxInstancesAssumed ? -1 : kv.Value.maxInstances, Assume = kv.Value.maxInstances == -1 || !kv.Value.maxInstancesAssumed ? -1 : kv.Value.maxInstances, PayloadType = payloadType == PSharpBaseType.Null ? null : payloadType }; }).ToList()); }
internal PSharpType MakePSharpType(FuncTerm type) { string caseType = (type.Function as Id)?.Name; switch (caseType) { case "BaseType": string actualType = ((Id)type.Args.First()).Name; return(baseTypes[actualType]); case "NmdTupType": var fields = new List <TypedName>(); FuncTerm curTerm = type; do { // Get the NmdTupTypeField out var field = (FuncTerm)curTerm.Args.ElementAt(0); Node[] args = field.Args.ToArray(); fields.Add(new TypedName { Name = ((Cnst)args[0]).GetStringValue(), Type = MakePSharpType((FuncTerm)args[1]) }); // Advance to the next FuncTerm (terminated by IdTerm) curTerm = curTerm.Args.ElementAt(1) as FuncTerm; } while (curTerm != null); string namedTupleRepr = $"({string.Join(",", fields.Select(v => $"{v.Name}:{v.Type.OriginalRepresentation}"))})"; PSharpNamedTuple pSharpType = namedTuples.GetOrCreate( namedTupleRepr, () => new PSharpNamedTuple($"NamedTuple{namedTuples.Count + 1}", fields, namedTupleRepr)); return(pSharpType); case "SeqType": PSharpType elementType = MakePSharpType(type.Args.ElementAt(0) as FuncTerm); return(sequences.GetOrCreate( elementType.OriginalRepresentation, () => new PSharpSeqType($"Sequence{sequences.Count + 1}", elementType))); case null: throw new Exception("Invalid PType passed"); default: throw new ArgumentOutOfRangeException(nameof(type), $"{caseType} not yet implemented"); } }