Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Tuple Sub-Clauses #601

Open
AdamSpeight2008 opened this issue Jul 12, 2021 · 0 comments
Open

[Proposal] Tuple Sub-Clauses #601

AdamSpeight2008 opened this issue Jul 12, 2021 · 0 comments

Comments

@AdamSpeight2008
Copy link
Contributor

AdamSpeight2008 commented Jul 12, 2021

Tuple Sub-Clauses

I would like to use TupleSyntax as both argument to a Select Case and as arguments to a Case clause.
Those tuple clauses each action as sub-clause, where all of the sub-clauses have to match, for the case to be consider a valid option. These sub-clause would be the current permitted clauses, with a few additional ones.

Is Nothing    ' Is this sub-clause nothing?
IsNot Nothing ' Is this sub-clause not nothing?
              ' An empty sub-clause standing for "Not Applicable" or "I Don't Care"

Consequences

Select Case ( arg0, arg1, arg2)
       Case (     ,     ,     )
         ' Always True
       Case Else
         ' Never Executed
End Select

Example

Suppose we have the following class.

Class IsTypeClause Inherits SyntaxNode
  Public ReadOnly Property KindOfIsKeyword  As KeywordSyntax
  Public ReadOnly Property DeclarationAs    As Optional(Of DeclarationAsClause)
  Public ReadOnly Property KindOfTypeTarger As Union(Of TypeArgumentListSyntax, TypeSyntax) 
End Class

And then overrides a function that returns then kind of this node.

Overrides Function GetNodeKind() As SyntaxKind
  Select Case ( Me.KindOfIsKeyword	  , Me.DeclarationAs	, Me.KindOfTypeTarget)
         Case ( Is SyntaxKind.IsKeyword	  , Is Nothing		, Is TypeSyntax)		: Return SyntaxKind.IsTypeClause
         Case ( Is SyntaxKind.IsKeyword	  , Is Nothing		, Is TypeArgumentListSyntax)	: Return SyntaxKind.IsTypesClause
         Case ( Is SyntaxKind.IsKeyword   , IsNot Nothing	, Is TypeSyntax)		: Return SyntaxKind.IsTypeClauseWithDecl
         Case ( Is SyntaxKind.IsKeyword`  , IsNot Nothing	, Is TypeArgumentListSyntax)	: Return SyntaxKind.IsTypesClauseithDecl
         Case ( Is SyntaxKind.IsNotKeyword, Is Nothing		, Is TypeSyntax)		: Return SyntaxKind.IsNotTypeClause
         Case ( Is SyntaxKind.IsNotKeyword, Is Nothing		, Is TypeArgumentListSyntax)	: Return SyntaxKind.IsNotTypesClause
         Case ( Is SyntaxKind.IsNotKeyword, IsNot Nothing	, Is TypeSyntax)		: Return SyntaxKind.IsNotTypeClauseithDecl
         Case ( Is SyntaxKind.IsNotKeyword, IsNot Nothing	, Is TypeArgumentListSyntax) 	: Return SyntaxKind.IsNotTypesClauseithDecl
         Case Else : Return SyntaxKInd.IsTypeClause_Invalid
  End Select
End Function

If the compiler had some smarts, rather than lowering this to the naive implementation of a list of If Then and ElseIf Else End If statements. That it could be lowered to a set of nested if statements, reducing the number of comparison checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant