History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-793
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Rodrigo B. de Oliveira
Reporter: Cedric Vivier
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Boo

Compiler does not emit gendarme-compliant IL when using interpolation expressions

Created: 22/Jan/07 05:44 PM   Updated: 12/Feb/07 04:36 PM
Component/s: Compiler
Affects Version/s: None
Fix Version/s: 0.7.7

Time Tracking:
Not Specified

File Attachments: 1. Text File interpolation-1.patch (2 kb)
2. Text File interpolation-2.patch (2 kb)
3. Text File interpolation.patch (2 kb)



 Description  « Hide
Here is a simple testcase :

==================================================================
cedric@laptop:~/dev/workspace/boo-svn/tests$ cat interpolation.boo
x = 2

print "TEST 1 (starting with expression)"
print "${x}+2=4"

print "TEST 2 (not starting with expression)"
print "Calculus: ${x}+2=4"
==================================================================

After compiling it with booc, let's run gendarme on the resulting assembly :

===========================================================================
cedric@laptop:~/dev/workspace/boo-svn/tests$ gendarme interpolation.exe
Gendarme v0.0.3.1
Copyright (C) 2005-2006 Novell, Inc. and contributors

/home/cedric/dev/workspace/boo-svn/tests/interpolation.exe - completed (0,150614 seconds).

1 assemblies processed in 0,156524 seconds.

1. UseStringEmptyRule

Problem: The method 'System.Void InterpolationModule::Main(System.String[])' use literal "" instead of String.Empty.

Details:
InterpolationModule::Main:0017: instance of an empty string has been found.

Solution: Change the empty string for String.Empty.
==================================================================================

By disassembling the assembly we see that there is a ldstr "" appended to the stringbuffer when (and only when) the interpolation expression starts with an expression :

===========================================================================
cedric@laptop:~/dev/workspace/boo-svn/tests$ monodis interpolation.exe
(...)
IL_0000: ldc.i4 2
IL_0005: stloc.0
IL_0006: nop
IL_0007: ldstr "TEST 1 (starting with expression)"
IL_000c: call void class [mscorlib]System.Console::WriteLine(string)
IL_0011: nop
IL_0012: newobj instance void class [mscorlib]System.Text.StringBuilder::.ctor()
IL_0017: ldstr ""
IL_001c: call instance class [mscorlib]System.Text.StringBuilder class [mscorlib]System.Text.StringBuilder::Append(string)
IL_0021: ldloc.0
IL_0022: box [mscorlib]System.Int32
IL_0027: call instance class [mscorlib]System.Text.StringBuilder class [mscorlib]System.Text.StringBuilder::Append(object)

Attached a patch who fixes this misbehavior and also optimizes interpolation by instancing the StringBuffer with constructor(string) instead of constructor() when the first expression is a string - thus saving an unnecessary call to Append(string).



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Cedric Vivier - 06/Feb/07 04:00 AM
Works with "patch -p0 < interpolation-1.patch" from base directory (boo/).

Cedric Vivier - 12/Feb/07 03:06 PM
Same patch made from svn diff this time.

Cedric Vivier - 12/Feb/07 03:07 PM
Previous comment is about "interpolation-2.patch" of course.

Arron Washington - 12/Feb/07 04:36 PM
Passed all test-cases + peverify, so committed.