Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,19 @@ class BridgedDeclNameRef {
BRIDGED_INLINE swift::DeclNameRef unbridged() const;
};

SWIFT_NAME("BridgedDeclNameRef.createParsed(_:baseName:argumentLabels:)")
BridgedDeclNameRef BridgedDeclNameRef_createParsed(BridgedASTContext cContext,
swift::DeclBaseName baseName,
BridgedArrayRef cLabels);
SWIFT_NAME("BridgedDeclNameRef.createParsed(_:moduleSelector:baseName:"
"argumentLabels:)")
BridgedDeclNameRef
BridgedDeclNameRef_createParsed(BridgedASTContext cContext,
swift::Identifier cModuleSelector,
swift::DeclBaseName cBaseName,
BridgedArrayRef cLabels);

SWIFT_NAME("BridgedDeclNameRef.createParsed(_:)")
SWIFT_NAME("BridgedDeclNameRef.createParsed(_:moduleSelector:baseName:)")
BridgedDeclNameRef
BridgedDeclNameRef_createParsed(swift::DeclBaseName baseName);
BridgedDeclNameRef_createParsed(BridgedASTContext cContext,
swift::Identifier cModuleSelector,
swift::DeclBaseName cBaseName);

class BridgedDeclNameLoc {
const void *_Nullable LocationInfo;
Expand Down Expand Up @@ -941,11 +946,12 @@ BridgedDocumentationAttr BridgedDocumentationAttr_createParsed(

SWIFT_NAME(
"BridgedDynamicReplacementAttr.createParsed(_:atLoc:attrNameLoc:lParenLoc:"
"replacedFunction:rParenLoc:)")
"replacedFunction:replacedFunctionLoc:rParenLoc:)")
BridgedDynamicReplacementAttr BridgedDynamicReplacementAttr_createParsed(
BridgedASTContext cContext, swift::SourceLoc atLoc,
swift::SourceLoc attrNameLoc, swift::SourceLoc lParenLoc,
BridgedDeclNameRef cReplacedFunction, swift::SourceLoc rParenLoc);
BridgedASTContext cContext, swift::SourceLoc cAtLoc,
swift::SourceLoc cAttrNameLoc, swift::SourceLoc cLParenLoc,
BridgedDeclNameRef cReplacedFunction,
BridgedDeclNameLoc cReplacedFunctionLoc, swift::SourceLoc cRParenLoc);

SWIFT_NAME("BridgedEffectsAttr.createParsed(_:atLoc:range:effectKind:)")
BridgedEffectsAttr BridgedEffectsAttr_createParsed(
Expand Down Expand Up @@ -1276,22 +1282,24 @@ enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedSpecializationKind : uint8_t {
};

SWIFT_NAME("BridgedSpecializeAttr.createParsed(_:atLoc:range:whereClause:"
"exported:kind:taretFunction:spiGroups:availableAttrs:)")
"exported:kind:targetFunction:targetFunctionLoc:spiGroups:"
"availableAttrs:)")
BridgedSpecializeAttr BridgedSpecializeAttr_createParsed(
BridgedASTContext cContext, swift::SourceLoc atLoc,
swift::SourceRange range, BridgedNullableTrailingWhereClause cWhereClause,
bool exported, BridgedSpecializationKind cKind,
BridgedDeclNameRef cTargetFunction, BridgedArrayRef cSPIGroups,
BridgedArrayRef cAvailableAttrs);
BridgedDeclNameRef cTargetFunction, BridgedDeclNameLoc cTargetFunctionLoc,
BridgedArrayRef cSPIGroups, BridgedArrayRef cAvailableAttrs);

SWIFT_NAME("BridgedSpecializedAttr.createParsed(_:atLoc:range:whereClause:"
"exported:kind:taretFunction:spiGroups:availableAttrs:)")
"exported:kind:targetFunction:targetFunctionLoc:spiGroups:"
"availableAttrs:)")
BridgedSpecializedAttr BridgedSpecializedAttr_createParsed(
BridgedASTContext cContext, swift::SourceLoc atLoc,
swift::SourceRange range, BridgedNullableTrailingWhereClause cWhereClause,
bool exported, BridgedSpecializationKind cKind,
BridgedDeclNameRef cTargetFunction, BridgedArrayRef cSPIGroups,
BridgedArrayRef cAvailableAttrs);
BridgedDeclNameRef cTargetFunction, BridgedDeclNameLoc cTargetFunctionLoc,
BridgedArrayRef cSPIGroups, BridgedArrayRef cAvailableAttrs);

