Skip to content

Commit

Permalink
Merge pull request #696 from microsoft/metadataUpdate
Browse files Browse the repository at this point in the history
Update metadata to 33.0.18-preview
  • Loading branch information
AArnott authored Sep 22, 2022
2 parents fef9088 + 642ddff commit 89e7e0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<IncludeSymbols Condition=" '$(DebugType)' != 'embedded' ">true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<MetadataVersion>31.0.4-preview</MetadataVersion>
<MetadataVersion>33.0.18-preview</MetadataVersion>
<!-- <DiaMetadataVersion>0.2.185-preview-g7e1e6a442c</DiaMetadataVersion> -->
<ApiDocsVersion>0.1.7-alpha</ApiDocsVersion>
</PropertyGroup>
Expand Down
21 changes: 15 additions & 6 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4403,8 +4403,9 @@ private EnumDeclarationSyntax DeclareEnum(TypeDefinition typeDef)
continue;
}

bool enumBaseTypeIsSigned = enumBaseType is PredefinedTypeSyntax { Keyword: { RawKind: (int)SyntaxKind.LongKeyword or (int)SyntaxKind.IntKeyword or (int)SyntaxKind.ShortKeyword or (int)SyntaxKind.SByteKeyword } };
Constant value = this.Reader.GetConstant(valueHandle);
ExpressionSyntax enumValue = flagsEnum ? this.ToHexExpressionSyntax(value) : this.ToExpressionSyntax(value);
ExpressionSyntax enumValue = flagsEnum ? this.ToHexExpressionSyntax(value, enumBaseTypeIsSigned) : this.ToExpressionSyntax(value);
EnumMemberDeclarationSyntax enumMember = EnumMemberDeclaration(SafeIdentifier(enumValueName))
.WithEqualsValue(EqualsValueClause(enumValue));
enumValues.Add(enumMember);
Expand Down Expand Up @@ -5971,22 +5972,30 @@ static ExpressionSyntax FloatExpression(float value)
}
}

private ExpressionSyntax ToHexExpressionSyntax(Constant constant)
private ExpressionSyntax ToHexExpressionSyntax(Constant constant, bool assignableToSignedInteger)
{
BlobReader blobReader = this.Reader.GetBlobReader(constant.Value);
BlobReader blobReader2 = this.Reader.GetBlobReader(constant.Value);
BlobReader blobReader3 = this.Reader.GetBlobReader(constant.Value);
return constant.TypeCode switch
{
ConstantTypeCode.SByte => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadSByte()), blobReader2.ReadSByte())),
ConstantTypeCode.SByte => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadSByte()), blobReader2.ReadSByte())), SyntaxKind.SByteKeyword),
ConstantTypeCode.Byte => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadByte()), blobReader2.ReadByte())),
ConstantTypeCode.Int16 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt16()), blobReader2.ReadInt16())),
ConstantTypeCode.Int16 => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt16()), blobReader2.ReadInt16())), SyntaxKind.ShortKeyword),
ConstantTypeCode.UInt16 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadUInt16()), blobReader2.ReadUInt16())),
ConstantTypeCode.Int32 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt32()), blobReader2.ReadInt32())),
ConstantTypeCode.Int32 => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt32()), blobReader2.ReadInt32())), SyntaxKind.IntKeyword),
ConstantTypeCode.UInt32 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadUInt32()), blobReader2.ReadUInt32())),
ConstantTypeCode.Int64 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt64()), blobReader2.ReadInt64())),
ConstantTypeCode.Int64 => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt64()), blobReader2.ReadInt64())), SyntaxKind.LongKeyword),
ConstantTypeCode.UInt64 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadUInt64()), blobReader2.ReadUInt64())),
_ => throw new NotSupportedException("ConstantTypeCode not supported: " + constant.TypeCode),
};

ExpressionSyntax UncheckedSignedWrapper(LiteralExpressionSyntax value, SyntaxKind signedType)
{
return assignableToSignedInteger && value.Token.Text.StartsWith("0xF", StringComparison.OrdinalIgnoreCase)
? UncheckedExpression(CastExpression(PredefinedType(Token(signedType)), value))
: value;
}
}

private IEnumerable<NamespaceMetadata> GetNamespacesToSearch(string? @namespace)
Expand Down
7 changes: 4 additions & 3 deletions test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,13 @@ public void InterestingAPIs(
"HBITMAP_UserMarshal", // in+out handle pointer
"GetDiskFreeSpaceExW", // ULARGE_INTEGER replaced with keyword: ulong.
"MsiGetProductPropertyW", // MSIHANDLE (a 32-bit handle)
"tcp_opt_sack", // nested structs with inline arrays with nested struct elements
"TCP_OPT_SACK", // nested structs with inline arrays with nested struct elements
"HANDLETABLE", // nested structs with inline arrays with nint element
"SYSTEM_POLICY_INFORMATION", // nested structs with inline arrays with IntPtr element
"D3D11_BLEND_DESC1", // nested structs with inline arrays with element that is NOT nested
"RTM_DEST_INFO", // nested structs with inline arrays with element whose name collides with another
"DISPPARAMS",
"PICTYPE", // An enum with -1 as an enum value
"CoCreateInstance", // a hand-written friendly overload
"JsVariantToValue",
"D2D1_DEFAULT_FLATTENING_TOLERANCE", // a float constant
Expand Down Expand Up @@ -1236,7 +1237,7 @@ internal partial struct LOGFONTW
/// <para>This doc was truncated.</para>
/// <para><see href=""https://docs.microsoft.com/windows/win32/api//dimm/ns-dimm-logfontw#members"">Read more on docs.microsoft.com</see>.</para>
/// </summary>
internal winmdroot.Graphics.Gdi.FONT_WEIGHT lfWeight;
internal int lfWeight;
/// <summary>
/// <para>Type: <b>BYTE</b> <b>TRUE</b> to specify an italic font.</para>
/// <para><see href=""https://docs.microsoft.com/windows/win32/api//dimm/ns-dimm-logfontw#members"">Read more on docs.microsoft.com</see>.</para>
Expand Down Expand Up @@ -1265,7 +1266,7 @@ internal partial struct LOGFONTW
/// <summary>Type: <b>BYTE</b></summary>
internal winmdroot.Graphics.Gdi.FONT_QUALITY lfQuality;
/// <summary>Type: <b>BYTE</b></summary>
internal winmdroot.Graphics.Gdi.FONT_PITCH_AND_FAMILY lfPitchAndFamily;
internal byte lfPitchAndFamily;
/// <summary>
/// <para>Type: <b>TCHAR[LF_FACESIZE]</b> Specifies a null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters, including the terminating null character. The <a href=""https://docs.microsoft.com/windows/desktop/api/wingdi/nf-wingdi-enumfontfamiliesa"">EnumFontFamilies</a> function can be used to enumerate the typeface names of all currently available fonts. If <b>lfFaceName</b> is an empty string, GDI uses the first font that matches the other specified attributes.</para>
/// <para><see href=""https://docs.microsoft.com/windows/win32/api//dimm/ns-dimm-logfontw#members"">Read more on docs.microsoft.com</see>.</para>
Expand Down

0 comments on commit 89e7e0c

Please sign in to comment.