Skip to content

Commit

Permalink
Implement parsing for records (#40467)
Browse files Browse the repository at this point in the history
As agreed in LDM, the specification requires that a data contextual
keyword be present in front of the class and a parameter list to be
present after the identifier, for the type to be a record.

The absence of either of these two elements will be a semantic error,
not a parsing error.
  • Loading branch information
agocke authored Jan 5, 2020
1 parent 1331a9d commit 8769e0b
Show file tree
Hide file tree
Showing 37 changed files with 1,212 additions and 412 deletions.
3 changes: 2 additions & 1 deletion eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<ToolsetPackagesDir>$(RepoRoot)build\ToolsetPackages\</ToolsetPackagesDir>

<RoslynPortableTargetFrameworks>net472;netcoreapp2.1</RoslynPortableTargetFrameworks>
<!-- PROTOTYPE: Swap the order of the frameworks back before merging -->
<RoslynPortableTargetFrameworks>netcoreapp2.1;net472</RoslynPortableTargetFrameworks>
<RoslynCheckCodeStyle Condition="'$(ContinuousIntegrationBuild)' != 'true' or '$(RoslynEnforceCodeStyle)' == 'true'">true</RoslynCheckCodeStyle>
<UseSharedCompilation>true</UseSharedCompilation>

Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5927,4 +5927,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_ExternEventInitializer" xml:space="preserve">
<value>'{0}': extern event cannot have initializer</value>
</data>
<data name="IDS_FeatureRecords" xml:space="preserve">
<value>records</value>
</data>
</root>
16 changes: 13 additions & 3 deletions src/Compilers/CSharp/Portable/Declarations/DeclarationModifiers.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Runtime.CompilerServices;

namespace Microsoft.CodeAnalysis.CSharp
{
[Flags]
internal enum DeclarationModifiers
internal enum DeclarationModifiers : uint
{
None = 0,
Abstract = 1 << 0,
Expand Down Expand Up @@ -34,9 +35,18 @@ internal enum DeclarationModifiers
Async = 1 << 20,
Ref = 1 << 21, // used only for structs

All = (1 << 22) - 1, // all modifiers
Unset = 1 << 22, // used when a modifiers value hasn't yet been computed
Data = 1 << 22,

All = (1 << 23) - 1, // all modifiers
Unset = 1 << 23, // used when a modifiers value hasn't yet been computed

AccessibilityMask = PrivateProtected | Private | Protected | Internal | ProtectedInternal | Public,
}

internal static class DeclarationModifierExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool HasFlag(this DeclarationModifiers modifiers, DeclarationModifiers flag)
=> (modifiers & flag) != 0;
}
}
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ internal enum MessageID
IDS_FeatureSwitchExpression = MessageBase + 12763,
IDS_FeatureAsyncUsing = MessageBase + 12764,
IDS_FeatureLambdaDiscardParameters = MessageBase + 12765,
IDS_FeatureRecords = MessageBase + 12766,
}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -293,6 +294,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
{
// Preview features.
case MessageID.IDS_FeatureLambdaDiscardParameters: // semantic check
case MessageID.IDS_FeatureRecords:
return LanguageVersion.Preview;

// C# 8.0 features.
Expand Down
5 changes: 3 additions & 2 deletions src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

370 changes: 262 additions & 108 deletions src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8769e0b

Please sign in to comment.