Skip to content

Commit 89e7e0c

Browse files
authored
Merge pull request #696 from microsoft/metadataUpdate
Update metadata to 33.0.18-preview
2 parents fef9088 + 642ddff commit 89e7e0c

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<IncludeSymbols Condition=" '$(DebugType)' != 'embedded' ">true</IncludeSymbols>
3737
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
3838

39-
<MetadataVersion>31.0.4-preview</MetadataVersion>
39+
<MetadataVersion>33.0.18-preview</MetadataVersion>
4040
<!-- <DiaMetadataVersion>0.2.185-preview-g7e1e6a442c</DiaMetadataVersion> -->
4141
<ApiDocsVersion>0.1.7-alpha</ApiDocsVersion>
4242
</PropertyGroup>

src/Microsoft.Windows.CsWin32/Generator.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,8 +4403,9 @@ private EnumDeclarationSyntax DeclareEnum(TypeDefinition typeDef)
44034403
continue;
44044404
}
44054405

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

5974-
private ExpressionSyntax ToHexExpressionSyntax(Constant constant)
5975+
private ExpressionSyntax ToHexExpressionSyntax(Constant constant, bool assignableToSignedInteger)
59755976
{
59765977
BlobReader blobReader = this.Reader.GetBlobReader(constant.Value);
59775978
BlobReader blobReader2 = this.Reader.GetBlobReader(constant.Value);
5979+
BlobReader blobReader3 = this.Reader.GetBlobReader(constant.Value);
59785980
return constant.TypeCode switch
59795981
{
5980-
ConstantTypeCode.SByte => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadSByte()), blobReader2.ReadSByte())),
5982+
ConstantTypeCode.SByte => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadSByte()), blobReader2.ReadSByte())), SyntaxKind.SByteKeyword),
59815983
ConstantTypeCode.Byte => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadByte()), blobReader2.ReadByte())),
5982-
ConstantTypeCode.Int16 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt16()), blobReader2.ReadInt16())),
5984+
ConstantTypeCode.Int16 => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt16()), blobReader2.ReadInt16())), SyntaxKind.ShortKeyword),
59835985
ConstantTypeCode.UInt16 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadUInt16()), blobReader2.ReadUInt16())),
5984-
ConstantTypeCode.Int32 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt32()), blobReader2.ReadInt32())),
5986+
ConstantTypeCode.Int32 => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt32()), blobReader2.ReadInt32())), SyntaxKind.IntKeyword),
59855987
ConstantTypeCode.UInt32 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadUInt32()), blobReader2.ReadUInt32())),
5986-
ConstantTypeCode.Int64 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt64()), blobReader2.ReadInt64())),
5988+
ConstantTypeCode.Int64 => UncheckedSignedWrapper(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadInt64()), blobReader2.ReadInt64())), SyntaxKind.LongKeyword),
59875989
ConstantTypeCode.UInt64 => LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(ToHex(blobReader.ReadUInt64()), blobReader2.ReadUInt64())),
59885990
_ => throw new NotSupportedException("ConstantTypeCode not supported: " + constant.TypeCode),
59895991
};
5992+
5993+
ExpressionSyntax UncheckedSignedWrapper(LiteralExpressionSyntax value, SyntaxKind signedType)
5994+
{
5995+
return assignableToSignedInteger && value.Token.Text.StartsWith("0xF", StringComparison.OrdinalIgnoreCase)
5996+
? UncheckedExpression(CastExpression(PredefinedType(Token(signedType)), value))
5997+
: value;
5998+
}
59905999
}
59916000

59926001
private IEnumerable<NamespaceMetadata> GetNamespacesToSearch(string? @namespace)

test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,13 @@ public void InterestingAPIs(
314314
"HBITMAP_UserMarshal", // in+out handle pointer
315315
"GetDiskFreeSpaceExW", // ULARGE_INTEGER replaced with keyword: ulong.
316316
"MsiGetProductPropertyW", // MSIHANDLE (a 32-bit handle)
317-
"tcp_opt_sack", // nested structs with inline arrays with nested struct elements
317+
"TCP_OPT_SACK", // nested structs with inline arrays with nested struct elements
318318
"HANDLETABLE", // nested structs with inline arrays with nint element
319319
"SYSTEM_POLICY_INFORMATION", // nested structs with inline arrays with IntPtr element
320320
"D3D11_BLEND_DESC1", // nested structs with inline arrays with element that is NOT nested
321321
"RTM_DEST_INFO", // nested structs with inline arrays with element whose name collides with another
322322
"DISPPARAMS",
323+
"PICTYPE", // An enum with -1 as an enum value
323324
"CoCreateInstance", // a hand-written friendly overload
324325
"JsVariantToValue",
325326
"D2D1_DEFAULT_FLATTENING_TOLERANCE", // a float constant
@@ -1236,7 +1237,7 @@ internal partial struct LOGFONTW
12361237
/// <para>This doc was truncated.</para>
12371238
/// <para><see href=""https://docs.microsoft.com/windows/win32/api//dimm/ns-dimm-logfontw#members"">Read more on docs.microsoft.com</see>.</para>
12381239
/// </summary>
1239-
internal winmdroot.Graphics.Gdi.FONT_WEIGHT lfWeight;
1240+
internal int lfWeight;
12401241
/// <summary>
12411242
/// <para>Type: <b>BYTE</b> <b>TRUE</b> to specify an italic font.</para>
12421243
/// <para><see href=""https://docs.microsoft.com/windows/win32/api//dimm/ns-dimm-logfontw#members"">Read more on docs.microsoft.com</see>.</para>
@@ -1265,7 +1266,7 @@ internal partial struct LOGFONTW
12651266
/// <summary>Type: <b>BYTE</b></summary>
12661267
internal winmdroot.Graphics.Gdi.FONT_QUALITY lfQuality;
12671268
/// <summary>Type: <b>BYTE</b></summary>
1268-
internal winmdroot.Graphics.Gdi.FONT_PITCH_AND_FAMILY lfPitchAndFamily;
1269+
internal byte lfPitchAndFamily;
12691270
/// <summary>
12701271
/// <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>
12711272
/// <para><see href=""https://docs.microsoft.com/windows/win32/api//dimm/ns-dimm-logfontw#members"">Read more on docs.microsoft.com</see>.</para>

0 commit comments

Comments
 (0)