SWIFT_NAME(
"BridgedSPIAccessControlAttr.createParsed(_:atLoc:range:spiGroupName:)")
Expand Down Expand Up @@ -2544,9 +2552,10 @@ BridgedOpaqueReturnTypeOfTypeAttr_createParsed(
// MARK: TypeReprs
//===----------------------------------------------------------------------===//

SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:loc:name:)")
SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:name:loc:)")
BridgedUnqualifiedIdentTypeRepr BridgedUnqualifiedIdentTypeRepr_createParsed(
BridgedASTContext cContext, swift::SourceLoc loc, swift::Identifier id);
BridgedASTContext cContext, BridgedDeclNameRef cName,
BridgedDeclNameLoc cLoc);

SWIFT_NAME(
"BridgedArrayTypeRepr.createParsed(_:base:leftSquareLoc:rightSquareLoc:)")
Expand Down Expand Up @@ -2580,8 +2589,8 @@ BridgedCompileTimeLiteralTypeRepr_createParsed(BridgedASTContext cContext,
SWIFT_NAME("BridgedDeclRefTypeRepr.createParsed(_:base:name:nameLoc:"
"genericArguments:angleRange:)")
BridgedDeclRefTypeRepr BridgedDeclRefTypeRepr_createParsed(
BridgedASTContext cContext, BridgedTypeRepr cBase, swift::Identifier name,
swift::SourceLoc loc, BridgedArrayRef cGenericArguments,
BridgedASTContext cContext, BridgedTypeRepr cBase, BridgedDeclNameRef cName,
BridgedDeclNameLoc cLoc, BridgedArrayRef cGenericArguments,
swift::SourceRange angleRange);

SWIFT_NAME("BridgedDictionaryTypeRepr.createParsed(_:leftSquareLoc:keyType:"
Expand All @@ -2606,8 +2615,8 @@ BridgedFunctionTypeRepr BridgedFunctionTypeRepr_createParsed(
SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:name:nameLoc:"
"genericArgs:leftAngleLoc:rightAngleLoc:)")
BridgedUnqualifiedIdentTypeRepr BridgedUnqualifiedIdentTypeRepr_createParsed(
BridgedASTContext cContext, swift::Identifier name,
swift::SourceLoc nameLoc, BridgedArrayRef genericArgs,
BridgedASTContext cContext, BridgedDeclNameRef cName,
BridgedDeclNameLoc cNameLoc, BridgedArrayRef genericArgs,
swift::SourceLoc lAngleLoc, swift::SourceLoc rAngleLoc);

SWIFT_NAME("BridgedOptionalTypeRepr.createParsed(_:base:questionLoc:)")
Expand Down
45 changes: 34 additions & 11 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1253,19 +1253,22 @@ class DynamicReplacementAttr final
friend class DynamicallyReplacedDeclRequest;

DeclNameRef ReplacedFunctionName;
DeclNameLoc ReplacedFunctionNameLoc;
LazyMemberLoader *Resolver = nullptr;
uint64_t ResolverContextData;

/// Create an @_dynamicReplacement(for:) attribute written in the source.
DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange,
DeclNameRef replacedFunctionName,
DeclNameLoc replacedFunctionNameLoc,
SourceRange parenRange);

DynamicReplacementAttr(DeclNameRef name, AbstractFunctionDecl *f)
: DeclAttribute(DeclAttrKind::DynamicReplacement, SourceLoc(),
SourceRange(),
/*Implicit=*/false),
ReplacedFunctionName(name), Resolver(nullptr), ResolverContextData(0) {
ReplacedFunctionName(name), ReplacedFunctionNameLoc(),
Resolver(nullptr), ResolverContextData(0) {
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
}

Expand All @@ -1274,8 +1277,8 @@ class DynamicReplacementAttr final
: DeclAttribute(DeclAttrKind::DynamicReplacement, SourceLoc(),
SourceRange(),
/*Implicit=*/false),
ReplacedFunctionName(name), Resolver(Resolver),
ResolverContextData(Data) {
ReplacedFunctionName(name), ReplacedFunctionNameLoc(),
Resolver(Resolver), ResolverContextData(Data) {
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
}

Expand All @@ -1296,7 +1299,8 @@ class DynamicReplacementAttr final
public:
static DynamicReplacementAttr *
create(ASTContext &Context, SourceLoc AtLoc, SourceLoc DynReplLoc,
SourceLoc LParenLoc, DeclNameRef replacedFunction, SourceLoc RParenLoc);
SourceLoc LParenLoc, DeclNameRef replacedFunction,
DeclNameLoc replacedFunctionNameLoc, SourceLoc RParenLoc);

static DynamicReplacementAttr *create(ASTContext &ctx,
DeclNameRef replacedFunction,
Expand All @@ -1311,6 +1315,10 @@ class DynamicReplacementAttr final
return ReplacedFunctionName;
}

DeclNameLoc getReplacedFunctionNameLoc() const {
return ReplacedFunctionNameLoc;
}

/// Retrieve the location of the opening parentheses, if there is one.
SourceLoc getLParenLoc() const;

Expand Down Expand Up @@ -1800,6 +1808,7 @@ class AbstractSpecializeAttr
GenericSignature specializedSignature;

DeclNameRef targetFunctionName;
DeclNameLoc targetFunctionNameLoc;
LazyMemberLoader *resolver = nullptr;
uint64_t resolverContextData;
size_t numSPIGroups;
Expand All @@ -1812,7 +1821,9 @@ class AbstractSpecializeAttr
TrailingWhereClause *clause,
bool exported,
SpecializationKind kind, GenericSignature specializedSignature,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName,
DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
size_t typeErasedParamsCount);

Expand Down Expand Up @@ -1896,6 +1907,10 @@ class AbstractSpecializeAttr
return targetFunctionName;
}

