Skip to content

Commit 0cc49b8

Browse files
committed
Fixing Issues for Microsoft Job
- Fix duplicate Entries in prettifyNames - Add RemapTypes to fix remappings in manual Files - Add RemoveStaticUsings to fix static usings in manual files - Removed Timing recoding from TransformFunctions (was meant to be temp) - Added RemapAllAsync to NameUtils - Moved regex logic to FileUtils
1 parent 0ce3d28 commit 0cc49b8

File tree

11 files changed

+492
-134
lines changed

11 files changed

+492
-134
lines changed

generator.json

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
"ClangScraper",
1010
"ImportManualFiles",
1111
"ChangeNamespace",
12+
"RemapTypes",
13+
"RemoveStaticUsings",
1214
"TransformInterfaces",
1315
"TransformCOM",
1416
"DisableWarnings",
15-
"TransformFunctions"
17+
"TransformFunctions",
18+
"PrettifyNames"
1619
],
1720
"ClangScraper": {
1821
"ClangSharpResponseFiles": [
@@ -34,11 +37,13 @@
3437
"sources/Windows/shared/strsafe/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/strsafe/Windows.cs",
3538
"sources/Windows/shared/ws2ipdef/Windows.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/ws2ipdef/Windows.cs",
3639
"sources/Windows/shared/Iprtrmib/MIB_OPAQUE_INFO.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/Iprtrmib/MIB_OPAQUE_INFO.cs",
40+
"sources/Windows/shared/winerror/**.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/Windows/shared/winerror/**.cs",
3741
"sources/WinRT/winrt/windows.applicationmodel.email/IEmailMailboxSmimeEncryptionAlgorithm.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.applicationmodel.email/EmailMailboxSmimeEncryptionAlgorithm.cs",
3842
"sources/WinRT/winrt/windows.applicationmodel.email/IEmailMailboxSmimeSigningAlgorithm.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.applicationmodel.email/EmailMailboxSmimeSigningAlgorithm.cs",
3943
"sources/WinRT/winrt/windows.perception.spatial/ISpatialCoordinateSystem.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.perception.spatial/ISpatialCoordinateSystem.cs",
4044
"sources/WinRT/winrt/windows.security.authentication.web.core/IID.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.security.authentication.web.core/IID.Manual.cs",
41-
"sources/WinRT/winrt/windows.ui.input/IID.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.ui.input/IID.Manual.cs"
45+
"sources/WinRT/winrt/windows.ui.input/IID.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/windows.ui.input/IID.Manual.cs",
46+
"sources/WinRT/winrt/winstring/WinRT.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/WinRT/winrt/winstring/WinRT.cs"
4247
},
4348
"InputSourceRoot": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows",
4449
"InputTestRoot": "eng/submodules/terrafx.interop.windows/tests/Interop/Windows",
@@ -53,45 +58,50 @@
5358
"sources/**/helper-types/*Attribute.gen.cs",
5459
"sources/**/helper-types/HRESULT.gen.cs",
5560
"sources/**/helper-types/BOOL.gen.cs",
56-
"sources/**/helper-types/HSTRING.gen.cs"
61+
"sources/**/helper-types/HSTRING.gen.cs",
62+
"sources/WinRT/um/efswrtinterop/WinRT.gen.cs",
63+
"sources/WinRT/um/appserviceinterop/WinRT.gen.cs",
64+
"sources/WinRT/winrt/windows.media.casting/CastingConnectionErrorStatus.gen.cs",
65+
"sources/WinRT/winrt/windows.media.casting/CastingConnectionState.gen.cs"
5766
],
5867
"InjectedRemappedNames": {
5968
"BOOL": "MaybeBool<int>",
6069
"HANDLE": "Handle"
6170
},
6271
"InjectedGeneratorOptions": [
6372
"--config",
64-
"dont-use-using-statics-for-guid-members"
73+
"dont-use-using-statics-for-guid-members",
74+
"dont-use-using-statics-for-enums"
6575
]
6676
},
6777
"ImportManualFiles": {
6878
"ManualImports": {
69-
"sources/**.Manual.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/**.Manual.cs",
70-
"!sources/**/INativeGuid.Manual.cs": "!**/INativeGuid.Manual.cs",
71-
"!sources/**/HWND.Manual.cs": "!**/HWND.Manual.cs",
72-
"!sources/**/HRESULT.Manual.cs": "!**/HRESULT.Manual.cs",
73-
"!sources/**/ID2D1*.Manual.cs": "!**/ID2D1*.Manual.cs",
74-
"!sources/**/d2d1_1helper/DirectX.Manual.cs": "!**/d2d1_1helper/DirectX.Manual.cs",
75-
"!sources/**/DirectXHelpers/DirectX.Manual.cs": "!**/DirectXHelpers/DirectX.Manual.cs",
76-
"!sources/**/d2d1/DirectX.Manual.cs": "!**/d2d1/DirectX.Manual.cs",
77-
"!sources/**/IWeakReference.Manual.cs": "!**/IWeakReference.Manual.cs",
78-
"!sources/**/IDispatchEx.Manual.cs": "!**/IDispatchEx.Manual.cs",
79-
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER.Manual.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER.Manual.cs",
80-
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM1_PARSE_HELPER.Manual.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM1_PARSE_HELPER.Manual.cs",
81-
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM2_PARSE_HELPER.Manual.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM2_PARSE_HELPER.Manual.cs",
82-
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM3_PARSE_HELPER.Manual.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM3_PARSE_HELPER.Manual.cs",
83-
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM4_PARSE_HELPER.Manual.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM4_PARSE_HELPER.Manual.cs",
84-
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM5_PARSE_HELPER.Manual.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM5_PARSE_HELPER.Manual.cs",
85-
"!sources/**/ShObjIdl_core/Windows.Manual.cs": "!**/ShObjIdl_core/Windows.Manual.cs",
86-
"!sources/**/propvarutil/Windows.Manual.cs": "!**/propvarutil/Windows.Manual.cs",
87-
"!sources/**/uuids/Windows.Manual.cs": "!**/uuids/Windows.Manual.cs",
88-
"!sources/**/gdipluscolor/Color.Manual.cs": "!**/gdipluscolor/Color.Manual.cs",
89-
"!sources/**/windows.ui.input/IID.Manual.cs": "!**/windows.ui.input/IID.Manual.cs",
90-
"!sources/**/windows.security.authentication.web.core/IID.Manual.cs": "!**/windows.security.authentication.web.core/IID.Manual.cs",
91-
"!sources/**/roapi/WinRT.Manual.cs": "!**/roapi/WinRT.Manual.cs",
92-
"!sources/**/windows.graphics.directx.direct3d11.interop/WinRT.Manual.cs": "!**/windows.graphics.directx.direct3d11.interop/WinRT.Manual.cs",
93-
"!sources/**/roparameterizediid/**.Manual.cs": "!**/roparameterizediid/**.Manual.cs",
94-
"!sources/**/d2d1_1/D2D1_**.Manual.cs": "!**/d2d1_1/D2D1_**.Manual.cs"
79+
"sources/**.TerraFXAdditions.gen.cs": "eng/submodules/terrafx.interop.windows/sources/Interop/Windows/**.Manual.cs",
80+
"!sources/**/INativeGuid.TerraFXAdditions.gen.cs": "!**/INativeGuid.Manual.cs",
81+
"!sources/**/HWND.TerraFXAdditions.gen.cs": "!**/HWND.Manual.cs",
82+
"!sources/**/HRESULT.TerraFXAdditions.gen.cs": "!**/HRESULT.Manual.cs",
83+
"!sources/**/ID2D1*.TerraFXAdditions.gen.cs": "!**/ID2D1*.Manual.cs",
84+
"!sources/**/d2d1_1helper/DirectX.TerraFXAdditions.gen.cs": "!**/d2d1_1helper/DirectX.Manual.cs",
85+
"!sources/**/DirectXHelpers/DirectX.TerraFXAdditions.gen.cs": "!**/DirectXHelpers/DirectX.Manual.cs",
86+
"!sources/**/d2d1/DirectX.TerraFXAdditions.gen.cs": "!**/d2d1/DirectX.Manual.cs",
87+
"!sources/**/IWeakReference.TerraFXAdditions.gen.cs": "!**/IWeakReference.Manual.cs",
88+
"!sources/**/IDispatchEx.TerraFXAdditions.gen.cs": "!**/IDispatchEx.Manual.cs",
89+
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER.TerraFXAdditions.gen.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER.Manual.cs",
90+
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM1_PARSE_HELPER.TerraFXAdditions.gen.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM1_PARSE_HELPER.Manual.cs",
91+
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM2_PARSE_HELPER.TerraFXAdditions.gen.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM2_PARSE_HELPER.Manual.cs",
92+
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM3_PARSE_HELPER.TerraFXAdditions.gen.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM3_PARSE_HELPER.Manual.cs",
93+
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM4_PARSE_HELPER.TerraFXAdditions.gen.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM4_PARSE_HELPER.Manual.cs",
94+
"!sources/**/CD3DX12_PIPELINE_STATE_STREAM5_PARSE_HELPER.TerraFXAdditions.gen.cs": "!**/CD3DX12_PIPELINE_STATE_STREAM5_PARSE_HELPER.Manual.cs",
95+
"!sources/**/ShObjIdl_core/Windows.TerraFXAdditions.gen.cs": "!**/ShObjIdl_core/Windows.Manual.cs",
96+
"!sources/**/propvarutil/Windows.TerraFXAdditions.gen.cs": "!**/propvarutil/Windows.Manual.cs",
97+
"!sources/**/uuids/Windows.TerraFXAdditions.gen.cs": "!**/uuids/Windows.Manual.cs",
98+
"!sources/**/gdipluscolor/Color.TerraFXAdditions.gen.cs": "!**/gdipluscolor/Color.Manual.cs",
99+
"!sources/**/windows.ui.input/IID.TerraFXAdditions.gen.cs": "!**/windows.ui.input/IID.Manual.cs",
100+
"!sources/**/windows.security.authentication.web.core/IID.TerraFXAdditions.gen.cs": "!**/windows.security.authentication.web.core/IID.Manual.cs",
101+
"!sources/**/roapi/WinRT.TerraFXAdditions.gen.cs": "!**/roapi/WinRT.Manual.cs",
102+
"!sources/**/windows.graphics.directx.direct3d11.interop/WinRT.TerraFXAdditions.gen.cs": "!**/windows.graphics.directx.direct3d11.interop/WinRT.Manual.cs",
103+
"!sources/**/roparameterizediid/**.TerraFXAdditions.gen.cs": "!**/roparameterizediid/**.Manual.cs",
104+
"!sources/**/d2d1_1/D2D1_**.TerraFXAdditions.gen.cs": "!**/d2d1_1/D2D1_**.Manual.cs"
95105
}
96106
},
97107
"ChangeNamespace": {
@@ -100,6 +110,14 @@
100110
"TerraFX.Interop(?!.Windows)(.*)": "Silk.NET$1"
101111
}
102112
},
113+
"RemapTypes": {
114+
"Mappings": {
115+
"HSTRING": "HString",
116+
"HRESULT": "HResult",
117+
"BOOL": "MaybeBool<int>",
118+
"HANDLE": "Handle"
119+
}
120+
},
103121
"TransformInterfaces": {
104122
"AdditionalInterfaces": [
105123
"IDispatchEx"
@@ -127,9 +145,13 @@
127145
"TransformFunctions": {
128146
},
129147
"PrettifyNames": {
148+
"LongAcronymThreshold": 4,
130149
"NameOverrides": {
131150
"HSTRING": "HString",
132-
"HRESULT": "HResult"
151+
"HRESULT": "HResult",
152+
"GUID": "IID",
153+
"ISVGPointList": "ISVGPointList",
154+
"ISVGPoint": "ISVGPoint"
133155
}
134156
}
135157
},

sources/SilkTouch/SilkTouch/Clang/ClangScraper.cs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ private async Task ScrapeBindingsAsync(
294294
cacheKey = null;
295295
}
296296

297+
Dictionary<Regex, string> regexConverters = [];
298+
foreach (var import in cfg.ManualOverrides ?? [])
299+
{
300+
string regexPatternIn = FileUtils.GlobToRegexInput(import.Key);
301+
string regexPatternOut = FileUtils.GlobToRegexOutput(import.Value);
302+
303+
regexConverters.Add(new(regexPatternIn), regexPatternOut);
304+
}
305+
297306
string? cacheDir = null;
298307

299308
// Figure out what the common root is so we can aggregate the file paths without collisions
@@ -392,31 +401,7 @@ static MemoryStream Reopen(MemoryStream ms) =>
392401
}
393402

