Files
swift-mirror/include/swift/Bridging/ASTGen.h
Hamish Knight 9d4a78678a [Sema] Add logic to diagnose regex feature availability
Add the necessary compiler-side logic to allow
the regex parsing library to hand back a set of
features for a regex literal, which can then be
diagnosed by ExprAvailabilityWalker if the
availability context isn't sufficient. No tests
as this only adds the necessary infrastructure,
we don't yet hand back the features from the regex
parsing library.
2024-10-28 17:09:47 +00:00

135 lines
5.8 KiB
C++

//===--- ASTGen.h -----------------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 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
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_BRIDGING_ASTGEN_H
#define SWIFT_BRIDGING_ASTGEN_H
#include "swift/AST/ASTBridging.h"
#include "swift/Parse/ParseBridging.h"
#ifdef __cplusplus
extern "C" {
#endif
void *_Nonnull swift_ASTGen_createQueuedDiagnostics();
void swift_ASTGen_destroyQueuedDiagnostics(void *_Nonnull queued);
void swift_ASTGen_addQueuedSourceFile(
void *_Nonnull queuedDiagnostics, ssize_t bufferID,
void *_Nonnull sourceFile, const uint8_t *_Nonnull displayNamePtr,
intptr_t displayNameLength, ssize_t parentID, ssize_t positionInParent);
void swift_ASTGen_addQueuedDiagnostic(
void *_Nonnull queued, const char *_Nonnull text, ptrdiff_t textLength,
BridgedDiagnosticSeverity severity, const void *_Nullable sourceLoc,
const void *_Nullable *_Nullable highlightRanges,
ptrdiff_t numHighlightRanges);
void swift_ASTGen_renderQueuedDiagnostics(
void *_Nonnull queued, ssize_t contextSize, ssize_t colorize,
BridgedStringRef *_Nonnull renderedString);
// FIXME: Hack because we cannot easily get to the already-parsed source
// file from here. Fix this egregious oversight!
void *_Nullable swift_ASTGen_parseSourceFile(const char *_Nonnull buffer,
size_t bufferLength,
const char *_Nonnull moduleName,
const char *_Nonnull filename,
void *_Nullable ctx);
void swift_ASTGen_destroySourceFile(void *_Nonnull sourceFile);
/// Check whether the given source file round-trips correctly. Returns 0 if
/// round-trip succeeded, non-zero otherwise.
int swift_ASTGen_roundTripCheck(void *_Nonnull sourceFile);
/// Emit parser diagnostics for given source file.. Returns non-zero if any
/// diagnostics were emitted.
int swift_ASTGen_emitParserDiagnostics(
BridgedASTContext astContext,
void *_Nonnull diagEngine, void *_Nonnull sourceFile, int emitOnlyErrors,
int downgradePlaceholderErrorsToWarnings);
// Build AST nodes for the top-level entities in the syntax.
void swift_ASTGen_buildTopLevelASTNodes(
BridgedDiagnosticEngine diagEngine, void *_Nonnull sourceFile,
BridgedDeclContext declContext, BridgedASTContext astContext,
BridgedLegacyParser legacyParser, void *_Nonnull outputContext,
void (*_Nonnull)(void *_Nonnull, void *_Nonnull));
void swift_ASTGen_freeBridgedString(BridgedStringRef);
/// Build a TypeRepr for AST node for the type at the given source location in
/// the specified file.
swift::TypeRepr *_Nullable swift_ASTGen_buildTypeRepr(
BridgedDiagnosticEngine diagEngine, void *_Nonnull sourceFile,
BridgedSourceLoc sourceLoc, BridgedDeclContext declContext,
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
BridgedSourceLoc *_Nonnull endSourceLoc);
/// Build a Decl for AST node for the type at the given source location in the
/// specified file.
swift::Decl *_Nullable swift_ASTGen_buildDecl(
BridgedDiagnosticEngine diagEngine, void *_Nonnull sourceFile,
BridgedSourceLoc sourceLoc, BridgedDeclContext declContext,
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
BridgedSourceLoc *_Nonnull endSourceLoc);
/// Build a Expr for AST node for the type at the given source location in the
/// specified file.
swift::Expr *_Nullable swift_ASTGen_buildExpr(
BridgedDiagnosticEngine diagEngine, void *_Nonnull sourceFile,
BridgedSourceLoc sourceLoc, BridgedDeclContext declContext,
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
BridgedSourceLoc *_Nonnull endSourceLoc);
/// Build a Stmt for AST node for the type at the given source location in the
/// specified file.
swift::Stmt *_Nullable swift_ASTGen_buildStmt(
BridgedDiagnosticEngine diagEngine, void *_Nonnull sourceFile,
BridgedSourceLoc sourceLoc, BridgedDeclContext declContext,
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
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,
BridgedRegexLiteralPatternFeatures *_Nonnull featuresOut,
BridgedSourceLoc diagLoc, BridgedDiagnosticEngine diagEngine);
void swift_ASTGen_freeBridgedRegexLiteralPatternFeatures(
BridgedRegexLiteralPatternFeatures features);
void swift_ASTGen_getSwiftVersionForRegexPatternFeature(
BridgedRegexLiteralPatternFeatureKind kind,
BridgedSwiftVersion *_Nonnull versionOut);
void swift_ASTGen_getDescriptionForRegexPatternFeature(
BridgedRegexLiteralPatternFeatureKind kind, BridgedASTContext astContext,
BridgedStringRef *_Nonnull descriptionOut);
intptr_t swift_ASTGen_configuredRegions(
BridgedASTContext astContext,
void *_Nonnull sourceFile,
BridgedIfConfigClauseRangeInfo *_Nullable *_Nonnull);
void swift_ASTGen_freeConfiguredRegions(
BridgedIfConfigClauseRangeInfo *_Nullable regions, intptr_t numRegions);
#ifdef __cplusplus
}
#endif
#endif // SWIFT_BRIDGING_ASTGEN_H