File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ impl Expression {
3131 }
3232 }
3333
34+ /// If the expression consists only of raw bytecode, then return that bytecode.
35+ pub fn as_raw ( & self ) -> Option < & [ u8 ] > {
36+ match & self . operations [ ..] {
37+ [ Operation :: Raw ( bytecode) ] => Some ( bytecode) ,
38+ _ => None ,
39+ }
40+ }
41+
3442 /// Add an operation to the expression.
3543 ///
3644 /// This should only be used for operations that have no explicit operands.
@@ -1776,4 +1784,13 @@ mod tests {
17761784 let mut sections = Sections :: new ( EndianVec :: new ( LittleEndian ) ) ;
17771785 assert_eq ! ( dwarf. write( & mut sections) , Err ( Error :: InvalidReference ) ) ;
17781786 }
1787+
1788+ #[ test]
1789+ fn test_expression_as_raw ( ) {
1790+ assert_eq ! ( Expression :: new( ) . as_raw( ) , None ) ;
1791+ assert_eq ! ( Expression :: raw( b"1234" . into( ) ) . as_raw( ) , Some ( & b"1234" [ ..] ) ) ;
1792+ let mut expression = Expression :: raw ( b"1234" . into ( ) ) ;
1793+ expression. op_constu ( 1 ) ;
1794+ assert_eq ! ( expression. as_raw( ) , None ) ;
1795+ }
17791796}
You can’t perform that action at this time.
0 commit comments