@@ -84,15 +84,16 @@ namespace Sass {
84
84
85
85
bool List::operator == (const Expression& rhs) const
86
86
{
87
- if (List_Ptr_Const r = Cast<List>(&rhs)) {
87
+ if (auto r = Cast<List>(&rhs)) {
88
88
if (length () != r->length ()) return false ;
89
89
if (separator () != r->separator ()) return false ;
90
90
if (is_bracketed () != r->is_bracketed ()) return false ;
91
91
for (size_t i = 0 , L = length (); i < L; ++i) {
92
- Expression_Obj rv = r->at (i);
93
- Expression_Obj lv = this ->at (i);
94
- if (!lv || !rv) return false ;
95
- if (!(*lv == *rv)) return false ;
92
+ auto rv = r->at (i);
93
+ auto lv = this ->at (i);
94
+ if (!lv && rv) return false ;
95
+ else if (!rv && lv) return false ;
96
+ else if (*lv != *rv) return false ;
96
97
}
97
98
return true ;
98
99
}
@@ -141,13 +142,14 @@ namespace Sass {
141
142
142
143
bool Map::operator == (const Expression& rhs) const
143
144
{
144
- if (Map_Ptr_Const r = Cast<Map>(&rhs)) {
145
+ if (auto r = Cast<Map>(&rhs)) {
145
146
if (length () != r->length ()) return false ;
146
147
for (auto key : keys ()) {
147
- Expression_Obj lv = at (key);
148
- Expression_Obj rv = r->at (key);
149
- if (!rv || !lv) return false ;
150
- if (!(*lv == *rv)) return false ;
148
+ auto rv = r->at (key);
149
+ auto lv = this ->at (key);
150
+ if (!lv && rv) return false ;
151
+ else if (!rv && lv) return false ;
152
+ else if (*lv != *rv) return false ;
151
153
}
152
154
return true ;
153
155
}
@@ -229,19 +231,12 @@ namespace Sass {
229
231
230
232
bool Binary_Expression::operator ==(const Expression& rhs) const
231
233
{
232
- try
233
- {
234
- Binary_Expression_Ptr_Const m = Cast<Binary_Expression>(&rhs);
235
- if (m == 0 ) return false ;
234
+ if (auto m = Cast<Binary_Expression>(&rhs)) {
236
235
return type () == m->type () &&
237
- *left () == *m->left () &&
238
- *right () == *m->right ();
236
+ *left () == *m->left () &&
237
+ *right () == *m->right ();
239
238
}
240
- catch (std::bad_cast&)
241
- {
242
- return false ;
243
- }
244
- catch (...) { throw ; }
239
+ return false ;
245
240
}
246
241
247
242
size_t Binary_Expression::hash () const
@@ -267,9 +262,9 @@ namespace Sass {
267
262
268
263
bool Function::operator == (const Expression& rhs) const
269
264
{
270
- if (Function_Ptr_Const r = Cast<Function>(&rhs)) {
271
- Definition_Ptr_Const d1 = Cast<Definition>(definition ());
272
- Definition_Ptr_Const d2 = Cast<Definition>(r->definition ());
265
+ if (auto r = Cast<Function>(&rhs)) {
266
+ auto d1 = Cast<Definition>(definition ());
267
+ auto d2 = Cast<Definition>(r->definition ());
273
268
return d1 && d2 && d1 == d2 && is_css () == r->is_css ();
274
269
}
275
270
return false ;
@@ -317,20 +312,14 @@ namespace Sass {
317
312
318
313
bool Function_Call::operator ==(const Expression& rhs) const
319
314
{
320
- try
321
- {
322
- Function_Call_Ptr_Const m = Cast<Function_Call>(&rhs);
323
- if (!(m && *sname () == *m->sname ())) return false ;
324
- if (!(m && arguments ()->length () == m->arguments ()->length ())) return false ;
325
- for (size_t i =0 , L = arguments ()->length (); i < L; ++i)
326
- if (!(*(*arguments ())[i] == *(*m->arguments ())[i])) return false ;
315
+ if (auto m = Cast<Function_Call>(&rhs)) {
316
+ if (*sname () != *m->sname ()) return false ;
317
+ if (arguments ()->length () != m->arguments ()->length ()) return false ;
318
+ for (size_t i = 0 , L = arguments ()->length (); i < L; ++i)
319
+ if (*arguments ()->get (i) != *m->arguments ()->get (i)) return false ;
327
320
return true ;
328
321
}
329
- catch (std::bad_cast&)
330
- {
331
- return false ;
332
- }
333
- catch (...) { throw ; }
322
+ return false ;
334
323
}
335
324
336
325
size_t Function_Call::hash () const
@@ -366,16 +355,10 @@ namespace Sass {
366
355
367
356
bool Variable::operator ==(const Expression& rhs) const
368
357
{
369
- try
370
- {
371
- Variable_Ptr_Const e = Cast<Variable>(&rhs);
372
- return e && name () == e->name ();
373
- }
374
- catch (std::bad_cast&)
375
- {
376
- return false ;
358
+ if (auto e = Cast<Variable>(&rhs)) {
359
+ return name () == e->name ();
377
360
}
378
- catch (...) { throw ; }
361
+ return false ;
379
362
}
380
363
381
364
size_t Variable::hash ()
@@ -452,21 +435,23 @@ namespace Sass {
452
435
453
436
bool Number::operator == (const Expression& rhs) const
454
437
{
455
- if (auto rhsnr = Cast<Number>(&rhs)) {
456
- return *this == *rhsnr ;
438
+ if (auto n = Cast<Number>(&rhs)) {
439
+ return *this == *n ;
457
440
}
458
441
return false ;
459
442
}
460
443
461
444
bool Number::operator == (const Number& rhs) const
462
445
{
446
+ // unitless or only having one unit are equivalent (3.4)
447
+ // therefore we need to reduce the units beforehand
463
448
Number l (*this ), r (rhs); l.reduce (); r.reduce ();
464
449
size_t lhs_units = l.numerators .size () + l.denominators .size ();
465
450
size_t rhs_units = r.numerators .size () + r.denominators .size ();
466
- // unitless and only having one unit seems equivalent (will change in future)
467
451
if (!lhs_units || !rhs_units) {
468
452
return NEAR_EQUAL (l.value (), r.value ());
469
453
}
454
+ // ensure both have same units
470
455
l.normalize (); r.normalize ();
471
456
Units &lhs_unit = l, &rhs_unit = r;
472
457
return lhs_unit == rhs_unit &&
@@ -475,21 +460,26 @@ namespace Sass {
475
460
476
461
bool Number::operator < (const Number& rhs) const
477
462
{
463
+ // unitless or only having one unit are equivalent (3.4)
464
+ // therefore we need to reduce the units beforehand
478
465
Number l (*this ), r (rhs); l.reduce (); r.reduce ();
479
466
size_t lhs_units = l.numerators .size () + l.denominators .size ();
480
467
size_t rhs_units = r.numerators .size () + r.denominators .size ();
481
- // unitless and only having one unit seems equivalent (will change in future)
482
468
if (!lhs_units || !rhs_units) {
483
469
return l.value () < r.value ();
484
470
}
471
+ // ensure both have same units
485
472
l.normalize (); r.normalize ();
486
473
Units &lhs_unit = l, &rhs_unit = r;
487
474
if (!(lhs_unit == rhs_unit)) {
488
475
/* ToDo: do we always get usefull backtraces? */
489
476
throw Exception::IncompatibleUnits (rhs, *this );
490
477
}
491
- return lhs_unit < rhs_unit ||
492
- l.value () < r.value ();
478
+ if (lhs_unit == rhs_unit) {
479
+ return l.value () < r.value ();
480
+ } else {
481
+ return lhs_unit < rhs_unit;
482
+ }
493
483
}
494
484
495
485
// ///////////////////////////////////////////////////////////////////////
@@ -512,7 +502,7 @@ namespace Sass {
512
502
513
503
bool Color::operator == (const Expression& rhs) const
514
504
{
515
- if (Color_Ptr_Const r = Cast<Color>(&rhs)) {
505
+ if (auto r = Cast<Color>(&rhs)) {
516
506
return r_ == r->r () &&
517
507
g_ == r->g () &&
518
508
b_ == r->b () &&
@@ -545,7 +535,7 @@ namespace Sass {
545
535
546
536
bool Custom_Error::operator == (const Expression& rhs) const
547
537
{
548
- if (Custom_Error_Ptr_Const r = Cast<Custom_Error>(&rhs)) {
538
+ if (auto r = Cast<Custom_Error>(&rhs)) {
549
539
return message () == r->message ();
550
540
}
551
541
return false ;
@@ -564,7 +554,7 @@ namespace Sass {
564
554
565
555
bool Custom_Warning::operator == (const Expression& rhs) const
566
556
{
567
- if (Custom_Warning_Ptr_Const r = Cast<Custom_Warning>(&rhs)) {
557
+ if (auto r = Cast<Custom_Warning>(&rhs)) {
568
558
return message () == r->message ();
569
559
}
570
560
return false ;
@@ -586,7 +576,7 @@ namespace Sass {
586
576
587
577
bool Boolean::operator == (const Expression& rhs) const
588
578
{
589
- if (Boolean_Ptr_Const r = Cast<Boolean>(&rhs)) {
579
+ if (auto r = Cast<Boolean>(&rhs)) {
590
580
return (value () == r->value ());
591
581
}
592
582
return false ;
@@ -642,13 +632,12 @@ namespace Sass {
642
632
643
633
bool String_Schema::operator == (const Expression& rhs) const
644
634
{
645
- if (String_Schema_Ptr_Const r = Cast<String_Schema>(&rhs)) {
635
+ if (auto r = Cast<String_Schema>(&rhs)) {
646
636
if (length () != r->length ()) return false ;
647
637
for (size_t i = 0 , L = length (); i < L; ++i) {
648
- Expression_Obj rv = (*r)[i];
649
- Expression_Obj lv = (*this )[i];
650
- if (!lv || !rv) return false ;
651
- if (!(*lv == *rv)) return false ;
638
+ auto rv = (*r)[i];
639
+ auto lv = (*this )[i];
640
+ if (*lv != *rv) return false ;
652
641
}
653
642
return true ;
654
643
}
@@ -707,10 +696,10 @@ namespace Sass {
707
696
708
697
bool String_Constant::operator == (const Expression& rhs) const
709
698
{
710
- if (String_Quoted_Ptr_Const qstr = Cast<String_Quoted>(&rhs)) {
711
- return ( value () == qstr->value () );
712
- } else if (String_Constant_Ptr_Const cstr = Cast<String_Constant>(&rhs)) {
713
- return ( value () == cstr->value () );
699
+ if (auto qstr = Cast<String_Quoted>(&rhs)) {
700
+ return value () == qstr->value ();
701
+ } else if (auto cstr = Cast<String_Constant>(&rhs)) {
702
+ return value () == cstr->value ();
714
703
}
715
704
return false ;
716
705
}
@@ -753,10 +742,10 @@ namespace Sass {
753
742
754
743
bool String_Quoted::operator == (const Expression& rhs) const
755
744
{
756
- if (String_Quoted_Ptr_Const qstr = Cast<String_Quoted>(&rhs)) {
757
- return ( value () == qstr->value () );
758
- } else if (String_Constant_Ptr_Const cstr = Cast<String_Constant>(&rhs)) {
759
- return ( value () == cstr->value () );
745
+ if (auto qstr = Cast<String_Quoted>(&rhs)) {
746
+ return value () == qstr->value ();
747
+ } else if (auto cstr = Cast<String_Constant>(&rhs)) {
748
+ return value () == cstr->value ();
760
749
}
761
750
return false ;
762
751
}
@@ -778,7 +767,7 @@ namespace Sass {
778
767
779
768
bool Null::operator == (const Expression& rhs) const
780
769
{
781
- return rhs. concrete_type () == NULL_VAL ;
770
+ return Cast<Null>(&rhs) != NULL ;
782
771
}
783
772
784
773
size_t Null::hash () const
0 commit comments