Debian Codegraph @

src/chunk/chunk.rs

raw
1 use super::{conversion_from_glib, parameter_ffi_call_out};
2 use crate::analysis::{
3 function_parameters::TransformationType, return_value,
4 safety_assertion_mode::SafetyAssertionMode,
5 };
6
7 #[derive(Clone, Debug)]
8 pub enum Chunk {
9 Comment(Vec<Chunk>),
10 Chunks(Vec<Chunk>),
11 BlockHalf(Vec<Chunk>), // Block without open bracket, temporary
12 UnsafeSmart(Vec<Chunk>), // TODO: remove (will change generated results)
13 Unsafe(Vec<Chunk>),
14 #[allow(clippy::upper_case_acronyms)]
15 FfiCallTODO(String),
16 FfiCall {
17 name: String,
18 params: Vec<Chunk>,
19 ignore_return: bool,
20 },
21 FfiCallParameter {
22 transformation_type: TransformationType,
23 },
24 FfiCallOutParameter {
25 par: parameter_ffi_call_out::Parameter,
26 },
27 // TODO: separate without return_value::Info
28 FfiCallConversion {
29 ret: return_value::Info,
30 array_length_name: Option<String>,
31 call: Box<Chunk>,
32 },
33 Let {
34 name: String,
35 is_mut: bool,
36 value: Box<Chunk>,
37 type_: Option<Box<Chunk>>,
38 },
39 Uninitialized,
40 UninitializedNamed {
41 name: String,
42 },
43 NullPtr,
44 NullMutPtr,
45 Custom(String),
46 Tuple(Vec<Chunk>, TupleMode),
47 FromGlibConversion {
48 mode: conversion_from_glib::Mode,
49 array_length_name: Option<String>,
50 value: Box<Chunk>,
51 },
52 OptionalReturn {
53 condition: String,
54 value: Box<Chunk>,
55 },
56 AssertErrorSanity,
57 ErrorResultReturn {
58 ret: Option<Box<Chunk>>,
59 value: Box<Chunk>,
60 },
61 AssertInit(SafetyAssertionMode),
62 Connect {
63 signal: String,
64 trampoline: String,
65 in_trait: bool,
66 is_detailed: bool,
67 },
68 Name(String),
69 ExternCFunc {
70 name: String,
71 parameters: Vec<Param>,
72 body: Box<Chunk>,
73 return_value: Option<String>,
74 bounds: String,
75 },
76 Cast {
77 name: String,
78 type_: String,
79 },
80 Call {
81 func_name: String,
82 arguments: Vec<Chunk>,
83 },
84 }
85
86 impl Chunk {
87 pub fn is_uninitialized(&self) -> bool {
88 matches!(*self, Self::Uninitialized)
89 }
90 }
91
92 #[derive(Clone, Debug)]
93 pub struct Param {
94 pub name: String,
95 pub typ: String,
96 }
97
98 pub fn chunks(ch: Chunk) -> Vec<Chunk> {
99 vec![ch]
100 }
101
102 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
103 pub enum TupleMode {
104 Auto, // "", "1", "(1,2)"
105 WithUnit, // "()", "1", "(1,2)"
106 #[deprecated]
107 #[allow(dead_code)]
108 Simple, // "()", "(1)", "(1,2)"
109 }