forked from GoogleCloudPlatform/cloud-debug-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_expression_evaluator.cc
More file actions
745 lines (579 loc) · 21.6 KB
/
binary_expression_evaluator.cc
File metadata and controls
745 lines (579 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "binary_expression_evaluator.h"
#include <cmath>
#include <limits>
#include "model.h"
#include "messages.h"
#include "numeric_cast_evaluator.h"
namespace devtools {
namespace cdbg {
// Implementation of Java modulo (%) operator for int data type.
static jint ComputeModulo(jint x, jint y) {
return x % y;
}
// Implementation of Java modulo (%) operator for long data type.
static jlong ComputeModulo(jlong x, jlong y) {
return x % y;
}
// Implementation of Java modulo (%) operator for float data type.
static jfloat ComputeModulo(jfloat x, jfloat y) {
return std::fmod(static_cast<float>(x), static_cast<float>(y));
}
// Implementation of Java modulo (%) operator for double data type.
static jdouble ComputeModulo(jdouble x, jdouble y) {
return std::fmod(static_cast<double>(x), static_cast<double>(y));
}
// Checks that the divisor will not trigger "division by zero" signal.
static bool IsDivisionByZero(jint divisor) {
return divisor == 0;
}
// Checks that the divisor will not trigger "division by zero" signal.
static bool IsDivisionByZero(jlong divisor) {
return divisor == 0;
}
// Checks that the divisor will not trigger "division by zero" signal.
static bool IsDivisionByZero(jfloat divisor) {
return false; // Floating point division never triggers the signal
}
// Checks that the divisor will not trigger "division by zero" signal.
static bool IsDivisionByZero(jdouble divisor) {
return false; // Floating point division never triggers the signal
}
// Detects edge case in integer division that causes SIGFPE signal.
static bool IsDivisionOverflow(jint value1, jint value2) {
return (value1 == std::numeric_limits<jint>::min()) &&
(value2 == -1);
}
// Detects edge case in integer division that causes SIGFPE signal.
static bool IsDivisionOverflow(jlong value1, jlong value2) {
return (value1 == std::numeric_limits<jlong>::min()) &&
(value2 == -1);
}
// Detects edge case in integer division that causes SIGFPE signal.
static bool IsDivisionOverflow(jfloat value1, jfloat value2) {
return false; // This condition does not apply to floating point.
}
// Detects edge case in integer division that causes SIGFPE signal.
static bool IsDivisionOverflow(jdouble value1, jdouble value2) {
return false; // This condition does not apply to floating point.
}
// Compares two Java strings.
static bool IsEqual(jstring string1, jstring string2) {
if ((string1 == nullptr) || (string2 == nullptr)) {
return string1 == string2;
}
const jint length1 = jni()->GetStringLength(string1);
const jint length2 = jni()->GetStringLength(string2);
if (length1 != length2) {
return false;
}
if (length1 == 0) {
return true;
}
const jchar* data1 = jni()->GetStringCritical(string1, nullptr);
if (data1 == nullptr) { // Some error occurred.
return false;
}
const jchar* data2 = jni()->GetStringCritical(string2, nullptr);
if (data2 == nullptr) { // Some error occurred.
jni()->ReleaseStringCritical(string1, data1);
return false;
}
const bool is_equal = (memcmp(data1, data2, sizeof(jchar) * length1) == 0);
jni()->ReleaseStringCritical(string1, data1);
jni()->ReleaseStringCritical(string2, data2);
return is_equal;
}
BinaryExpressionEvaluator::BinaryExpressionEvaluator(
BinaryJavaExpression::Type type,
std::unique_ptr<ExpressionEvaluator> arg1,
std::unique_ptr<ExpressionEvaluator> arg2)
: type_(type),
arg1_(std::move(arg1)),
arg2_(std::move(arg2)),
computer_(nullptr) {
result_type_.type = JType::Object;
}
bool BinaryExpressionEvaluator::Compile(
ReadersFactory* readers_factory,
FormatMessageModel* error_message) {
if (!arg1_->Compile(readers_factory, error_message)) {
return false;
}
if (!arg2_->Compile(readers_factory, error_message)) {
return false;
}
switch (type_) {
case BinaryJavaExpression::Type::add:
case BinaryJavaExpression::Type::sub:
case BinaryJavaExpression::Type::mul:
case BinaryJavaExpression::Type::div:
case BinaryJavaExpression::Type::mod:
return CompileArithmetical(error_message);
case BinaryJavaExpression::Type::conditional_and:
case BinaryJavaExpression::Type::conditional_or:
case BinaryJavaExpression::Type::eq:
case BinaryJavaExpression::Type::ne:
case BinaryJavaExpression::Type::le:
case BinaryJavaExpression::Type::ge:
case BinaryJavaExpression::Type::lt:
case BinaryJavaExpression::Type::gt:
return CompileConditional(error_message);
case BinaryJavaExpression::Type::bitwise_and:
case BinaryJavaExpression::Type::bitwise_or:
case BinaryJavaExpression::Type::bitwise_xor:
return CompileBitwise(error_message);
case BinaryJavaExpression::Type::shl:
case BinaryJavaExpression::Type::shr_s:
case BinaryJavaExpression::Type::shr_u:
return CompileShift(error_message);
}
// Compiler should catch any missing enums. We should never get here.
return false;
}
bool BinaryExpressionEvaluator::CompileArithmetical(
FormatMessageModel* error_message) {
// TODO(vlif): unbox (Java Language Specification section 5.1.8).
// TODO(vlif): implement concatenation for strings
// Apply numeric promotions (Java Language Specification section 5.6.2)
// and initialize the computation routine.
if (IsEitherType(JType::Double)) {
if (!ApplyNumericPromotions<jdouble>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::ArithmeticComputer<jdouble>;
result_type_ = { JType::Double };
return true;
} else if (IsEitherType(JType::Float)) {
if (!ApplyNumericPromotions<jfloat>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::ArithmeticComputer<jfloat>;
result_type_ = { JType::Float };
return true;
} else if (IsEitherType(JType::Long)) {
if (!ApplyNumericPromotions<jlong>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::ArithmeticComputer<jlong>;
result_type_ = { JType::Long };
return true;
} else {
if (!ApplyNumericPromotions<jint>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::ArithmeticComputer<jint>;
result_type_ = { JType::Int };
return true;
}
}
bool BinaryExpressionEvaluator::CompileConditional(
FormatMessageModel* error_message) {
const JSignature& signature1 = arg1_->GetStaticType();
const JSignature& signature2 = arg2_->GetStaticType();
// Conditional operations applied to objects.
if ((signature1.type == JType::Object) &&
(signature2.type == JType::Object) &&
((type_ == BinaryJavaExpression::Type::eq) ||
(type_ == BinaryJavaExpression::Type::ne))) {
// Use regular comparison operators ("==" and "!=") to compare Java
// strings. This is not consistent with Java language. The way to compare
// strings in Java is through "equals" method, but expression evaluator
// doesn't support methods yet. Also it wouldn't make sense if breakpoint
// condition like (myName == "vlad") would always evaluate to false.
// TODO(vlif): support string comparison through "equals" method and keep
// this kind of string comparison for inline strings only.
if ((signature1.object_signature == kJavaStringClassSignature) &&
(signature2.object_signature == kJavaStringClassSignature)) {
computer_ = &BinaryExpressionEvaluator::ConditionalStringComputer;
} else {
computer_ = &BinaryExpressionEvaluator::ConditionalObjectComputer;
}
result_type_ = { JType::Boolean };
return true;
}
// TODO(vlif): unbox (Java Language Specification section 5.1.8).
FormatMessageModel unused_error_message;
if (CompileBooleanConditional(&unused_error_message)) {
return true;
}
// Numerical comparison operators.
if ((type_ == BinaryJavaExpression::Type::eq) ||
(type_ == BinaryJavaExpression::Type::ne) ||
(type_ == BinaryJavaExpression::Type::le) ||
(type_ == BinaryJavaExpression::Type::ge) ||
(type_ == BinaryJavaExpression::Type::lt) ||
(type_ == BinaryJavaExpression::Type::gt)) {
// Apply numeric promotions (Java Language Specification section 5.6.2)
// and initialize the computation routine.
if (IsEitherType(JType::Double)) {
if (!ApplyNumericPromotions<jdouble>(error_message)) {
return false;
}
computer_ =
&BinaryExpressionEvaluator::NumericalComparisonComputer<jdouble>;
} else if (IsEitherType(JType::Float)) {
if (!ApplyNumericPromotions<jfloat>(error_message)) {
return false;
}
computer_ =
&BinaryExpressionEvaluator::NumericalComparisonComputer<jfloat>;
} else if (IsEitherType(JType::Long)) {
if (!ApplyNumericPromotions<jlong>(error_message)) {
return false;
}
computer_ =
&BinaryExpressionEvaluator::NumericalComparisonComputer<jlong>;
} else {
if (!ApplyNumericPromotions<jint>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::NumericalComparisonComputer<jint>;
}
result_type_ = { JType::Boolean };
return true;
}
*error_message = { TypeMismatch };
return false;
}
bool BinaryExpressionEvaluator::CompileBooleanConditional(
FormatMessageModel* error_message) {
// Conditional operations that apply to boolean arguments.
if (IsBooleanType(arg1_->GetStaticType().type) &&
IsBooleanType(arg2_->GetStaticType().type) &&
((type_ == BinaryJavaExpression::Type::conditional_and) ||
(type_ == BinaryJavaExpression::Type::conditional_or) ||
(type_ == BinaryJavaExpression::Type::eq) ||
(type_ == BinaryJavaExpression::Type::ne) ||
(type_ == BinaryJavaExpression::Type::bitwise_and) ||
(type_ == BinaryJavaExpression::Type::bitwise_or) ||
(type_ == BinaryJavaExpression::Type::bitwise_xor))) {
computer_ = &BinaryExpressionEvaluator::ConditionalBooleanComputer;
result_type_ = { JType::Boolean };
return true;
}
*error_message = { TypeMismatch };
return false;
}
bool BinaryExpressionEvaluator::CompileBitwise(
FormatMessageModel* error_message) {
// TODO(vlif): unbox (Java Language Specification section 5.1.8).
// Bitwise operators become conditional when applied to boolean arguments
// (Java Language Specification, section 15.22.2).
FormatMessageModel unused_error_message;
if (CompileBooleanConditional(&unused_error_message)) {
return true;
}
// Integer bitwise operators are only applicable to int and long.
if (!IsIntegerType(arg1_->GetStaticType().type) ||
!IsIntegerType(arg2_->GetStaticType().type)) {
*error_message = { TypeMismatch };
return false;
}
// Shift of "long".
if (IsEitherType(JType::Long)) {
if (!ApplyNumericPromotions<jlong>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::BitwiseComputer<jlong>;
result_type_ = { JType::Long };
return true;
}
// Shift of "int".
if (!ApplyNumericPromotions<jint>(error_message)) {
return false;
}
computer_ = &BinaryExpressionEvaluator::BitwiseComputer<jint>;
result_type_ = { JType::Int };
return true;
}
bool BinaryExpressionEvaluator::CompileShift(
FormatMessageModel* error_message) {
// TODO(vlif): unbox (Java Language Specification section 5.1.8).
// Numeric promotion is applied separately for each argument
// (Java Language Specification section 15.19)
if (!IsIntegerType(arg1_->GetStaticType().type) ||
!IsIntegerType(arg2_->GetStaticType().type)) {
*error_message = { TypeMismatch };
return false;
}
if (!ApplyShiftNumericPromotion(&arg1_, error_message) ||
!ApplyShiftNumericPromotion(&arg2_, error_message)) {
return false;
}
switch (arg1_->GetStaticType().type) {
case JType::Int:
computer_ = &BinaryExpressionEvaluator::ShiftComputer<jint, uint32, 0x1f>;
result_type_ = { JType::Int };
return true;
case JType::Long:
computer_ =
&BinaryExpressionEvaluator::ShiftComputer<jlong, uint64, 0x3f>;
result_type_ = { JType::Long };
return true;
default:
*error_message = { TypeMismatch };
return false;
}
}
bool BinaryExpressionEvaluator::IsEitherType(JType type) const {
return (arg1_->GetStaticType().type == type) ||
(arg2_->GetStaticType().type == type);
}
template <typename TTargetType>
bool BinaryExpressionEvaluator::ApplyNumericPromotions(
FormatMessageModel* error_message) {
return ApplyNumericCast<TTargetType>(&arg1_, error_message) &&
ApplyNumericCast<TTargetType>(&arg2_, error_message);
}
bool BinaryExpressionEvaluator::ApplyShiftNumericPromotion(
std::unique_ptr<ExpressionEvaluator>* arg,
FormatMessageModel* error_message) {
switch ((*arg)->GetStaticType().type) {
case JType::Byte:
case JType::Char:
case JType::Short:
return ApplyNumericCast<jint>(arg, error_message);
case JType::Int:
case JType::Long:
return true; // No numeric promotion needed.
default:
*error_message = { TypeMismatch };
return false; // Shift operator not applicable for this type.
}
}
ErrorOr<JVariant> BinaryExpressionEvaluator::Evaluate(
const EvaluationContext& evaluation_context) const {
ErrorOr<JVariant> arg1_value = arg1_->Evaluate(evaluation_context);
if (arg1_value.is_error()) {
return arg1_value;
}
// TODO(vlif): evaluate second argument on demand. For example in this one:
// (true || exp)
// "exp" should never be evaluated.
ErrorOr<JVariant> arg2_value = arg2_->Evaluate(evaluation_context);
if (arg2_value.is_error()) {
return arg2_value;
}
return (this->*computer_)(arg1_value.value(), arg2_value.value());
}
template <typename T>
ErrorOr<JVariant> BinaryExpressionEvaluator::ArithmeticComputer(
const JVariant& arg1,
const JVariant& arg2) const {
T value1 = T();
if (!arg1.get<T>(&value1)) {
return INTERNAL_ERROR_MESSAGE;
}
T value2 = T();
if (!arg2.get<T>(&value2)) {
return INTERNAL_ERROR_MESSAGE;
}
switch (type_) {
case BinaryJavaExpression::Type::add:
return JVariant::Primitive<T>(value1 + value2);
case BinaryJavaExpression::Type::sub:
return JVariant::Primitive<T>(value1 - value2);
case BinaryJavaExpression::Type::mul:
return JVariant::Primitive<T>(value1 * value2);
case BinaryJavaExpression::Type::mod:
case BinaryJavaExpression::Type::div:
if (IsDivisionByZero(value2)) {
return FormatMessageModel { DivisionByZero };
}
if (IsDivisionOverflow(value1, value2)) {
return FormatMessageModel { IntegerDivisionOverflow };
}
if (type_ == BinaryJavaExpression::Type::div) {
return JVariant::Primitive<T>(value1 / value2);
} else {
return JVariant::Primitive<T>(ComputeModulo(value1, value2));
}
default:
DCHECK(false); // Any non arithmetic operations are unexpected here.
return INTERNAL_ERROR_MESSAGE;
}
}
template <typename T>
ErrorOr<JVariant> BinaryExpressionEvaluator::BitwiseComputer(
const JVariant& arg1,
const JVariant& arg2) const {
T value1 = T();
if (!arg1.get<T>(&value1)) {
return INTERNAL_ERROR_MESSAGE;
}
T value2 = T();
if (!arg2.get<T>(&value2)) {
return INTERNAL_ERROR_MESSAGE;
}
switch (type_) {
case BinaryJavaExpression::Type::bitwise_and:
return JVariant::Primitive<T>(value1 & value2);
case BinaryJavaExpression::Type::bitwise_or:
return JVariant::Primitive<T>(value1 | value2);
case BinaryJavaExpression::Type::bitwise_xor:
return JVariant::Primitive<T>(value1 ^ value2);
default:
DCHECK(false); // Any other operations are unexpected here.
return INTERNAL_ERROR_MESSAGE;
}
}
template <typename T, typename TUnsigned, uint16 Bitmask>
ErrorOr<JVariant> BinaryExpressionEvaluator::ShiftComputer(
const JVariant& arg1,
const JVariant& arg2) const {
T value1 = T();
if (!arg1.get<T>(&value1)) {
return INTERNAL_ERROR_MESSAGE;
}
jint value2 = 0;
if (!arg2.get<jint>(&value2)) {
jlong value2_long = 0;
if (!arg2.get<jlong>(&value2_long)) {
return INTERNAL_ERROR_MESSAGE;
}
value2 = static_cast<jint>(value2_long);
}
// From Java Language Specification, section 15.19:
// If the promoted type of the left-hand operand is int, only the five lowest-
// order bits of the right-hand operand are used as the shift distance. It is
// as if the right-hand operand were subjected to a bitwise logical AND
// operator & (15.22.1) with the mask value 0x1f (0b11111). The shift
// distance actually used is therefore always in the range 0 to 31, inclusive.
// If the promoted type of the left-hand operand is long, then only the six
// lowest-order bits of the right-hand operand are used as the shift distance.
// It is as if the right-hand operand were subjected to a bitwise logical AND
// operator & (15.22.1) with the mask value 0x3f (0b111111). The shift
// distance actually used is therefore always in the range 0 to 63, inclusive.
value2 &= Bitmask;
switch (type_) {
case BinaryJavaExpression::Type::shl:
return JVariant::Primitive<T>(value1 << value2);
case BinaryJavaExpression::Type::shr_s:
return JVariant::Primitive<T>(value1 >> value2);
case BinaryJavaExpression::Type::shr_u:
return JVariant::Primitive<T>(static_cast<TUnsigned>(value1) >> value2);
default:
DCHECK(false); // Any operations other than shift are unexpected here.
return INTERNAL_ERROR_MESSAGE;
}
}
ErrorOr<JVariant> BinaryExpressionEvaluator::ConditionalObjectComputer(
const JVariant& arg1,
const JVariant& arg2) const {
jobject object1 = nullptr;
if (!arg1.get<jobject>(&object1)) {
return INTERNAL_ERROR_MESSAGE;
}
jobject object2 = nullptr;
if (!arg2.get<jobject>(&object2)) {
return INTERNAL_ERROR_MESSAGE;
}
switch (type_) {
case BinaryJavaExpression::Type::eq:
return JVariant::Boolean(jni()->IsSameObject(object1, object2));
case BinaryJavaExpression::Type::ne:
return JVariant::Boolean(!jni()->IsSameObject(object1, object2));
default:
DCHECK(false); // Any other operations are not supported for objects.
return INTERNAL_ERROR_MESSAGE;
}
}
ErrorOr<JVariant> BinaryExpressionEvaluator::ConditionalStringComputer(
const JVariant& arg1,
const JVariant& arg2) const {
jobject object1 = nullptr;
if (!arg1.get<jobject>(&object1)) {
return INTERNAL_ERROR_MESSAGE;
}
jobject object2 = nullptr;
if (!arg2.get<jobject>(&object2)) {
return INTERNAL_ERROR_MESSAGE;
}
const bool is_equal =
IsEqual(static_cast<jstring>(object1), static_cast<jstring>(object2));
switch (type_) {
case BinaryJavaExpression::Type::eq:
return JVariant::Boolean(is_equal);
case BinaryJavaExpression::Type::ne:
return JVariant::Boolean(!is_equal);
default:
DCHECK(false); // Any other operations are not supported for strings.
return INTERNAL_ERROR_MESSAGE;
}
}
ErrorOr<JVariant> BinaryExpressionEvaluator::ConditionalBooleanComputer(
const JVariant& arg1,
const JVariant& arg2) const {
jboolean boolean1 = false;
if (!arg1.get<jboolean>(&boolean1)) {
return INTERNAL_ERROR_MESSAGE;
}
jboolean boolean2 = false;
if (!arg2.get<jboolean>(&boolean2)) {
return INTERNAL_ERROR_MESSAGE;
}
switch (type_) {
case BinaryJavaExpression::Type::conditional_and:
case BinaryJavaExpression::Type::bitwise_and:
return JVariant::Boolean(boolean1 && boolean2);
case BinaryJavaExpression::Type::conditional_or:
case BinaryJavaExpression::Type::bitwise_or:
return JVariant::Boolean(boolean1 || boolean2);
case BinaryJavaExpression::Type::eq:
return JVariant::Boolean(boolean1 == boolean2);
case BinaryJavaExpression::Type::ne:
case BinaryJavaExpression::Type::bitwise_xor:
return JVariant::Boolean(boolean1 != boolean2);
default:
DCHECK(false); // Any other operations are unexpected here.
return INTERNAL_ERROR_MESSAGE;
}
}
template <typename T>
ErrorOr<JVariant> BinaryExpressionEvaluator::NumericalComparisonComputer(
const JVariant& arg1,
const JVariant& arg2) const {
T value1 = T();
if (!arg1.get<T>(&value1)) {
return INTERNAL_ERROR_MESSAGE;
}
T value2 = T();
if (!arg2.get<T>(&value2)) {
return INTERNAL_ERROR_MESSAGE;
}
switch (type_) {
case BinaryJavaExpression::Type::eq:
return JVariant::Boolean(value1 == value2);
case BinaryJavaExpression::Type::ne:
case BinaryJavaExpression::Type::bitwise_xor:
return JVariant::Boolean(value1 != value2);
case BinaryJavaExpression::Type::le:
return JVariant::Boolean(value1 <= value2);
case BinaryJavaExpression::Type::ge:
return JVariant::Boolean(value1 >= value2);
case BinaryJavaExpression::Type::lt:
return JVariant::Boolean(value1 < value2);
case BinaryJavaExpression::Type::gt:
return JVariant::Boolean(value1 > value2);
default:
DCHECK(false); // Any other operations are not supported for booleans.
return INTERNAL_ERROR_MESSAGE;
}
}
} // namespace cdbg
} // namespace devtools