8000 C++-backend: use a comparer when sorting in IncludeResolver (beta-3.0) by mortend · Pull Request #461 · fuse-open/uno · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

C++-backend: use a comparer when sorting in IncludeResolver (beta-3.0) #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/compiler/backend/cpp/DeclarationComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace Uno.Compiler.Backends.CPlusPlus
{
/** A comparer that makes strings starting with '#' come out first. */
public class DeclarationComparer : IComparer<string>
{
public static readonly DeclarationComparer Singleton = new DeclarationComparer();

public int Compare(string x, string y)
{
var xIsDirective = x.Length > 0 && x[0] == '#';
var yIsDirective = y.Length > 0 && y[0] == '#';

return xIsDirective && !yIsDirective
? -1
: !xIsDirective && yIsDirective
? 1
: x.CompareTo(y);
}
}
}
8 changes: 4 additions & 4 deletions src/compiler/backend/cpp/IncludeResolver.cs
Original file line number Diff line number Diff line change
885B Expand Up @@ -31,7 +31,7 @@ public string[] GetIncludes(Function f)
includes.Add(_backend.GetIncludeFilename(t));

var result = includes.ToArray();
Array.Sort(result);
Array.Sort(result, DeclarationComparer.Singleton);
return result;
}

Expand Down Expand Up @@ -141,9 +141,9 @@ public Declarations GetDeclarations(DataType dt, CppType type)
Inline = inlineDeclarations,
};

Array.Sort(result.Header);
Array.Sort(result.Source);
Array.Sort(result.Inline);
Array.Sort(result.Header, DeclarationComparer.Singleton);
Array.Sort(result.Source, DeclarationComparer.Singleton);
Array.Sort(result.Inline, DeclarationComparer.Singleton);
return result;
}

Expand Down
0