mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring bootstrapping, and is enabled in more places. Move the regex literal parsing logic there so it is enabled in more host environments, and makes use of CMake's Swift support. Enable all of the regex literal tests when ASTGen is built, to ensure everything is working. Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources, because they are no longer needed.
This commit is contained in:
@@ -245,11 +245,8 @@ else()
|
|||||||
#define COMPILED_WITH_SWIFT
|
#define COMPILED_WITH_SWIFT
|
||||||
|
|
||||||
#include \"Basic/BasicBridging.h\"
|
#include \"Basic/BasicBridging.h\"
|
||||||
#include \"AST/ASTBridging.h\"
|
|
||||||
#include \"SIL/SILBridging.h\"
|
#include \"SIL/SILBridging.h\"
|
||||||
#include \"SILOptimizer/OptimizerBridging.h\"
|
#include \"SILOptimizer/OptimizerBridging.h\"
|
||||||
|
|
||||||
#include \"Parse/RegexParserBridging.h\"
|
|
||||||
")
|
")
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
|
||||||
|
|||||||
@@ -67,39 +67,22 @@ let package = Package(
|
|||||||
.library(
|
.library(
|
||||||
name: "swiftCompilerModules",
|
name: "swiftCompilerModules",
|
||||||
type: .static,
|
type: .static,
|
||||||
targets: ["Basic", "AST", "Parse", "SIL", "Optimizer", "_CompilerRegexParser"]),
|
targets: ["Basic", "SIL", "Optimizer"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
],
|
],
|
||||||
// Note that targets and their dependencies must align with
|
// Note that targets and their dependencies must align with
|
||||||
// 'SwiftCompilerSources/Sources/CMakeLists.txt'
|
// 'SwiftCompilerSources/Sources/CMakeLists.txt'
|
||||||
targets: [
|
targets: [
|
||||||
.compilerModuleTarget(
|
|
||||||
name: "_CompilerRegexParser",
|
|
||||||
dependencies: [],
|
|
||||||
path: "_RegexParser_Sources",
|
|
||||||
swiftSettings: [
|
|
||||||
// Workaround until `_CompilerRegexParser` is imported as implementation-only
|
|
||||||
// by `_StringProcessing`.
|
|
||||||
.unsafeFlags([
|
|
||||||
"-Xfrontend",
|
|
||||||
"-disable-implicit-string-processing-module-import"
|
|
||||||
])]),
|
|
||||||
.compilerModuleTarget(
|
.compilerModuleTarget(
|
||||||
name: "Basic",
|
name: "Basic",
|
||||||
dependencies: []),
|
dependencies: []),
|
||||||
.compilerModuleTarget(
|
|
||||||
name: "AST",
|
|
||||||
dependencies: ["Basic"]),
|
|
||||||
.compilerModuleTarget(
|
|
||||||
name: "Parse",
|
|
||||||
dependencies: ["Basic", "AST", "_CompilerRegexParser"]),
|
|
||||||
.compilerModuleTarget(
|
.compilerModuleTarget(
|
||||||
name: "SIL",
|
name: "SIL",
|
||||||
dependencies: ["Basic"]),
|
dependencies: ["Basic"]),
|
||||||
.compilerModuleTarget(
|
.compilerModuleTarget(
|
||||||
name: "Optimizer",
|
name: "Optimizer",
|
||||||
dependencies: ["Basic", "SIL", "Parse"]),
|
dependencies: ["Basic", "SIL"]),
|
||||||
],
|
],
|
||||||
cxxLanguageStandard: .cxx17
|
cxxLanguageStandard: .cxx17
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
# This source file is part of the Swift.org open source project
|
|
||||||
#
|
|
||||||
# Copyright (c) 2022 Apple Inc. and the Swift project authors
|
|
||||||
# Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
#
|
|
||||||
# See http://swift.org/LICENSE.txt for license information
|
|
||||||
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
||||||
|
|
||||||
add_swift_compiler_module(AST
|
|
||||||
DEPENDS
|
|
||||||
Basic
|
|
||||||
SOURCES
|
|
||||||
DiagnosticEngine.swift)
|
|
||||||
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
//===--- DiagnosticEngine.swift -------------------------------------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2022 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 ASTBridging
|
|
||||||
|
|
||||||
import Basic
|
|
||||||
|
|
||||||
public typealias DiagID = BridgedDiagID
|
|
||||||
|
|
||||||
public protocol DiagnosticArgument {
|
|
||||||
func _withBridgedDiagnosticArgument(_ fn: (BridgedDiagnosticArgument) -> Void)
|
|
||||||
}
|
|
||||||
extension String: DiagnosticArgument {
|
|
||||||
public func _withBridgedDiagnosticArgument(_ fn: (BridgedDiagnosticArgument) -> Void) {
|
|
||||||
_withBridgedStringRef { fn(BridgedDiagnosticArgument($0)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
extension Int: DiagnosticArgument {
|
|
||||||
public func _withBridgedDiagnosticArgument(_ fn: (BridgedDiagnosticArgument) -> Void) {
|
|
||||||
fn(BridgedDiagnosticArgument(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct DiagnosticFixIt {
|
|
||||||
public let start: SourceLoc
|
|
||||||
public let byteLength: Int
|
|
||||||
public let text: String
|
|
||||||
|
|
||||||
public init(start: SourceLoc, byteLength: Int, replacement text: String) {
|
|
||||||
self.start = start
|
|
||||||
self.byteLength = byteLength
|
|
||||||
self.text = text
|
|
||||||
}
|
|
||||||
|
|
||||||
func withBridgedDiagnosticFixIt(_ fn: (BridgedDiagnosticFixIt) -> Void) {
|
|
||||||
text._withBridgedStringRef { bridgedTextRef in
|
|
||||||
let bridgedDiagnosticFixIt = BridgedDiagnosticFixIt(
|
|
||||||
start.bridged, UInt32(byteLength),
|
|
||||||
bridgedTextRef)
|
|
||||||
fn(bridgedDiagnosticFixIt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct DiagnosticEngine {
|
|
||||||
private let bridged: BridgedDiagnosticEngine
|
|
||||||
|
|
||||||
public init(bridged: BridgedDiagnosticEngine) {
|
|
||||||
self.bridged = bridged
|
|
||||||
}
|
|
||||||
public init?(bridged: BridgedNullableDiagnosticEngine) {
|
|
||||||
guard let raw = bridged.raw else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
self.bridged = BridgedDiagnosticEngine(raw: raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func diagnose(_ position: SourceLoc?,
|
|
||||||
_ id: DiagID,
|
|
||||||
_ args: [DiagnosticArgument],
|
|
||||||
highlight: CharSourceRange? = nil,
|
|
||||||
fixIts: [DiagnosticFixIt] = []) {
|
|
||||||
|
|
||||||
let bridgedSourceLoc: BridgedSourceLoc = position.bridged
|
|
||||||
let highlightStart: BridgedSourceLoc
|
|
||||||
let highlightLength: UInt32
|
|
||||||
if let highlight = highlight {
|
|
||||||
highlightStart = highlight.start.bridged
|
|
||||||
highlightLength = highlight.byteLength
|
|
||||||
} else {
|
|
||||||
highlightStart = BridgedSourceLoc()
|
|
||||||
highlightLength = 0
|
|
||||||
}
|
|
||||||
var bridgedArgs: [BridgedDiagnosticArgument] = []
|
|
||||||
var bridgedFixIts: [BridgedDiagnosticFixIt] = []
|
|
||||||
|
|
||||||
// Build a higher-order function to wrap every 'withBridgedXXX { ... }'
|
|
||||||
// calls, so we don't escape anything from the closure. 'bridgedArgs' and
|
|
||||||
// 'bridgedFixIts' are temporary storage to store bridged values. So they
|
|
||||||
// should not be used after the closure is executed.
|
|
||||||
|
|
||||||
var closure: () -> Void = {
|
|
||||||
bridgedArgs.withBridgedArrayRef { bridgedArgsRef in
|
|
||||||
bridgedFixIts.withBridgedArrayRef { bridgedFixItsRef in
|
|
||||||
bridged.diagnose(at: bridgedSourceLoc, id, bridgedArgsRef,
|
|
||||||
highlightAt: highlightStart,
|
|
||||||
highlightLength: highlightLength,
|
|
||||||
fixIts: bridgedFixItsRef)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 'reversed()' because the closure should be wrapped in that order.
|
|
||||||
for arg in args.reversed() {
|
|
||||||
closure = { [closure, arg] in
|
|
||||||
arg._withBridgedDiagnosticArgument { bridgedArg in
|
|
||||||
bridgedArgs.append(bridgedArg)
|
|
||||||
closure()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 'reversed()' because the closure should be wrapped in that order.
|
|
||||||
for fixIt in fixIts.reversed() {
|
|
||||||
closure = { [closure, fixIt] in
|
|
||||||
fixIt.withBridgedDiagnosticFixIt { bridgedFixIt in
|
|
||||||
bridgedFixIts.append(bridgedFixIt)
|
|
||||||
closure()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closure()
|
|
||||||
}
|
|
||||||
|
|
||||||
public func diagnose(_ position: SourceLoc?,
|
|
||||||
_ id: DiagID,
|
|
||||||
_ args: DiagnosticArgument...,
|
|
||||||
highlight: CharSourceRange? = nil,
|
|
||||||
fixIts: DiagnosticFixIt...) {
|
|
||||||
diagnose(position, id, args, highlight: highlight, fixIts: fixIts)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
import ASTBridging
|
import BasicBridging
|
||||||
|
|
||||||
public struct SourceLoc {
|
public struct SourceLoc {
|
||||||
/// Points into a source file.
|
/// Points into a source file.
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
|
|
||||||
# NOTE: Subdirectories must be added in dependency order.
|
# NOTE: Subdirectories must be added in dependency order.
|
||||||
|
|
||||||
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
|
|
||||||
add_subdirectory(_RegexParser)
|
|
||||||
endif()
|
|
||||||
add_subdirectory(Basic)
|
add_subdirectory(Basic)
|
||||||
add_subdirectory(AST)
|
|
||||||
add_subdirectory(Parse)
|
|
||||||
add_subdirectory(SIL)
|
add_subdirectory(SIL)
|
||||||
add_subdirectory(Optimizer)
|
add_subdirectory(Optimizer)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
||||||
|
|
||||||
set(dependencies)
|
set(dependencies)
|
||||||
list(APPEND dependencies Basic SIL Parse)
|
list(APPEND dependencies Basic SIL)
|
||||||
|
|
||||||
add_swift_compiler_module(Optimizer DEPENDS ${dependencies})
|
add_swift_compiler_module(Optimizer DEPENDS ${dependencies})
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
import AST
|
|
||||||
import SIL
|
import SIL
|
||||||
import OptimizerBridging
|
import OptimizerBridging
|
||||||
|
|
||||||
@@ -41,12 +40,6 @@ extension Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Context {
|
|
||||||
var diagnosticEngine: DiagnosticEngine {
|
|
||||||
return DiagnosticEngine(bridged: _bridged.getDiagnosticEngine())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A context which allows mutation of a function's SIL.
|
/// A context which allows mutation of a function's SIL.
|
||||||
protocol MutatingContext : Context {
|
protocol MutatingContext : Context {
|
||||||
// Called by all instruction mutations, including inserted new instructions.
|
// Called by all instruction mutations, including inserted new instructions.
|
||||||
|
|||||||
@@ -12,14 +12,12 @@
|
|||||||
|
|
||||||
import SIL
|
import SIL
|
||||||
import OptimizerBridging
|
import OptimizerBridging
|
||||||
import Parse
|
|
||||||
|
|
||||||
@_cdecl("initializeSwiftModules")
|
@_cdecl("initializeSwiftModules")
|
||||||
public func initializeSwiftModules() {
|
public func initializeSwiftModules() {
|
||||||
registerSILClasses()
|
registerSILClasses()
|
||||||
registerSwiftAnalyses()
|
registerSwiftAnalyses()
|
||||||
registerSwiftPasses()
|
registerSwiftPasses()
|
||||||
initializeSwiftParseModules()
|
|
||||||
registerOptimizerTests()
|
registerOptimizerTests()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
# This source file is part of the Swift.org open source project
|
|
||||||
#
|
|
||||||
# Copyright (c) 2022 Apple Inc. and the Swift project authors
|
|
||||||
# Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
#
|
|
||||||
# See http://swift.org/LICENSE.txt for license information
|
|
||||||
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
||||||
|
|
||||||
set(dependencies Basic AST)
|
|
||||||
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
|
|
||||||
list(APPEND dependencies _CompilerRegexParser)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_swift_compiler_module(Parse
|
|
||||||
DEPENDS
|
|
||||||
${dependencies}
|
|
||||||
SOURCES
|
|
||||||
Parse.swift
|
|
||||||
Regex.swift)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
//===--- Parse.swift - SourceLoc bridiging utilities ------------------===//
|
|
||||||
//
|
|
||||||
// This source file is part of the Swift.org open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2022 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
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
@_cdecl("initializeSwiftParseModules")
|
|
||||||
public func initializeSwiftParseModules() {
|
|
||||||
registerRegexParser()
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# This source file is part of the Swift.org open source project
|
|
||||||
#
|
|
||||||
# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
|
|
||||||
# Licensed under Apache License v2.0 with Runtime Library Exception
|
|
||||||
#
|
|
||||||
# See http://swift.org/LICENSE.txt for license information
|
|
||||||
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
||||||
|
|
||||||
file(GLOB_RECURSE _LIBSWIFT_REGEX_PARSER_SOURCES
|
|
||||||
"${SWIFT_PATH_TO_STRING_PROCESSING_SOURCE}/Sources/_RegexParser/*.swift")
|
|
||||||
set(LIBSWIFT_REGEX_PARSER_SOURCES)
|
|
||||||
foreach(source ${_LIBSWIFT_REGEX_PARSER_SOURCES})
|
|
||||||
file(TO_CMAKE_PATH "${source}" source)
|
|
||||||
list(APPEND LIBSWIFT_REGEX_PARSER_SOURCES ${source})
|
|
||||||
endforeach()
|
|
||||||
message(STATUS "Using Experimental String Processing library for libswift _RegexParser (${SWIFT_PATH_TO_STRING_PROCESSING_SOURCE}).")
|
|
||||||
|
|
||||||
add_swift_compiler_module(_CompilerRegexParser
|
|
||||||
SOURCES
|
|
||||||
"${LIBSWIFT_REGEX_PARSER_SOURCES}")
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../swift-experimental-string-processing/Sources/_RegexParser
|
|
||||||
@@ -13,9 +13,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
void initializeSwiftModules();
|
void initializeSwiftModules();
|
||||||
void initializeSwiftParseModules();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeSwiftModules() {}
|
void initializeSwiftModules() {}
|
||||||
void initializeSwiftParseModules() {}
|
|
||||||
|
|||||||
@@ -2073,13 +2073,6 @@ ERROR(expected_closure_literal,none,
|
|||||||
ERROR(expected_multiple_closures_block_rbrace,none,
|
ERROR(expected_multiple_closures_block_rbrace,none,
|
||||||
"expected '}' at the end of a trailing closures block", ())
|
"expected '}' at the end of a trailing closures block", ())
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// MARK: diagnostics emitted by Swift libraries
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ERROR(foreign_diagnostic,none,
|
|
||||||
"%0", (StringRef))
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// MARK: macros
|
// MARK: macros
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initializeSwiftModules();
|
void initializeSwiftModules();
|
||||||
void initializeSwiftParseModules();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,20 @@ swift::Stmt *_Nullable swift_ASTGen_buildStmt(
|
|||||||
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
|
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
|
||||||
BridgedSourceLoc *_Nonnull endSourceLoc);
|
BridgedSourceLoc *_Nonnull endSourceLoc);
|
||||||
|
|
||||||
|
// MARK: - Regex parsing
|
||||||
|
|
||||||
|
bool swift_ASTGen_lexRegexLiteral(const char *_Nonnull *_Nonnull curPtrPtr,
|
||||||
|
const char *_Nonnull bufferEndPtr,
|
||||||
|
bool mustBeRegex,
|
||||||
|
BridgedNullableDiagnosticEngine diagEngine);
|
||||||
|
|
||||||
|
bool swift_ASTGen_parseRegexLiteral(BridgedStringRef inputPtr,
|
||||||
|
size_t *_Nonnull versionOut,
|
||||||
|
void *_Nonnull UnsafeMutableRawPointer,
|
||||||
|
size_t captureStructureSize,
|
||||||
|
BridgedSourceLoc diagLoc,
|
||||||
|
BridgedDiagnosticEngine diagEngine);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,6 +5,26 @@ add_pure_swift_host_library(swiftLLVMJSON STATIC EMIT_MODULE
|
|||||||
swiftBasic
|
swiftBasic
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(ASTGen_Swift_dependencies)
|
||||||
|
|
||||||
|
# If requested, build the regular expression parser into the compiler itself.
|
||||||
|
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
|
||||||
|
file(GLOB_RECURSE _COMPILER_REGEX_PARSER_SOURCES
|
||||||
|
"${SWIFT_PATH_TO_STRING_PROCESSING_SOURCE}/Sources/_RegexParser/*.swift")
|
||||||
|
set(COMPILER_REGEX_PARSER_SOURCES)
|
||||||
|
foreach(source ${_COMPILER_REGEX_PARSER_SOURCES})
|
||||||
|
file(TO_CMAKE_PATH "${source}" source)
|
||||||
|
list(APPEND COMPILER_REGEX_PARSER_SOURCES ${source})
|
||||||
|
endforeach()
|
||||||
|
message(STATUS "Using Experimental String Processing library for _CompilerRegexParser (${SWIFT_PATH_TO_STRING_PROCESSING_SOURCE}).")
|
||||||
|
|
||||||
|
add_pure_swift_host_library(_CompilerRegexParser STATIC EMIT_MODULE
|
||||||
|
"${COMPILER_REGEX_PARSER_SOURCES}"
|
||||||
|
)
|
||||||
|
|
||||||
|
list(APPEND ASTGen_Swift_dependencies _CompilerRegexParser)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_pure_swift_host_library(swiftASTGen STATIC
|
add_pure_swift_host_library(swiftASTGen STATIC
|
||||||
Sources/ASTGen/ASTGen.swift
|
Sources/ASTGen/ASTGen.swift
|
||||||
Sources/ASTGen/Bridge.swift
|
Sources/ASTGen/Bridge.swift
|
||||||
@@ -19,6 +39,7 @@ add_pure_swift_host_library(swiftASTGen STATIC
|
|||||||
Sources/ASTGen/ParameterClause.swift
|
Sources/ASTGen/ParameterClause.swift
|
||||||
Sources/ASTGen/Patterns.swift
|
Sources/ASTGen/Patterns.swift
|
||||||
Sources/ASTGen/PluginHost.swift
|
Sources/ASTGen/PluginHost.swift
|
||||||
|
Sources/ASTGen/Regex.swift
|
||||||
Sources/ASTGen/SourceFile.swift
|
Sources/ASTGen/SourceFile.swift
|
||||||
Sources/ASTGen/SourceManager.swift
|
Sources/ASTGen/SourceManager.swift
|
||||||
Sources/ASTGen/SourceManager+MacroExpansionContext.swift
|
Sources/ASTGen/SourceManager+MacroExpansionContext.swift
|
||||||
@@ -39,6 +60,7 @@ add_pure_swift_host_library(swiftASTGen STATIC
|
|||||||
SwiftSyntaxMacros
|
SwiftSyntaxMacros
|
||||||
SwiftSyntaxMacroExpansion
|
SwiftSyntaxMacroExpansion
|
||||||
swiftLLVMJSON
|
swiftLLVMJSON
|
||||||
|
${ASTGen_Swift_dependencies}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(c_include_paths
|
set(c_include_paths
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ let package = Package(
|
|||||||
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
|
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
|
||||||
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
|
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
|
||||||
"swiftLLVMJSON",
|
"swiftLLVMJSON",
|
||||||
|
"_CompilerRegexParser",
|
||||||
],
|
],
|
||||||
path: "Sources/ASTGen",
|
path: "Sources/ASTGen",
|
||||||
swiftSettings: swiftSetttings
|
swiftSettings: swiftSetttings
|
||||||
@@ -74,6 +75,12 @@ let package = Package(
|
|||||||
path: "Sources/LLVMJSON",
|
path: "Sources/LLVMJSON",
|
||||||
swiftSettings: swiftSetttings
|
swiftSettings: swiftSetttings
|
||||||
),
|
),
|
||||||
|
.target(
|
||||||
|
name: "_CompilerRegexParser",
|
||||||
|
dependencies: [],
|
||||||
|
path: "_RegexParser_Sources",
|
||||||
|
swiftSettings: swiftSetttings
|
||||||
|
),
|
||||||
],
|
],
|
||||||
cxxLanguageStandard: .cxx17
|
cxxLanguageStandard: .cxx17
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -81,6 +81,13 @@ extension BridgedSourceRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
init(bridged: BridgedStringRef) {
|
||||||
|
self.init(
|
||||||
|
decoding: UnsafeBufferPointer(start: bridged.data, count: bridged.count),
|
||||||
|
as: UTF8.self
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
mutating func withBridgedString<R>(_ body: (BridgedStringRef) throws -> R) rethrows -> R {
|
mutating func withBridgedString<R>(_ body: (BridgedStringRef) throws -> R) rethrows -> R {
|
||||||
try withUTF8 { buffer in
|
try withUTF8 { buffer in
|
||||||
try body(BridgedStringRef(data: buffer.baseAddress, count: buffer.count))
|
try body(BridgedStringRef(data: buffer.baseAddress, count: buffer.count))
|
||||||
|
|||||||
@@ -11,27 +11,22 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
import _RegexParserBridging
|
import _RegexParserBridging
|
||||||
import AST
|
import ASTBridging
|
||||||
import Basic
|
import BasicBridging
|
||||||
|
|
||||||
#if canImport(_CompilerRegexParser)
|
#if canImport(_CompilerRegexParser)
|
||||||
@_spi(CompilerInterface) import _CompilerRegexParser
|
@_spi(CompilerInterface) import _CompilerRegexParser
|
||||||
|
|
||||||
func registerRegexParser() {
|
|
||||||
Parser_registerRegexLiteralParsingFn(_RegexLiteralParsingFn)
|
|
||||||
Parser_registerRegexLiteralLexingFn(_RegexLiteralLexingFn)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bridging between C++ lexer and swiftCompilerLexRegexLiteral.
|
/// Bridging between C++ lexer and swiftCompilerLexRegexLiteral.
|
||||||
///
|
///
|
||||||
/// Attempt to lex a regex literal string.
|
/// Attempt to lex a regex literal string.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - CurPtrPtr: A pointer to the current pointer of lexer, which should be
|
/// - curPtrPtr: A pointer to the current pointer of lexer, which should be
|
||||||
/// the start of the literal. This will be advanced to the point
|
/// the start of the literal. This will be advanced to the point
|
||||||
/// at which the lexer should resume, or will remain the same if
|
/// at which the lexer should resume, or will remain the same if
|
||||||
/// this is not a regex literal.
|
/// this is not a regex literal.
|
||||||
/// - BufferEndPtr: A pointer to the end of the buffer, which should not be
|
/// - bufferEndPtr: A pointer to the end of the buffer, which should not be
|
||||||
/// lexed past.
|
/// lexed past.
|
||||||
/// - mustBeRegex: A bool value whether an error during lexing should be
|
/// - mustBeRegex: A bool value whether an error during lexing should be
|
||||||
/// considered a regex literal, or some thing else. If true
|
/// considered a regex literal, or some thing else. If true
|
||||||
@@ -42,12 +37,13 @@ func registerRegexParser() {
|
|||||||
/// - Returns: A bool indicating whether lexing was completely erroneous, and
|
/// - Returns: A bool indicating whether lexing was completely erroneous, and
|
||||||
/// cannot be recovered from, or false if there either was no error,
|
/// cannot be recovered from, or false if there either was no error,
|
||||||
/// or there was a recoverable error.
|
/// or there was a recoverable error.
|
||||||
private func _RegexLiteralLexingFn(
|
@_cdecl("swift_ASTGen_lexRegexLiteral")
|
||||||
|
public func _RegexLiteralLexingFn(
|
||||||
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
|
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
|
||||||
_ bufferEndPtr: UnsafePointer<CChar>,
|
_ bufferEndPtr: UnsafePointer<CChar>,
|
||||||
_ mustBeRegex: CBool,
|
_ mustBeRegex: Bool,
|
||||||
_ bridgedDiagnosticEngine: BridgedNullableDiagnosticEngine
|
_ bridgedDiagnosticEngine: BridgedNullableDiagnosticEngine
|
||||||
) -> /*CompletelyErroneous*/ CBool {
|
) -> /*CompletelyErroneous*/ Bool {
|
||||||
let inputPtr = curPtrPtr.pointee
|
let inputPtr = curPtrPtr.pointee
|
||||||
|
|
||||||
guard let (resumePtr, error) = swiftCompilerLexRegexLiteral(
|
guard let (resumePtr, error) = swiftCompilerLexRegexLiteral(
|
||||||
@@ -62,9 +58,16 @@ private func _RegexLiteralLexingFn(
|
|||||||
|
|
||||||
if let error = error {
|
if let error = error {
|
||||||
// Emit diagnostic if diagnostics are enabled.
|
// Emit diagnostic if diagnostics are enabled.
|
||||||
if let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine) {
|
if let diagEnginePtr = bridgedDiagnosticEngine.raw {
|
||||||
let startLoc = SourceLoc(bridged: BridgedSourceLoc(raw: error.location))!
|
var message = error.message
|
||||||
diagEngine.diagnose(startLoc, .foreign_diagnostic, error.message)
|
message.withBridgedString { message in
|
||||||
|
BridgedDiagnostic(
|
||||||
|
at: BridgedSourceLoc(raw: error.location),
|
||||||
|
message: message,
|
||||||
|
severity: .error,
|
||||||
|
engine: BridgedDiagnosticEngine(raw: diagEnginePtr)
|
||||||
|
).finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return error.completelyErroneous
|
return error.completelyErroneous
|
||||||
}
|
}
|
||||||
@@ -74,27 +77,26 @@ private func _RegexLiteralLexingFn(
|
|||||||
/// Bridging between C++ parser and swiftCompilerParseRegexLiteral.
|
/// Bridging between C++ parser and swiftCompilerParseRegexLiteral.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - inputPtr: A null-terminated C string.
|
/// - input: Regex literal text.
|
||||||
/// - errOut: A buffer accepting an error string upon error.
|
/// - versionOut: A buffer accepting a regex literal format version.
|
||||||
/// - versionOut: A buffer accepting a regex literal format
|
|
||||||
/// version.
|
|
||||||
/// - captureStructureOut: A buffer accepting a byte sequence representing the
|
/// - captureStructureOut: A buffer accepting a byte sequence representing the
|
||||||
/// capture structure.
|
/// capture structure.
|
||||||
/// - captureStructureSize: The size of the capture structure buffer. Must be
|
/// - captureStructureSize: The size of the capture structure buffer. Must be
|
||||||
/// greater than or equal to `strlen(inputPtr)`.
|
/// greater than or equal to `input.size()`.
|
||||||
/// - bridgedDiagnosticBaseLoc: Source location of the start of the literal
|
/// - bridgedDiagnosticBaseLoc: Source location of the start of the literal
|
||||||
/// - bridgedDiagnosticEngine: Diagnostic engine to emit diagnostics.
|
/// - bridgedDiagnosticEngine: Diagnostic engine to emit diagnostics.
|
||||||
///
|
///
|
||||||
/// - Returns: `true` if there was a parse error, `false` otherwise.
|
/// - Returns: `true` if there was a parse error, `false` otherwise.
|
||||||
|
@_cdecl("swift_ASTGen_parseRegexLiteral")
|
||||||
public func _RegexLiteralParsingFn(
|
public func _RegexLiteralParsingFn(
|
||||||
_ inputPtr: UnsafePointer<CChar>,
|
_ input: BridgedStringRef,
|
||||||
_ versionOut: UnsafeMutablePointer<CUnsignedInt>,
|
_ versionOut: UnsafeMutablePointer<UInt>,
|
||||||
_ captureStructureOut: UnsafeMutableRawPointer,
|
_ captureStructureOut: UnsafeMutableRawPointer,
|
||||||
_ captureStructureSize: CUnsignedInt,
|
_ captureStructureSize: UInt,
|
||||||
_ bridgedDiagnosticBaseLoc: BridgedSourceLoc,
|
_ bridgedDiagnosticBaseLoc: BridgedSourceLoc,
|
||||||
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine
|
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let str = String(cString: inputPtr)
|
let str = String(bridged: input)
|
||||||
let captureBuffer = UnsafeMutableRawBufferPointer(
|
let captureBuffer = UnsafeMutableRawBufferPointer(
|
||||||
start: captureStructureOut, count: Int(captureStructureSize))
|
start: captureStructureOut, count: Int(captureStructureSize))
|
||||||
do {
|
do {
|
||||||
@@ -102,16 +104,23 @@ public func _RegexLiteralParsingFn(
|
|||||||
// For now, it is the same as the input.
|
// For now, it is the same as the input.
|
||||||
let (_, version) = try swiftCompilerParseRegexLiteral(
|
let (_, version) = try swiftCompilerParseRegexLiteral(
|
||||||
str, captureBufferOut: captureBuffer)
|
str, captureBufferOut: captureBuffer)
|
||||||
versionOut.pointee = CUnsignedInt(version)
|
versionOut.pointee = UInt(version)
|
||||||
return false
|
return false
|
||||||
} catch let error as CompilerParseError {
|
} catch let error as CompilerParseError {
|
||||||
var diagLoc = SourceLoc(bridged: bridgedDiagnosticBaseLoc)
|
var diagLoc = bridgedDiagnosticBaseLoc
|
||||||
let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine)
|
if diagLoc.isValid, let errorLoc = error.location {
|
||||||
if let _diagLoc = diagLoc, let errorLoc = error.location {
|
|
||||||
let offset = str.utf8.distance(from: str.startIndex, to: errorLoc)
|
let offset = str.utf8.distance(from: str.startIndex, to: errorLoc)
|
||||||
diagLoc = _diagLoc.advanced(by: offset)
|
diagLoc = diagLoc.advanced(by: offset)
|
||||||
|
}
|
||||||
|
var message = error.message
|
||||||
|
message.withBridgedString { message in
|
||||||
|
BridgedDiagnostic(
|
||||||
|
at: diagLoc,
|
||||||
|
message: message,
|
||||||
|
severity: .error,
|
||||||
|
engine: bridgedDiagnosticEngine
|
||||||
|
).finish()
|
||||||
}
|
}
|
||||||
diagEngine.diagnose(diagLoc, .foreign_diagnostic, error.message)
|
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("Expected CompilerParseError")
|
fatalError("Expected CompilerParseError")
|
||||||
@@ -121,6 +130,5 @@ public func _RegexLiteralParsingFn(
|
|||||||
#else // canImport(_CompilerRegexParser)
|
#else // canImport(_CompilerRegexParser)
|
||||||
|
|
||||||
#warning("Regex parsing is disabled")
|
#warning("Regex parsing is disabled")
|
||||||
func registerRegexParser() {}
|
|
||||||
|
|
||||||
#endif // canImport(_CompilerRegexParser)
|
#endif // canImport(_CompilerRegexParser)
|
||||||
1
lib/ASTGen/_RegexParser_Sources
Symbolic link
1
lib/ASTGen/_RegexParser_Sources
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../swift-experimental-string-processing/Sources/_RegexParser
|
||||||
@@ -58,6 +58,13 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
|
||||||
|
target_compile_definitions(swiftParse
|
||||||
|
PRIVATE
|
||||||
|
SWIFT_BUILD_REGEX_PARSER_IN_COMPILER
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(SWIFT_COMPILER_VERSION)
|
if(SWIFT_COMPILER_VERSION)
|
||||||
set_property(SOURCE ParseVersion.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
|
set_property(SOURCE ParseVersion.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
|
||||||
" -DSWIFT_COMPILER_VERSION=\"\\\"${SWIFT_COMPILER_VERSION}\\\"\"")
|
" -DSWIFT_COMPILER_VERSION=\"\\\"${SWIFT_COMPILER_VERSION}\\\"\"")
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "swift/AST/Identifier.h"
|
#include "swift/AST/Identifier.h"
|
||||||
#include "swift/Basic/LangOptions.h"
|
#include "swift/Basic/LangOptions.h"
|
||||||
#include "swift/Basic/SourceManager.h"
|
#include "swift/Basic/SourceManager.h"
|
||||||
|
#include "swift/Bridging/ASTGen.h"
|
||||||
#include "swift/Parse/Confusables.h"
|
#include "swift/Parse/Confusables.h"
|
||||||
#include "swift/Parse/RegexParserBridging.h"
|
#include "swift/Parse/RegexParserBridging.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
@@ -33,12 +34,6 @@
|
|||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
// Regex lexing delivered via libSwift.
|
|
||||||
static RegexLiteralLexingFn regexLiteralLexingFn = nullptr;
|
|
||||||
void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn fn) {
|
|
||||||
regexLiteralLexingFn = fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace swift;
|
using namespace swift;
|
||||||
|
|
||||||
// clang::isAsciiIdentifierStart and clang::isAsciiIdentifierContinue are
|
// clang::isAsciiIdentifierStart and clang::isAsciiIdentifierContinue are
|
||||||
@@ -2040,9 +2035,10 @@ bool Lexer::isPotentialUnskippableBareSlashRegexLiteral(const Token &Tok) const
|
|||||||
const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
|
const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
|
||||||
DiagnosticEngine *Diags,
|
DiagnosticEngine *Diags,
|
||||||
bool &CompletelyErroneous) const {
|
bool &CompletelyErroneous) const {
|
||||||
|
#if SWIFT_BUILD_REGEX_PARSER_IN_COMPILER
|
||||||
// We need to have experimental string processing enabled, and have the
|
// We need to have experimental string processing enabled, and have the
|
||||||
// parsing logic for regex literals available.
|
// parsing logic for regex literals available.
|
||||||
if (!LangOpts.EnableExperimentalStringProcessing || !regexLiteralLexingFn)
|
if (!LangOpts.EnableExperimentalStringProcessing)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
bool IsForwardSlash = (*TokStart == '/');
|
bool IsForwardSlash = (*TokStart == '/');
|
||||||
@@ -2088,9 +2084,9 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
|
|||||||
// - Ptr will not be advanced if this is not for a regex literal.
|
// - Ptr will not be advanced if this is not for a regex literal.
|
||||||
// - CompletelyErroneous will be set if there was an error that cannot be
|
// - CompletelyErroneous will be set if there was an error that cannot be
|
||||||
// recovered from.
|
// recovered from.
|
||||||
auto *Ptr = TokStart;
|
const char *Ptr = TokStart;
|
||||||
CompletelyErroneous =
|
CompletelyErroneous =
|
||||||
regexLiteralLexingFn(&Ptr, BufferEnd, MustBeRegex, Diags);
|
swift_ASTGen_lexRegexLiteral(&Ptr, BufferEnd, MustBeRegex, Diags);
|
||||||
|
|
||||||
// If we didn't make any lexing progress, this isn't a regex literal and we
|
// If we didn't make any lexing progress, this isn't a regex literal and we
|
||||||
// should fallback to lexing as something else.
|
// should fallback to lexing as something else.
|
||||||
@@ -2178,6 +2174,9 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
|
|||||||
}
|
}
|
||||||
assert(Ptr > TokStart && Ptr <= BufferEnd);
|
assert(Ptr > TokStart && Ptr <= BufferEnd);
|
||||||
return Ptr;
|
return Ptr;
|
||||||
|
#else
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Lexer::tryLexRegexLiteral(const char *TokStart) {
|
bool Lexer::tryLexRegexLiteral(const char *TokStart) {
|
||||||
|
|||||||
@@ -15,35 +15,29 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "swift/AST/DiagnosticsParse.h"
|
#include "swift/AST/DiagnosticsParse.h"
|
||||||
|
#include "swift/Bridging/ASTGen.h"
|
||||||
#include "swift/Parse/Parser.h"
|
#include "swift/Parse/Parser.h"
|
||||||
|
|
||||||
// Regex parser delivered via Swift modules.
|
|
||||||
#include "swift/Parse/RegexParserBridging.h"
|
|
||||||
static RegexLiteralParsingFn regexLiteralParsingFn = nullptr;
|
|
||||||
void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn fn) {
|
|
||||||
regexLiteralParsingFn = fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace swift;
|
using namespace swift;
|
||||||
|
|
||||||
ParserResult<Expr> Parser::parseExprRegexLiteral() {
|
ParserResult<Expr> Parser::parseExprRegexLiteral() {
|
||||||
assert(Tok.is(tok::regex_literal));
|
assert(Tok.is(tok::regex_literal));
|
||||||
assert(regexLiteralParsingFn);
|
|
||||||
|
|
||||||
|
#if SWIFT_BUILD_REGEX_PARSER_IN_COMPILER
|
||||||
auto regexText = Tok.getText();
|
auto regexText = Tok.getText();
|
||||||
|
|
||||||
// Let the Swift library parse the contents, returning an error, or null if
|
// Let the Swift library parse the contents, returning an error, or null if
|
||||||
// successful.
|
// successful.
|
||||||
unsigned version = 0;
|
size_t version = 0;
|
||||||
auto capturesBuf = Context.AllocateUninitialized<uint8_t>(
|
auto capturesBuf = Context.AllocateUninitialized<uint8_t>(
|
||||||
RegexLiteralExpr::getCaptureStructureSerializationAllocationSize(
|
RegexLiteralExpr::getCaptureStructureSerializationAllocationSize(
|
||||||
regexText.size()));
|
regexText.size()));
|
||||||
bool hadError = regexLiteralParsingFn(
|
bool hadError = swift_ASTGen_parseRegexLiteral(
|
||||||
regexText.str().c_str(), &version,
|
regexText,
|
||||||
/*captureStructureOut*/ capturesBuf.data(),
|
/*versionOut=*/&version,
|
||||||
/*captureStructureSize*/ capturesBuf.size(),
|
/*captureStructureOut=*/capturesBuf.data(),
|
||||||
/*diagBaseLoc*/ {(const uint8_t *)(Tok.getLoc().getOpaquePointerValue())},
|
/*captureStructureSize=*/capturesBuf.size(),
|
||||||
&Diags);
|
/*diagBaseLoc=*/Tok.getLoc(), &Diags);
|
||||||
auto loc = consumeToken();
|
auto loc = consumeToken();
|
||||||
SourceMgr.recordRegexLiteralStartLoc(loc);
|
SourceMgr.recordRegexLiteralStartLoc(loc);
|
||||||
|
|
||||||
@@ -53,4 +47,7 @@ ParserResult<Expr> Parser::parseExprRegexLiteral() {
|
|||||||
assert(version >= 1);
|
assert(version >= 1);
|
||||||
return makeParserResult(RegexLiteralExpr::createParsed(
|
return makeParserResult(RegexLiteralExpr::createParsed(
|
||||||
Context, loc, regexText, version, capturesBuf));
|
Context, loc, regexText, version, capturesBuf));
|
||||||
|
#else
|
||||||
|
llvm_unreachable("Lexer should not emit tok::regex_literal");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// RUN: %empty-directory(%t)
|
// RUN: %empty-directory(%t)
|
||||||
// RUN: %target-swift-ide-test -enable-bare-slash-regex -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
|
// RUN: %target-swift-ide-test -enable-bare-slash-regex -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ var qux: Regex<Substring> { / x}/ }
|
|||||||
// RUN: -req=complete -pos=4:28 %s -- -enable-bare-slash-regex %s == \
|
// RUN: -req=complete -pos=4:28 %s -- -enable-bare-slash-regex %s == \
|
||||||
// RUN: -req=complete -pos=5:28 %s -- -enable-bare-slash-regex %s
|
// RUN: -req=complete -pos=5:28 %s -- -enable-bare-slash-regex %s
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-string-processing -enable-bare-slash-regex
|
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-string-processing -enable-bare-slash-regex
|
||||||
// RUN: %target-typecheck-verify-swift -disable-availability-checking -disable-experimental-string-processing -enable-experimental-string-processing -enable-bare-slash-regex
|
// RUN: %target-typecheck-verify-swift -disable-availability-checking -disable-experimental-string-processing -enable-experimental-string-processing -enable-bare-slash-regex
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
prefix operator /
|
prefix operator /
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -disable-availability-checking
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
prefix operator /
|
prefix operator /
|
||||||
prefix operator ^/
|
prefix operator ^/
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// RUN: %{python} %utils/process-stats-dir.py --set-csv-baseline %t/stats.csv %t
|
// RUN: %{python} %utils/process-stats-dir.py --set-csv-baseline %t/stats.csv %t
|
||||||
// RUN: %FileCheck -input-file %t/stats.csv %s
|
// RUN: %FileCheck -input-file %t/stats.csv %s
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// Make sure we can skip in all of the below cases.
|
// Make sure we can skip in all of the below cases.
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies-without-types
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies-without-types
|
||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// We don't consider this a regex literal when skipping as it has an initial
|
// We don't consider this a regex literal when skipping as it has an initial
|
||||||
// space.
|
// space.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies-without-types
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies-without-types
|
||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -experimental-skip-non-inlinable-function-bodies
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// Make sure we properly handle `/.../` regex literals in skipped function
|
// Make sure we properly handle `/.../` regex literals in skipped function
|
||||||
// bodies. Currently we detect them and avoid skipping, but in the future we
|
// bodies. Currently we detect them and avoid skipping, but in the future we
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -typo-correction-limit 0
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -typo-correction-limit 0
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
// REQUIRES: concurrency
|
// REQUIRES: concurrency
|
||||||
|
|
||||||
prefix operator /
|
prefix operator /
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// Test the behavior of prefix '/' with regex literals enabled.
|
// Test the behavior of prefix '/' with regex literals enabled.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
_ = /abc/
|
_ = /abc/
|
||||||
_ = #/abc/#
|
_ = #/abc/#
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// Note there is purposefully no trailing newline here.
|
// Note there is purposefully no trailing newline here.
|
||||||
// expected-error@+2:20 {{unterminated regex literal}}
|
// expected-error@+2:20 {{unterminated regex literal}}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
_ = /(/ // expected-error@:7 {{expected ')'}}
|
_ = /(/ // expected-error@:7 {{expected ')'}}
|
||||||
_ = #/(/# // expected-error@:8 {{expected ')'}}
|
_ = #/(/# // expected-error@:8 {{expected ')'}}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-run-simple-swift(-Xfrontend -enable-bare-slash-regex)
|
// RUN: %target-run-simple-swift(-Xfrontend -enable-bare-slash-regex)
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler,string_processing,executable_test
|
// REQUIRES: swift_swift_parser,string_processing,executable_test
|
||||||
|
|
||||||
import StdlibUnittest
|
import StdlibUnittest
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-swift-frontend -emit-silgen -enable-bare-slash-regex -disable-availability-checking %s | %FileCheck %s
|
// RUN: %target-swift-frontend -emit-silgen -enable-bare-slash-regex -disable-availability-checking %s | %FileCheck %s
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
var s = #/abc/#
|
var s = #/abc/#
|
||||||
// CHECK: [[REGEX_STR_LITERAL:%[0-9]+]] = string_literal utf8 "#/abc/#"
|
// CHECK: [[REGEX_STR_LITERAL:%[0-9]+]] = string_literal utf8 "#/abc/#"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -I %t
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking -I %t
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
import A
|
import A
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
struct S {
|
struct S {
|
||||||
func foo() {
|
func foo() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
Regex {} // expected-error {{regex builder requires the 'RegexBuilder' module be imported'}} {{5:1-1=import RegexBuilder\n\n}}
|
Regex {} // expected-error {{regex builder requires the 'RegexBuilder' module be imported'}} {{5:1-1=import RegexBuilder\n\n}}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -target %target-cpu-apple-macosx12.0
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -target %target-cpu-apple-macosx12.0
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
// REQUIRES: OS=macosx
|
// REQUIRES: OS=macosx
|
||||||
|
|
||||||
import RegexBuilder
|
import RegexBuilder
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -target %target-cpu-apple-macosx12.0
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -target %target-cpu-apple-macosx12.0
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
// REQUIRES: OS=macosx
|
// REQUIRES: OS=macosx
|
||||||
|
|
||||||
_ = /x/ // expected-error {{'Regex' is only available in}}
|
_ = /x/ // expected-error {{'Regex' is only available in}}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
|
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
postfix operator ^^
|
postfix operator ^^
|
||||||
postfix func ^^ <T> (_ x: T) -> T { x }
|
postfix func ^^ <T> (_ x: T) -> T { x }
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
let r0 = #/./#
|
let r0 = #/./#
|
||||||
let _: Regex<Substring> = r0
|
let _: Regex<Substring> = r0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %target-typecheck-verify-swift -disable-implicit-string-processing-module-import -disable-availability-checking
|
// RUN: %target-typecheck-verify-swift -disable-implicit-string-processing-module-import -disable-availability-checking
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
// expected-error @+1 {{missing 'Regex' declaration, probably because the '_StringProcessing' module was not imported properly}}
|
// expected-error @+1 {{missing 'Regex' declaration, probably because the '_StringProcessing' module was not imported properly}}
|
||||||
let r0 = #/./#
|
let r0 = #/./#
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// REQUIRES: asserts
|
// REQUIRES: asserts
|
||||||
|
|
||||||
// Required for regex
|
// Required for regex
|
||||||
// REQUIRES: swift_in_compiler
|
// REQUIRES: swift_swift_parser
|
||||||
|
|
||||||
func then(_: Int = 0, x: Int = 0, fn: () -> Void = {}) {}
|
func then(_: Int = 0, x: Int = 0, fn: () -> Void = {}) {}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "swift/Basic/InitializeSwiftModules.h"
|
|
||||||
#include "swift/Basic/LLVMInitialize.h"
|
#include "swift/Basic/LLVMInitialize.h"
|
||||||
#include "swift/DependencyScan/DependencyScanImpl.h"
|
#include "swift/DependencyScan/DependencyScanImpl.h"
|
||||||
#include "swift/DependencyScan/DependencyScanningTool.h"
|
#include "swift/DependencyScan/DependencyScanningTool.h"
|
||||||
@@ -131,9 +130,6 @@ void swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner) {
|
|||||||
|
|
||||||
swiftscan_scanner_t swiftscan_scanner_create(void) {
|
swiftscan_scanner_t swiftscan_scanner_create(void) {
|
||||||
INITIALIZE_LLVM();
|
INITIALIZE_LLVM();
|
||||||
// We must initialize the swift modules responsible for parsing functionality,
|
|
||||||
// such as parsing regex.
|
|
||||||
initializeSwiftParseModules();
|
|
||||||
return wrap(new DependencyScanningTool());
|
return wrap(new DependencyScanningTool());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user