@@ -67,17 +67,9 @@ class ValidateIfConfigCondition :
67
67
auto UDRE = dyn_cast<UnresolvedDeclRefExpr>(E);
68
68
if (!UDRE ||
69
69
!UDRE->hasName () ||
70
- UDRE->getRefKind () != Kind)
70
+ UDRE->getRefKind () != Kind ||
71
+ UDRE->getName ().isCompoundName ())
71
72
return None;
72
- if (UDRE->getName ().isCompoundName ()) {
73
- if (!Ctx.isSwiftVersion3 ())
74
- return None;
75
- // Swift3 used to accept compound names; warn and return the basename.
76
- D.diagnose (UDRE->getNameLoc ().getLParenLoc (),
77
- diag::swift3_conditional_compilation_expression_compound)
78
- .fixItRemove ({ UDRE->getNameLoc ().getLParenLoc (),
79
- UDRE->getNameLoc ().getRParenLoc () });
80
- }
81
73
82
74
return UDRE->getName ().getBaseIdentifier ().str ();
83
75
}
@@ -155,59 +147,6 @@ class ValidateIfConfigCondition :
155
147
return LHS;
156
148
}
157
149
158
- // In Swift3 mode, leave sequence as a sequence because it has strange
159
- // evaluation rule. See 'EvaluateIfConfigCondition::visitSequenceExpr'.
160
- Expr *validateSequence (ArrayRef<Expr *> &S) {
161
- assert (Ctx.isSwiftVersion3 ());
162
-
163
- SmallVector<Expr *, 3 > Filtered;
164
- SmallVector<unsigned , 2 > AndIdxs;
165
- Filtered.push_back (validate (S[0 ]));
166
- S = S.slice (1 );
167
-
168
- while (!S.empty ()) {
169
- auto OpName = getDeclRefStr (S[0 ], DeclRefKind::BinaryOperator);
170
- if (!OpName.hasValue () || (*OpName != " ||" && *OpName != " &&" )) {
171
- // Warning and ignore in Swift3 mode.
172
- D.diagnose (
173
- S[0 ]->getLoc (),
174
- diag::swift3_unsupported_conditional_compilation_expression_type)
175
- .highlight ({ S[0 ]->getLoc (), S[1 ]->getEndLoc () });
176
- } else {
177
- // Remember the start and end of '&&' sequence.
178
- bool InAnd = (AndIdxs.size () & 1 ) == 1 ;
179
- if ((*OpName == " &&" && !InAnd) || (*OpName == " ||" && InAnd))
180
- AndIdxs.push_back (Filtered.size () - 1 );
181
-
182
- Filtered.push_back (S[0 ]);
183
- Filtered.push_back (validate (S[1 ]));
184
- }
185
- S = S.slice (2 );
186
- }
187
- assert ((Filtered.size () & 1 ) == 1 );
188
-
189
- // If the last OpName is '&&', close it with a parenthesis, except if the
190
- // operators are '&&' only.
191
- if ((1 == (AndIdxs.size () & 1 )) && AndIdxs.back () > 0 )
192
- AndIdxs.push_back (Filtered.size () - 1 );
193
- // Emit fix-its to make this sequence compatilble with Swift >=4 even in
194
- // Swift3 mode.
195
- if (AndIdxs.size () >= 2 ) {
196
- assert ((AndIdxs.size () & 1 ) == 0 );
197
- auto diag = D.diagnose (
198
- Filtered[AndIdxs[0 ]]->getStartLoc (),
199
- diag::swift3_conditional_compilation_expression_precedence);
200
- for (unsigned i = 0 , e = AndIdxs.size (); i < e; i += 2 ) {
201
- diag.fixItInsert (Filtered[AndIdxs[i]]->getStartLoc (), " (" );
202
- diag.fixItInsertAfter (Filtered[AndIdxs[i + 1 ]]->getEndLoc (), " )" );
203
- }
204
- }
205
-
206
- if (Filtered.size () == 1 )
207
- return Filtered[0 ];
208
- return SequenceExpr::create (Ctx, Filtered);
209
- }
210
-
211
150
public:
212
151
ValidateIfConfigCondition (ASTContext &Ctx, DiagnosticEngine &D)
213
152
: Ctx(Ctx), D(D), HasError(false ) {}
@@ -369,14 +308,9 @@ class ValidateIfConfigCondition :
369
308
// Fold sequence expression for non-Swift3 mode.
370
309
Expr *visitSequenceExpr (SequenceExpr *E) {
371
310
ArrayRef<Expr*> Elts = E->getElements ();
372
- Expr *foldedExpr;
373
- if (Ctx.isSwiftVersion3 ()) {
374
- foldedExpr = validateSequence (Elts);
375
- } else {
376
- auto LHS = validate (Elts[0 ]);
377
- Elts = Elts.slice (1 );
378
- foldedExpr = foldSequence (LHS, Elts);
379
- }
311
+ Expr *foldedExpr = validate (Elts[0 ]);
312
+ Elts = Elts.slice (1 );
313
+ foldedExpr = foldSequence (foldedExpr, Elts);
380
314
assert (Elts.empty ());
381
315
return foldedExpr;
382
316
}
@@ -477,42 +411,13 @@ class EvaluateIfConfigCondition :
477
411
}
478
412
479
413
bool visitBinaryExpr (BinaryExpr *E) {
480
- assert (!Ctx.isSwiftVersion3 () && " BinaryExpr in Swift3 mode" );
481
414
auto OpName = getDeclRefStr (E->getFn ());
482
415
auto Args = E->getArg ()->getElements ();
483
416
if (OpName == " ||" ) return visit (Args[0 ]) || visit (Args[1 ]);
484
417
if (OpName == " &&" ) return visit (Args[0 ]) && visit (Args[1 ]);
485
418
llvm_unreachable (" unsupported binary operator" );
486
419
}
487
420
488
- bool visitSequenceExpr (SequenceExpr *E) {
489
- assert (Ctx.isSwiftVersion3 () && " SequenceExpr in non-Swift3 mode" );
490
- ArrayRef<Expr *> Elems = E->getElements ();
491
- auto Result = visit (Elems[0 ]);
492
- Elems = Elems.slice (1 );
493
- while (!Elems.empty ()) {
494
- auto OpName = getDeclRefStr (Elems[0 ]);
495
-
496
- if (OpName == " ||" ) {
497
- Result = Result || visit (Elems[1 ]);
498
- if (Result)
499
- // Note that this is the Swift3 behavior.
500
- // e.g. 'false || true && false' evaluates to 'true'.
501
- return true ;
502
- } else if (OpName == " &&" ) {
503
- Result = Result && visit (Elems[1 ]);
504
- if (!Result)
505
- // Ditto.
506
- // e.g. 'false && true || true' evaluates to 'false'.
507
- return false ;
508
- } else {
509
- llvm_unreachable (" must be removed in validation phase" );
510
- }
511
- Elems = Elems.slice (2 );
512
- }
513
- return Result;
514
- }
515
-
516
421
bool visitExpr (Expr *E) { llvm_unreachable (" Unvalidated condition?" ); }
517
422
};
518
423
0 commit comments