Skip to content

Commit

Permalink
remove support for the experiemental "character literals" feature.
Browse files Browse the repository at this point in the history
Swift SVN r30509
  • Loading branch information
lattner committed Jul 22, 2015
1 parent bbed5aa commit 0001dc2
Show file tree
Hide file tree
Showing 47 changed files with 23 additions and 489 deletions.
3 changes: 1 addition & 2 deletions docs/LangRef.html
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,6 @@ <h3 id="expr-literal">Literals</h3>
<pre class="grammar">
expr-literal ::= <a href="#integer_literal">integer_literal</a>
expr-literal ::= <a href="#floating_literal">floating_literal</a>
expr-literal ::= <a href="#character_literal">character_literal</a>
expr-literal ::= <a href="#string_literal">string_literal</a>
expr-literal ::= expr-array
expr-literal ::= expr-dictionary
Expand All @@ -1696,7 +1695,7 @@ <h3 id="expr-literal">Literals</h3>
depending on its lexical form. The type of the literal is inferred
based on its context. If there is no contextual type information for an
expression, all unresolved types are inferred to 'IntegerLiteralType'
type, to 'FloatLiteralType', to 'CharacterLiteralType', and to
type, to 'FloatLiteralType', and to
'StringLiteralType', respectively.
If a literal is used and these types are not defined, then the code is
malformed.</p>
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ ERROR(lex_unterminated_block_comment,lexing,none,
NOTE(lex_comment_start,lexing,none,
"comment started here", ())

ERROR(lex_invalid_multi_code_point_character_literal,lexing,none,
"invalid multiple-code-point character literal", ())
ERROR(lex_unterminated_character_literal,lexing,none,
"unterminated character literal", ())
ERROR(lex_invalid_character_literal,lexing,none,
"invalid character literal", ())

ERROR(lex_unterminated_string,lexing,none,
"unterminated string literal", ())
Expand Down
7 changes: 0 additions & 7 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,6 @@ ERROR(no_IntegerLiteralType_found,sema_tce,none,
"standard library error: IntegerLiteralType not defined", ())
ERROR(no_FloatLiteralType_found,sema_tce,none,
"standard library error: FloatLiteralType not defined", ())
ERROR(no_CharacterLiteralType_found,sema_tce,none,
"standard library error: CharacterLiteralType not defined", ())
ERROR(no_StringLiteralType_found,sema_tce,none,
"standard library error: StringLiteralType not defined", ())
ERROR(no_MaxBuiltinIntegerType_found,sema_tce,none,
Expand Down Expand Up @@ -1580,11 +1578,6 @@ ERROR(builtin_boolean_literal_broken_proto,sema_tce,none,
ERROR(boolean_literal_broken_proto,sema_tce,none,
"protocol 'BooleanLiteralConvertible' is broken", ())

ERROR(builtin_character_literal_broken_proto,sema_tce,none,
"protocol '_BuiltinCharacterLiteralConvertible' is broken", ())
ERROR(character_literal_broken_proto,sema_tce,none,
"protocol 'CharacterLiteralConvertible' is broken", ())

ERROR(builtin_unicode_scalar_literal_broken_proto,sema_tce,none,
"protocol '_BuiltinUnicodeScalarLiteralConvertible' is broken", ())
ERROR(unicode_scalar_literal_broken_proto,sema_tce,none,
Expand Down
18 changes: 0 additions & 18 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,24 +620,6 @@ class BooleanLiteralExpr : public LiteralExpr {
}
};

/// CharacterLiteral - Character literal, like 'x'. After semantic analysis
/// assigns types, this is guaranteed to only have a 32-bit BuiltinIntegerType.
class CharacterLiteralExpr : public LiteralExpr {
uint32_t Val;
SourceLoc Loc;
public:
CharacterLiteralExpr(uint32_t Val, SourceLoc Loc)
: LiteralExpr(ExprKind::CharacterLiteral, /*Implicit=*/false),
Val(Val), Loc(Loc) {}

uint32_t getValue() const { return Val; }
SourceRange getSourceRange() const { return Loc; }

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::CharacterLiteral;
}
};

/// StringLiteralExpr - String literal, like '"foo"'. After semantic
/// analysis assigns types, this is guaranteed to only have a
/// BuiltinRawPointerType.
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/ExprNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ ABSTRACT_EXPR(Literal, Expr)
EXPR(FloatLiteral, NumberLiteralExpr)
EXPR_RANGE(NumberLiteral, IntegerLiteral, FloatLiteral)
EXPR(BooleanLiteral, LiteralExpr)
EXPR(CharacterLiteral, LiteralExpr)
EXPR(StringLiteral, LiteralExpr)
EXPR(InterpolatedStringLiteral, LiteralExpr)
EXPR(MagicIdentifierLiteral, LiteralExpr)
Expand Down
4 changes: 0 additions & 4 deletions include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ IDENTIFIER(BooleanLiteralType)
IDENTIFIER_(builtinBooleanLiteral)
IDENTIFIER(booleanLiteral)

IDENTIFIER(CharacterLiteralType)
IDENTIFIER(characterLiteral)
IDENTIFIER_(builtinCharacterLiteral)

IDENTIFIER(ExtendedGraphemeClusterLiteralType)
IDENTIFIER_(builtinExtendedGraphemeClusterLiteral)
IDENTIFIER(extendedGraphemeClusterLiteral)
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/KnownProtocols.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ PROTOCOL(_DestructorSafeContainer)

LITERAL_CONVERTIBLE_PROTOCOL(ArrayLiteralConvertible, array)
LITERAL_CONVERTIBLE_PROTOCOL(BooleanLiteralConvertible, boolean)
LITERAL_CONVERTIBLE_PROTOCOL(CharacterLiteralConvertible, character)
LITERAL_CONVERTIBLE_PROTOCOL(DictionaryLiteralConvertible, dictionary)
LITERAL_CONVERTIBLE_PROTOCOL(ExtendedGraphemeClusterLiteralConvertible, character)
LITERAL_CONVERTIBLE_PROTOCOL(FloatLiteralConvertible, floating-point)
Expand All @@ -66,7 +65,6 @@ LITERAL_CONVERTIBLE_PROTOCOL(_ColorLiteralConvertible, color)
LITERAL_CONVERTIBLE_PROTOCOL(_ImageLiteralConvertible, image)

BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinBooleanLiteralConvertible)
BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinCharacterLiteralConvertible)
BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinExtendedGraphemeClusterLiteralConvertible)
BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinFloatLiteralConvertible)
BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinIntegerLiteralConvertible)
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ namespace swift {
/// provide compiler debugging facilities.
class LangOptions {
public:

/// \brief Enable legacy character literals.
bool EnableCharacterLiterals = false;

/// \brief Whether we are debugging the constraint solver.
///
Expand Down
1 change: 0 additions & 1 deletion include/swift/IDE/SyntaxModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum class SyntaxNodeKind : uint8_t {
String,
/// Marks the parens for a string interpolation.
StringInterpolationAnchor,
Character,
CommentLine,
CommentBlock,
DocCommentLine,
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ def disable_availability_checking : Flag<["-"],
"disable-availability-checking">,
HelpText<"Disable checking for potentially unavailable APIs">;

def enable_character_literals : Flag<["-"], "enable-character-literals">,
HelpText<"Enable legacy character literals">;

def enable_objc_implicit_properties :
Flag<["-"], "enable-objc-implicit-properties">,
HelpText<"Import Objective-C \"implicit properties\" as properties">;
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Parse/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,6 @@ class Lexer {
return getStringLiteralSegments(Str, Segments, Diags);
}

/// \brief Return the UTF32 codepoint for the specified character literal.
uint32_t getEncodedCharacterLiteral(const Token &Tok);

static SourceLoc getSourceLoc(const char *Loc) {
return SourceLoc(llvm::SMLoc::getFromPointer(Loc));
}
Expand Down Expand Up @@ -410,7 +407,6 @@ class Lexer {

unsigned lexCharacter(const char *&CurPtr,
bool StopAtDoubleQuote, bool EmitDiagnostics);
void lexCharacterLiteral();
void lexStringLiteral();
void lexEscapedIdentifier();

Expand Down
1 change: 0 additions & 1 deletion include/swift/Parse/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ enum class tok {
integer_literal,
floating_literal,
string_literal,
character_literal,
sil_local_name, // %42 in SIL mode.
pound_if,
pound_else,
Expand Down
3 changes: 0 additions & 3 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ class SILBuilder {
IntegerLiteralInst *createIntegerLiteral(IntegerLiteralExpr *E) {
return insert(IntegerLiteralInst::create(E, F));
}
IntegerLiteralInst *createIntegerLiteral(CharacterLiteralExpr *E) {
return insert(IntegerLiteralInst::create(E, F));
}
IntegerLiteralInst *createIntegerLiteral(SILLocation Loc, SILType Ty,
intmax_t Value) {
return insert(IntegerLiteralInst::create(Loc, Ty, Value, F));
Expand Down
4 changes: 1 addition & 3 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

namespace swift {

class CharacterLiteralExpr;
class DeclRefExpr;
class FloatLiteralExpr;
class FuncDecl;
Expand Down Expand Up @@ -945,15 +944,14 @@ class GlobalAddrInst : public LiteralInst {
};

/// IntegerLiteralInst - Encapsulates an integer constant, as defined originally
/// by an an IntegerLiteralExpr or CharacterLiteralExpr.
/// by an IntegerLiteralExpr.
class IntegerLiteralInst : public LiteralInst {
unsigned numBits;

IntegerLiteralInst(SILLocation Loc, SILType Ty, const APInt &Value);

public:
static IntegerLiteralInst *create(IntegerLiteralExpr *E, SILFunction &B);
static IntegerLiteralInst *create(CharacterLiteralExpr *E, SILFunction &B);
static IntegerLiteralInst *create(SILLocation Loc, SILType Ty,
intmax_t Value, SILFunction &B);
static IntegerLiteralInst *create(SILLocation Loc, SILType Ty,
Expand Down
4 changes: 0 additions & 4 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,10 +1411,6 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
<< ')';
}

void visitCharacterLiteralExpr(CharacterLiteralExpr *E) {
printCommon(E, "character_literal_expr") << " value=" << E->getValue()<<')';
}

void printStringEncoding(StringLiteralExpr::Encoding encoding) {
switch (encoding) {
case StringLiteralExpr::UTF8: OS << "utf8"; break;
Expand Down
1 change: 0 additions & 1 deletion lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ bool Expr::canAppendCallParentheses() const {
case ExprKind::IntegerLiteral:
case ExprKind::FloatLiteral:
case ExprKind::BooleanLiteral:
case ExprKind::CharacterLiteral:
case ExprKind::StringLiteral:
case ExprKind::InterpolatedStringLiteral:
case ExprKind::MagicIdentifierLiteral:
Expand Down
2 changes: 0 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.DisableAvailabilityChecking |=
Args.hasArg(OPT_disable_availability_checking);

Opts.EnableCharacterLiterals |= Args.hasArg(OPT_enable_character_literals);

if (auto A = Args.getLastArg(OPT_enable_access_control,
OPT_disable_access_control)) {
Opts.EnableAccessControl
Expand Down
1 change: 0 additions & 1 deletion lib/IDE/SyntaxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ SyntaxModelContext::SyntaxModelContext(SourceFile &SrcFile)
case tok::integer_literal: Kind = SyntaxNodeKind::Integer; break;
case tok::floating_literal: Kind = SyntaxNodeKind::Floating; break;
case tok::string_literal: Kind = SyntaxNodeKind::String; break;
case tok::character_literal: Kind = SyntaxNodeKind::Character; break;
case tok::comment:
if (Tok.getText().startswith("///"))
Kind = SyntaxNodeKind::DocCommentLine;
Expand Down
2 changes: 0 additions & 2 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4823,7 +4823,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
case KnownProtocolKind::_DestructorSafeContainer:
case KnownProtocolKind::ArrayLiteralConvertible:
case KnownProtocolKind::BooleanLiteralConvertible:
case KnownProtocolKind::CharacterLiteralConvertible:
case KnownProtocolKind::DictionaryLiteralConvertible:
case KnownProtocolKind::ExtendedGraphemeClusterLiteralConvertible:
case KnownProtocolKind::FloatLiteralConvertible:
Expand All @@ -4835,7 +4834,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
case KnownProtocolKind::_ColorLiteralConvertible:
case KnownProtocolKind::_ImageLiteralConvertible:
case KnownProtocolKind::_BuiltinBooleanLiteralConvertible:
case KnownProtocolKind::_BuiltinCharacterLiteralConvertible:
case KnownProtocolKind::_BuiltinExtendedGraphemeClusterLiteralConvertible:
case KnownProtocolKind::_BuiltinFloatLiteralConvertible:
case KnownProtocolKind::_BuiltinIntegerLiteralConvertible:
Expand Down
74 changes: 0 additions & 74 deletions lib/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,75 +1008,6 @@ unsigned Lexer::lexCharacter(const char *&CurPtr, bool StopAtDoubleQuote,
return CharValue;
}


/// lexCharacterLiteral:
/// character_literal ::= '([^'\\\n\r]|character_escape)'
void Lexer::lexCharacterLiteral() {
const char *TokStart = CurPtr-1;
assert(*TokStart == '\'' && "Unexpected start");

unsigned CharValue = lexCharacter(CurPtr, false, true);

// If we have '', we have an invalid character literal.
if (CharValue == ~0U) {
diagnose(TokStart, diag::lex_invalid_character_literal);
if (*CurPtr == '\'')
++CurPtr;
return formToken(tok::character_literal, TokStart);
}

// If this wasn't a normal character, then this is a malformed character.
if (CharValue == ~1U) {
// Skip until we see a single quote, newline, or EOF, whatever comes first.
while (true) {
const char C = *CurPtr;
if (C == '\n' || C == '\r' || C == '\'' || C == 0)
break;
CurPtr++;
}

// If we successfully skipped to the single quote, assume that it
// terminates the character literal and eat it now.
if (*CurPtr == '\'')
++CurPtr;
return formToken(tok::character_literal, TokStart);
}

if (*CurPtr != '\'') {
// Skip until we see a single quote, newline, or EOF, whatever comes first.
while (true) {
const char C = *CurPtr;
if (C == '\n' || C == '\r' || C == '\'' || C == 0)
break;
CurPtr++;
}

// If we successfully skipped to the single quote, assume that it
// terminates the character literal and eat it now.
if (*CurPtr == '\'') {
diagnose(TokStart, diag::lex_invalid_multi_code_point_character_literal);
++CurPtr;
} else {
diagnose(TokStart, diag::lex_unterminated_character_literal);
}
return formToken(tok::unknown, TokStart);
}
++CurPtr;
return formToken(tok::character_literal, TokStart);
}

uint32_t Lexer::getEncodedCharacterLiteral(const Token &Tok) {
assert(Tok.is(tok::character_literal));
const char *CharStart = Tok.getText().data() + 1;
uint32_t CodePoint = lexCharacter(CharStart, false, false);
if (CodePoint == ~0U || CodePoint == ~1U) {
// We have already diagnosed an error. Return REPLACEMENT CHARACTER as the
// value.
return 0xFFFD;
}
return CodePoint;
}

/// skipToEndOfInterpolatedExpression - Given the first character after a \(
/// sequence in a string literal (the start of an interpolated expression),
/// scan forward to the end of the interpolated expression and return the end.
Expand Down Expand Up @@ -1409,11 +1340,6 @@ void Lexer::lexImpl() {
const char *TokStart = CurPtr;

switch (*CurPtr++) {
case '\'':
if (LangOpts.EnableCharacterLiterals)
return lexCharacterLiteral();
SWIFT_FALLTHROUGH;

default: {
char const *tmp = CurPtr-1;
if (advanceIfValidStartOfIdentifier(tmp, BufferEnd))
Expand Down
9 changes: 0 additions & 9 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ MagicIdentifierLiteralExpr::Kind getMagicIdentifierLiteralKind(tok Kind) {
/// integer_literal
/// floating_literal
/// string_literal
/// character_literal
/// nil
/// true
/// false
Expand Down Expand Up @@ -719,14 +718,6 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
/*Implicit=*/false));
break;
}
case tok::character_literal: {
uint32_t Codepoint = L->getEncodedCharacterLiteral(Tok);
SourceLoc Loc = consumeToken(tok::character_literal);
Result = makeParserResult(
new (Context) CharacterLiteralExpr(Codepoint, Loc));
break;
}

case tok::at_sign:
// Objective-C programmers habitually type @"foo", so recover gracefully
// with a fixit. If this isn't @"foo", just handle it like an unknown
Expand Down
7 changes: 0 additions & 7 deletions lib/SIL/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,6 @@ IntegerLiteralInst::create(IntegerLiteralExpr *E, SILFunction &F) {
E->getValue(), F);
}

IntegerLiteralInst *
IntegerLiteralInst::create(CharacterLiteralExpr *E, SILFunction &F) {
return create(E,
SILType::getPrimitiveObjectType(E->getType()->getCanonicalType()),
E->getValue(), F);
}

/// getValue - Return the APInt for the underlying integer literal.
APInt IntegerLiteralInst::getValue() const {
return APInt(numBits,
Expand Down
9 changes: 1 addition & 8 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ namespace {
RValue visitIntegerLiteralExpr(IntegerLiteralExpr *E, SGFContext C);
RValue visitFloatLiteralExpr(FloatLiteralExpr *E, SGFContext C);
RValue visitBooleanLiteralExpr(BooleanLiteralExpr *E, SGFContext C);
RValue visitCharacterLiteralExpr(CharacterLiteralExpr *E, SGFContext C);


RValue emitStringLiteral(Expr *E, StringRef Str, SGFContext C,
StringLiteralExpr::Encoding encoding);

Expand Down Expand Up @@ -756,12 +755,6 @@ RValue RValueEmitter::visitBooleanLiteralExpr(BooleanLiteralExpr *E,
return RValue(SGF, E, ManagedValue::forUnmanaged(boolValue));
}

RValue RValueEmitter::visitCharacterLiteralExpr(CharacterLiteralExpr *E,
SGFContext C) {
return RValue(SGF, E,
ManagedValue::forUnmanaged(SGF.B.createIntegerLiteral(E)));
}

RValue RValueEmitter::emitStringLiteral(Expr *E, StringRef Str,
SGFContext C,
StringLiteralExpr::Encoding encoding) {
Expand Down
Loading

0 comments on commit 0001dc2

Please sign in to comment.