File tree Expand file tree Collapse file tree 5 files changed +18
-3
lines changed
Expand file tree Collapse file tree 5 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ public static IEnumerable<CodeHint> GetHints(this SyntaxNode rootNode)
4848 private static IEnumerable < CodeHint > DetectFunctionsToInline ( SyntaxNode rootNode )
4949 {
5050 var localFunctions = rootNode . FunctionDefinitions ( ) . ToList ( ) ;
51- foreach ( var function in localFunctions )
51+ var nonMainFunctions = localFunctions . Where ( o => ! o . IsMain ( ) ) . ToList ( ) ;
52+ foreach ( var function in nonMainFunctions )
5253 {
5354 var callSites =
5455 localFunctions
@@ -68,8 +69,8 @@ private static IEnumerable<CodeHint> DetectFunctionsToInline(SyntaxNode rootNode
6869
6970 private static IEnumerable < CodeHint > DetectUnusedFunctionParam ( SyntaxNode rootNode )
7071 {
71- var localFunctions = rootNode . FunctionDefinitions ( ) . ToList ( ) ;
72- foreach ( var function in localFunctions . Where ( o => ! o . IsMain ( ) ) )
72+ var localFunctions = rootNode . FunctionDefinitions ( ) . Where ( o => ! o . IsMain ( ) ) . ToList ( ) ;
73+ foreach ( var function in localFunctions )
7374 {
7475 foreach ( var paramName in function . ParamNames . Select ( o => o . Token . Content ) )
7576 {
Original file line number Diff line number Diff line change 1313using System . Collections . Generic ;
1414using System . Linq ;
1515using Shrinker . Parser . SyntaxNodes ;
16+ // ReSharper disable StringLiteralTypo
1617
1718namespace Shrinker . Parser . Optimizations
1819{
Original file line number Diff line number Diff line change @@ -652,6 +652,7 @@ namespace $NAMESPACE$
652652 <s : Boolean x : Key =" /Default/UserDictionary/Words/=nums/@EntryIndexedValue" >True</s : Boolean >
653653 <s : Boolean x : Key =" /Default/UserDictionary/Words/=Plex/@EntryIndexedValue" >True</s : Boolean >
654654 <s : Boolean x : Key =" /Default/UserDictionary/Words/=printrun/@EntryIndexedValue" >True</s : Boolean >
655+ <s : Boolean x : Key =" /Default/UserDictionary/Words/=Renamable/@EntryIndexedValue" >True</s : Boolean >
655656 <s : Boolean x : Key =" /Default/UserDictionary/Words/=screenpro/@EntryIndexedValue" >True</s : Boolean >
656657 <s : Boolean x : Key =" /Default/UserDictionary/Words/=Shadertoy/@EntryIndexedValue" >True</s : Boolean >
657658 <s : Boolean x : Key =" /Default/UserDictionary/Words/=Shrinker/@EntryIndexedValue" >True</s : Boolean >
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ public void CheckGolfingCodeNames(
6363 "void foo() { int a = 1; }|void f() { int a = 1; }" ,
6464 "void foo() { int _a = 1; }|void f() { int a = 1; }" ,
6565 "void main() { int number = 1; }|void main() { int n = 1; }" ,
66+ "void mainImage() { int number = 1; }|void mainImage() { int n = 1; }" ,
6667 "int foo() { int number = 1; number++; return number; }|int f() { int n = 1; n++; return n; }" ,
6768 "int foo() { int number = 1; return ++number; }|int f() { int n = 1; return ++n; }" ,
6869 "int foo() { int number = 1; return number++; }|int f() { int n = 1; return n++; }" ,
Original file line number Diff line number Diff line change @@ -42,6 +42,17 @@ public void CheckDetectingFunctionToInline()
4242 Assert . That ( rootNode . GetHints ( ) . OfType < FunctionToInlineHint > ( ) . ToList ( ) , Has . Count . EqualTo ( 1 ) ) ;
4343 }
4444
45+ [ Test ]
46+ public void CheckInlineHintNotGivenForMainFunctions ( )
47+ {
48+ var lexer = new Lexer ( ) ;
49+ lexer . Load ( "vec3 mainImage() { return vec3(0); } vec3 main() { return mainImage(); }" ) ;
50+
51+ var rootNode = new Parser ( lexer ) . Parse ( ) ;
52+
53+ Assert . That ( rootNode . GetHints ( ) . OfType < FunctionToInlineHint > ( ) . ToList ( ) , Is . Empty ) ;
54+ }
55+
4556 [ Test , Sequential ]
4657 public void CheckDetectingFunctionWithUnusedParam (
4758 [ Values (
You can’t perform that action at this time.
0 commit comments