mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -53,17 +53,11 @@ public struct DiagnosticFixIt {
|
||||
}
|
||||
|
||||
public struct DiagnosticEngine {
|
||||
private let bridged: BridgedDiagnosticEngine
|
||||
private let bridged: swift.DiagnosticEngine
|
||||
|
||||
public init(bridged: BridgedDiagnosticEngine) {
|
||||
public init(bridged: swift.DiagnosticEngine) {
|
||||
self.bridged = bridged
|
||||
}
|
||||
public init?(bridged: BridgedOptionalDiagnosticEngine) {
|
||||
guard let object = bridged.object else {
|
||||
return nil
|
||||
}
|
||||
self.bridged = BridgedDiagnosticEngine(object: object)
|
||||
}
|
||||
|
||||
public func diagnose(_ position: SourceLoc?,
|
||||
_ id: DiagID,
|
||||
|
||||
@@ -46,7 +46,7 @@ private func _RegexLiteralLexingFn(
|
||||
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
|
||||
_ bufferEndPtr: UnsafePointer<CChar>,
|
||||
_ mustBeRegex: CBool,
|
||||
_ bridgedDiagnosticEngine: BridgedOptionalDiagnosticEngine
|
||||
_ bridgedDiagnosticEngine: swift.DiagnosticEngine?
|
||||
) -> /*CompletelyErroneous*/ CBool {
|
||||
let inputPtr = curPtrPtr.pointee
|
||||
|
||||
@@ -62,7 +62,8 @@ private func _RegexLiteralLexingFn(
|
||||
|
||||
if let error = error {
|
||||
// Emit diagnostic if diagnostics are enabled.
|
||||
if let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine) {
|
||||
if let bridged = bridgedDiagnosticEngine {
|
||||
let diagEngine = DiagnosticEngine(bridged: bridged)
|
||||
let startLoc = SourceLoc(
|
||||
locationInFile: error.location.assumingMemoryBound(to: UInt8.self))!
|
||||
diagEngine.diagnose(startLoc, .regex_literal_parsing_error, error.message)
|
||||
@@ -93,7 +94,7 @@ public func _RegexLiteralParsingFn(
|
||||
_ captureStructureOut: UnsafeMutableRawPointer,
|
||||
_ captureStructureSize: CUnsignedInt,
|
||||
_ bridgedDiagnosticBaseLoc: swift.SourceLoc,
|
||||
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine
|
||||
_ bridgedDiagnosticEngine: swift.DiagnosticEngine
|
||||
) -> Bool {
|
||||
let str = String(cString: inputPtr)
|
||||
let captureBuffer = UnsafeMutableRawBufferPointer(
|
||||
|
||||
@@ -39,22 +39,12 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
|
||||
#include "swift/AST/DiagnosticsAll.def"
|
||||
} BridgedDiagID;
|
||||
|
||||
typedef struct {
|
||||
void * _Nonnull object;
|
||||
} BridgedDiagnosticEngine;
|
||||
|
||||
typedef struct {
|
||||
void *_Nullable object;
|
||||
} BridgedOptionalDiagnosticEngine;
|
||||
|
||||
// FIXME: Can we bridge InFlightDiagnostic?
|
||||
void DiagnosticEngine_diagnose(BridgedDiagnosticEngine, swift::SourceLoc loc,
|
||||
void DiagnosticEngine_diagnose(swift::DiagnosticEngine &, swift::SourceLoc loc,
|
||||
BridgedDiagID diagID, BridgedArrayRef arguments,
|
||||
swift::CharSourceRange highlight,
|
||||
BridgedArrayRef fixIts);
|
||||
|
||||
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine);
|
||||
|
||||
SWIFT_END_NULLABILITY_ANNOTATIONS
|
||||
|
||||
#endif // SWIFT_AST_ASTBRIDGING_H
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
//===--- BridgingUtils.h - utilities for swift bridging -------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SWIFT_AST_BRIDGINGUTILS_H
|
||||
#define SWIFT_AST_BRIDGINGUTILS_H
|
||||
|
||||
#include "swift/AST/ASTBridging.h"
|
||||
#include "swift/AST/DiagnosticEngine.h"
|
||||
|
||||
namespace swift {
|
||||
|
||||
inline BridgedDiagnosticEngine getBridgedDiagnosticEngine(DiagnosticEngine *D) {
|
||||
return {(void *)D};
|
||||
}
|
||||
inline BridgedOptionalDiagnosticEngine
|
||||
getBridgedOptionalDiagnosticEngine(DiagnosticEngine *D) {
|
||||
return {(void *)D};
|
||||
}
|
||||
|
||||
} // namespace swift
|
||||
|
||||
#endif
|
||||
|
||||
@@ -781,7 +781,7 @@ namespace swift {
|
||||
|
||||
/// Class responsible for formatting diagnostics and presenting them
|
||||
/// to the user.
|
||||
class DiagnosticEngine {
|
||||
class SWIFT_IMPORT_REFERENCE DiagnosticEngine {
|
||||
public:
|
||||
/// The source manager used to interpret source locations and
|
||||
/// display diagnostics.
|
||||
|
||||
@@ -178,4 +178,11 @@
|
||||
#define SWIFT_VFORMAT(fmt)
|
||||
#endif
|
||||
|
||||
// Tells Swift's ClangImporter to import a C++ type as a foreign reference type.
|
||||
#if __has_attribute(swift_attr)
|
||||
#define SWIFT_IMPORT_REFERENCE __attribute__((swift_attr("import_as_ref")))
|
||||
#else
|
||||
#define SWIFT_IMPORT_REFERENCE
|
||||
#endif
|
||||
|
||||
#endif // SWIFT_BASIC_COMPILER_H
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
/// past.
|
||||
/// - MustBeRegex: whether an error during lexing should be considered a regex
|
||||
/// literal, or some thing else.
|
||||
/// - BridgedOptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
|
||||
/// token using this engine.
|
||||
/// - OptionalDiagnosticEngine: RegexLiteralLexingFn should diagnose the
|
||||
/// token using this engine.
|
||||
///
|
||||
/// Returns: A bool indicating whether lexing was completely erroneous, and
|
||||
/// cannot be recovered from, or false if there either was no error,
|
||||
@@ -36,7 +36,7 @@
|
||||
typedef bool (*RegexLiteralLexingFn)(
|
||||
/*CurPtrPtr*/ const char *_Nonnull *_Nonnull,
|
||||
/*BufferEnd*/ const char *_Nonnull,
|
||||
/*MustBeRegex*/ bool, BridgedOptionalDiagnosticEngine);
|
||||
/*MustBeRegex*/ bool, swift::DiagnosticEngine *_Nullable);
|
||||
void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
|
||||
|
||||
/// Parse a regex literal string. Takes the following arguments:
|
||||
@@ -48,8 +48,8 @@ void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn _Nullable fn);
|
||||
/// - CaptureStructureSize: The size of the capture structure buffer. Must be
|
||||
/// greater than or equal to `strlen(InputPtr) + 3`.
|
||||
/// - DiagnosticBaseLoc: Start location of the regex literal.
|
||||
/// - BridgedDiagnosticEngine: RegexLiteralParsingFn should diagnose the
|
||||
/// parsing errors using this engine.
|
||||
/// - DiagnosticEngine: RegexLiteralParsingFn should diagnose the
|
||||
/// parsing errors using this engine.
|
||||
///
|
||||
/// Returns: A bool value indicating if there was an error while parsing.
|
||||
typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull,
|
||||
@@ -57,7 +57,7 @@ typedef bool (*RegexLiteralParsingFn)(/*InputPtr*/ const char *_Nonnull,
|
||||
/*CaptureStructureOut*/ void *_Nonnull,
|
||||
/*CaptureStructureSize*/ unsigned,
|
||||
/*DiagnosticBaseLoc*/ swift::SourceLoc,
|
||||
BridgedDiagnosticEngine);
|
||||
swift::DiagnosticEngine &);
|
||||
void Parser_registerRegexLiteralParsingFn(RegexLiteralParsingFn _Nullable fn);
|
||||
|
||||
#endif // REGEX_PARSER_BRIDGING
|
||||
|
||||
@@ -17,28 +17,18 @@
|
||||
|
||||
using namespace swift;
|
||||
|
||||
namespace {
|
||||
/// BridgedDiagnosticEngine -> DiagnosticEngine *.
|
||||
DiagnosticEngine *getDiagnosticEngine(const BridgedDiagnosticEngine &bridged) {
|
||||
return static_cast<DiagnosticEngine *>(bridged.object);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void DiagnosticEngine_diagnose(
|
||||
BridgedDiagnosticEngine bridgedEngine, SourceLoc loc,
|
||||
BridgedDiagID bridgedDiagID,
|
||||
DiagnosticEngine &engine, SourceLoc loc, BridgedDiagID bridgedDiagID,
|
||||
BridgedArrayRef /*DiagnosticArgument*/ bridgedArguments,
|
||||
CharSourceRange highlight,
|
||||
BridgedArrayRef /*DiagnosticInfo::FixIt*/ bridgedFixIts) {
|
||||
auto *D = getDiagnosticEngine(bridgedEngine);
|
||||
|
||||
auto diagID = static_cast<DiagID>(bridgedDiagID);
|
||||
SmallVector<DiagnosticArgument, 2> arguments;
|
||||
for (auto arg : getArrayRef<DiagnosticArgument>(bridgedArguments)) {
|
||||
arguments.push_back(arg);
|
||||
}
|
||||
auto inflight = D->diagnose(loc, diagID, arguments);
|
||||
auto inflight = engine.diagnose(loc, diagID, arguments);
|
||||
|
||||
// Add highlight.
|
||||
if (highlight.isValid()) {
|
||||
@@ -52,8 +42,3 @@ void DiagnosticEngine_diagnose(
|
||||
inflight.fixItReplaceChars(range.getStart(), range.getEnd(), text);
|
||||
}
|
||||
}
|
||||
|
||||
bool DiagnosticEngine_hadAnyError(BridgedDiagnosticEngine bridgedEngine) {
|
||||
auto *D = getDiagnosticEngine(bridgedEngine);
|
||||
return D->hadAnyError();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/Parse/Lexer.h"
|
||||
#include "swift/AST/BridgingUtils.h"
|
||||
#include "swift/AST/DiagnosticsParse.h"
|
||||
#include "swift/AST/Identifier.h"
|
||||
#include "swift/Basic/LangOptions.h"
|
||||
@@ -2091,7 +2090,7 @@ const char *Lexer::tryScanRegexLiteral(const char *TokStart, bool MustBeRegex,
|
||||
// recovered from.
|
||||
auto *Ptr = TokStart;
|
||||
CompletelyErroneous = regexLiteralLexingFn(
|
||||
&Ptr, BufferEnd, MustBeRegex, getBridgedOptionalDiagnosticEngine(Diags));
|
||||
&Ptr, BufferEnd, MustBeRegex, Diags);
|
||||
|
||||
// If we didn't make any lexing progress, this isn't a regex literal and we
|
||||
// should fallback to lexing as something else.
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/BridgingUtils.h"
|
||||
#include "swift/AST/DiagnosticsParse.h"
|
||||
#include "swift/Basic/BridgingUtils.h"
|
||||
#include "swift/Parse/ParsedSyntaxRecorder.h"
|
||||
#include "swift/Parse/Parser.h"
|
||||
@@ -51,8 +49,7 @@ ParserResult<Expr> Parser::parseExprRegexLiteral() {
|
||||
regexLiteralParsingFn(regexText.str().c_str(), &version,
|
||||
/*captureStructureOut*/ capturesBuf.data(),
|
||||
/*captureStructureSize*/ capturesBuf.size(),
|
||||
/*diagBaseLoc*/ Tok.getLoc(),
|
||||
getBridgedDiagnosticEngine(&Diags));
|
||||
/*diagBaseLoc*/ Tok.getLoc(), Diags);
|
||||
auto loc = consumeToken();
|
||||
SourceMgr.recordRegexLiteralStartLoc(loc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user