UnaryOperatorExpression에도 괄호를 무조건 치도록 수정
This commit is contained in:
static
2025-03-11 08:24:50 +00:00
parent 873987829f
commit 2e238b1163

View File

@@ -660,17 +660,18 @@ impl WriteString for AlignOf {
impl WriteString for UnaryOperatorExpression {
fn write_string(&self) -> String {
let operand = self.operand.write_string();
match self.operator.node {
UnaryOperator::PostIncrement => format!("{}++", self.operand.write_string()),
UnaryOperator::PostDecrement => format!("{}--", self.operand.write_string()),
UnaryOperator::PreIncrement => format!("++{}", self.operand.write_string()),
UnaryOperator::PreDecrement => format!("--{}", self.operand.write_string()),
UnaryOperator::Address => format!("&{}", self.operand.write_string()),
UnaryOperator::Indirection => format!("*{}", self.operand.write_string()),
UnaryOperator::Plus => format!("+{}", self.operand.write_string()),
UnaryOperator::Minus => format!("-{}", self.operand.write_string()),
UnaryOperator::Complement => format!("~{}", self.operand.write_string()),
UnaryOperator::Negate => format!("!{}", self.operand.write_string()),
UnaryOperator::PostIncrement => format!("({operand}++)"),
UnaryOperator::PostDecrement => format!("({operand}--)"),
UnaryOperator::PreIncrement => format!("(++{operand})"),
UnaryOperator::PreDecrement => format!("(--{operand})"),
UnaryOperator::Address => format!("(&{operand})"),
UnaryOperator::Indirection => format!("(*{operand})"),
UnaryOperator::Plus => format!("(+{operand})"),
UnaryOperator::Minus => format!("(-{operand})"),
UnaryOperator::Complement => format!("(~{operand})"),
UnaryOperator::Negate => format!("(!{operand})"),
}
}
}
@@ -691,209 +692,43 @@ impl WriteString for BinaryOperatorExpression {
BinaryOperator::Index => {
format!("{}[{}]", self.lhs.write_string(), self.rhs.write_string())
}
BinaryOperator::Multiply => {
format!(
"({} * {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Divide => {
format!(
"({} / {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Modulo => {
format!(
"({} % {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Plus => {
format!(
"({} + {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Minus => {
format!(
"({} - {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::ShiftLeft => {
format!(
"({} << {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::ShiftRight => {
format!(
"({} >> {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Less => {
format!(
"({} < {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Greater => {
format!(
"({} > {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::LessOrEqual => {
format!(
"({} <= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::GreaterOrEqual => {
format!(
"({} >= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Equals => {
format!(
"({} == {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::NotEquals => {
format!(
"({} != {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::BitwiseAnd => {
format!(
"({} & {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::BitwiseXor => {
format!(
"({} ^ {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::BitwiseOr => {
format!(
"({} | {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::LogicalAnd => {
format!(
"({} && {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::LogicalOr => {
format!(
"({} || {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::Assign => {
format!(
"({} = {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignMultiply => {
format!(
"({} *= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignDivide => {
format!(
"({} /= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignModulo => {
format!(
"({} %= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignPlus => {
format!(
"({} += {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignMinus => {
format!(
"({} -= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignShiftLeft => {
format!(
"({} <<= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignShiftRight => {
format!(
"({} >>= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignBitwiseAnd => {
format!(
"({} &= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignBitwiseXor => {
format!(
"({} ^= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
BinaryOperator::AssignBitwiseOr => {
format!(
"({} |= {})",
self.lhs.write_string(),
self.rhs.write_string()
)
}
_ => format!(
"({} {} {})",
self.lhs.write_string(),
match self.operator.node {
BinaryOperator::Multiply => "*",
BinaryOperator::Divide => "/",
BinaryOperator::Modulo => "%",
BinaryOperator::Plus => "+",
BinaryOperator::Minus => "-",
BinaryOperator::ShiftLeft => "<<",
BinaryOperator::ShiftRight => ">>",
BinaryOperator::Less => "<",
BinaryOperator::Greater => ">",
BinaryOperator::LessOrEqual => "<=",
BinaryOperator::GreaterOrEqual => ">=",
BinaryOperator::Equals => "==",
BinaryOperator::NotEquals => "!=",
BinaryOperator::BitwiseAnd => "&",
BinaryOperator::BitwiseXor => "^",
BinaryOperator::BitwiseOr => "|",
BinaryOperator::LogicalAnd => "&&",
BinaryOperator::LogicalOr => "||",
BinaryOperator::Assign => "=",
BinaryOperator::AssignMultiply => "*=",
BinaryOperator::AssignDivide => "/=",
BinaryOperator::AssignModulo => "%=",
BinaryOperator::AssignPlus => "+=",
BinaryOperator::AssignMinus => "-=",
BinaryOperator::AssignShiftLeft => "<<=",
BinaryOperator::AssignShiftRight => ">>=",
BinaryOperator::AssignBitwiseAnd => "&=",
BinaryOperator::AssignBitwiseXor => "^=",
BinaryOperator::AssignBitwiseOr => "|=",
_ => unreachable!(),
},
self.rhs.write_string(),
),
}
}
}