394403
// Add it to the dictionary.
395-
if (
396-
!(isTest ? aggregatedTests : aggregatedSources).TryAdd(
397-
relativeKey,
398-
CSharpSyntaxTree.ParseText(
399-
SourceText.From(
400-
cfg.ManualOverrides?.TryGetValue(
401-
relativePath,
402-
out var @override
403-
) ?? false
404-
? File.OpenRead(
405-
await inputResolver.ResolvePath(@override)
406-
)
407-
: stream
408-
),
409-
path: relativeKey
410-
)
411-
)
412-
)
413-
{
414-
logger.LogError(
415-
"Failed to add {0} - are the response file outputs conflicting?",
416-
relativeKey
417-
);
418-
}
419-
else
404+
if (!FileUtils.ImportIfRegexMatches(regexConverters, relativePath, isTest, relativeKey, aggregatedTests, aggregatedSources, logger, stream))
420405
{
421406
logger.LogTrace("ClangSharp generated {0}", relativeKey);
422407
}

sources/SilkTouch/SilkTouch/Mods/Common/ModLoader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class ModLoader
3333
nameof(TransformCOM) => typeof(TransformCOM),
3434
nameof(DisableWarnings) => typeof(DisableWarnings),
3535
nameof(ImportManualFiles) => typeof(ImportManualFiles),
36+
nameof(RemapTypes) => typeof(RemapTypes),
37+
nameof(RemoveStaticUsings) => typeof(RemoveStaticUsings),
3638
_ => null,
3739
};
3840
}

