11//! Functions for parsing and evaluating DWARF expressions.
22
3+ #[ cfg( feature = "read" ) ]
34use alloc:: vec:: Vec ;
45use core:: mem;
56
@@ -938,6 +939,7 @@ impl<R: Reader> Expression<R> {
938939 /// let mut eval = expression.evaluation(unit.encoding());
939940 /// let mut result = eval.evaluate().unwrap();
940941 /// ```
942+ #[ cfg( feature = "read" ) ]
941943 #[ inline]
942944 pub fn evaluation ( self , encoding : Encoding ) -> Evaluation < R > {
943945 Evaluation :: new ( self . 0 , encoding)
@@ -982,8 +984,13 @@ impl<R: Reader> OperationIter<R> {
982984
983985/// Specification of what storage should be used for [`Evaluation`].
984986///
985- /// Normally you would only need to use [`StoreOnHeap`], which places the stacks and the results
986- /// on the heap using [`Vec`]. This is the default storage type parameter for [`Evaluation`].
987+ #[ cfg_attr(
988+ feature = "read" ,
989+ doc = "
990+ Normally you would only need to use [`StoreOnHeap`], which places the stacks and the results
991+ on the heap using [`Vec`]. This is the default storage type parameter for [`Evaluation`].
992+ "
993+ ) ]
987994///
988995/// If you need to avoid [`Evaluation`] from allocating memory, e.g. for signal safety,
989996/// you can provide you own storage specification:
@@ -1030,6 +1037,7 @@ pub trait EvaluationStorage<R: Reader> {
10301037 type Result : ArrayLike < Item = Piece < R > > ;
10311038}
10321039
1040+ #[ cfg( feature = "read" ) ]
10331041impl < R : Reader > EvaluationStorage < R > for StoreOnHeap {
10341042 type Stack = Vec < Value > ;
10351043 type ExpressionStack = Vec < ( R , R ) > ;
@@ -1108,6 +1116,7 @@ pub struct Evaluation<R: Reader, S: EvaluationStorage<R> = StoreOnHeap> {
11081116 result : ArrayVec < S :: Result > ,
11091117}
11101118
1119+ #[ cfg( feature = "read" ) ]
11111120impl < R : Reader > Evaluation < R > {
11121121 /// Create a new DWARF expression evaluator.
11131122 ///
@@ -1116,6 +1125,19 @@ impl<R: Reader> Evaluation<R> {
11161125 pub fn new ( bytecode : R , encoding : Encoding ) -> Self {
11171126 Self :: new_in ( bytecode, encoding)
11181127 }
1128+
1129+ /// Get the result of this `Evaluation`.
1130+ ///
1131+ /// # Panics
1132+ /// Panics if this `Evaluation` has not been driven to completion.
1133+ pub fn result ( self ) -> Vec < Piece < R > > {
1134+ match self . state {
1135+ EvaluationState :: Complete => self . result . into_vec ( ) ,
1136+ _ => {
1137+ panic ! ( "Called `Evaluation::result` on an `Evaluation` that has not been completed" )
1138+ }
1139+ }
1140+ }
11191141}
11201142
11211143impl < R : Reader , S : EvaluationStorage < R > > Evaluation < R , S > {
@@ -1956,21 +1978,6 @@ impl<R: Reader, S: EvaluationStorage<R>> Evaluation<R, S> {
19561978 }
19571979}
19581980
1959- impl < R : Reader > Evaluation < R , StoreOnHeap > {
1960- /// Get the result of this `Evaluation`.
1961- ///
1962- /// # Panics
1963- /// Panics if this `Evaluation` has not been driven to completion.
1964- pub fn result ( self ) -> Vec < Piece < R > > {
1965- match self . state {
1966- EvaluationState :: Complete => self . result . into_vec ( ) ,
1967- _ => {
1968- panic ! ( "Called `Evaluation::result` on an `Evaluation` that has not been completed" )
1969- }
1970- }
1971- }
1972- }
1973-
19741981#[ cfg( test) ]
19751982// Tests require leb128::write.
19761983#[ cfg( feature = "write" ) ]
0 commit comments