public void LiftedPrefixForPropertyImplementedAsNativeIndexerWorksWhenUsingTheReturnValue() { AssertCorrectForBoth( @"int? this[int x] { get { return 0; } set {} } public void M() { int i = 0; // BEGIN var x = ++this[i]; // END }", @" var $x = this[$i] = $Lift(this[$i] + 1); ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name) }); }
public void DivisionCompoundAssignmentOnlyInvokesTargetOnceForIntegralPropertiesImplementedAsNativeIndexers() { DoForAllIntegerTypes(type => AssertCorrect( @"class X { public type this[int x] { get { return 0; } set {} } } public X F1() { return null; } public void M() { int i = 0; type j = 0; // BEGIN F1()[i] /= j; // END } ".Replace("type", type), @" var $tmp1 = this.F1(); $tmp1[$i] = $IntDiv($tmp1[$i], $j); ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name) })); }
public void DivisionCompoundAssignmentWorksForFloatingPointPropertiesImplementedAsNativeIndexers() { DoForAllFloatingPointTypes(type => AssertCorrect( @"public type this[int x] { get { return 0; } set {} } public void M() { int i = 0; type j = 0; // BEGIN this[i] /= j; // END } ".Replace("type", type), @" this[$i] /= $j; ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name) })); }
public void CompoundAssigningToIndexerImplementedAsInlineCodeWorks() { AssertCorrectForBulkOperators( @"int this[int x, int y] { get { return 0; } set {} } public void M() { int i = 0, j = 1, k = 2; // BEGIN this[i, j] += k; // END }", @" set_(this)._($i)._($j)._(get_(this)._($i)._($j) + $k); ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.InlineCode("get_({this})._({x})._({y})"), MethodScriptSemantics.InlineCode("set_({this})._({x})._({y})._({value})")) : PropertyScriptSemantics.Field(p.Name) }); }
public void CompoundAssigningToPropertyImplementedAsNativeIndexerWorks() { AssertCorrectForBulkOperators( @"int this[int x] { get { return 0; } set {} } public void M() { int i = 0, j = 1, k = 2, l; // BEGIN l = this[i] += k; // END }", @" $l = this[$i] += $k; ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name) }); }
public void CanUseObjectInitializerWhenPropertySetMethodHasInlineCodeImplementation() { AssertCorrect( @"class X { public int x; public int P { get; set; } } public void M() { int i = 0, j = 0; // BEGIN var x = new X { x = i, P = j }; // END }", @" var $tmp1 = new {sm_X}(); $tmp1.$x = $i; set_P($tmp1, $j); var $x = $tmp1; ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.Name == "P" ? PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.InlineCode("get_P({this})"), MethodScriptSemantics.InlineCode("set_P({this}, {value})")) : PropertyScriptSemantics.Field(p.Name) }); }
public void ReadingIndexerImplementedAsNativeIndexerWorks() { AssertCorrect( @"int this[int x] { get { return 0; } set {} } public void M() { int a = 0, b = 0; // BEGIN var c = this[a]; // END }", @" var $c = this[$a]; ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name) }); }
public void AssigningToPropertyImplementedAsNativeIndexerWorksStruct() { AssertCorrect( @"int this[int x] { get { return 0; } set {} } public void M() { int i = 0, j = 1, k = 2, l; // BEGIN l = this[i] = k; // END }", @" this[$i] = $Clone($k, {to_Int32}); $l = $Clone(this[$i], {to_Int32}); ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name), GetTypeSemantics = t => TypeScriptSemantics.MutableValueType(t.Name) }); }
public void AssigningToIndexerImplementedAsInlineCodeWorksStruct() { AssertCorrect( @"int this[int x, int y] { get { return 0; } set {} } public void M() { int i = 0, j = 1, k = 2; // BEGIN this[i, j] = k; // END }", @" set_(this)._($Clone($i, {to_Int32}))._($Clone($j, {to_Int32}))._($Clone($k, {to_Int32})); ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.InlineCode("get_({this})._({x})._({y})"), MethodScriptSemantics.InlineCode("set_({this})._({x})._({y})._({value})")) : PropertyScriptSemantics.Field(p.Name), GetTypeSemantics = t => TypeScriptSemantics.MutableValueType(t.Name) }); }
public void PostfixForPropertyImplementedAsNativeIndexerWorks() { AssertCorrectForBoth( @"int this[int x] { get { return 0; } set {} } public void M() { int i = 0, j = 1; // BEGIN j = this[i]++; // END }", @" $j = this[$i]++; ", metadataImporter: new MockMetadataImporter { GetPropertySemantics = p => p.IsIndexer ? PropertyScriptSemantics.NativeIndexer() : PropertyScriptSemantics.Field(p.Name) }); }
public void ForeachStatementWithStrucElementType() { AssertCorrect( @" class MyEnumerable { public MyEnumerator GetEnumerator() { return null; } } sealed class MyEnumerator { public int Current { get { return 0; } } public bool MoveNext() {} } public void M() { MyEnumerable list = null; // BEGIN foreach (var item in list) { int x = 0; } // END }", @" var $tmp1 = $list.GetEnumerator(); while ($tmp1.MoveNext()) { var $item = $Clone($tmp1.Current, {to_Int32}); var $x = $Clone(0, {to_Int32}); } ", metadataImporter: new MockMetadataImporter { GetTypeSemantics = t => TypeScriptSemantics.MutableValueType(t.Name), GetPropertySemantics = p => PropertyScriptSemantics.Field(p.Name) }); }
public void ForeachOverArrayIsOptimizedToForLoopStruct() { AssertCorrect( @"public void M() { var arr = new[] { 1, 2, 3}; // BEGIN foreach (var item in arr) { int x = 0; } // END }", @" for (var $tmp1 = 0; $tmp1 < $arr.Length; $tmp1++) { var $item = $Clone($arr[$tmp1], {to_Int32}); var $x = $Clone(0, {to_Int32}); } ", metadataImporter: new MockMetadataImporter { GetTypeSemantics = t => TypeScriptSemantics.MutableValueType(t.Name), GetPropertySemantics = p => PropertyScriptSemantics.Field(p.Name) }); }