private object VisitChildrenWithNewScope(IHasScope decl, IRuleNode context) { using (scope.NewContext(CurrentScope.MakeChildScope())) { decl.Scope = CurrentScope; return(VisitChildren(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 = 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); }