diff --git a/CodeGeneration/Sources/SyntaxSupport/AttributeKinds.swift b/CodeGeneration/Sources/SyntaxSupport/AttributeKinds.swift deleted file mode 100644 index 71e71618759..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/AttributeKinds.swift +++ /dev/null @@ -1,849 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public class Attribute { - public let name: String - public let swiftName: String - - public init(name: String, swiftName: String? = nil) { - self.name = name - self.swiftName = swiftName ?? name - } -} - -public class TypeAttribute: Attribute { - public init(name: String) { - super.init(name: name) - } -} - -public class DeclAttribute: Attribute { - public let className: String - - public init(name: String, className: String, swiftName: String? = nil) { - self.className = className - super.init(name: name, swiftName: swiftName) - } -} - -public class SimpleDeclAttribute: DeclAttribute {} - -public class ContextualDeclAttribute: DeclAttribute { - public init(name: String, className: String) { - super.init(name: name, className: className) - } -} - -public class ContextualSimpleDeclAttribute: SimpleDeclAttribute { - public init(name: String, className: String) { - super.init(name: name, className: className) - } -} - -public class DeclAttributeAlias: Attribute { - public let className: String - - public init(name: String, className: String, swiftName: String? = nil) { - self.className = className - super.init(name: name, swiftName: swiftName) - - } -} - -public class ContextualDeclAttributeAlias: DeclAttributeAlias {} - -public class BuiltinDeclModifier: Attribute {} - -// Type attributes -public let TYPE_ATTR_KINDS = [ - TypeAttribute(name: "autoclosure"), - TypeAttribute(name: "convention"), - TypeAttribute(name: "noescape"), - TypeAttribute(name: "escaping"), - TypeAttribute(name: "differentiable"), - TypeAttribute(name: "noDerivative"), - TypeAttribute(name: "async"), - TypeAttribute(name: "Sendable"), - TypeAttribute(name: "unchecked"), - TypeAttribute(name: "_local"), - TypeAttribute(name: "_noMetadata"), - TypeAttribute(name: "_opaqueReturnTypeOf"), -] - -// Schema for `DeclAttribute`s: -// -// - Attribute name. -// - C++ class name without the 'Attr' suffix -// - Options for the attribute, including: -// * the declarations the attribute can appear on -// * whether duplicates are allowed -// - Unique attribute identifier used for serialization. This -// can never be changed. -// -// SimpleDeclAttribute is the same, but the class becomes -// SimpleDeclAttr on the C++ side. -// -// Please help ease code review/audits: -// - Please place the "OnXYZ" flags together on the next line. -// - Please place the non-OnXYZ flags together on the next to last line. -// - Please place the unique code number on the last line. -// - Please sort attributes by serialization number. -// - Please create a "NOTE" comment if a unique number is skipped. -// -// If you're adding a new kind of "attribute" that is spelled without a leading -// '@' symbol, add an entry to the `DECL_MODIFIER_KINDS` array instead. -// -// If you're adding a new underscored attribute here, please document it in -// docs/ReferenceGuides/UnderscoredAttributes.md. -public let DECL_ATTR_KINDS: [Attribute] = [ - DeclAttribute( - name: "_silgen_name", - className: "SILGenName", - swiftName: "_silgen_name" - ), - DeclAttribute( - name: "available", - className: "Available", - swiftName: "available" - ), - DeclAttribute( - name: "objc", - className: "ObjC", - swiftName: "objc" - ), - SimpleDeclAttribute( - name: "dynamicCallable", - className: "DynamicCallable", - swiftName: "dynamicCallable" - ), - DeclAttribute( - name: "main", - className: "MainType", - swiftName: "main" - ), - SimpleDeclAttribute( - name: "_exported", - className: "Exported", - swiftName: "_exported" - ), - SimpleDeclAttribute( - name: "dynamicMemberLookup", - className: "DynamicMemberLookup", - swiftName: "dynamicMemberLookup" - ), - SimpleDeclAttribute( - name: "NSCopying", - className: "NSCopying", - swiftName: "NSCopying" - ), - SimpleDeclAttribute( - name: "IBAction", - className: "IBAction", - swiftName: "IBAction" - ), - SimpleDeclAttribute( - name: "IBDesignable", - className: "IBDesignable", - swiftName: "IBDesignable" - ), - SimpleDeclAttribute( - name: "IBInspectable", - className: "IBInspectable", - swiftName: "IBInspectable" - ), - SimpleDeclAttribute( - name: "IBOutlet", - className: "IBOutlet", - swiftName: "IBOutlet" - ), - SimpleDeclAttribute( - name: "NSManaged", - className: "NSManaged", - swiftName: "NSManaged" - ), - SimpleDeclAttribute( - name: "LLDBDebuggerFunction", - className: "LLDBDebuggerFunction", - swiftName: "LLDBDebuggerFunction" - ), - SimpleDeclAttribute( - name: "UIApplicationMain", - className: "UIApplicationMain", - swiftName: "UIApplicationMain" - ), - SimpleDeclAttribute( - name: "unsafe_no_objc_tagged_pointer", - className: "UnsafeNoObjCTaggedPointer", - swiftName: "unsafe_no_objc_tagged_pointer" - ), - DeclAttribute( - name: "inline", - className: "Inline", - swiftName: "inline" - ), - DeclAttribute( - name: "_semantics", - className: "Semantics", - swiftName: "_semantics" - ), - SimpleDeclAttribute( - name: "_transparent", - className: "Transparent", - swiftName: "_transparent" - ), - SimpleDeclAttribute( - name: "requires_stored_property_inits", - className: "RequiresStoredPropertyInits", - swiftName: "requires_stored_property_inits" - ), - SimpleDeclAttribute( - name: "nonobjc", - className: "NonObjC", - swiftName: "nonobjc" - ), - SimpleDeclAttribute( - name: "_fixed_layout", - className: "FixedLayout", - swiftName: "_fixed_layout" - ), - SimpleDeclAttribute( - name: "inlinable", - className: "Inlinable", - swiftName: "inlinable" - ), - DeclAttribute( - name: "_specialize", - className: "Specialize", - swiftName: "_specialize" - ), - SimpleDeclAttribute( - name: "objcMembers", - className: "ObjCMembers", - swiftName: "objcMembers" - ), - ContextualSimpleDeclAttribute( - name: "_compilerInitialized", - className: "CompilerInitialized" - ), - SimpleDeclAttribute( - name: "_hasStorage", - className: "HasStorage", - swiftName: "_hasStorage" - ), - DeclAttribute( - name: "__raw_doc_comment", - className: "RawDocComment", - swiftName: "__raw_doc_comment" - ), - DeclAttribute( - name: "_effects", - className: "Effects", - swiftName: "_effects" - ), - DeclAttribute( - name: "__objc_bridged", - className: "ObjCBridged", - swiftName: "__objc_bridged" - ), - SimpleDeclAttribute( - name: "NSApplicationMain", - className: "NSApplicationMain", - swiftName: "NSApplicationMain" - ), - SimpleDeclAttribute( - name: "_objc_non_lazy_realization", - className: "ObjCNonLazyRealization", - swiftName: "_objc_non_lazy_realization" - ), - DeclAttribute( - name: "__synthesized_protocol", - className: "SynthesizedProtocol", - swiftName: "__synthesized_protocol" - ), - SimpleDeclAttribute( - name: "testable", - className: "Testable", - swiftName: "testable" - ), - DeclAttribute( - name: "_alignment", - className: "Alignment", - swiftName: "_alignment" - ), - SimpleDeclAttribute( - name: "rethrows", - className: "AtRethrows", - swiftName: "atRethrows" - ), - DeclAttribute( - name: "_swift_native_objc_runtime_base", - className: "SwiftNativeObjCRuntimeBase", - swiftName: "_swift_native_objc_runtime_base" - ), - SimpleDeclAttribute( - name: "warn_unqualified_access", - className: "WarnUnqualifiedAccess", - swiftName: "warn_unqualified_access" - ), - SimpleDeclAttribute( - name: "_show_in_interface", - className: "ShowInInterface", - swiftName: "_show_in_interface" - ), - DeclAttribute( - name: "_cdecl", - className: "CDecl", - swiftName: "_cdecl" - ), - SimpleDeclAttribute( - name: "usableFromInline", - className: "UsableFromInline", - swiftName: "usableFromInline" - ), - SimpleDeclAttribute( - name: "discardableResult", - className: "DiscardableResult", - swiftName: "discardableResult" - ), - SimpleDeclAttribute( - name: "GKInspectable", - className: "GKInspectable", - swiftName: "GKInspectable" - ), - DeclAttribute( - name: "_implements", - className: "Implements", - swiftName: "_implements" - ), - DeclAttribute( - name: "_objcRuntimeName", - className: "ObjCRuntimeName", - swiftName: "_objcRuntimeName" - ), - SimpleDeclAttribute( - name: "_staticInitializeObjCMetadata", - className: "StaticInitializeObjCMetadata", - swiftName: "_staticInitializeObjCMetadata" - ), - DeclAttribute( - name: "_restatedObjCConformance", - className: "RestatedObjCConformance", - swiftName: "_restatedObjCConformance" - ), - - // NOTE: 71 is unused - - DeclAttribute( - name: "_objcImplementation", - className: "ObjCImplementation", - swiftName: "_objcImplementation" - ), - DeclAttribute( - name: "_optimize", - className: "Optimize", - swiftName: "_optimize" - ), - DeclAttribute( - name: "_clangImporterSynthesizedType", - className: "ClangImporterSynthesizedType", - swiftName: "_clangImporterSynthesizedType" - ), - SimpleDeclAttribute( - name: "_weakLinked", - className: "WeakLinked", - swiftName: "_weakLinked" - ), - SimpleDeclAttribute( - name: "frozen", - className: "Frozen", - swiftName: "frozen" - ), - DeclAttributeAlias( - name: "_frozen", - className: "Frozen", - swiftName: "_frozen" - ), - SimpleDeclAttribute( - name: "_forbidSerializingReference", - className: "ForbidSerializingReference", - swiftName: "_forbidSerializingReference" - ), - SimpleDeclAttribute( - name: "_hasInitialValue", - className: "HasInitialValue", - swiftName: "_hasInitialValue" - ), - SimpleDeclAttribute( - name: "_nonoverride", - className: "NonOverride", - swiftName: "_nonoverride" - ), - DeclAttribute( - name: "_dynamicReplacement", - className: "DynamicReplacement", - swiftName: "_dynamicReplacement" - ), - SimpleDeclAttribute( - name: "_borrowed", - className: "Borrowed", - swiftName: "_borrowed" - ), - DeclAttribute( - name: "_private", - className: "PrivateImport", - swiftName: "_private" - ), - SimpleDeclAttribute( - name: "_alwaysEmitIntoClient", - className: "AlwaysEmitIntoClient", - swiftName: "_alwaysEmitIntoClient" - ), - SimpleDeclAttribute( - name: "_implementationOnly", - className: "ImplementationOnly", - swiftName: "_implementationOnly" - ), - DeclAttribute( - name: "_custom", - className: "Custom", - swiftName: "_custom" - ), - SimpleDeclAttribute( - name: "propertyWrapper", - className: "PropertyWrapper", - swiftName: "propertyWrapper" - ), - SimpleDeclAttribute( - name: "_disfavoredOverload", - className: "DisfavoredOverload", - swiftName: "_disfavoredOverload" - ), - SimpleDeclAttribute( - name: "resultBuilder", - className: "ResultBuilder", - swiftName: "resultBuilder" - ), - DeclAttribute( - name: "_projectedValueProperty", - className: "ProjectedValueProperty", - swiftName: "_projectedValueProperty" - ), - SimpleDeclAttribute( - name: "_nonEphemeral", - className: "NonEphemeral", - swiftName: "_nonEphemeral" - ), - DeclAttribute( - name: "differentiable", - className: "Differentiable", - swiftName: "differentiable" - ), - SimpleDeclAttribute( - name: "_hasMissingDesignatedInitializers", - className: "HasMissingDesignatedInitializers", - swiftName: "_hasMissingDesignatedInitializers" - ), - SimpleDeclAttribute( - name: "_inheritsConvenienceInitializers", - className: "InheritsConvenienceInitializers", - swiftName: "_inheritsConvenienceInitializers" - ), - DeclAttribute( - name: "_typeEraser", - className: "TypeEraser", - swiftName: "_typeEraser" - ), - SimpleDeclAttribute( - name: "IBSegueAction", - className: "IBSegueAction", - swiftName: "IBSegueAction" - ), - DeclAttribute( - name: "_originallyDefinedIn", - className: "OriginallyDefinedIn", - swiftName: "_originallyDefinedIn" - ), - DeclAttribute( - name: "derivative", - className: "Derivative", - swiftName: "derivative" - ), - DeclAttribute( - name: "_spi", - className: "SPIAccessControl", - swiftName: "_spi" - ), - DeclAttribute( - name: "transpose", - className: "Transpose", - swiftName: "transpose" - ), - SimpleDeclAttribute( - name: "noDerivative", - className: "NoDerivative", - swiftName: "noDerivative" - ), - - // 101 was @asyncHandler and is now unused - - SimpleDeclAttribute( - name: "globalActor", - className: "GlobalActor", - swiftName: "globalActor" - ), - - SimpleDeclAttribute( - name: "_specializeExtension", - className: "SpecializeExtension", - swiftName: "_specializeExtension" - ), - SimpleDeclAttribute( - name: "Sendable", - className: "Sendable", - swiftName: "Sendable" - ), - SimpleDeclAttribute( - name: "_marker", - className: "Marker", - swiftName: "_marker" - ), - SimpleDeclAttribute( - name: "reasync", - className: "AtReasync", - swiftName: "atReasync" - ), - - // 111 was an experimental @completionHandlerAsync and is now unused - - // 113 was experimental _unsafeSendable and is now unused - - // Previously experimental _unsafeMainActor - SimpleDeclAttribute( - name: "_unsafeInheritExecutor", - className: "UnsafeInheritExecutor", - swiftName: "_unsafeInheritExecutor" - ), - SimpleDeclAttribute( - name: "_implicitSelfCapture", - className: "ImplicitSelfCapture", - swiftName: "_implicitSelfCapture" - ), - SimpleDeclAttribute( - name: "_inheritActorContext", - className: "InheritActorContext", - swiftName: "_inheritActorContext" - ), - SimpleDeclAttribute( - name: "_eagerMove", - className: "EagerMove", - swiftName: "_eagerMove" - ), - SimpleDeclAttribute( - name: "_lexicalLifetimes", - className: "LexicalLifetimes", - swiftName: "_lexicalLifetimes" - ), - SimpleDeclAttribute( - name: "_noEagerMove", - className: "NoEagerMove", - swiftName: "_noEagerMove" - ), - SimpleDeclAttribute( - name: "_assemblyVision", - className: "EmitAssemblyVisionRemarks", - swiftName: "_assemblyVision" - ), - DeclAttribute( - name: "_nonSendable", - className: "NonSendable", - swiftName: "_nonSendable" - ), - SimpleDeclAttribute( - name: "_noImplicitCopy", - className: "NoImplicitCopy", - swiftName: "_noImplicitCopy" - ), - SimpleDeclAttribute( - name: "_noLocks", - className: "NoLocks", - swiftName: "_noLocks" - ), - SimpleDeclAttribute( - name: "_noAllocation", - className: "NoAllocation", - swiftName: "_noAllocation" - ), - SimpleDeclAttribute( - name: "preconcurrency", - className: "Preconcurrency", - swiftName: "preconcurrency" - ), - DeclAttribute( - name: "_unavailableFromAsync", - className: "UnavailableFromAsync", - swiftName: "_unavailableFromAsync" - ), - DeclAttribute( - name: "exclusivity", - className: "Exclusivity", - swiftName: "exclusivity" - ), - DeclAttribute( - name: "backDeployed", - className: "BackDeployed", - swiftName: "backDeployed" - ), - DeclAttributeAlias( - name: "_backDeploy", - className: "BackDeployed", - swiftName: "_backDeploy" - ), - SimpleDeclAttribute( - name: "_moveOnly", - className: "MoveOnly", - swiftName: "_moveOnly" - ), - SimpleDeclAttribute( - name: "_alwaysEmitConformanceMetadata", - className: "AlwaysEmitConformanceMetadata", - swiftName: "_alwaysEmitConformanceMetadata" - ), - DeclAttribute( - name: "_expose", - className: "Expose", - swiftName: "_expose" - ), - SimpleDeclAttribute( - name: "typeWrapper", - className: "TypeWrapper", - swiftName: "typeWrapper" - ), - SimpleDeclAttribute( - name: "_spiOnly", - className: "SPIOnly", - swiftName: "_spiOnly" - ), - DeclAttribute( - name: "_documentation", - className: "Documentation", - swiftName: "_documentation" - ), - SimpleDeclAttribute( - name: "typeWrapperIgnored", - className: "TypeWrapperIgnored", - swiftName: "typeWrapperIgnored" - ), - SimpleDeclAttribute( - name: "_noMetadata", - className: "NoMetadata", - swiftName: "_noMetadata" - ), - SimpleDeclAttribute( - name: "runtimeMetadata", - className: "RuntimeMetadata", - swiftName: "runtimeMetadata" - ), -] - -/// Schema for declaration modifiers: -/// -/// - Modifier name. -/// - C++ class name without the 'Attr' suffix -/// - Options for the attribute, including: -/// * the declarations the attribute can appear on -/// * whether duplicates are allowed -/// - Unique attribute identifier used for serialization. This -/// can never be changed. -/// -/// SimpleDeclAttribute is the same, but the class becomes -/// SimpleDeclAttr on the C++ side. -/// -/// Please help ease code review/audits: -/// - Please place the "OnXYZ" flags together on the next line. -/// - Please place the non-OnXYZ flags together on the next to last line. -/// - Please place the unique code number on the last line. -/// - Please sort attributes by serialization number. -/// - Please create a "NOTE" comment if a unique number is skipped. -/// -/// If you're adding a new kind of attribute that is spelled with a leading -/// '@' symbol, add an entry to the `DECL_ATTR_KINDS` array instead. - -// These are not really attributes or modifiers in the C++ AST and they are -// serialized directly into the ASTs they are attached to rather than using -// the generic attribute serialization infrastructure. -public let DECL_MODIFIER_KINDS: [Attribute] = CONTEXTUAL_DECL_MODIFIER_KINDS + NONCONTEXTUAL_DECL_MODIFIER_KINDS - -// Modifiers that not exclusively used for declarations -public let CONTEXTUAL_DECL_MODIFIER_KINDS: [Attribute] = [ - ContextualDeclAttribute( - name: "weak", - className: "ReferenceOwnership" - ), - ContextualDeclAttributeAlias( - name: "unowned", - className: "ReferenceOwnership", - swiftName: "unowned" - ), - SimpleDeclAttribute( - name: "rethrows", - className: "Rethrows", - swiftName: "`rethrows`" - ), - ContextualSimpleDeclAttribute( - name: "isolated", - className: "Isolated" - ), - ContextualSimpleDeclAttribute( - name: "async", - className: "Async" - ), - SimpleDeclAttribute( - name: "reasync", - className: "Reasync", - swiftName: "reasync" - ), - ContextualSimpleDeclAttribute( - name: "consuming", - className: "Consuming" - ), - ContextualSimpleDeclAttribute( - name: "borrowing", - className: "Borrowing" - ), - ContextualSimpleDeclAttribute( - name: "_const", - className: "CompileTimeConst" - ), -] - -// Modifiers that exclusively used for declarations -public let NONCONTEXTUAL_DECL_MODIFIER_KINDS: [Attribute] = [ - BuiltinDeclModifier( - name: "static", - swiftName: "`static`" - ), - BuiltinDeclModifier( - name: "class", - swiftName: "`class`" - ), - ContextualSimpleDeclAttribute( - name: "final", - className: "Final" - ), - ContextualSimpleDeclAttribute( - name: "required", - className: "Required" - ), - ContextualSimpleDeclAttribute( - name: "optional", - className: "Optional" - ), - ContextualSimpleDeclAttribute( - name: "lazy", - className: "Lazy" - ), - ContextualSimpleDeclAttribute( - name: "dynamic", - className: "Dynamic" - ), - ContextualSimpleDeclAttribute( - name: "infix", - className: "Infix" - ), - ContextualSimpleDeclAttribute( - name: "prefix", - className: "Prefix" - ), - ContextualSimpleDeclAttribute( - name: "postfix", - className: "Postfix" - ), - ContextualSimpleDeclAttribute( - name: "__consuming", - className: "LegacyConsuming" - ), - ContextualSimpleDeclAttribute( - name: "mutating", - className: "Mutating" - ), - ContextualSimpleDeclAttribute( - name: "nonmutating", - className: "NonMutating" - ), - ContextualSimpleDeclAttribute( - name: "convenience", - className: "Convenience" - ), - ContextualSimpleDeclAttribute( - name: "override", - className: "Override" - ), - DeclAttribute( - name: "private", - className: "AccessControl", - swiftName: "`private`" - ), - DeclAttributeAlias( - name: "fileprivate", - className: "AccessControl", - swiftName: "`fileprivate`" - ), - DeclAttributeAlias( - name: "internal", - className: "AccessControl", - swiftName: "`internal`" - ), - DeclAttributeAlias( - name: "public", - className: "AccessControl", - swiftName: "`public`" - ), - ContextualDeclAttributeAlias( - name: "package", - className: "AccessControl", - swiftName: "package" - ), - ContextualDeclAttributeAlias( - name: "open", - className: "AccessControl", - swiftName: "open" - ), - DeclAttribute( - name: "__setter_access", - className: "SetterAccess", - swiftName: "__setter_access" - ), - ContextualSimpleDeclAttribute( - name: "indirect", - className: "Indirect" - ), - ContextualSimpleDeclAttribute( - name: "nonisolated", - className: "Nonisolated" - ), - ContextualSimpleDeclAttribute( - name: "distributed", - className: "DistributedActor" - ), - ContextualSimpleDeclAttribute( - name: "_local", - className: "KnownToBeLocal" - ), -] - -public let DEPRECATED_MODIFIER_KINDS: [Attribute] = [ - // TODO: Remove this once we don't need to support 'actor' as a modifier - ContextualSimpleDeclAttribute( - name: "actor", - className: "Actor" - ) -] diff --git a/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift b/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift index 05dcaa558de..474d95239eb 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift @@ -87,11 +87,9 @@ struct GenerateSwiftSyntax: ParsableCommand { GeneratedFileSpec(swiftideUtilsGeneratedDir + ["SyntaxClassification.swift"], syntaxClassificationFile), // SwiftParser - GeneratedFileSpec(swiftParserGeneratedDir + ["DeclarationModifier.swift"], declarationModifierFile), GeneratedFileSpec(swiftParserGeneratedDir + ["IsLexerClassified.swift"], isLexerClassifiedFile), GeneratedFileSpec(swiftParserGeneratedDir + ["Parser+Entry.swift"], parserEntryFile), GeneratedFileSpec(swiftParserGeneratedDir + ["TokenSpecStaticMembers.swift"], tokenSpecStaticMembersFile), - GeneratedFileSpec(swiftParserGeneratedDir + ["TypeAttribute.swift"], typeAttributeFile), // SwiftParserDiagnostics GeneratedFileSpec(swiftParserDiagnosticsGeneratedDir + ["ChildNameForDiagnostics.swift"], childNameForDiagnosticFile), diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/DeclarationModifierFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/DeclarationModifierFile.swift deleted file mode 100644 index 007bb8cbcb7..00000000000 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/DeclarationModifierFile.swift +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -import SwiftSyntax -import SwiftSyntaxBuilder -import SyntaxSupport -import Utils - -let declarationModifierFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax("@_spi(RawSyntax) import SwiftSyntax") - - try! EnumDeclSyntax("enum DeclarationModifier: TokenSpecSet") { - for attribute in DECL_MODIFIER_KINDS { - DeclSyntax("case \(raw: attribute.swiftName)") - } - - try InitializerDeclSyntax("init?(lexeme: Lexer.Lexeme)") { - try SwitchExprSyntax("switch PrepareForKeywordMatch(lexeme)") { - for attribute in DECL_MODIFIER_KINDS { - SwitchCaseSyntax("case TokenSpec(.\(raw: attribute.swiftName)):") { - ExprSyntax("self = .\(raw: attribute.swiftName)") - } - } - SwitchCaseSyntax("default:") { - StmtSyntax("return nil") - } - } - } - - try VariableDeclSyntax("var spec: TokenSpec") { - try SwitchExprSyntax("switch self") { - for attribute in NONCONTEXTUAL_DECL_MODIFIER_KINDS { - SwitchCaseSyntax("case .\(raw: attribute.swiftName):") { - StmtSyntax("return .keyword(.\(raw: attribute.swiftName))") - } - } - for attribute in CONTEXTUAL_DECL_MODIFIER_KINDS { - SwitchCaseSyntax("case .\(raw: attribute.swiftName):") { - StmtSyntax("return TokenSpec(.\(raw: attribute.swiftName), recoveryPrecedence: .declKeyword)") - } - } - } - } - } -} diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/TypeAttributeFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/TypeAttributeFile.swift deleted file mode 100644 index 1fd7e268e19..00000000000 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/TypeAttributeFile.swift +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -import SwiftSyntax -import SwiftSyntaxBuilder -import SyntaxSupport -import Utils - -let typeAttributeFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax("@_spi(RawSyntax) import SwiftSyntax") - - try! ExtensionDeclSyntax("extension Parser") { - try EnumDeclSyntax("enum TypeAttribute: TokenSpecSet") { - for attribute in TYPE_ATTR_KINDS { - DeclSyntax("case \(raw: attribute.name)") - } - - try InitializerDeclSyntax("init?(lexeme: Lexer.Lexeme)") { - try! SwitchExprSyntax("switch PrepareForKeywordMatch(lexeme)") { - for attribute in TYPE_ATTR_KINDS { - SwitchCaseSyntax("case TokenSpec(.\(raw: attribute.name)):") { - ExprSyntax("self = .\(raw: attribute.swiftName)") - } - } - SwitchCaseSyntax("default:") { - StmtSyntax("return nil") - } - } - } - - try VariableDeclSyntax("var spec: TokenSpec") { - SwitchExprSyntax(switchKeyword: .keyword(.switch), expression: ExprSyntax("self")) { - for attribute in TYPE_ATTR_KINDS { - SwitchCaseSyntax("case .\(raw: attribute.swiftName):") { - StmtSyntax("return .keyword(.\(raw: attribute.name))") - } - } - } - } - } - } -} diff --git a/Sources/SwiftParser/CMakeLists.txt b/Sources/SwiftParser/CMakeLists.txt index c131bb0c1c0..cdd5504b890 100644 --- a/Sources/SwiftParser/CMakeLists.txt +++ b/Sources/SwiftParser/CMakeLists.txt @@ -35,11 +35,9 @@ add_swift_host_library(SwiftParser TriviaParser.swift Types.swift - generated/DeclarationModifier.swift generated/IsLexerClassified.swift generated/Parser+Entry.swift generated/TokenSpecStaticMembers.swift - generated/TypeAttribute.swift Lexer/Cursor.swift Lexer/Lexeme.swift diff --git a/Sources/SwiftParser/Lookahead.swift b/Sources/SwiftParser/Lookahead.swift index aabb189d0e8..f96c98f3c35 100644 --- a/Sources/SwiftParser/Lookahead.swift +++ b/Sources/SwiftParser/Lookahead.swift @@ -141,7 +141,7 @@ extension Parser.Lookahead { } // Determine which attribute it is. - if let (attr, handle) = self.at(anyIn: Parser.TypeAttribute.self) { + if let (attr, handle) = self.at(anyIn: TypeAttribute.self) { // Ok, it is a valid attribute, eat it, and then process it. self.eat(handle) if case .convention = attr { diff --git a/Sources/SwiftParser/TokenSpecSet.swift b/Sources/SwiftParser/TokenSpecSet.swift index 4004fdd6c80..22246c80b04 100644 --- a/Sources/SwiftParser/TokenSpecSet.swift +++ b/Sources/SwiftParser/TokenSpecSet.swift @@ -328,6 +328,125 @@ enum DeclarationKeyword: TokenSpecSet { } } +enum DeclarationModifier: TokenSpecSet { + case __consuming + case __setter_access + case _const + case _local + case async + case borrowing + case `class` + case consuming + case convenience + case distributed + case dynamic + case `fileprivate` + case final + case indirect + case infix + case `internal` + case isolated + case lazy + case mutating + case nonisolated + case nonmutating + case open + case optional + case override + case package + case postfix + case prefix + case `private` + case `public` + case reasync + case required + case `rethrows` + case `static` + case unowned + case weak + + init?(lexeme: Lexer.Lexeme) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(.__consuming): self = .__consuming + case TokenSpec(.__setter_access): self = .__setter_access + case TokenSpec(._const): self = ._const + case TokenSpec(._local): self = ._local + case TokenSpec(.async): self = .async + case TokenSpec(.borrowing): self = .borrowing + case TokenSpec(.class): self = .class + case TokenSpec(.consuming): self = .consuming + case TokenSpec(.convenience): self = .convenience + case TokenSpec(.distributed): self = .distributed + case TokenSpec(.dynamic): self = .dynamic + case TokenSpec(.fileprivate): self = .fileprivate + case TokenSpec(.final): self = .final + case TokenSpec(.indirect): self = .indirect + case TokenSpec(.infix): self = .infix + case TokenSpec(.internal): self = .internal + case TokenSpec(.isolated): self = .isolated + case TokenSpec(.lazy): self = .lazy + case TokenSpec(.mutating): self = .mutating + case TokenSpec(.nonisolated): self = .nonisolated + case TokenSpec(.nonmutating): self = .nonmutating + case TokenSpec(.open): self = .open + case TokenSpec(.optional): self = .optional + case TokenSpec(.override): self = .override + case TokenSpec(.package): self = .package + case TokenSpec(.postfix): self = .postfix + case TokenSpec(.prefix): self = .prefix + case TokenSpec(.private): self = .private + case TokenSpec(.public): self = .public + case TokenSpec(.reasync): self = .reasync + case TokenSpec(.required): self = .required + case TokenSpec(.rethrows): self = .rethrows + case TokenSpec(.static): self = .static + case TokenSpec(.unowned): self = .unowned + case TokenSpec(.weak): self = .weak + default: return nil + } + } + + var spec: TokenSpec { + switch self { + case .__consuming: return .keyword(.__consuming) + case .__setter_access: return .keyword(.__setter_access) + case ._const: return TokenSpec(._const, recoveryPrecedence: .declKeyword) + case ._local: return .keyword(._local) + case .async: return TokenSpec(.async, recoveryPrecedence: .declKeyword) + case .borrowing: return TokenSpec(.borrowing, recoveryPrecedence: .declKeyword) + case .class: return .keyword(.class) + case .consuming: return TokenSpec(.consuming, recoveryPrecedence: .declKeyword) + case .convenience: return .keyword(.convenience) + case .distributed: return .keyword(.distributed) + case .dynamic: return .keyword(.dynamic) + case .fileprivate: return .keyword(.fileprivate) + case .final: return .keyword(.final) + case .indirect: return .keyword(.indirect) + case .infix: return .keyword(.infix) + case .internal: return .keyword(.internal) + case .isolated: return TokenSpec(.isolated, recoveryPrecedence: .declKeyword) + case .lazy: return .keyword(.lazy) + case .mutating: return .keyword(.mutating) + case .nonisolated: return .keyword(.nonisolated) + case .nonmutating: return .keyword(.nonmutating) + case .open: return .keyword(.open) + case .optional: return .keyword(.optional) + case .override: return .keyword(.override) + case .package: return .keyword(.package) + case .postfix: return .keyword(.postfix) + case .prefix: return .keyword(.prefix) + case .private: return .keyword(.private) + case .public: return .keyword(.public) + case .reasync: return TokenSpec(.reasync, recoveryPrecedence: .declKeyword) + case .required: return .keyword(.required) + case .rethrows: return TokenSpec(.rethrows, recoveryPrecedence: .declKeyword) + case .static: return .keyword(.static) + case .unowned: return TokenSpec(.unowned, recoveryPrecedence: .declKeyword) + case .weak: return TokenSpec(.weak, recoveryPrecedence: .declKeyword) + } + } +} + /// Union of the following token kind subsets: /// - `DeclarationModifier` /// - `DeclarationKeyword` @@ -463,6 +582,56 @@ enum SwitchCaseStart: TokenSpecSet { } } +enum TypeAttribute: TokenSpecSet { + case _local + case _noMetadata + case _opaqueReturnTypeOf + case async + case autoclosure + case convention + case differentiable + case escaping + case noDerivative + case noescape + case Sendable + case unchecked + + init?(lexeme: Lexer.Lexeme) { + switch PrepareForKeywordMatch(lexeme) { + case TokenSpec(._local): self = ._local + case TokenSpec(._noMetadata): self = ._noMetadata + case TokenSpec(._opaqueReturnTypeOf): self = ._opaqueReturnTypeOf + case TokenSpec(.async): self = .async + case TokenSpec(.autoclosure): self = .autoclosure + case TokenSpec(.convention): self = .convention + case TokenSpec(.differentiable): self = .differentiable + case TokenSpec(.escaping): self = .escaping + case TokenSpec(.noDerivative): self = .noDerivative + case TokenSpec(.noescape): self = .noescape + case TokenSpec(.Sendable): self = .Sendable + case TokenSpec(.unchecked): self = .unchecked + default: return nil + } + } + + var spec: TokenSpec { + switch self { + case ._local: return .keyword(._local) + case ._noMetadata: return .keyword(._noMetadata) + case ._opaqueReturnTypeOf: return .keyword(._opaqueReturnTypeOf) + case .async: return .keyword(.async) + case .autoclosure: return .keyword(.autoclosure) + case .convention: return .keyword(.convention) + case .differentiable: return .keyword(.differentiable) + case .escaping: return .keyword(.escaping) + case .noDerivative: return .keyword(.noDerivative) + case .noescape: return .keyword(.noescape) + case .Sendable: return .keyword(.Sendable) + case .unchecked: return .keyword(.unchecked) + } + } +} + @_spi(Diagnostics) public enum TypeSpecifier: TokenSpecSet { case `inout` diff --git a/Sources/SwiftParser/Types.swift b/Sources/SwiftParser/Types.swift index e97fa537701..ab7a9eab896 100644 --- a/Sources/SwiftParser/Types.swift +++ b/Sources/SwiftParser/Types.swift @@ -1011,7 +1011,7 @@ extension Parser { } mutating func parseTypeAttribute() -> RawAttributeListSyntax.Element { - let typeAttr = Parser.TypeAttribute(lexeme: self.peek()) + let typeAttr = TypeAttribute(lexeme: self.peek()) switch typeAttr { case ._local, ._noMetadata, .async, .escaping, .noDerivative, .noescape, .Sendable, .unchecked, .autoclosure: diff --git a/Sources/SwiftParser/generated/DeclarationModifier.swift b/Sources/SwiftParser/generated/DeclarationModifier.swift deleted file mode 100644 index ce4a56335b5..00000000000 --- a/Sources/SwiftParser/generated/DeclarationModifier.swift +++ /dev/null @@ -1,205 +0,0 @@ -//// Automatically generated by generate-swiftsyntax -//// Do not edit directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -@_spi(RawSyntax) import SwiftSyntax - -enum DeclarationModifier: TokenSpecSet { - case weak - case unowned - case `rethrows` - case isolated - case async - case reasync - case consuming - case borrowing - case _const - case `static` - case `class` - case final - case required - case optional - case lazy - case dynamic - case infix - case prefix - case postfix - case __consuming - case mutating - case nonmutating - case convenience - case override - case `private` - case `fileprivate` - case `internal` - case `public` - case package - case open - case __setter_access - case indirect - case nonisolated - case distributed - case _local - - init?(lexeme: Lexer.Lexeme) { - switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.weak): - self = .weak - case TokenSpec(.unowned): - self = .unowned - case TokenSpec(.`rethrows`): - self = .`rethrows` - case TokenSpec(.isolated): - self = .isolated - case TokenSpec(.async): - self = .async - case TokenSpec(.reasync): - self = .reasync - case TokenSpec(.consuming): - self = .consuming - case TokenSpec(.borrowing): - self = .borrowing - case TokenSpec(._const): - self = ._const - case TokenSpec(.`static`): - self = .`static` - case TokenSpec(.`class`): - self = .`class` - case TokenSpec(.final): - self = .final - case TokenSpec(.required): - self = .required - case TokenSpec(.optional): - self = .optional - case TokenSpec(.lazy): - self = .lazy - case TokenSpec(.dynamic): - self = .dynamic - case TokenSpec(.infix): - self = .infix - case TokenSpec(.prefix): - self = .prefix - case TokenSpec(.postfix): - self = .postfix - case TokenSpec(.__consuming): - self = .__consuming - case TokenSpec(.mutating): - self = .mutating - case TokenSpec(.nonmutating): - self = .nonmutating - case TokenSpec(.convenience): - self = .convenience - case TokenSpec(.override): - self = .override - case TokenSpec(.`private`): - self = .`private` - case TokenSpec(.`fileprivate`): - self = .`fileprivate` - case TokenSpec(.`internal`): - self = .`internal` - case TokenSpec(.`public`): - self = .`public` - case TokenSpec(.package): - self = .package - case TokenSpec(.open): - self = .open - case TokenSpec(.__setter_access): - self = .__setter_access - case TokenSpec(.indirect): - self = .indirect - case TokenSpec(.nonisolated): - self = .nonisolated - case TokenSpec(.distributed): - self = .distributed - case TokenSpec(._local): - self = ._local - default: - return nil - } - } - - var spec: TokenSpec { - switch self { - case .`static`: - return .keyword(.`static`) - case .`class`: - return .keyword(.`class`) - case .final: - return .keyword(.final) - case .required: - return .keyword(.required) - case .optional: - return .keyword(.optional) - case .lazy: - return .keyword(.lazy) - case .dynamic: - return .keyword(.dynamic) - case .infix: - return .keyword(.infix) - case .prefix: - return .keyword(.prefix) - case .postfix: - return .keyword(.postfix) - case .__consuming: - return .keyword(.__consuming) - case .mutating: - return .keyword(.mutating) - case .nonmutating: - return .keyword(.nonmutating) - case .convenience: - return .keyword(.convenience) - case .override: - return .keyword(.override) - case .`private`: - return .keyword(.`private`) - case .`fileprivate`: - return .keyword(.`fileprivate`) - case .`internal`: - return .keyword(.`internal`) - case .`public`: - return .keyword(.`public`) - case .package: - return .keyword(.package) - case .open: - return .keyword(.open) - case .__setter_access: - return .keyword(.__setter_access) - case .indirect: - return .keyword(.indirect) - case .nonisolated: - return .keyword(.nonisolated) - case .distributed: - return .keyword(.distributed) - case ._local: - return .keyword(._local) - case .weak: - return TokenSpec(.weak, recoveryPrecedence: .declKeyword) - case .unowned: - return TokenSpec(.unowned, recoveryPrecedence: .declKeyword) - case .`rethrows`: - return TokenSpec(.`rethrows`, recoveryPrecedence: .declKeyword) - case .isolated: - return TokenSpec(.isolated, recoveryPrecedence: .declKeyword) - case .async: - return TokenSpec(.async, recoveryPrecedence: .declKeyword) - case .reasync: - return TokenSpec(.reasync, recoveryPrecedence: .declKeyword) - case .consuming: - return TokenSpec(.consuming, recoveryPrecedence: .declKeyword) - case .borrowing: - return TokenSpec(.borrowing, recoveryPrecedence: .declKeyword) - case ._const: - return TokenSpec(._const, recoveryPrecedence: .declKeyword) - } - } -} diff --git a/Sources/SwiftParser/generated/TypeAttribute.swift b/Sources/SwiftParser/generated/TypeAttribute.swift deleted file mode 100644 index 4b9f8fa3bf9..00000000000 --- a/Sources/SwiftParser/generated/TypeAttribute.swift +++ /dev/null @@ -1,92 +0,0 @@ -//// Automatically generated by generate-swiftsyntax -//// Do not edit directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -@_spi(RawSyntax) import SwiftSyntax - -extension Parser { - enum TypeAttribute: TokenSpecSet { - case autoclosure - case convention - case noescape - case escaping - case differentiable - case noDerivative - case async - case Sendable - case unchecked - case _local - case _noMetadata - case _opaqueReturnTypeOf - - init?(lexeme: Lexer.Lexeme) { - switch PrepareForKeywordMatch(lexeme) { - case TokenSpec(.autoclosure): - self = .autoclosure - case TokenSpec(.convention): - self = .convention - case TokenSpec(.noescape): - self = .noescape - case TokenSpec(.escaping): - self = .escaping - case TokenSpec(.differentiable): - self = .differentiable - case TokenSpec(.noDerivative): - self = .noDerivative - case TokenSpec(.async): - self = .async - case TokenSpec(.Sendable): - self = .Sendable - case TokenSpec(.unchecked): - self = .unchecked - case TokenSpec(._local): - self = ._local - case TokenSpec(._noMetadata): - self = ._noMetadata - case TokenSpec(._opaqueReturnTypeOf): - self = ._opaqueReturnTypeOf - default: - return nil - } - } - - var spec: TokenSpec { - switch self { - case .autoclosure: - return .keyword(.autoclosure) - case .convention: - return .keyword(.convention) - case .noescape: - return .keyword(.noescape) - case .escaping: - return .keyword(.escaping) - case .differentiable: - return .keyword(.differentiable) - case .noDerivative: - return .keyword(.noDerivative) - case .async: - return .keyword(.async) - case .Sendable: - return .keyword(.Sendable) - case .unchecked: - return .keyword(.unchecked) - case ._local: - return .keyword(._local) - case ._noMetadata: - return .keyword(._noMetadata) - case ._opaqueReturnTypeOf: - return .keyword(._opaqueReturnTypeOf) - } - } - } -}