/// <summary> /// Visit a port mock member /// </summary> /// <param name="plan">Test file plan</param> /// <param name="testSetPlan">TestSetPlan to visit</param> /// <param name="portMockMember">Port mock syntax node</param> private void VisitPortMockMember(TestFilePlan plan, TestSetPlan testSetPlan, PortMockMemberNode portMockMember) { // --- Check ID duplication var id = portMockMember.Id; if (testSetPlan.ContainsSymbol(id)) { ReportError(Errors.T0006, plan, portMockMember.IdSpan, id); return; } // --- Get port address var portAddress = Eval(plan, testSetPlan, portMockMember.Expr); var portMock = portAddress != null ? new PortMockPlan(portAddress.AsWord()) : null; // --- Get pulses var pulsesOk = true; var nextPulseStart = 0L; foreach (var pulse in portMockMember.Pulses) { // --- Get pulse expression values var value = Eval(plan, testSetPlan, pulse.ValueExpr); var pulse1 = Eval(plan, testSetPlan, pulse.Pulse1Expr); if (value == null || pulse1 == null) { pulsesOk = false; continue; } ExpressionValue pulse2 = null; if (pulse.Pulse2Expr != null) { pulse2 = Eval(plan, testSetPlan, pulse.Pulse2Expr); if (pulse2 == null) { pulsesOk = false; continue; } } // --- Create a new pulse PortPulsePlan pulsePlan; if (pulse2 == null) { // --- We have only value and length pulsePlan = new PortPulsePlan(value.AsByte(), nextPulseStart, nextPulseStart + pulse1.AsNumber() - 1); } else { // --- We have pulse value, start, and end pulsePlan = new PortPulsePlan(value.AsByte(), pulse1.AsNumber(), pulse.IsInterval ? pulse2.AsNumber() : pulse1.AsNumber() + pulse2.AsNumber() - 1); } nextPulseStart = pulsePlan.EndTact + 1; portMock?.AddPulse(pulsePlan); } // --- Create the entire port mock if (portMock != null && pulsesOk) { testSetPlan.SetPortMock(id, portMock); } }