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
|
//! ref: composer/src/Composer/DependencyResolver/Rule2Literals.php
use shirabe_php_shim::PhpMixed;
use crate::dependency_resolver::generic_rule::RuleLiterals;
use crate::dependency_resolver::request::Request;
use crate::dependency_resolver::rule::{ReasonData, Rule};
#[derive(Debug)]
pub struct Rule2Literals {
pub(crate) literal1: i64,
pub(crate) literal2: i64,
literals: Vec<i64>,
}
impl Rule2Literals {
pub fn new(
literal1: i64,
literal2: i64,
reason: shirabe_php_shim::PhpMixed,
reason_data: shirabe_php_shim::PhpMixed,
) -> Self {
let (literal1, literal2) = if literal1 < literal2 {
(literal1, literal2)
} else {
(literal2, literal1)
};
Self {
inner: Rule::new(reason, reason_data),
literal1,
literal2,
literals: vec![literal1, literal2],
}
}
pub fn get_hash(&self) -> String {
format!("{},{}", self.literal1, self.literal2)
}
pub fn equals(&self, rule: &dyn RuleLiterals) -> bool {
// PHP: specialized fast-case for instanceof self, then fallback to literal comparison
// In Rust: use get_literals() for all cases (semantically equivalent)
let literals = rule.get_literals();
if literals.len() != 2 {
return false;
}
if self.literal1 != literals[0] {
return false;
}
if self.literal2 != literals[1] {
return false;
}
true
}
pub fn is_assertion(&self) -> bool {
false
}
pub fn to_string(&self) -> String {
let prefix = if self.inner.is_disabled() {
"disabled("
} else {
"("
};
format!("{}{}|{})", prefix, self.literal1, self.literal2)
}
}
impl RuleLiterals for Rule2Literals {
fn get_literals(&self) -> &Vec<i64> {
&self.literals
}
}
impl Rule for Rule2Literals {
fn bitfield(&self) -> i64 {
todo!()
}
fn bitfield_mut(&mut self) -> &mut i64 {
todo!()
}
fn request(&self) -> Option<&Request> {
todo!()
}
fn request_mut(&mut self) -> Option<&mut Request> {
todo!()
}
fn reason_data(&self) -> Option<&ReasonData> {
todo!()
}
fn reason_data_mut(&mut self) -> Option<&mut ReasonData> {
todo!()
}
fn get_literals(&self) -> Vec<i64> {
todo!()
}
fn get_hash(&self) -> PhpMixed {
todo!()
}
fn to_string(&self) -> String {
todo!()
}
fn equals(&self, rule: &dyn Rule) -> bool {
todo!()
}
fn is_assertion(&self) -> bool {
todo!()
}
}
|