From 2c331e9c695ed05a75bfea357e935ae42e6a6589 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 4 Mar 2023 03:38:16 +0100 Subject: [PATCH] Implement more bitwise operation for parser bitfields These will be used in the parser. Maybe this type should be a struct with boolean fields. The current way has the upside that the usage is exactly the same as in C++. --- fish-rust/src/parse_constants.rs | 8 +++++++- fish-rust/src/tokenizer.rs | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fish-rust/src/parse_constants.rs b/fish-rust/src/parse_constants.rs index ff3b7bbc8..9490f8cdf 100644 --- a/fish-rust/src/parse_constants.rs +++ b/fish-rust/src/parse_constants.rs @@ -6,7 +6,7 @@ use crate::wchar::{wstr, WString, L}; use crate::wchar_ffi::{wcharz, WCharFromFFI, WCharToFFI}; use crate::wutil::{sprintf, wgettext_fmt}; use cxx::{CxxWString, UniquePtr}; -use std::ops::{BitAnd, BitOrAssign}; +use std::ops::{BitAnd, BitOr, BitOrAssign}; use widestring_suffix::widestrs; pub type SourceOffset = u32; @@ -39,6 +39,12 @@ impl BitAnd for ParseTreeFlags { (self.0 & rhs.0) != 0 } } +impl BitOr for ParseTreeFlags { + type Output = ParseTreeFlags; + fn bitor(self, rhs: Self) -> Self::Output { + Self(self.0 | rhs.0) + } +} impl BitOrAssign for ParseTreeFlags { fn bitor_assign(&mut self, rhs: Self) { self.0 |= rhs.0 diff --git a/fish-rust/src/tokenizer.rs b/fish-rust/src/tokenizer.rs index c273e8bf6..72bdaf700 100644 --- a/fish-rust/src/tokenizer.rs +++ b/fish-rust/src/tokenizer.rs @@ -180,6 +180,11 @@ impl BitOr for TokFlags { Self(self.0 | rhs.0) } } +impl BitOrAssign for TokFlags { + fn bitor_assign(&mut self, rhs: Self) { + self.0 |= rhs.0 + } +} /// Flag telling the tokenizer to accept incomplete parameters, i.e. parameters with mismatching /// parenthesis, etc. This is useful for tab-completion.