Skip to content

Commit

Permalink
Fixed #1483.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebattista committed Mar 9, 2023
1 parent 26711db commit 2c3d951
Show file tree
Hide file tree
Showing 7 changed files with 2,450 additions and 21 deletions.
2,433 changes: 2,433 additions & 0 deletions scripts/ChangesSinceLastRelease.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ private static bool HasGuidAttribute(SyntaxList<AttributeListSyntax> attributeLi
return ret;
}

private static bool HasPropertyKeyAttribute(SyntaxList<AttributeListSyntax> attributeLists)
{
bool ret = attributeLists.Any(list => list.Attributes.Any(attr => attr.Name.ToString() == "PropertyKey"));
return ret;
}

private static bool HasConstantAttribute(SyntaxList<AttributeListSyntax> attributeLists)
{
return attributeLists.Any(list => list.Attributes.Any(attr => attr.Name.ToString() == "Constant"));
Expand Down Expand Up @@ -1271,7 +1265,7 @@ private FieldDefinitionHandle WriteClassFields(ClassDeclarationSyntax node)
{
fieldAttributes = FieldAttributes.Public | FieldAttributes.Static;

if (!HasGuidAttribute(field.AttributeLists) && !HasPropertyKeyAttribute(field.AttributeLists) && !HasConstantAttribute(field.AttributeLists))
if (!HasGuidAttribute(field.AttributeLists) && !HasConstantAttribute(field.AttributeLists))
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion sources/ConstantsScraper/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"ConstantScraper": {
"commandName": "Project",
"commandLineArgs": "--repoRoot $(ProjectDir)..\\.. --arch x64 --enumsJson $(ProjectDir)..\\..\\generation\\scraper\\enums.json --headerTextFile $(ProjectDir)..\\..\\generation\\scraper\\ConstantsHeader.txt @$(ProjectDir)..\\..\\generation\\scraper\\ConstantsScraper.rsp @$(ProjectDir)..\\..\\generation\\emitter\\requiredNamespacesForNames.rsp @$(ProjectDir)..\\..\\generation\\emitter\\remap.rsp"
"commandLineArgs": "--scraperOutputDir $(ProjectDir)..\\..\\generation\\WinSDK\\obj\\generated @$(ProjectDir)..\\..\\generation\\WinSDK\\obj\\generated\\traversedFileToNamespace.rsp --enumsJson $(ProjectDir)..\\..\\generation\\WinSDK\\enums.json --headerTextFile $(ProjectDir)..\\..\\generation\\WinSDK\\ConstantsScraper.header.txt @$(ProjectDir)..\\..\\generation\\WinSDK\\ConstantsScraper.settings.rsp @$(ProjectDir)..\\..\\generation\\WinSDK\\requiredNamespacesForNames.rsp @$(ProjectDir)..\\..\\generation\\WinSDK\\emitter.settings.rsp"
}
}
}
2 changes: 2 additions & 0 deletions sources/GeneratorSdk/MetadataTasks/ScrapeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ private void AppendTraversedFilesAndNamespaces(StringBuilder rsp)
{
rsp.Insert(0, "--traversedFileToNamespace\n");
}

File.WriteAllText(Path.Combine(this.ScraperOutputDir, "traversedFileToNamespace.rsp"), rsp.ToString());
}
}
}
2 changes: 1 addition & 1 deletion sources/MetadataUtils/ConstantWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void AddPropKey(string structType, string name, string args)
this.namesToValues[name] = args;

this.Writer.WriteLine(
$@" [PropertyKey({args})]
$@" [Constant({args})]
public static readonly {structType} {name};");

this.Writer.WriteLine();
Expand Down
13 changes: 12 additions & 1 deletion sources/MetadataUtils/ConstantsScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,18 @@ private void AddConstantGuid(string defineGuidKeyword, string originalNamespace,
if (defineGuidKeyword == "DEFINE_DEVPROPKEY" || defineGuidKeyword == "DEFINE_PROPERTYKEY")
{
string structType = defineGuidKeyword == "DEFINE_DEVPROPKEY" ? "DEVPROPKEY" : "PROPERTYKEY";
writer.AddPropKey(structType, name, args);

var guidParts = args[..args.LastIndexOf(',')].Split(", ");
for (int i = 0; i < guidParts.Length; i++)
{
guidParts[i] = Convert.ToUInt32(guidParts[i].Trim(), 16).ToString();
}

var fmtid = $"{{{string.Join(", ", guidParts)}}}";
var pid = args[(args.LastIndexOf(',') + 1)..].Trim();
pid = pid.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase) ? Convert.ToUInt32(pid, 16).ToString() : pid;

writer.AddPropKey(structType, name, $"\"{fmtid}, {pid}\"");
}
else
{
Expand Down
11 changes: 0 additions & 11 deletions sources/Win32MetadataInterop/PropertyKeyAttribute.cs

This file was deleted.

0 comments on commit 2c3d951

Please sign in to comment.