@@ -135,27 +135,37 @@ impl<'tu, 'ge> Field<'tu, 'ge> {
135
135
pub fn default_value ( & self ) -> Option < Cow < str > > {
136
136
match self {
137
137
& Self :: Clang { entity, .. } => {
138
- let mut children = vec ! [ ] ;
139
- let mut skipping_typeref = true ;
140
- entity. visit_children ( |c, _| {
141
- if skipping_typeref && c. get_kind ( ) != EntityKind :: TypeRef {
142
- skipping_typeref = false ;
143
- }
144
- if !skipping_typeref {
145
- children. push ( c) ;
146
- EntityVisitResult :: Recurse
147
- } else {
148
- EntityVisitResult :: Continue
149
- }
138
+ // fixme: clang-2.0.0 contains a bug that causes rust-1.78.0+ to panic when calling .tokenize()
139
+ // https://github.com/KyleMayes/clang-rs/pull/58
140
+ // this seems to be happening on entries marked as CV_DEPRECATED_EXTERNAL which don't have default args
141
+ let has_literal_children = entity. visit_children ( |c, _| match c. get_kind ( ) {
142
+ EntityKind :: BoolLiteralExpr
143
+ | EntityKind :: CompoundLiteralExpr
144
+ | EntityKind :: UnexposedExpr
145
+ | EntityKind :: DeclRefExpr
146
+ | EntityKind :: CallExpr
147
+ | EntityKind :: StaticCastExpr
148
+ | EntityKind :: CStyleCastExpr
149
+ | EntityKind :: InitListExpr
150
+ | EntityKind :: ParenExpr
151
+ | EntityKind :: IntegerLiteral
152
+ | EntityKind :: FloatingLiteral
153
+ | EntityKind :: CharacterLiteral
154
+ | EntityKind :: StringLiteral
155
+ | EntityKind :: UnaryOperator
156
+ | EntityKind :: BinaryOperator => EntityVisitResult :: Break ,
157
+ _ => EntityVisitResult :: Continue ,
150
158
} ) ;
151
159
152
- if let Some ( range) = entity. get_range ( ) {
153
- let tokens = range. tokenize ( ) ;
154
- let equal_pos = tokens
155
- . iter ( )
156
- . position ( |t| t. get_kind ( ) == TokenKind :: Punctuation && t. get_spelling ( ) == "=" ) ;
157
- if let Some ( equal_pos) = equal_pos {
158
- return Some ( constant:: render_constant_cpp ( & tokens[ equal_pos + 1 ..] ) . into ( ) ) ;
160
+ if has_literal_children {
161
+ if let Some ( range) = entity. get_range ( ) {
162
+ let tokens = range. tokenize ( ) ;
163
+ let default_value_tokens = tokens
164
+ . splitn ( 2 , |t| t. get_kind ( ) == TokenKind :: Punctuation && t. get_spelling ( ) == "=" )
165
+ . nth ( 1 ) ;
166
+ if let Some ( default_value_tokens) = default_value_tokens {
167
+ return Some ( constant:: render_constant_cpp ( default_value_tokens) . into ( ) ) ;
168
+ }
159
169
}
160
170
}
161
171
None
0 commit comments