[Mono-bugs] [Bug 75292][Nor] New - C# compiler can't generate CodeDOM Iteration

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jun 17 09:15:06 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by llaske at c2s.fr.

http://bugzilla.ximian.com/show_bug.cgi?id=75292

--- shadow/75292	2005-06-17 09:15:06.000000000 -0400
+++ shadow/75292.tmp.11394	2005-06-17 09:15:06.000000000 -0400
@@ -0,0 +1,100 @@
+Bug#: 75292
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: Windows XP SP 2
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: llaske at c2s.fr               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: C# compiler can't generate CodeDOM Iteration
+
+I'm using Mono to write a compiler and I need to generate a loop.
+So, I'm using CodeIterationStatement class and CSharpCodeProvider to do 
+the generation.
+
+Unfortunatly, I can't generate a valid C# code statement and compiler 
+stop with an error.
+
+Here is my code (I took a sample from MSDN library):
+
+			// Declares and initializes an integer variable 
+named testInt.
+			CodeVariableDeclarationStatement testInt = new 
+CodeVariableDeclarationStatement(typeof(int), "testInt", new 
+CodePrimitiveExpression(1) );
+
+			// Creates a for loop that sets testInt to 0 and 
+continues incrementing testInt by 1 each loop until testInt is not less 
+than 10.
+			CodeIterationStatement forLoop = new 
+CodeIterationStatement(
+				// initStatement parameter for pre-loop 
+initialization.
+				testInt,
+				// testExpression parameter to test for 
+continuation condition.
+				new CodeBinaryOperatorExpression( new 
+CodeVariableReferenceExpression("testInt"), 
+				CodeBinaryOperatorType.LessThan, new 
+CodePrimitiveExpression(10) ),
+				// incrementStatement parameter indicates 
+statement to execute after each iteration.
+				new CodeAssignStatement( new 
+CodeVariableReferenceExpression("testInt"), new 
+CodeBinaryOperatorExpression( 
+				new CodeVariableReferenceExpression
+("testInt"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression
+(1) )),
+				// statements parameter contains the 
+statements to execute during each interation of the loop.
+				// Each loop iteration the value of the 
+integer is output using the Console.WriteLine method.
+				new CodeStatement[] { new 
+CodeExpressionStatement( new CodeMethodInvokeExpression( new 
+CodeMethodReferenceExpression( 
+									
+	new CodeTypeReferenceExpression("Console"), "WriteLine" ), new 
+CodeMethodInvokeExpression( 
+									
+	new CodeVariableReferenceExpression
+("testInt"), "ToString" ) ) ) } );
+			mtd1.Statements.Add(forLoop);
+
+
+As a result, I expect to have something like this (and it's what I have 
+when I'm using .NET Framework 1.1):
+
+            for (int testInt = 1; (testInt < 10); testInt = (testInt + 
+1)) {
+                Console.WriteLine(testInt.ToString());
+            }
+
+Unfortunatly, Mono generate:
+
+            for (int testInt = 1;
+            ; (testInt < 10); testInt = (testInt + 1)) {
+                Console.WriteLine(testInt.ToString());
+            }
+
+Strangly, there is two semi-colon so I guess it's why compiler can't do 
+its job.
+
+I made few test but with no more result:
+- Separate declaration and assignement for "testInt",
+- Replace initialization by nothing,
+- Replace initialization by a boolean ("true")
+-...
+
+I made the test on Mono 1.0.6 and Mono 1.1.7 with the same result.
+
+Including (if I can join a file :-) is the full sample to reproduce this 
+bug. Just compile to "LoopTest.exe" and launch it. It must generate 
+a "loop.cs" and when it works a "loop.exe".


More information about the mono-bugs mailing list