sources/SilkTouch/SilkTouch/Mods/ImportManualFiles.cs

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
6262

6363
foreach (var import in cfg.ManualImports)
6464
{
65-
string regexPatternIn = GlobToRegexInput(import.Value);
66-
string regexPatternOut = GlobToRegexOutput(import.Key);
65+
string regexPatternIn = FileUtils.GlobToRegexInput(import.Value);
66+
string regexPatternOut = FileUtils.GlobToRegexOutput(import.Key);
6767

6868
pathGlobs.Add(import.Value);
6969

@@ -77,43 +77,17 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
7777

7878
foreach (var file in files)
7979
{
80-
foreach (var regex in regexConverters)
81-
{
82-
if (regex.Key.Match(file).Success)
83-
{
84-
string outputLocation = regex.Key.Replace(file, regex.Value);
85-
bool isTest = outputLocation.StartsWith("tests/");
86-
outputLocation = outputLocation.Remove(
87-
0,
88-
outputLocation.IndexOf(isTest ? "tests/" : "sources/")
89-
);
90-
string relativeKey = outputLocation.Remove(0, isTest ? 6 : 8);
91-
if (
92-
!(isTest ? aggregatedTests : aggregatedSources).TryAdd(
93-
relativeKey,
94-
CSharpSyntaxTree.ParseText(
95-
SourceText.From(File.OpenRead(file)),
96-
path: relativeKey
97-
)
98-
)
99-
)
100-
{
101-
logger.LogError(
102-
"Failed to add {0} - are the response file outputs conflicting?",
103-
relativeKey
104-
);
105-
}
106-
else
107-
{
108-
logger.LogTrace("ClangSharp generated {0}", relativeKey);
109-
}
110-
}
111-
}
80+
FileUtils.ImportIfRegexMatches(regexConverters, file, false, null, aggregatedTests, aggregatedSources, logger);
11281
}
11382

11483
var src = ctx.SourceProject;
11584
foreach (var (fname, tree) in aggregatedSources)
11685
{
86+
if (!fname.EndsWith(".gen.cs"))
87+
{
88+
logger.LogWarning($"Imported file {fname} does not end in .gen.cs which may produce undefined behavior");
89+
}
90+
11791
src = src
11892
?.AddDocument(
11993
Path.GetFileName(fname),
@@ -139,18 +113,5 @@ await tree.GetRootAsync(ct),
139113

140114
ctx.TestProject = test;
141115
}
142-
143-
private string GlobToRegexInput(string glob)
144-
{
145-
return glob.Replace("*", "**").Replace("****", "(.*)").Replace("**", @"([^\/]*)");
146-
}
147-
148-
private string GlobToRegexOutput(string glob)
149-
{
150-
int index = 1;
151-
return glob.Split("**")
152-
.SelectMany(split => split.Split('*'))
153-
.Aggregate((s1, s2) => $"{s1}${index++}{s2}");
154-
}
155116
}
156117
}

sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ functions is null || functionNames is null
202202
// Add it to the rewriter's list of names to... rewrite...
203203
types[typeName] = (
204204
newTypeName.Prettify(translator, allowAllCaps: true), // <-- lenient about caps for type names
205-
// TODO deprecate secondaries if they're within the baseline?
205+
// TODO deprecate secondaries if they're within the baseline?
206206
constNames
207-
.Concat(prettifiedOnly)
207+
.Concat(prettifiedOnly.DistinctBy(kvp => kvp.Key).ToDictionary())
208208
.ToDictionary(x => x.Key, x => x.Value.Primary.Prettify(translator)),
209209
functionNames?.ToDictionary(
210210
x => x.Key,
@@ -268,11 +268,13 @@ functions is null || functionNames is null
268268
var sw = Stopwatch.StartNew();
269269
logger.LogDebug("Discovering references to symbols to rename for {}...", ctx.JobKey);
270270
ctx.SourceProject = proj;
271+
271272
var comp =
272273
await proj.GetCompilationAsync(ct)
273274
?? throw new InvalidOperationException(
274275
"Failed to obtain compilation for source project!"
275276
);
277+
276278
await NameUtils.RenameAllAsync(
277279
ctx,
278280
types.SelectMany(x =>
@@ -316,6 +318,7 @@ z.MethodKind is MethodKind.Constructor or MethodKind.Destructor
316318
logger,
317319
ct
318320
);
321+
319322
logger.LogDebug(
320323
"Reference renaming took {} seconds for {}.",
321324
sw.Elapsed.TotalSeconds,
@@ -761,7 +764,7 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
761764

762765
// Merge with the other partials.
763766
(inner.NonFunctions ??= new List<string>()).AddRange(
764-
_classInProgress.Value.NonFunctions
767+
_classInProgress.Value.NonFunctions.Where(val => !inner.NonFunctions?.Contains(val) ?? true)
765768
);
766769
(inner.Functions ??= new List<(string, MethodDeclarationSyntax)>()).AddRange(
767770
_classInProgress.Value.Functions

0 commit comments

Comments
 (0)