11// Copyright Kani Contributors
22// SPDX-License-Identifier: Apache-2.0 OR MIT
33//! This crate implements irep serialization using serde Serializer.
4- use crate :: irep:: { Irep , IrepId , Symbol , SymbolTable } ;
54use crate :: InternedString ;
6- use serde :: ser :: { SerializeMap , Serializer } ;
5+ use crate :: irep :: { Irep , IrepId , Symbol , SymbolTable } ;
76use serde:: Serialize ;
7+ use serde:: ser:: { SerializeMap , Serializer } ;
88
99impl Serialize for Irep {
1010 fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
@@ -145,14 +145,16 @@ impl Serialize for Symbol {
145145#[ cfg( test) ]
146146mod test {
147147 use super :: * ;
148- use serde_test:: { assert_ser_tokens , Token } ;
148+ use serde_test:: { Token , assert_ser_tokens } ;
149149 #[ test]
150150 fn serialize_irep ( ) {
151151 let irep = Irep :: empty ( ) ;
152- assert_ser_tokens (
153- & irep,
154- & [ Token :: Map { len : None } , Token :: String ( "id" ) , Token :: String ( "empty" ) , Token :: MapEnd ] ,
155- ) ;
152+ assert_ser_tokens ( & irep, & [
153+ Token :: Map { len : None } ,
154+ Token :: String ( "id" ) ,
155+ Token :: String ( "empty" ) ,
156+ Token :: MapEnd ,
157+ ] ) ;
156158 }
157159
158160 #[ test]
@@ -187,80 +189,77 @@ mod test {
187189 is_weak : false ,
188190 } ;
189191 sym_table. insert ( symbol) ;
190- assert_ser_tokens (
191- & sym_table,
192- & [
193- Token :: Map { len : None } ,
194- Token :: String ( "symbolTable" ) ,
195- Token :: Map { len : Some ( 1 ) } ,
196- Token :: String ( "my_name" ) ,
197- // symbol start
198- Token :: Map { len : None } ,
199- // type irep
200- Token :: String ( "type" ) ,
201- Token :: Map { len : None } ,
202- Token :: String ( "id" ) ,
203- Token :: String ( "empty" ) ,
204- Token :: MapEnd ,
205- // value irep
206- Token :: String ( "value" ) ,
207- Token :: Map { len : None } ,
208- Token :: String ( "id" ) ,
209- Token :: String ( "empty" ) ,
210- Token :: MapEnd ,
211- // value locaton
212- Token :: String ( "location" ) ,
213- Token :: Map { len : None } ,
214- Token :: String ( "id" ) ,
215- Token :: String ( "empty" ) ,
216- Token :: MapEnd ,
217- Token :: String ( "name" ) ,
218- Token :: String ( "my_name" ) ,
219- Token :: String ( "module" ) ,
220- Token :: String ( "" ) ,
221- Token :: String ( "baseName" ) ,
222- Token :: String ( "" ) ,
223- Token :: String ( "prettyName" ) ,
224- Token :: String ( "" ) ,
225- Token :: String ( "mode" ) ,
226- Token :: String ( "" ) ,
227- Token :: String ( "isType" ) ,
228- Token :: Bool ( false ) ,
229- Token :: String ( "isMacro" ) ,
230- Token :: Bool ( false ) ,
231- Token :: String ( "isExported" ) ,
232- Token :: Bool ( false ) ,
233- Token :: String ( "isInput" ) ,
234- Token :: Bool ( false ) ,
235- Token :: String ( "isOutput" ) ,
236- Token :: Bool ( false ) ,
237- Token :: String ( "isStateVar" ) ,
238- Token :: Bool ( false ) ,
239- Token :: String ( "isProperty" ) ,
240- Token :: Bool ( false ) ,
241- Token :: String ( "isStaticLifetime" ) ,
242- Token :: Bool ( false ) ,
243- Token :: String ( "isThreadLocal" ) ,
244- Token :: Bool ( false ) ,
245- Token :: String ( "isLvalue" ) ,
246- Token :: Bool ( false ) ,
247- Token :: String ( "isFileLocal" ) ,
248- Token :: Bool ( false ) ,
249- Token :: String ( "isExtern" ) ,
250- Token :: Bool ( false ) ,
251- Token :: String ( "isVolatile" ) ,
252- Token :: Bool ( false ) ,
253- Token :: String ( "isParameter" ) ,
254- Token :: Bool ( false ) ,
255- Token :: String ( "isAuxiliary" ) ,
256- Token :: Bool ( false ) ,
257- Token :: String ( "isWeak" ) ,
258- Token :: Bool ( false ) ,
259- Token :: MapEnd ,
260- Token :: MapEnd ,
261- Token :: MapEnd ,
262- ] ,
263- ) ;
192+ assert_ser_tokens ( & sym_table, & [
193+ Token :: Map { len : None } ,
194+ Token :: String ( "symbolTable" ) ,
195+ Token :: Map { len : Some ( 1 ) } ,
196+ Token :: String ( "my_name" ) ,
197+ // symbol start
198+ Token :: Map { len : None } ,
199+ // type irep
200+ Token :: String ( "type" ) ,
201+ Token :: Map { len : None } ,
202+ Token :: String ( "id" ) ,
203+ Token :: String ( "empty" ) ,
204+ Token :: MapEnd ,
205+ // value irep
206+ Token :: String ( "value" ) ,
207+ Token :: Map { len : None } ,
208+ Token :: String ( "id" ) ,
209+ Token :: String ( "empty" ) ,
210+ Token :: MapEnd ,
211+ // value locaton
212+ Token :: String ( "location" ) ,
213+ Token :: Map { len : None } ,
214+ Token :: String ( "id" ) ,
215+ Token :: String ( "empty" ) ,
216+ Token :: MapEnd ,
217+ Token :: String ( "name" ) ,
218+ Token :: String ( "my_name" ) ,
219+ Token :: String ( "module" ) ,
220+ Token :: String ( "" ) ,
221+ Token :: String ( "baseName" ) ,
222+ Token :: String ( "" ) ,
223+ Token :: String ( "prettyName" ) ,
224+ Token :: String ( "" ) ,
225+ Token :: String ( "mode" ) ,
226+ Token :: String ( "" ) ,
227+ Token :: String ( "isType" ) ,
228+ Token :: Bool ( false ) ,
229+ Token :: String ( "isMacro" ) ,
230+ Token :: Bool ( false ) ,
231+ Token :: String ( "isExported" ) ,
232+ Token :: Bool ( false ) ,
233+ Token :: String ( "isInput" ) ,
234+ Token :: Bool ( false ) ,
235+ Token :: String ( "isOutput" ) ,
236+ Token :: Bool ( false ) ,
237+ Token :: String ( "isStateVar" ) ,
238+ Token :: Bool ( false ) ,
239+ Token :: String ( "isProperty" ) ,
240+ Token :: Bool ( false ) ,
241+ Token :: String ( "isStaticLifetime" ) ,
242+ Token :: Bool ( false ) ,
243+ Token :: String ( "isThreadLocal" ) ,
244+ Token :: Bool ( false ) ,
245+ Token :: String ( "isLvalue" ) ,
246+ Token :: Bool ( false ) ,
247+ Token :: String ( "isFileLocal" ) ,
248+ Token :: Bool ( false ) ,
249+ Token :: String ( "isExtern" ) ,
250+ Token :: Bool ( false ) ,
251+ Token :: String ( "isVolatile" ) ,
252+ Token :: Bool ( false ) ,
253+ Token :: String ( "isParameter" ) ,
254+ Token :: Bool ( false ) ,
255+ Token :: String ( "isAuxiliary" ) ,
256+ Token :: Bool ( false ) ,
257+ Token :: String ( "isWeak" ) ,
258+ Token :: Bool ( false ) ,
259+ Token :: MapEnd ,
260+ Token :: MapEnd ,
261+ Token :: MapEnd ,
262+ ] ) ;
264263 }
265264
266265 #[ test]
@@ -269,41 +268,38 @@ mod test {
269268 let one_irep = Irep :: one ( ) ;
270269 let sub_irep = Irep :: just_sub ( vec ! [ empty_irep. clone( ) , one_irep] ) ;
271270 let top_irep = Irep :: just_sub ( vec ! [ sub_irep, empty_irep] ) ;
272- assert_ser_tokens (
273- & top_irep,
274- & [
275- // top_irep
276- Token :: Map { len : None } ,
277- Token :: String ( "id" ) ,
278- Token :: String ( "" ) ,
279- Token :: String ( "sub" ) ,
280- Token :: Seq { len : Some ( 2 ) } ,
281- // sub_irep
282- Token :: Map { len : None } ,
283- Token :: String ( "id" ) ,
284- Token :: String ( "" ) ,
285- Token :: String ( "sub" ) ,
286- Token :: Seq { len : Some ( 2 ) } ,
287- // empty_irep
288- Token :: Map { len : None } ,
289- Token :: String ( "id" ) ,
290- Token :: String ( "empty" ) ,
291- Token :: MapEnd ,
292- // one_irep
293- Token :: Map { len : None } ,
294- Token :: String ( "id" ) ,
295- Token :: String ( "1" ) ,
296- Token :: MapEnd ,
297- Token :: SeqEnd ,
298- Token :: MapEnd ,
299- // empty_irep
300- Token :: Map { len : None } ,
301- Token :: String ( "id" ) ,
302- Token :: String ( "empty" ) ,
303- Token :: MapEnd ,
304- Token :: SeqEnd ,
305- Token :: MapEnd ,
306- ] ,
307- ) ;
271+ assert_ser_tokens ( & top_irep, & [
272+ // top_irep
273+ Token :: Map { len : None } ,
274+ Token :: String ( "id" ) ,
275+ Token :: String ( "" ) ,
276+ Token :: String ( "sub" ) ,
277+ Token :: Seq { len : Some ( 2 ) } ,
278+ // sub_irep
279+ Token :: Map { len : None } ,
280+ Token :: String ( "id" ) ,
281+ Token :: String ( "" ) ,
282+ Token :: String ( "sub" ) ,
283+ Token :: Seq { len : Some ( 2 ) } ,
284+ // empty_irep
285+ Token :: Map { len : None } ,
286+ Token :: String ( "id" ) ,
287+ Token :: String ( "empty" ) ,
288+ Token :: MapEnd ,
289+ // one_irep
290+ Token :: Map { len : None } ,
291+ Token :: String ( "id" ) ,
292+ Token :: String ( "1" ) ,
293+ Token :: MapEnd ,
294+ Token :: SeqEnd ,
295+ Token :: MapEnd ,
296+ // empty_irep
297+ Token :: Map { len : None } ,
298+ Token :: String ( "id" ) ,
299+ Token :: String ( "empty" ) ,
300+ Token :: MapEnd ,
301+ Token :: SeqEnd ,
302+ Token :: MapEnd ,
303+ ] ) ;
308304 }
309305}
0 commit comments