DeclNameLoc getTargetFunctionNameLoc() const {
return targetFunctionNameLoc;
}

/// \p forDecl is the value decl that the attribute belongs to.
ValueDecl *getTargetFunctionDecl(const ValueDecl *forDecl) const;

Expand Down Expand Up @@ -1925,19 +1940,23 @@ class SpecializeAttr final : public AbstractSpecializeAttr,
TrailingWhereClause *clause,
bool exported,
SpecializationKind kind, GenericSignature specializedSignature,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName,
DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
size_t typeErasedParamsCount) :
AbstractSpecializeAttr(DeclAttrKind::Specialize, atLoc, Range, clause,
exported, kind, specializedSignature, targetFunctionName,
spiGroups, availabilityAttrs, typeErasedParamsCount) {}
targetFunctionNameLoc, spiGroups, availabilityAttrs,
typeErasedParamsCount) {}

public:
static SpecializeAttr *
create(ASTContext &Ctx, SourceLoc atLoc, SourceRange Range,
TrailingWhereClause *clause, bool exported,
SpecializationKind kind,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName, DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
GenericSignature specializedSignature = nullptr);

Expand Down Expand Up @@ -1981,19 +2000,23 @@ class SpecializedAttr final : public AbstractSpecializeAttr ,
TrailingWhereClause *clause,
bool exported,
SpecializationKind kind, GenericSignature specializedSignature,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName,
DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
size_t typeErasedParamsCount) :
AbstractSpecializeAttr(DeclAttrKind::Specialized, atLoc, Range, clause,
exported, kind, specializedSignature, targetFunctionName,
spiGroups, availabilityAttrs, typeErasedParamsCount) {}
targetFunctionNameLoc, spiGroups, availabilityAttrs,
typeErasedParamsCount) {}

public:
static SpecializedAttr *
create(ASTContext &Ctx, SourceLoc atLoc, SourceRange Range,
TrailingWhereClause *clause, bool exported,
SpecializationKind kind,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName, DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
GenericSignature specializedSignature = nullptr);

