public Machine Put(string name, PParser.ImplMachineDeclContext tree) { var machine = new Machine(name, tree); CheckConflicts(machine, Namespace(machines), Namespace(interfaces), Namespace(enums), Namespace(typedefs)); machines.Add(name, machine); return(machine); }
public override object VisitImplMachineDecl(PParser.ImplMachineDeclContext context) { var symbolName = context.name.GetText(); var decl = CurrentScope.Put(symbolName, context); nodesToDeclarations.Put(context, decl); return(VisitChildrenWithNewScope(decl, context)); }
public override object VisitImplMachineDecl(PParser.ImplMachineDeclContext context) { // MACHINE name=iden var machine = (Machine)nodesToDeclarations.Get(context); // cardinality? var hasAssume = context.cardinality()?.ASSUME() != null; var hasAssert = context.cardinality()?.ASSERT() != null; var cardinality = int.Parse(context.cardinality()?.IntLiteral().GetText() ?? "-1"); machine.Assume = hasAssume ? cardinality : -1; machine.Assert = hasAssert ? cardinality : -1; // annotationSet? if (context.annotationSet() != null) { throw new NotImplementedException("impl machine annotations"); } // (COLON idenList)? if (context.idenList() is PParser.IdenListContext interfaces) { foreach (var pInterfaceNameCtx in interfaces._names) { var pInterfaceName = pInterfaceNameCtx.GetText(); if (!CurrentScope.Lookup(pInterfaceName, out Interface pInterface)) { throw Handler.MissingDeclaration(pInterfaceNameCtx, "interface", pInterfaceName); } machine.AddInterface(pInterface); } } // receivesSends* foreach (var receivesSends in context.receivesSends()) { var recvSendTuple = (Tuple <string, PEvent[]>)Visit(receivesSends); var eventSetType = recvSendTuple.Item1; if (eventSetType.Equals("RECV", StringComparison.InvariantCulture)) { if (machine.Receives == null) { machine.Receives = new EventSet(); } foreach (PEvent @event in recvSendTuple.Item2) { machine.Receives.AddEvent(@event); } } else if (eventSetType.Equals("SEND", StringComparison.InvariantCulture)) { if (machine.Sends == null) { machine.Sends = new EventSet(); } foreach (PEvent @event in recvSendTuple.Item2) { machine.Sends.AddEvent(@event); } } else { throw Handler.InternalError(receivesSends, "grammar changed surrounding receives/sends."); } } // machineBody using (currentScope.NewContext(machine.Scope)) using (currentMachine.NewContext(machine)) { Visit(context.machineBody()); } return(machine); }
public override object VisitImplMachineDecl(PParser.ImplMachineDeclContext context) { // MACHINE name=iden var machine = (Machine)nodesToDeclarations.Get(context); // cardinality? var hasAssume = context.cardinality()?.ASSUME() != null; var hasAssert = context.cardinality()?.ASSERT() != null; var cardinality = long.Parse(context.cardinality()?.IntLiteral().GetText() ?? "-1"); if (cardinality > uint.MaxValue) { throw Handler.ValueOutOfRange(context.cardinality(), "uint32"); } machine.Assume = hasAssume ? (uint?)cardinality : null; machine.Assert = hasAssert ? (uint?)cardinality : null; // receivesSends* foreach (var receivesSends in context.receivesSends()) { var recvSendTuple = (Tuple <string, PEvent[]>)Visit(receivesSends); var eventSetType = recvSendTuple.Item1; if (eventSetType.Equals("RECV", StringComparison.InvariantCulture)) { if (machine.Receives == null) { machine.Receives = new EventSet(); } foreach (var @event in recvSendTuple.Item2) { machine.Receives.AddEvent(@event); } } else if (eventSetType.Equals("SEND", StringComparison.InvariantCulture)) { if (machine.Sends == null) { machine.Sends = new EventSet(); } foreach (var @event in recvSendTuple.Item2) { machine.Sends.AddEvent(@event); } } else { Debug.Fail("grammar changed surrounding receives/sends."); } } if (machine.Receives == null) { machine.Receives = CurrentScope.UniversalEventSet; } if (machine.Sends == null) { machine.Sends = CurrentScope.UniversalEventSet; } // machineBody using (currentScope.NewContext(machine.Scope)) using (currentMachine.NewContext(machine)) { Visit(context.machineBody()); } // initialize the corresponding interface currentScope.Value.Get(machine.Name, out Interface @interface); @interface.ReceivableEvents = machine.Receives; @interface.PayloadType = machine.PayloadType; return(machine); }