@@ -45,7 +45,7 @@ public KopCodeHelper(CodeBlock block)
4545
4646 private void AddSignalDefinitions ( Network network )
4747 {
48- var signals = network . Children . Flatten ( x => x . Children ) . OfType < Signal > ( ) ;
48+ var signals = network . Children . Flatten ( x => x . Children ) . OfType < Signal > ( ) . OrderBy ( x => x . Name , new NaturalComparer ( ) ) ;
4949
5050 foreach ( var signal in signals )
5151 {
@@ -84,6 +84,24 @@ private void AddContactDefinitions(Network network, CodeBlock block)
8484 {
8585 var ops = FlattenOrdered ( network . Children , x => x . Children ) . OfType < IOperationOrSignal > ( ) . ToList ( ) ;
8686
87+ foreach ( var op in ops )
88+ {
89+ if ( op is Signal )
90+ {
91+ }
92+ else if ( op is And || ( op is Or && op . Children . Count == 1 ) )
93+ {
94+ }
95+ else
96+ {
97+ if ( op is Or && op . Children . Count > 1 )
98+ {
99+ //We need to fill this before
100+ op . CreateContactAndFillCardinality ( op ) ;
101+ }
102+ }
103+ }
104+
87105 foreach ( var op in ops )
88106 {
89107 if ( op is Signal )
@@ -107,22 +125,22 @@ private void AddContactDefinitions(Network network, CodeBlock block)
107125 op . Children [ 0 ] . OperationId = _currentId ;
108126 }
109127
110- if ( ! ( op is Distributor ) )
111- _currentId ++ ;
112-
113128 if ( op is Or && op . Children . Count > 1 )
114129 {
115130 op . CreateContactAndFillCardinality ( op ) ;
116131 }
132+
133+ if ( ! ( op is Distributor ) && ! op . DoNotCreateContact )
134+ _currentId ++ ;
117135 }
118136 }
119137
120138 /*_sb.AppendLine("<!--");
121- foreach (var op in ops)
139+ foreach (var op in ops)
122140 {
123- _sb.AppendLine(op.ToString() + " -- " + op.OperationId);
124- }
125- _sb.AppendLine("-->");*/
141+ _sb.AppendLine(op.ToString() + " -- " + op.OperationId);
142+ }
143+ _sb.AppendLine("-->");*/
126144
127145 foreach ( var op in ops )
128146 {
@@ -528,7 +546,7 @@ private void AddWires(IOperationOrSignal op)
528546 }
529547 else if ( c is And && c . Children . FirstOrDefault ( ) is Or )
530548 {
531- foreach ( var chIn in c . Children . FirstOrDefault ( ) . Children )
549+ foreach ( var chIn in c . Children . FirstOrDefault ( ) . Children )
532550 {
533551 foreach ( var ch in GetAllOrSignals ( chIn ) )
534552 {
@@ -545,7 +563,7 @@ private void AddWires(IOperationOrSignal op)
545563 }
546564 }
547565 else
548- {
566+ {
549567 if ( sng is Signal )
550568 {
551569 _sb . AppendLine ( "<IdentCon UId=\" " + ( ( Signal ) sng ) . SignalId + "\" />" + " <!-- " + ( ( Signal ) sng ) . Name + " -->" ) ;
@@ -573,35 +591,32 @@ private void AddWires(IOperationOrSignal op)
573591 _sb . AppendLine ( "</Wire>" ) ;
574592 _currentId ++ ;
575593 }
576- else if ( op is Or && op . Children . Count > 1 )
577- {
578- int i = 1 ;
579- foreach ( var ch in op . Children )
594+ else if ( op is Or or & & op . Children . Count > 1 )
595+ {
596+ var orInputCounter = 1 ;
597+ void ImportChildOrs ( Or childOr )
580598 {
581- if ( ch is And && ch . Children . Last ( ) is Or ) //Todo nur ein letztes or im and, könnte weiter verschachtelt sein
599+ var aaa = or ;
600+ foreach ( var ch in childOr . Children )
582601 {
583- foreach ( var ch2 in ch . Children . Last ( ) . Children )
602+ if ( ch . Children . Count > 0 && ch . Children . Last ( ) is Or subChildOr )
584603 {
585- _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( "<!-- Wire 1 Or -->" ) ) ) ;
586- _sb . AppendLine ( "<NameCon UId=\" " + ch2 . OperationId + "\" Name=\" out\" />" + " <!-- " + ch2 . ToString ( ) + " -->" ) ;
587- _sb . AppendLine ( "<NameCon UId=\" " + op . OperationId + "\" Name=\" in" + i + "\" />" + " <!-- " + op . ToString ( ) + " -->" ) ;
588- _sb . AppendLine ( "</Wire>" ) ;
589- i ++ ;
590- _currentId ++ ;
604+ ImportChildOrs ( subChildOr ) ;
591605 }
592- }
593- else
594- {
595- if ( ! op . DoNotCreateContact )
606+ else
596607 {
597- _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( "<!-- Wire 2 Or -->" ) ) ) ;
608+ _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( ( op . DebugInfo != null ? " <!-- dbg: " + op . DebugInfo + "-->" : "" ) + "<!-- Wire 2 Or -->" ) ) ) ;
598609 _sb . AppendLine ( "<NameCon UId=\" " + ch . OperationId + "\" Name=\" out\" />" + " <!-- " + ch . ToString ( ) + " -->" ) ;
599- _sb . AppendLine ( "<NameCon UId=\" " + op . OperationId + "\" Name=\" in" + i + "\" />" + " <!-- " + op . ToString ( ) + " -->" ) ;
610+ _sb . AppendLine ( "<NameCon UId=\" " + op . OperationId + "\" Name=\" in" + orInputCounter + "\" />" + " <!-- " + op . ToString ( ) + " -->" ) ;
600611 _sb . AppendLine ( "</Wire>" ) ;
601- i ++ ;
612+ orInputCounter ++ ;
602613 _currentId ++ ;
603614 }
604615 }
616+ } ;
617+ if ( ! op . DoNotCreateContact )
618+ {
619+ ImportChildOrs ( or ) ;
605620 }
606621 }
607622 else if ( op is CompareOperator )
@@ -653,15 +668,15 @@ private void AddWires(IOperationOrSignal op)
653668 }
654669 }
655670 }
656- else if ( op is And || op is Or )
671+ else if ( op is And /* || op is Or */ /* do we still get here? only with Or with one child */ )
657672 {
658673 for ( int n = 0 ; n < op . Children . Count - 1 ; n ++ )
659674 {
660675 var ch = op . Children [ n ] ;
661676 var next = op . Children [ n + 1 ] ;
662677 if ( next is Or )
663678 {
664- _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( "<!-- Wire And next Or -->" ) ) ) ;
679+ _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( ( op . DebugInfo != null ? " <!-- dbg: " + op . DebugInfo + "-->" : "" ) + "<!-- Wire And next Or -->" ) ) ) ;
665680 _sb . AppendLine ( "<NameCon UId=\" " + ch . OperationId + "\" Name=\" out\" />" + ( ch is Signal ? " <!-- " + ( ( Signal ) ch ) . Name + " -->" : "" ) ) ;
666681 foreach ( var orSignal in next . Children )
667682 {
@@ -682,7 +697,7 @@ private void AddWires(IOperationOrSignal op)
682697 }
683698 else
684699 {
685- _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( "<!-- Wire And -->" ) ) ) ;
700+ _sb . AppendLine ( "<Wire UId=\" " + _currentId + "\" >" + ( debug ?? ( ( op . DebugInfo != null ? " <!-- dbg: " + op . DebugInfo + "-->" : "" ) + "<!-- Wire And -->" ) ) ) ;
686701 var outName = "out" ;
687702 if ( ch is FunctionCall || ch is S_Move || ch is Move || ch is Convert )
688703 outName = "eno" ;
@@ -1060,9 +1075,9 @@ public string GetXml(ref int id)
10601075 }
10611076 }
10621077 /*_sb.AppendLine("<!--");
1063- _sb.AppendLine("<!--");
1064- PrintTree(_block, _sb);
1065- _sb.AppendLine("-->");*/
1078+ _sb.AppendLine("<!--");
1079+ PrintTree(_block, _sb);
1080+ _sb.AppendLine("-->");*/
10661081 return _sb . ToString ( ) ;
10671082 }
10681083
0 commit comments