Expand Down
15 changes: 15 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ ERROR(forbidden_interpolated_string,none,
ERROR(forbidden_extended_escaping_string,none,
"%0 cannot be an extended escaping string literal", (StringRef))

ERROR(expected_identifier_in_module_selector,none,
"expected module name in module selector", ())
ERROR(expected_identifier_after_module_selector,none,
"expected identifier after module selector", ())
NOTE(extra_whitespace_module_selector,none,
"remove extraneous whitespace after '::'", ())
ERROR(module_selector_submodule_not_allowed,none,
"module selector cannot specify a submodule", ())
NOTE(replace_module_selector_with_member_lookup,none,
"replace '::' with '.'", ())

//------------------------------------------------------------------------------
// MARK: Lexer diagnostics
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -2199,5 +2210,9 @@ ERROR(using_decl_invalid_specifier,PointsToFirstBadToken,
ERROR(experimental_using_decl_disabled,PointsToFirstBadToken,
"'using' is an experimental feature that is currently disabled", ())

ERROR(impossible_parse,none,
"parser entered impossible state; please file a bug report with this "
"source file", ())

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
1 change: 1 addition & 0 deletions include/swift/AST/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ PUNCTUATOR(period_prefix, ".")
PUNCTUATOR(comma, ",")
PUNCTUATOR(ellipsis, "...")
PUNCTUATOR(colon, ":")
PUNCTUATOR(colon_colon, "::")
PUNCTUATOR(semi, ";")
PUNCTUATOR(equal, "=")
PUNCTUATOR(at_sign, "@")
Expand Down
43 changes: 38 additions & 5 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,8 @@ class Parser {
/// \returns the value returned by \c f
/// \note When calling, you may need to specify the \c Val type
/// explicitly as a type parameter.
template <typename Val>
Val lookahead(unsigned char K,
llvm::function_ref<Val(CancellableBacktrackingScope &)> f) {
template <typename Fn>
decltype(auto) lookahead(unsigned char K, Fn f) {
CancellableBacktrackingScope backtrackScope(*this);

for (unsigned char i = 0; i < K; ++i)
Expand Down Expand Up @@ -772,6 +771,17 @@ class Parser {
consumeStartingCharacterOfCurrentToken(tok Kind = tok::oper_binary_unspaced,
size_t Len = 1);

/// If the next token is \c tok::colon, consume it; if the next token is
/// \c tok::colon_colon, split it into two \c tok::colons and consume the
/// first; otherwise, do nothing and return false.
bool consumeIfColonSplittingDoubles() {
if (!Tok.isAny(tok::colon, tok::colon_colon))
return false;

consumeStartingCharacterOfCurrentToken(tok::colon);
return true;
}

//===--------------------------------------------------------------------===//
// Primitive Parsing

Expand Down Expand Up @@ -1063,7 +1073,7 @@ class Parser {
std::optional<bool> &Exported,
std::optional<SpecializeAttr::SpecializationKind> &Kind,
TrailingWhereClause *&TrailingWhereClause, DeclNameRef &targetFunction,
AvailabilityRange *SILAvailability,
DeclNameLoc &targetFunctionLoc, AvailabilityRange *SILAvailability,
SmallVectorImpl<Identifier> &spiGroups,
SmallVectorImpl<AvailableAttr *> &availableAttrs,
llvm::function_ref<bool(Parser &)> parseSILTargetName,
Expand Down Expand Up @@ -1807,6 +1817,19 @@ class Parser {
void parseOptionalArgumentLabel(Identifier &name, SourceLoc &loc,
bool isAttr = false);

/// Attempts to parse a \c module-selector if one is present.
///
/// \verbatim
/// module-selector: identifier '::'
/// \endverbatim
///
/// \return \c None if no selector is present or a selector is present but
/// is not allowed; an instance with an empty \c Identifier if a
/// selector is present but has no valid identifier; an instance with
/// a valid \c Identifier if a selector is present and includes a
/// module name.
std::optional<Located<Identifier>> parseModuleSelector();

enum class DeclNameFlag : uint8_t {
/// If passed, operator basenames are allowed.
AllowOperators = 1 << 0,
Expand All @@ -1819,6 +1842,9 @@ class Parser {
/// not ordinary identifiers.
AllowKeywordsUsingSpecialNames = AllowKeywords | 1 << 2,

/// If passed, module selectors are not permitted on this declaration name.
ModuleSelectorUnsupported = 1 << 3,

/// If passed, compound names with argument lists are allowed, unless they
/// have empty argument lists.
AllowCompoundNames = 1 << 4,
Expand All @@ -1830,13 +1856,19 @@ class Parser {
/// cases this doesn't actually make sense but we need to accept them for
/// backwards compatibility.
AllowLowercaseAndUppercaseSelf = 1 << 6,

/// If passed, `$0` etc. are allowed.
AllowAnonymousParamNames = 1 << 7,
};
using DeclNameOptions = OptionSet<DeclNameFlag>;

friend DeclNameOptions operator|(DeclNameFlag flag1, DeclNameFlag flag2) {
return DeclNameOptions(flag1) | flag2;
}

/// Parse a declaration name that results in a `DeclNameRef` in the syntax
/// tree.
///
/// Without \c DeclNameFlag::AllowCompoundNames, parse an
/// unqualified-decl-base-name.
///
Expand All @@ -1860,7 +1892,8 @@ class Parser {
SourceLoc &rightAngleLoc, ArgumentList *&argList, bool isExprBasic,
DiagRef diag);

ParserResult<Expr> parseExprIdentifier(bool allowKeyword);
ParserResult<Expr> parseExprIdentifier(bool allowKeyword,
bool allowModuleSelector = true);
Expr *parseExprEditorPlaceholder(Token PlaceholderTok,
Identifier PlaceholderId);

Expand Down
3 changes: 2 additions & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,8 @@ namespace {

printFlag(!ABIRoleInfo(D).providesAPI(), "abi_only");

printSourceRange(D->getSourceRange(), &D->getASTContext());
if (D->getStartLoc().isValid() && D->getEndLoc().isValid())
printSourceRange(D->getSourceRange(), &D->getASTContext());
printFlag(D->TrailingSemiLoc.isValid(), "trailing_semi",
DeclModifierColor);

Expand Down
Loading