Skip to content

[SwiftSyntax] Add a human readable name for diagnostics to all nodes #60847

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

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions utils/gyb_syntax_support/AttributeNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

ATTRIBUTE_NODES = [
# token-list -> token? token-list?
Node('TokenList', kind='SyntaxCollection',
Node('TokenList', name_for_diagnostics='token list', kind='SyntaxCollection',
element='Token'),

# token-list -> token token-list?
Node('NonEmptyTokenList', kind='SyntaxCollection',
element='Token', omit_when_empty=True),
Node('NonEmptyTokenList', name_for_diagnostics='token list',
kind='SyntaxCollection', element='Token', omit_when_empty=True),

Node('CustomAttribute', kind='Syntax',
Node('CustomAttribute', name_for_diagnostics='attribute', kind='Syntax',
description='''
A custom `@` attribute.
''',
Expand All @@ -37,7 +37,7 @@
# | named-attribute-string-argument
# | back-deploy-attr-spec-list
# )? ')'?
Node('Attribute', kind='Syntax',
Node('Attribute', name_for_diagnostics='attribute', kind='Syntax',
description='''
An `@` attribute.
''',
Expand Down Expand Up @@ -89,7 +89,7 @@
]),

# attribute-list -> attribute attribute-list?
Node('AttributeList', kind='SyntaxCollection',
Node('AttributeList', name_for_diagnostics='attributes', kind='SyntaxCollection',
omit_when_empty=True,
element='Syntax', element_name='Attribute',
element_choices=[
Expand All @@ -102,7 +102,8 @@
# specialize-spec-attr-list?
# | generic-where-clause
# specialize-spec-attr-list?
Node('SpecializeAttributeSpecList', kind='SyntaxCollection',
Node('SpecializeAttributeSpecList',
name_for_diagnostics="argument to '@_specialize", kind='SyntaxCollection',
description='''
A collection of arguments for the `@_specialize` attribute
''',
Expand All @@ -114,7 +115,7 @@
'GenericWhereClause',
]),

Node('AvailabilityEntry', kind='Syntax',
Node('AvailabilityEntry', name_for_diagnostics='availability entry', kind='Syntax',
description='''
The availability argument for the _specialize attribute
''',
Expand All @@ -131,6 +132,7 @@
# Representation of e.g. 'exported: true,'
# labeled-specialize-entry -> identifier ':' token ','?
Node('LabeledSpecializeEntry', kind='Syntax',
name_for_diagnostics='attribute argument',
description='''
A labeled argument for the `@_specialize` attribute like
`exported: true`
Expand All @@ -151,6 +153,7 @@
# Representation of e.g. 'exported: true,'
# labeled-specialize-entry -> identifier ':' token ','?
Node('TargetFunctionEntry', kind='Syntax',
name_for_diagnostics='attribute argument',
description='''
A labeled argument for the `@_specialize` attribute with a function
decl value like
Expand All @@ -173,6 +176,7 @@
# The argument of '@_dynamic_replacement(for:)' or '@_private(sourceFile:)'
# named-attribute-string-arg -> 'name': string-literal
Node('NamedAttributeStringArgument', kind='Syntax',
name_for_diagnostics='attribute argument',
description='''
The argument for the `@_dynamic_replacement` or `@_private`
attribute of the form `for: "function()"` or `sourceFile:
Expand All @@ -188,7 +192,7 @@
Child('Declname', kind='DeclName'),
]),
]),
Node('DeclName', kind='Syntax', children=[
Node('DeclName', name_for_diagnostics='declaration name', kind='Syntax', children=[
Child('DeclBaseName', kind='Syntax', description='''
The base name of the protocol\'s requirement.
''',
Expand All @@ -205,7 +209,8 @@
# The argument of '@_implements(...)'
# implements-attr-arguments -> simple-type-identifier ','
# (identifier | operator) decl-name-arguments
Node('ImplementsAttributeArguments', kind='Syntax',
Node('ImplementsAttributeArguments', name_for_diagnostics='@_implements arguemnts',
kind='Syntax',
description='''
The arguments for the `@_implements` attribute of the form
`Type, methodName(arg1Label:arg2Label:)`
Expand Down Expand Up @@ -234,7 +239,8 @@
]),

# objc-selector-piece -> identifier? ':'?
Node('ObjCSelectorPiece', kind='Syntax',
Node('ObjCSelectorPiece', name_for_diagnostics='Objective-C selector piece',
kind='Syntax',
description='''
A piece of an Objective-C selector. Either consisting of just an
identifier for a nullary selector, an identifier and a colon for a
Expand All @@ -246,13 +252,15 @@
]),

# objc-selector -> objc-selector-piece objc-selector?
Node('ObjCSelector', kind='SyntaxCollection', element='ObjCSelectorPiece'),
Node('ObjCSelector', name_for_diagnostics='Objective-C selector',
kind='SyntaxCollection', element='ObjCSelectorPiece'),

# The argument of '@differentiable(...)'.
# differentiable-attr-arguments ->
# differentiability-kind? '.'? differentiability-params-clause? ','?
# generic-where-clause?
Node('DifferentiableAttributeArguments', kind='Syntax',
Node('DifferentiableAttributeArguments',
name_for_diagnostics="'@differentiable' arguments", kind='Syntax',
description='''
The arguments for the `@differentiable` attribute: an optional
differentiability kind, an optional differentiability parameter clause,
Expand All @@ -276,7 +284,8 @@

# differentiability-params-clause ->
# 'wrt' ':' (differentiability-param | differentiability-params)
Node('DifferentiabilityParamsClause', kind='Syntax',
Node('DifferentiabilityParamsClause',
name_for_diagnostics="'@differentiable' argument", kind='Syntax',
description='A clause containing differentiability parameters.',
children=[
Child('WrtLabel', kind='IdentifierToken',
Expand All @@ -292,7 +301,8 @@
]),

# differentiability-params -> '(' differentiability-param-list ')'
Node('DifferentiabilityParams', kind='Syntax',
Node('DifferentiabilityParams', name_for_diagnostics='differentiability parameters',
kind='Syntax',
description='The differentiability parameters.',
children=[
Child('LeftParen', kind='LeftParenToken'),
Expand All @@ -304,11 +314,13 @@

# differentiability-param-list ->
# differentiability-param differentiability-param-list?
Node('DifferentiabilityParamList', kind='SyntaxCollection',
Node('DifferentiabilityParamList',
name_for_diagnostics='differentiability parameters', kind='SyntaxCollection',
element='DifferentiabilityParam'),

# differentiability-param -> ('self' | identifier | integer-literal) ','?
Node('DifferentiabilityParam', kind='Syntax',
Node('DifferentiabilityParam', name_for_diagnostics='differentiability parameter',
kind='Syntax',
description='''
A differentiability parameter: either the "self" identifier, a function
parameter name, or a function parameter index.
Expand All @@ -330,7 +342,9 @@
#
# derivative-registration-attr-arguments ->
# 'of' ':' func-decl-name ','? differentiability-params-clause?
Node('DerivativeRegistrationAttributeArguments', kind='Syntax',
Node('DerivativeRegistrationAttributeArguments',
name_for_diagnostics='attribute arguments',
kind='Syntax',
description='''
The arguments for the '@derivative(of:)' and '@transpose(of:)'
attributes: the 'of:' label, the original declaration name, and an
Expand Down Expand Up @@ -369,6 +383,7 @@
# base-type ->
# member-type-identifier | base-type-identifier
Node('QualifiedDeclName', kind='Syntax',
name_for_diagnostics='declaration name',
description='''
An optionally qualified function declaration name (e.g. `+(_:_:)`,
`A.B.C.foo(_:_:)`).
Expand Down Expand Up @@ -402,6 +417,7 @@
# NOTE: This is duplicated with `DeclName` above. Change `DeclName`
# description and use it if possible.
Node('FunctionDeclName', kind='Syntax',
name_for_diagnostics='function declaration name',
description='A function declaration name (e.g. `foo(_:_:)`).',
children=[
Child('Name', kind='Syntax', description='''
Expand All @@ -423,6 +439,7 @@
# The arguments of '@_backDeploy(...)'
# back-deploy-attr-spec-list -> 'before' ':' back-deploy-version-list
Node('BackDeployAttributeSpecList', kind='Syntax',
name_for_diagnostics="'@_backDeploy' arguments",
description='''
A collection of arguments for the `@_backDeploy` attribute
''',
Expand All @@ -441,11 +458,11 @@

# back-deploy-version-list ->
# back-deploy-version-entry back-deploy-version-list?
Node('BackDeployVersionList', kind='SyntaxCollection',
element='BackDeployVersionArgument'),
Node('BackDeployVersionList', name_for_diagnostics='version list',
kind='SyntaxCollection', element='BackDeployVersionArgument'),

# back-deploy-version-entry -> availability-version-restriction ','?
Node('BackDeployVersionArgument', kind='Syntax',
Node('BackDeployVersionArgument', name_for_diagnostics='version', kind='Syntax',
description='''
A single platform/version pair in a `@_backDeploy` attribute,
e.g. `iOS 10.1`.
Expand Down
15 changes: 9 additions & 6 deletions utils/gyb_syntax_support/AvailabilityNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

AVAILABILITY_NODES = [
# availability-spec-list -> availability-entry availability-spec-list?
Node('AvailabilitySpecList', kind='SyntaxCollection',
element='AvailabilityArgument'),
Node('AvailabilitySpecList', name_for_diagnostics="'@availability' arguments",
kind='SyntaxCollection', element='AvailabilityArgument'),

# Wrapper for all the different entries that may occur inside @available
# availability-entry -> '*' ','?
# | identifier ','?
# | availability-version-restriction ','?
# | availability-versioned-argument ','?
Node('AvailabilityArgument', kind='Syntax',
Node('AvailabilityArgument', name_for_diagnostics="'@available' argument",
kind='Syntax',
description='''
A single argument to an `@available` argument like `*`, `iOS 10.1`,
or `message: "This has been deprecated"`.
Expand All @@ -38,7 +39,8 @@

# Representation of 'deprecated: 2.3', 'message: "Hello world"' etc.
# availability-versioned-argument -> identifier ':' version-tuple
Node('AvailabilityLabeledArgument', kind='Syntax',
Node('AvailabilityLabeledArgument', name_for_diagnostics="'@available' argument",
kind='Syntax',
description='''
A argument to an `@available` attribute that consists of a label and
a value, e.g. `message: "This has been deprecated"`.
Expand All @@ -57,7 +59,8 @@

# Representation for 'iOS 10', 'swift 3.4' etc.
# availability-version-restriction -> identifier version-tuple
Node('AvailabilityVersionRestriction', kind='Syntax',
Node('AvailabilityVersionRestriction', name_for_diagnostics="'@available' argument",
kind='Syntax',
description='''
An argument to `@available` that restricts the availability on a
certain platform to a version, e.g. `iOS 10` or `swift 3.4`.
Expand All @@ -76,7 +79,7 @@
# version-tuple -> integer-literal
# | float-literal
# | float-literal '.' integer-literal
Node('VersionTuple', kind='Syntax',
Node('VersionTuple', name_for_diagnostics='version tuple', kind='Syntax',
description='''
A version number of the form major.minor.patch in which the minor
and patch part may be omitted.
Expand Down
6 changes: 3 additions & 3 deletions utils/gyb_syntax_support/Child.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Child(object):
def __init__(self, name, kind, description=None, is_optional=False,
token_choices=None, text_choices=None, node_choices=None,
collection_element_name=None,
classification=None, force_classification=False,
classification=None, force_classification=False,
is_indented=False, requires_leading_newline=False):
"""
If a classification is passed, it specifies the color identifiers in
that subtree should inherit for syntax coloring. Must be a member of
If a classification is passed, it specifies the color identifiers in
that subtree should inherit for syntax coloring. Must be a member of
SyntaxClassification in SyntaxClassifier.h.gyb
If force_classification is also set to true, all child nodes (not only
identifiers) inherit the syntax classification.
Expand Down
45 changes: 24 additions & 21 deletions utils/gyb_syntax_support/CommonNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@
from .Node import Node # noqa: I201

COMMON_NODES = [
Node('Decl', kind='Syntax'),
Node('Expr', kind='Syntax'),
Node('Stmt', kind='Syntax'),
Node('Type', kind='Syntax'),
Node('Pattern', kind='Syntax'),
Node('UnknownDecl', kind='Decl'),
Node('UnknownExpr', kind='Expr'),
Node('UnknownStmt', kind='Stmt'),
Node('UnknownType', kind='Type'),
Node('UnknownPattern', kind='Pattern'),
Node('Missing', kind='Syntax'),
Node('MissingDecl', kind='Decl', children=[
Node('Decl', name_for_diagnostics='declaration', kind='Syntax'),
Node('Expr', name_for_diagnostics='expression', kind='Syntax'),
Node('Stmt', name_for_diagnostics='statement', kind='Syntax'),
Node('Type', name_for_diagnostics='type', kind='Syntax'),
Node('Pattern', name_for_diagnostics='pattern', kind='Syntax'),
Node('UnknownDecl', name_for_diagnostics='declaration', kind='Decl'),
Node('UnknownExpr', name_for_diagnostics='expression', kind='Expr'),
Node('UnknownStmt', name_for_diagnostics='statement', kind='Stmt'),
Node('UnknownType', name_for_diagnostics='type', kind='Type'),
Node('UnknownPattern', name_for_diagnostics='pattern', kind='Pattern'),
Node('Missing', name_for_diagnostics=None, kind='Syntax'),
Node('MissingDecl', name_for_diagnostics='declaration', kind='Decl', children=[
Child('Attributes', kind='AttributeList',
collection_element_name='Attribute', is_optional=True),
Child('Modifiers', kind='ModifierList',
collection_element_name='Modifier', is_optional=True),
]),
Node('MissingExpr', kind='Expr'),
Node('MissingStmt', kind='Stmt'),
Node('MissingType', kind='Type'),
Node('MissingPattern', kind='Pattern'),
Node('MissingExpr', name_for_diagnostics='expression', kind='Expr'),
Node('MissingStmt', name_for_diagnostics='statement', kind='Stmt'),
Node('MissingType', name_for_diagnostics='type', kind='Type'),
Node('MissingPattern', name_for_diagnostics='pattern', kind='Pattern'),

# code-block-item = (decl | stmt | expr) ';'?
Node('CodeBlockItem', kind='Syntax', omit_when_empty=True,
Node('CodeBlockItem', name_for_diagnostics=None, kind='Syntax',
omit_when_empty=True,
description="""
A CodeBlockItem is any Syntax node that appears on its own line inside
a CodeBlock.
Expand All @@ -49,11 +50,12 @@
]),

# code-block-item-list -> code-block-item code-block-item-list?
Node('CodeBlockItemList', kind='SyntaxCollection',
element='CodeBlockItem', elements_separated_by_newline=True),
Node('CodeBlockItemList', name_for_diagnostics=None,
kind='SyntaxCollection', element='CodeBlockItem',
elements_separated_by_newline=True),

# code-block -> '{' stmt-list '}'
Node('CodeBlock', kind='Syntax',
Node('CodeBlock', name_for_diagnostics=None, kind='Syntax',
traits=['Braced', 'WithStatements'],
children=[
Child('LeftBrace', kind='LeftBraceToken'),
Expand All @@ -63,7 +65,8 @@
requires_leading_newline=True),
]),

Node('UnexpectedNodes', kind='SyntaxCollection', element='Syntax',
Node('UnexpectedNodes', name_for_diagnostics=None, kind='SyntaxCollection',
element='Syntax',
description='''
A collection of syntax nodes that occurred in the source code but
could not be used to form a valid syntax tree.
Expand Down
Loading