MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / new

Method new

src/program/array.rs:203–271  ·  view source on GitHub ↗
(ty: &str)

Source from the content-addressed store, hash-verified

201
202impl InitListType {
203 pub fn new(ty: &str) -> Self {
204 let mut row_num = usize::MAX;
205 let mut col_num = 0;
206
207 let mut de = Deserializer::from_input(ty);
208 if de.is_next_token("const") {
209 de.eat_token("const").unwrap();
210 }
211
212 let idx = usize::min(
213 de.input.find('*').unwrap_or(usize::MAX),
214 de.input.find('[').unwrap_or(usize::MAX),
215 );
216 if idx == usize::MAX {
217 unreachable!()
218 }
219 let ty_token = de.input[..idx].trim();
220 let input = &de.input[idx..];
221 let mut de = Deserializer::from_input(input);
222 let next_char = de.next_char().unwrap();
223
224 // StarList: *[3]
225 if next_char == '*' {
226 if de.is_next_token("const") {
227 de.eat_token("const").unwrap();
228 }
229 de.next_char()
230 .unwrap_or_else(|_| panic!("CharStarList: next char should be '[' here."));
231 col_num = de.parse_number().unwrap();
232 de.eat_token("]").unwrap();
233 if de.next_char().is_ok() {
234 return Self::Others;
235 }
236 // Fixed List: [3] or [3][4]
237 } else if next_char == '[' {
238 row_num = de.parse_number().unwrap();
239 de.eat_token("]").unwrap();
240 if let Ok(_next_char) = de.next_char() {
241 col_num = de.parse_number().unwrap();
242 de.eat_token("]").unwrap();
243 if de.next_char().is_ok() {
244 return Self::Others;
245 }
246 }
247 } else {
248 unreachable!()
249 }
250
251 let canonical_ty = super::gadget::ctype::retrieve_canonical_type(ty_token);
252
253 match canonical_ty.as_str() {
254 "char" => type_match!(CharList, CharStarList, row_num, col_num),
255 "unsigned char" => type_match!(UCharList, UCharStarList, row_num, col_num),
256 "float" => type_match!(FloatList, FloatStarList, row_num, col_num),
257 "double" => type_match!(DoubleList, DoubleStarList, row_num, col_num),
258 "int" => type_match!(I32List, I32StarList, row_num, col_num),
259 "int8_t" => type_match!(I8List, I8StarList, row_num, col_num),
260 "uint8_t" => type_match!(U8List, U8StarList, row_num, col_num),

Callers

nothing calls this directly

Calls 5

retrieve_canonical_typeFunction · 0.85
is_next_tokenMethod · 0.80
eat_tokenMethod · 0.80
next_charMethod · 0.80
parse_numberMethod · 0.80

Tested by

no test coverage detected