Skip to content

Commit 9534240

Browse files
committed
Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way to turn it off. rdar://problem/21935551 Swift SVN r30966
1 parent c8acc85 commit 9534240

36 files changed

+149
-36
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ option(SWIFT_ENABLE_TARGET_TVOS
6060
"Enable compiler support for targeting tvOS"
6161
TRUE)
6262

63+
option(SWIFT_ENABLE_OBJECT_LITERALS
64+
"Enable compiler support for object literals"
65+
TRUE)
66+
6367
set(SWIFT_VERSION "2.0" CACHE STRING
6468
"The user-visible version of the Swift compiler")
6569
set(SWIFT_VENDOR "" CACHE STRING

cmake/modules/AddSwift.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ function(_add_variant_c_compile_link_flags
5555
"-m${SWIFT_SDK_${sdk}_VERSION_MIN_NAME}-version-min=${SWIFT_SDK_${sdk}_DEPLOYMENT_VERSION}")
5656
endif()
5757

58-
if(${SWIFT_ENABLE_TARGET_TVOS})
59-
list(APPEND result
60-
" -DSWIFT_ENABLE_TARGET_TVOS=\"1\"")
61-
endif()
62-
6358
set("${result_var_name}" "${result}" PARENT_SCOPE)
6459
endfunction()
6560

@@ -99,6 +94,14 @@ function(_add_variant_c_compile_flags
9994
list(APPEND result "-DNDEBUG")
10095
endif()
10196

97+
if(SWIFT_ENABLE_TARGET_TVOS)
98+
list(APPEND result "-DSWIFT_ENABLE_TARGET_TVOS=\"1\"")
99+
endif()
100+
101+
if(SWIFT_ENABLE_OBJECT_LITERALS)
102+
list(APPEND result "-DSWIFT_ENABLE_OBJECT_LITERALS=\"1\"")
103+
endif()
104+
102105
set("${result_var_name}" "${result}" PARENT_SCOPE)
103106
endfunction()
104107

@@ -132,6 +135,10 @@ function(_add_variant_swift_compile_flags
132135
list(APPEND result "-D" "INTERNAL_CHECKS_ENABLED")
133136
endif()
134137

138+
if(SWIFT_ENABLE_OBJECT_LITERALS)
139+
list(APPEND result "-D" "SWIFT_ENABLE_OBJECT_LITERALS")
140+
endif()
141+
135142
set("${result_var_name}" "${result}" PARENT_SCOPE)
136143
endfunction()
137144

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,15 @@ ERROR(expected_rsquare_expr_list,expr_parsing,none,
987987
ERROR(expected_rsquare_array_expr,expr_parsing,PointsToFirstBadToken,
988988
"expected ']' in container literal expression", ())
989989

990+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
990991
// Object literal expressions
991992
ERROR(expected_identifier_after_l_square_lit,expr_parsing,none,
992993
"expected identifier after '[#' in object literal expression", ())
993994
ERROR(expected_arg_list_in_object_literal,expr_parsing,none,
994995
"expected argument list in object literal", ())
995996
ERROR(expected_r_square_lit_after_object_literal,expr_parsing,none,
996997
"expected '#]' at end of object literal expression", ())
998+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
997999

9981000
// If expressions
9991001
ERROR(expected_expr_after_if_question,expr_parsing,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,10 @@ ERROR(pattern_used_in_type,sema_nb,none,
339339
NOTE(note_module_as_type,sema_nb,none,
340340
"cannot use module %0 as a type", (Identifier))
341341

342+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
342343
ERROR(use_unknown_object_literal,sema_nb,none,
343344
"use of unknown object literal name %0", (Identifier))
345+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
344346

345347
ERROR(use_non_type_value,sema_nb,none,
346348
"%0 is not a type", (Identifier))
@@ -1624,8 +1626,10 @@ ERROR(interpolation_broken_proto,sema_tce,none,
16241626
"protocol 'StringInterpolationConvertible' is broken",
16251627
())
16261628

1629+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
16271630
ERROR(object_literal_broken_proto,sema_tce,none,
16281631
"object literal protocol is broken", ())
1632+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
16291633

16301634
ERROR(discard_expr_outside_of_assignment,sema_tce,none,
16311635
"'_' can only appear in a pattern or on the left side of an assignment",

include/swift/AST/Expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ class MagicIdentifierLiteralExpr : public LiteralExpr {
773773
}
774774
};
775775

776+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
776777
// ObjectLiteralExpr - An expression of the form
777778
// '[#Color(red: 1, blue: 0, green: 0, alpha: 1)#]' with a name and a list
778779
// argument. The components of the list argument are meant to be themselves
@@ -809,6 +810,7 @@ class ObjectLiteralExpr : public LiteralExpr {
809810
return E->getKind() == ExprKind::ObjectLiteral;
810811
}
811812
};
813+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
812814

813815
/// DiscardAssignmentExpr - A '_' in the left-hand side of an assignment, which
814816
/// discards the corresponding tuple element on the right-hand side.

include/swift/AST/ExprNodes.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ ABSTRACT_EXPR(Literal, Expr)
5656
EXPR(BooleanLiteral, LiteralExpr)
5757
EXPR(StringLiteral, LiteralExpr)
5858
EXPR(InterpolatedStringLiteral, LiteralExpr)
59-
EXPR(MagicIdentifierLiteral, LiteralExpr)
59+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
6060
EXPR(ObjectLiteral, LiteralExpr)
61-
EXPR_RANGE(Literal, NilLiteral, ObjectLiteral)
61+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
62+
EXPR(MagicIdentifierLiteral, LiteralExpr)
63+
EXPR_RANGE(Literal, NilLiteral, MagicIdentifierLiteral)
6264
EXPR(DiscardAssignment, Expr)
6365
EXPR(DeclRef, Expr)
6466
EXPR(SuperRef, Expr)

include/swift/AST/KnownProtocols.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ LITERAL_CONVERTIBLE_PROTOCOL(StringInterpolationConvertible, string)
6161
LITERAL_CONVERTIBLE_PROTOCOL(StringLiteralConvertible, string)
6262
LITERAL_CONVERTIBLE_PROTOCOL(NilLiteralConvertible, nil)
6363
LITERAL_CONVERTIBLE_PROTOCOL(UnicodeScalarLiteralConvertible, character)
64+
65+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
6466
LITERAL_CONVERTIBLE_PROTOCOL(_ColorLiteralConvertible, color)
6567
LITERAL_CONVERTIBLE_PROTOCOL(_ImageLiteralConvertible, image)
68+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
6669

6770
BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinBooleanLiteralConvertible)
6871
BUILTIN_LITERAL_CONVERTIBLE_PROTOCOL(_BuiltinExtendedGraphemeClusterLiteralConvertible)

include/swift/IDE/SyntaxModel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ enum class SyntaxNodeKind : uint8_t {
5353
AttributeBuiltin,
5454
/// An editor placeholder string <#like this#>.
5555
EditorPlaceholder,
56+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
5657
/// An editor object literal [#like(this)#]
5758
ObjectLiteral
59+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
5860
};
5961

6062
struct SyntaxNode {
@@ -105,7 +107,9 @@ enum class SyntaxStructureKind : uint8_t {
105107
CallExpression,
106108
ArrayExpression,
107109
DictionaryExpression,
110+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
108111
ObjectLiteralExpression,
112+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
109113
};
110114

111115
enum class SyntaxStructureElementKind : uint8_t {

include/swift/Parse/Parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,9 @@ class Parser {
11361136

11371137
Expr *parseExprAnonClosureArg();
11381138
ParserResult<Expr> parseExprList(tok LeftTok, tok RightTok);
1139+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
11391140
ParserResult<Expr> parseExprObjectLiteral();
1141+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
11401142
ParserResult<Expr> parseExprCallSuffix(ParserResult<Expr> fn,
11411143
Identifier firstSelectorPiece
11421144
= Identifier(),

include/swift/Parse/Tokens.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ PUNCTUATOR(r_brace, "}")
123123
PUNCTUATOR(l_square, "[")
124124
PUNCTUATOR(r_square, "]")
125125

126+
#ifdef SWIFT_ENABLE_OBJECT_LITERALS
126127
PUNCTUATOR(l_square_lit, "[#")
127128
PUNCTUATOR(r_square_lit, "#]")
129+
#endif // SWIFT_ENABLE_OBJECT_LITERALS
128130

129131
PUNCTUATOR(period, ".")
130132
PUNCTUATOR(period_prefix, ".")

0 commit comments

Comments
 (0)