Skip to content

Simplify AST for string literals to not depend on implicit tuple splat. #3801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2016
Merged
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
72 changes: 67 additions & 5 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,13 @@ class BooleanLiteralExpr : public LiteralExpr {
}
};

/// StringLiteralExpr - String literal, like '"foo"'. After semantic
/// analysis assigns types, this is guaranteed to only have a
/// BuiltinRawPointerType.
/// StringLiteralExpr - String literal, like '"foo"'.
class StringLiteralExpr : public LiteralExpr {
StringRef Val;
SourceRange Range;

ConcreteDeclRef BuiltinInitializer;
ConcreteDeclRef Initializer;

public:
/// The encoding that should be used for the string literal.
enum Encoding : unsigned {
Expand Down Expand Up @@ -926,6 +926,32 @@ class StringLiteralExpr : public LiteralExpr {
return StringLiteralExprBits.IsSingleExtendedGraphemeCluster;
}

/// Retrieve the builtin initializer that will be used to construct the string
/// literal.
///
/// Any type-checked string literal will have a builtin initializer, which is
/// called first to form a concrete Swift type.
ConcreteDeclRef getBuiltinInitializer() const { return BuiltinInitializer; }

/// Set the builtin initializer that will be used to construct the string
/// literal.
void setBuiltinInitializer(ConcreteDeclRef builtinInitializer) {
BuiltinInitializer = builtinInitializer;
}

/// Retrieve the initializer that will be used to construct the string
/// literal from the result of the initializer.
///
/// Only string literals that have no builtin literal conformance will have
/// this initializer, which will be called on the result of the builtin
/// initializer.
ConcreteDeclRef getInitializer() const { return Initializer; }

/// Set the initializer that will be used to construct the string literal.
void setInitializer(ConcreteDeclRef initializer) {
Initializer = initializer;
}

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::StringLiteral;
}
Expand Down Expand Up @@ -978,7 +1004,9 @@ class MagicIdentifierLiteralExpr : public LiteralExpr {
};
private:
SourceLoc Loc;

ConcreteDeclRef BuiltinInitializer;
ConcreteDeclRef Initializer;

public:
MagicIdentifierLiteralExpr(Kind kind, SourceLoc loc, bool implicit = false)
: LiteralExpr(ExprKind::MagicIdentifierLiteral, implicit), Loc(loc) {
Expand Down Expand Up @@ -1031,6 +1059,40 @@ class MagicIdentifierLiteralExpr : public LiteralExpr {
= static_cast<unsigned>(encoding);
}

/// Retrieve the builtin initializer that will be used to construct the string
/// literal.
///
/// Any type-checked string literal will have a builtin initializer, which is
/// called first to form a concrete Swift type.
ConcreteDeclRef getBuiltinInitializer() const {
assert(isString() && "Magic identifier literal is not a string");
return BuiltinInitializer;
}

/// Set the builtin initializer that will be used to construct the string
/// literal.
void setBuiltinInitializer(ConcreteDeclRef builtinInitializer) {
assert(isString() && "Magic identifier literal is not a string");
BuiltinInitializer = builtinInitializer;
}

/// Retrieve the initializer that will be used to construct the string
/// literal from the result of the initializer.
///
/// Only string literals that have no builtin literal conformance will have
/// this initializer, which will be called on the result of the builtin
/// initializer.
ConcreteDeclRef getInitializer() const {
assert(isString() && "Magic identifier literal is not a string");
return Initializer;
}

/// Set the initializer that will be used to construct the string literal.
void setInitializer(ConcreteDeclRef initializer) {
assert(isString() && "Magic identifier literal is not a string");
Initializer = initializer;
}

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::MagicIdentifierLiteral;
}
Expand Down
14 changes: 13 additions & 1 deletion lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,12 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
printCommon(E, "string_literal_expr")
<< " encoding=";
printStringEncoding(E->getEncoding());
OS << " value=" << QuotedString(E->getValue()) << ')';
OS << " value=" << QuotedString(E->getValue())
<< " builtin_initializer=";
E->getBuiltinInitializer().dump(OS);
OS << " initializer=";
E->getInitializer().dump(OS);
OS << ')';
}
void visitInterpolatedStringLiteralExpr(InterpolatedStringLiteralExpr *E) {
printCommon(E, "interpolated_string_literal_expr");
Expand All @@ -1657,6 +1662,13 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
case MagicIdentifierLiteralExpr::Column: OS << "#column"; break;
case MagicIdentifierLiteralExpr::DSOHandle: OS << "#dsohandle"; break;
}

if (E->isString()) {
OS << " builtin_initializer=";
E->getBuiltinInitializer().dump(OS);
OS << " initializer=";
E->getInitializer().dump(OS);
}
OS << ')';
}

Expand Down
6 changes: 3 additions & 3 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
NO_REFERENCE(MagicIdentifierLiteral);
NO_REFERENCE(DiscardAssignment);

SIMPLE_REFERENCE(DeclRef, getDecl);
SIMPLE_REFERENCE(DeclRef, getDeclRef);
SIMPLE_REFERENCE(SuperRef, getSelf);

case ExprKind::Type: {
Expand All @@ -381,7 +381,7 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
return ident->getComponentRange().back()->getBoundDecl();
}

SIMPLE_REFERENCE(OtherConstructorDeclRef, getDecl);
SIMPLE_REFERENCE(OtherConstructorDeclRef, getDeclRef);

PASS_THROUGH_REFERENCE(DotSyntaxBaseIgnored, getRHS);

Expand Down Expand Up @@ -439,8 +439,8 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
NO_REFERENCE(PostfixUnary);
NO_REFERENCE(Binary);
NO_REFERENCE(DotSyntaxCall);
NO_REFERENCE(ConstructorRefCall);

PASS_THROUGH_REFERENCE(ConstructorRefCall, getFn);
PASS_THROUGH_REFERENCE(Load, getSubExpr);
NO_REFERENCE(TupleShuffle);
NO_REFERENCE(UnresolvedTypeConversion);
Expand Down
Loading