-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQPAction.cpp
1398 lines (1139 loc) · 36.2 KB
/
QPAction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*------------------------------------------------------------------------------+
| |
| QP - QSDL Parser |
| |
| (C) 1994-98 Marc Diefenbruch |
| University of Essen, Germany |
| |
+---------------+-------------------+---------------+-------------------+-------+
| Module | File | Created | Project | |
+---------------+-------------------+---------------+-------------------+-------+
| QPAction | QPAction.cpp | 9. Aug 1994 | QP | |
+------------------------------------------------------------------------------*/
/* Lineal
000000000011111111112222222222333333333344444444445555555555666666666677777777778
012345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
#ifdef USE_PRAGMA
#pragma interface
#endif
/****************************************************************************
* Includes
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <DS/DSList.h>
#include <DS/DSRef.h>
#include <DS/DSString.h>
#include <DS/DSAction.h>
#include <DS/DSDecision.h>
#include <DS/DSTask.h>
#include <DS/DSNextState.h>
#include <DS/DSJoin.h>
#include <DS/DSReturn.h>
#include <DS/DSCreate.h>
#include <DS/DSCall.h>
#include <DS/DSReset.h>
#include <DS/DSSet.h>
#include <DS/DSStop.h>
#include <DS/DSOutput.h>
#include <DS/DSSignalRoute.h>
#include <DS/DSChannel.h>
#include <DS/DSTimer.h>
#include <DS/DSFormalParam.h>
#include <DS/DSProcedure.h>
#include <DS/DSOperandProcedureCall.h>
#include <DS/DSSystem.h>
#include <DS/DSRequest.h>
#include <DS/DSClear.h>
#include <DS/DSUpdate.h>
#include <DS/DSMachineService.h>
#include <DS/DSPipe.h>
#include <DS/DSLink.h>
#include "QPObjects.h"
#ifdef DMALLOC
#include <dmalloc.h>
#endif
/****************************************************************************
* Externe Variablen
****************************************************************************/
extern DSObjectRefStack p_stack;
extern DSStringList *p_ident_list;
extern DSSystem *p_system;
/****************************************************************************
* Globale Variablen
****************************************************************************/
DSOutputRefList *p_output_ref_list = NULL; // Merkliste zum nachtraeglichen
// Setzen der OUTPUT-Destination
// und des VIA-Pfades
DSRequestRefList *p_request_ref_list = NULL; // Merkliste zum nachtraeglichen
// Setzen der REQUEST-Destination
// und des VIA-Pfades
DSString *p_label;
DSNextStateRefList *p_forward_nextstate_list = NULL;
DSStringList *p_forward_statename_list = NULL;
extern "C" {
#include "QPError.h"
/****************************************************************************
* Funktionen
****************************************************************************/
void action_statement_1(const char *label)
{
#ifdef DEBUG
if (label)
{
qpDebugLog << "action_statement_1: " << label;
qpDebugLog << " (label)" << endl;
}
#endif
if (label)
{
p_label = new DSString(label);
assert(p_label);
}
else
{
p_label = NULL;
}
}
void action_statement_2(void)
{
// Falls kein VIA oder TO spezifiziert wurde, werden dieses
// Listen nicht automatisch geloescht, daher hier nochmals
// abfragen:
if (p_output_ref_list != NULL)
{
delete p_output_ref_list;
p_output_ref_list = NULL;
#ifdef DEBUG
qpDebugLog << "action_statement_2 (delete last obsolete output ref list)" << endl;
#endif
}
if (p_request_ref_list != NULL)
{
delete p_request_ref_list;
p_request_ref_list = NULL;
#ifdef DEBUG
qpDebugLog << "action_statement_2 (delete last obsolete request ref list)" << endl;
#endif
}
}
void terminator_statement_1(const char *label)
{
#ifdef DEBUG
if (label)
{
qpDebugLog << "terminator_statement_1: " << label;
qpDebugLog << " (label)" << endl;
}
#endif
if (label)
{
p_label = new DSString(label);
assert(p_label);
}
else
{
p_label = NULL;
}
}
void terminator_statement_2(void)
{
// Falls kein VIA oder TO spezifiziert wurde, werden dieses
// Listen nicht automatisch geloescht, daher hier nochmals
// abfragen:
if (p_output_ref_list != NULL)
{
delete p_output_ref_list;
p_output_ref_list = NULL;
#ifdef DEBUG
qpDebugLog << "terminator_statement_2 (delete last obsolete output ref list)" << endl;
#endif
}
if (p_request_ref_list != NULL)
{
delete p_request_ref_list;
p_request_ref_list = NULL;
#ifdef DEBUG
qpDebugLog << "terminator_statement_2 (delete last obsolete request ref list)" << endl;
#endif
}
}
void decision_1(void)
{
DSDecision *p_decision;
#ifdef DEBUG
qpDebugLog << "decision_1 (push/insert decision)" << endl;
#endif
assert(p_stack.Top());
p_decision = NewDecision((DSObject*)p_stack.Top(),
p_label); // Anlegen + Einfuegen
assert(p_decision);
p_label = NULL; // wegen Value Returning Procedure Call!
assert(p_stack.Push((DSObjectRef)p_decision) == DS_OK);
}
void decision_2(void)
{
DSDecision *p_decision;
DSExpression *p_expression;
DSAction *p_action;
assert(p_stack.Top());
if ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
#ifdef DEBUG
qpDebugLog << "decision_2 (set question + pop expression)" << endl;
#endif
p_expression = (DSExpression*)p_stack.Top();
assert(p_stack.Pop()); // Question vom Stack entfernen
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction*)p_stack.Top();
assert(p_action->GetTag() == DS_DECISION);
p_decision = (DSDecision*)p_stack.Top();
p_decision->SetQuestion(p_expression);
}
else // decision ANY !!!
{
#ifdef DEBUG
qpDebugLog << "decision_2 (any)" << endl;
#endif
}
}
void decision_3(void)
{
DSAction *p_action;
#ifdef DEBUG
qpDebugLog << "decision_3 (pop decision)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction*)p_stack.Top();
assert(p_action->GetTag() == DS_DECISION);
assert(p_stack.Pop()); // Eingefuegt ist bereits, nur vom Stack entfernen
}
void answer_part_1(void)
{
DSAction *p_action;
DSTransition *p_transition;
#ifdef DEBUG
qpDebugLog << "answer_part_1 (push/insert transition)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction*)p_stack.Top();
assert(p_action->GetTag() == DS_DECISION);
p_transition = NewTransition((DSObject*)p_stack.Top()); // Anlegen + Einfuegen
assert(p_transition);
assert(p_stack.Push((DSObjectRef)p_transition) == DS_OK);
}
void answer_part_2(void)
{
#ifdef DEBUG
qpDebugLog << "answer_part_2 (pop transition)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_TRANSITION);
assert(p_stack.Pop()); /* Eingefuegt ist bereits, nur vom Stack entfernen */
}
void else_part_1(void)
{
DSAction *p_action;
DSDecision *p_decision;
DSTransition *p_transition;
#ifdef DEBUG
qpDebugLog << "else_part_1 (push/insert transition)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction*)p_stack.Top();
assert(p_action->GetTag() == DS_DECISION);
p_decision = (DSDecision*)p_stack.Top();
p_transition = NewTransition(NULL); // Anlegen + Einfuegen
assert(p_transition);
p_decision->SetElseTransition(p_transition);
assert(p_stack.Push((DSObjectRef)p_transition) == DS_OK);
}
void else_part_2(void)
{
#ifdef DEBUG
qpDebugLog << "else_part_2 (pop transition)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_TRANSITION);
assert(p_stack.Pop()); /* Eingefuegt ist bereits, nur vom Stack entfernen */
}
void task_1(void)
{
DSTask *p_task;
#ifdef DEBUG
qpDebugLog << "task_1 (push/insert task)" << endl;
#endif
assert(p_stack.Top());
p_task = NewTask((DSObject*)p_stack.Top(),
p_label); // Anlegen + Einfuegen
assert(p_task);
p_label = NULL; // wichtig damit das Label nicht
// mehrfach vorkommt!
assert(p_stack.Push((DSObjectRef)p_task) == DS_OK);
}
void comma_assignment_statement_list_1(void)
{
DSAction *p_action;
DSTask *p_task;
DSExpression *p_expression = NULL;
#ifdef DEBUG
qpDebugLog << "comma_assignment_statement_list_1 (set expression + pop task)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_EXPRESSION);
p_expression = (DSExpression*)p_stack.Top();
assert(p_expression);
assert(p_stack.Pop()); // Expression vom Stack entfernen
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction*)p_stack.Top();
assert(p_action);
assert(p_action->GetTag() == DS_TASK);
p_task = (DSTask*)p_stack.Top();
assert(p_task);
p_task->SetExpression(p_expression);
assert(p_stack.Pop()); /* Eingefuegt ist bereits, nur vom Stack entfernen */
}
void comma_informal_text_list_1(const char *text)
{
DSAction *p_action;
DSTask *p_task;
assert(text);
#ifdef DEBUG
qpDebugLog << "comma_informal_text_list_1: " << text;
qpDebugLog << " (set informal text + pop task)" << endl;
#endif
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction*)p_stack.Top();
assert(p_action);
assert(p_action->GetTag() == DS_TASK);
p_task = (DSTask*)p_stack.Top();
assert(p_task);
p_task->SetInformalText(text);
assert(p_stack.Pop()); /* Eingefuegt ist bereits, nur vom Stack entfernen */
}
void nextstate_1(const char *statename)
{
DSNextState *p_nextstate;
DSStateRef p_state_ref;
#ifdef DEBUG
qpDebugLog << "nextstate_1: " << statename;
qpDebugLog << " (insert nextstate)" << endl;
#endif
assert(p_stack.Top());
if (!strcmp(statename, "-"))
{
p_nextstate = NewNextState((DSObject*)p_stack.Top(),
p_label,
NULL); // NULL = Zustand beibehalten!
// wegen 'State *' kann hier
// noch keine Aufloesung
// stattfinden!
assert(p_nextstate);
}
else
{
p_state_ref = (p_stack.Top())->GetStateRefByName(statename);
p_nextstate = NewNextState((DSObject*)p_stack.Top(),
p_label,
p_state_ref);
assert(p_nextstate);
if (p_state_ref == NULL) // Vorwaertsreferenz ?
{
if (p_forward_nextstate_list == NULL) // 1. Vorwaertsreferenz?
{
p_forward_nextstate_list = new DSNextStateRefList;
assert(p_forward_nextstate_list);
}
if (p_forward_statename_list == NULL) // 1. Vorwaertsreferenz?
{
p_forward_statename_list = new DSStringList;
assert(p_forward_statename_list);
}
assert(p_forward_nextstate_list->Append(p_nextstate) == DS_OK);
assert(p_forward_statename_list->Append(new DSString(statename)) == DS_OK);
}
}
}
void join_1(const char *label)
{
DSJoin *p_join;
assert(label);
#ifdef DEBUG
qpDebugLog << "join_1: " << label;
qpDebugLog << " (insert join)" << endl;
#endif
assert(p_stack.Top());
p_join = NewJoin((DSObject*)p_stack.Top(),
new DSString(label),
p_label);
assert(p_join);
}
void stop_1(void)
{
DSStop *p_stop;
#ifdef DEBUG
qpDebugLog << "stop_1 (insert stop)" << endl;
#endif
assert(p_stack.Top());
p_stop = NewStop((DSObject*)p_stack.Top(),
p_label);
assert(p_stop);
}
void return_1(void)
{
DSReturn *p_return;
DSExpression *p_expression = NULL;
assert(p_stack.Top());
if ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
#ifdef DEBUG
qpDebugLog << "return_1 (insert return with result)" << endl;
#endif
p_expression = (DSExpression*)p_stack.Top();
assert(p_stack.Pop()); // Result vom Stack entfernen
assert(p_stack.Top());
}
else
{
#ifdef DEBUG
qpDebugLog << "return_1 (insert return without result)" << endl;
#endif
}
p_return = NewReturn((DSObject*)p_stack.Top(),
p_expression,
p_label);
assert(p_return);
}
void create_body_1(const char *processname)
{
DSCreate *p_create;
DSProcessRef p_process_ref;
DSExpression *p_expression;
DSActualParamList *p_actual_param_list = NULL;
char str[120];
#ifdef DEBUG
qpDebugLog << "create_body_1 (insert create)" << endl;
#endif
assert(p_stack.Top());
// Aktuelle Parameter vom Stack holen:
while ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
if (!p_actual_param_list) p_actual_param_list = new DSActualParamList;
assert(p_actual_param_list);
p_expression = (DSExpression *)p_stack.Top();
assert(p_stack.Pop());
assert(p_actual_param_list->Prepend(p_expression) == DS_OK);
assert(p_stack.Top());
}
assert(p_stack.Top());
p_process_ref = (p_stack.Top())->GetProcessRefByName(processname);
if (p_process_ref == NULL)
{
sprintf(str, "Undefined process '%s'.\n", processname);
yyerror(str);
if (p_actual_param_list) delete p_actual_param_list;
return;
}
p_create = NewCreate((DSObject*)p_stack.Top(), // Anlegen + Einfuegen
p_label,
p_process_ref,
p_actual_param_list);
assert(p_create);
}
void procedure_call_body_1(const char *procedurename)
{
DSCall *p_procedure_call;
DSProcedureRef p_procedure_ref;
DSExpression *p_expression;
char str[120];
DSObject *p_object = NULL;
DSOperand *p_operand = NULL;
DSSortRef p_return_sort_ref;
DSFormalParamRef p_return_param_ref;
DSResult status;
assert(procedurename);
#ifdef DEBUG
qpDebugLog << "procedure_call_body_1: " << procedurename;
qpDebugLog << " (procedure name + push call)" << endl;
#endif
assert(p_stack.Top());
p_object = (DSObject*)p_stack.Top();
// Zum Aufruf gehoerende Prozedur suchen:
p_procedure_ref = p_object->GetProcedureRefByName(procedurename);
if (p_procedure_ref == NULL)
{
// bei value returning procedure calls
// kann es passieren das die umgebenden
// Expression (noch) kein Vater-Objekt
// besitzt. Dann ist es moeglich, dass
// der Prozedurname nicht so leicht
// aufgeloest werden kann:
for (status = p_stack.MoveFirst();
status == DS_OK;
status = p_stack.MoveNext())
{
p_object = (DSObject*)p_stack.GetCurrentData();
assert(p_object);
if (p_object->GetType() == DS_SYSTEM ||
p_object->GetType() == DS_BLOCK ||
p_object->GetType() == DS_PROCEDURE ||
p_object->GetType() == DS_PROCESS)
{
break;
}
p_object = NULL;
}
if (!p_object || !(p_procedure_ref = p_object->GetProcedureRefByName(procedurename)))
{
sprintf(str, "Undefined procedure '%s'.\n", procedurename);
yyerror(str);
return;
}
}
// Im folgenden wird unterschieden ob es sich um einen
// normalen Prozeduraufruf oder um einen "Value Returning
// Procedure Call" handelt.
// Bei ersterem ist das Vaterobjekt vom Typ DS_TRANSITION.
// Bei dem zweiten kann das Vaterobjekt von den Typen
// sein, die als Vater fuer Expressions zugelassen sind
// (siehe DSExpression.cc)
if (p_object->GetType() == DS_TRANSITION)
{
p_procedure_call = NewCall(p_object, // Anlegen + Einfuegen
p_label,
p_procedure_ref);
assert(p_procedure_call);
}
else // Value returning procedure call!
{
p_return_param_ref = p_procedure_ref->GetReturnParamRef();
if (p_return_param_ref)
{
p_return_sort_ref = p_return_param_ref->GetSortRef();
}
else
{
p_return_sort_ref = NULL;
}
// Jetzt zusaetzliche Expression mit einem Operanden
// erzeugen und auf den Stack legen:
p_operand = NewOperandProcedureCall(NULL);
assert(p_operand);
p_procedure_call = NewCall(p_operand, // Anlegen + Einfuegen
p_label,
p_procedure_ref);
assert(p_procedure_call);
p_expression = NewExpression(NULL,
p_operand, // Anlegen + Einfuegen
DS_OPT_NONE,
NULL,
p_return_sort_ref);
assert(p_expression);
assert(p_stack.Push((DSObjectRef)p_expression) == DS_OK);
}
assert(p_stack.Push((DSObjectRef)p_procedure_call) == DS_OK);
}
void procedure_call_body_2(void)
{
DSCall *p_procedure_call;
DSProcedureRef p_procedure_ref;
DSExpression *p_expression;
DSActualParamList *p_actual_param_list = NULL;
DSFormalParamList *p_formal_param_list = NULL;
char str[120];
DSCardinal p_formal_param_number;
DSCardinal p_actual_param_number;
DSAction *p_action;
#ifdef DEBUG
qpDebugLog << "procedure_call_body_2 (set actual parameters + pop call)" << endl;
#endif
assert(p_stack.Top());
// aktuelle Parameter vom Stack holen:
while ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
if (!p_actual_param_list) p_actual_param_list = new DSActualParamList;
assert(p_actual_param_list);
p_expression = (DSExpression *)p_stack.Top();
assert(p_stack.Pop());
assert(p_actual_param_list->Prepend(p_expression) == DS_OK);
assert(p_stack.Top());
}
// jetzt muss der Prozeduraufruf oben auf dem Stack liegen:
assert((p_stack.Top())->GetType() == DS_ACTION);
p_action = (DSAction *)p_stack.Top();
assert(p_action->GetTag() == DS_CALL);
p_procedure_call = (DSCall *)p_action;
assert(p_stack.Pop()); /* Prozeduraufruf vom Stack entfernen */
// Zum Aufruf gehoerende Prozedur holen:
p_procedure_ref = p_procedure_call->GetProcedureRef();
assert(p_procedure_ref);
// Formale Parameter der Prozedur holen (falls vorhanden):
p_formal_param_list = p_procedure_ref->GetFormalParamList();
if (p_formal_param_list)
{
p_formal_param_number = p_formal_param_list->NumberOfElements();
p_actual_param_number = p_actual_param_list->NumberOfElements();
if (p_formal_param_number != p_actual_param_number)
{
sprintf(str, "Call to procedure '%s' doesn't match it's declaration.\n",
p_procedure_ref->GetName()->GetString());
yyerror(str);
return;
}
}
if (p_actual_param_list)
{
assert(p_procedure_call->SetActualParamList(p_actual_param_list) == DS_OK);
}
// falls es sich um einen "Value Returning Procedure Call" handelte
// liegt jetzt noch ein DSExpression-Objekt auf dem Stack!
}
void set_statement_1(const char *name)
{
DSObject *p_object = NULL;
DSExpressionList *p_timer_index_list = NULL;
DSExpression *p_time;
DSExpression *p_timer_index;
DSSet *p_set;
DSTimerRef p_timer_ref;
char str[120];
DSResult status;
DSCardinal number_of_indices;
assert(name);
#ifdef DEBUG
qpDebugLog << "set_statement_1: " << name;
qpDebugLog << " (insert set + set time + set timer indices)" << endl;
#endif
// nach einem Prozess auf
// dem Stack suchen, bei dem die Suche nach Timer
// Deklarationen beginnen kann.
// (Das Top-Element des Stacks kann z. B. DSExpression
// sein (ohne parent), daher muss die Suche bei
// einem Prozess beginnen!)
for (status = p_stack.MoveFirst();
status == DS_OK;
status = p_stack.MoveNext())
{
p_object = (DSObject*)p_stack.GetCurrentData();
assert(p_object);
if (p_object->GetType() == DS_PROCESS ||
p_object->GetType() == DS_PROCEDURE)
{
break;
}
p_object = NULL;
}
assert(p_object);
p_timer_ref = p_object->GetTimerRefByName(name);
if (!p_timer_ref)
{
sprintf(str, "Undefined timer '%s'.\n", name);
yyerror(str);
return;
}
// Indices holen:
if (p_timer_ref->GetSortRefList() == NULL)
{
number_of_indices = 0;
}
else
{
number_of_indices = p_timer_ref->GetSortRefList()->NumberOfElements();
}
while ((p_stack.Top())->GetType() == DS_EXPRESSION &&
number_of_indices > 0)
{
if (!p_timer_index_list) p_timer_index_list = new DSExpressionList;
assert(p_timer_index_list);
p_timer_index = (DSExpression *)p_stack.Top();
assert(p_stack.Pop());
assert(p_timer_index_list->Prepend(p_timer_index) == DS_OK);
assert(p_stack.Top());
number_of_indices--;
}
if (number_of_indices > 0)
{
sprintf(str, "Missing index for timer '%s'.\n", name);
yyerror(str);
return;
}
// Zeit feststellen:
assert(p_stack.Top());
assert((p_stack.Top())->GetType() == DS_EXPRESSION);
p_time = (DSExpression*)p_stack.Top();
assert(p_stack.Pop()); // Zeit vom Stack entfernen
p_set = NewSet((DSObject*)p_stack.Top(),
p_label,
p_timer_ref,
p_timer_index_list,
p_time); // Anlegen + Einfuegen
assert(p_set);
}
void reset_statement_1(const char *name)
{
DSExpressionList *p_timer_index_list = NULL;
DSExpression *p_timer_index;
DSReset *p_reset;
DSTimerRef p_timer;
char str[120];
assert(name);
#ifdef DEBUG
qpDebugLog << "reset_statement_1: " << name;
qpDebugLog << " (timer name + insert reset + reset timer indices)" << endl;
#endif
// Indices holen:
while ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
if (!p_timer_index_list) p_timer_index_list = new DSExpressionList;
assert(p_timer_index_list);
p_timer_index = (DSExpression *)p_stack.Top();
assert(p_stack.Pop());
assert(p_timer_index_list->Prepend(p_timer_index) == DS_OK);
assert(p_stack.Top());
}
assert(p_stack.Top());
p_timer = (p_stack.Top())->GetTimerRefByName(name);
if (!p_timer)
{
sprintf(str, "Undefined timer '%s'.\n", name);
yyerror(str);
return;
}
p_reset = NewReset((DSObject*)p_stack.Top(),
p_label,
p_timer,
p_timer_index_list); // Anlegen + Einfuegen
assert(p_reset);
}
void output_1(void)
{
#ifdef DEBUG
qpDebugLog << "output_1 (prepare output list)" << endl;
#endif
p_output_ref_list = new DSOutputRefList;
assert(p_output_ref_list);
}
void ident_actual_param_1(const char *signal)
{
DSOutput *p_output;
DSSignalRef p_signal_ref;
DSExpression *p_expression;
DSActualParamList *p_actual_param_list = NULL;
char str[120];
assert(signal);
#ifdef DEBUG
qpDebugLog << "ident_actual_param_1: " << signal;
qpDebugLog << " (signal name + insert output + set parameters + pop expressions)" << endl;
#endif
assert(p_stack.Top());
while ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
if (!p_actual_param_list) p_actual_param_list = new DSActualParamList;
assert(p_actual_param_list);
p_expression = (DSExpression *)p_stack.Top();
assert(p_stack.Pop());
assert(p_actual_param_list->Prepend(p_expression) == DS_OK);
assert(p_stack.Top());
}
p_signal_ref = (p_stack.Top())->GetSignalRefByName(signal);
if (p_signal_ref == NULL)
{
sprintf(str, "Undefined signal '%s'.\n", signal);
yyerror(str);
if (p_actual_param_list) delete p_actual_param_list;
p_actual_param_list = NULL;
}
if (p_actual_param_list != NULL && // aktuelle Parameter aber
p_signal_ref->GetSortRefList() == NULL) // keine formalen Parameter?
{
sprintf(str, "Signal '%s' has no formal parameters but actual parameters given.\n", signal);
yyerror(str);
if (p_actual_param_list) delete p_actual_param_list;
p_actual_param_list = NULL;
}
p_output = NewOutput((DSObject*)p_stack.Top(), // Anlegen + Einfuegen
p_label,
p_signal_ref,
p_actual_param_list);
assert(p_output);
assert(p_output_ref_list->Append(p_output) == DS_OK);
// merken zum nachtraeglichen
// Setzen der Destination und
// des Pfades
}
void output_body_1(void) // Setzen der TO-Expression
{
DSExpression *p_expression;
DSResult status;
DSOutput *p_output;
assert(p_stack.Top());
if ((p_stack.Top())->GetType() == DS_EXPRESSION)
{
p_expression = (DSExpression*)p_stack.Top();
assert(p_stack.Pop()); // Destination vom Stack entfernen
#ifdef DEBUG
qpDebugLog << "output_body_1 (set output destination + pop expression + create via list)" << endl;
#endif
/*******************************************************/
/* Destination in alle zugehoerigen Outputs eintragen: */
/*******************************************************/
assert(p_output_ref_list);
for (status = p_output_ref_list->MoveFirst();
status == DS_OK;
status = p_output_ref_list->MoveNext())
{
p_output = (DSOutput*)p_output_ref_list->GetCurrentData();
assert(p_output);
p_output->SetProcessID(p_expression);
}
}
else
{
#ifdef DEBUG
qpDebugLog << "output_body_1 (create via list)" << endl;
#endif
}
p_ident_list = new DSStringList; // Namensliste vorbereiten
assert(p_ident_list);
}