MCPcopy Create free account
hub / github.com/IntegralPilot/rustc_codegen_jvm / compare_constants

Function compare_constants

src/oomir/interpret.rs:462–572  ·  view source on GitHub ↗

Helper for comparisons

(op1: Constant, op2: Constant)

Source from the content-addressed store, hash-verified

460 // Or potentially define an ordering based on keys? Simpler to return None.
461 }
462
463 for key in f1_keys {
464 let val1 = f1.get(key).unwrap(); // Key must exist based on checks
465 let val2 = f2.get(key).unwrap();
466 // Recursively call compare_constants!
467 match compare_constants(val1.clone(), val2.clone())? {
468 std::cmp::Ordering::Equal => continue, // Check next field
469 other_ordering => return Some(other_ordering), // Found difference
470 }
471 }
472
473 // If all params and fields are equal
474 Some(std::cmp::Ordering::Equal)
475 }
476
477 _ => None, // Incompatible types for comparison
478 }
479}
480
481// Internal equality check, handling recursion carefully
482fn eq_constants_internal(op1: Constant, op2: Constant) -> Option<bool> {
483 match compare_constants(op1, op2) {
484 // No clone needed here if compare_constants handles it
485 Some(std::cmp::Ordering::Equal) => Some(true),
486 Some(_) => Some(false), // Comparable but not equal
487 None => None, // Not comparable
488 }
489}
490
491pub fn eq_constants(op1: Constant, op2: Constant) -> Option<bool> {
492 eq_constants_internal(op1.clone(), op2.clone())
493}
494
495pub fn gt_constants(op1: Constant, op2: Constant) -> Option<bool> {
496 compare_constants(op1.clone(), op2.clone()).map(|ord| ord == std::cmp::Ordering::Greater)
497}
498
499pub fn lt_constants(op1: Constant, op2: Constant) -> Option<bool> {
500 compare_constants(op1, op2).map(|ord| ord == std::cmp::Ordering::Less)
501}
502
503pub fn ge_constants(op1: Constant, op2: Constant) -> Option<bool> {
504 compare_constants(op1, op2).map(|ord| ord != std::cmp::Ordering::Less)
505}
506
507pub fn le_constants(op1: Constant, op2: Constant) -> Option<bool> {
508 compare_constants(op1, op2).map(|ord| ord != std::cmp::Ordering::Greater)
509}
510
511fn do_bitwise_op<F>(op1: Constant, op2: Constant, func: F) -> Option<Constant>
512where
513 F: FnOnce(BigInt, BigInt) -> Result<BigInt, InterpretError>, // Assume BigInt for bitwise
514{
515 // Promote both to BigInt if possible, otherwise fallback to primitives
516 if let (Ok(bi1), Ok(bi2)) = (
517 parse_constant_to_bigint(&op1),
518 parse_constant_to_bigint(&op2),
519 ) {

Callers 5

eq_constants_internalFunction · 0.85
gt_constantsFunction · 0.85
lt_constantsFunction · 0.85
ge_constantsFunction · 0.85
le_constantsFunction · 0.85

Calls 3

parse_constant_to_bigintFunction · 0.85
lenMethod · 0.80

Tested by

no test coverage detected