@@ -3238,12 +3238,6 @@ class type cilPrinter = object
32383238 * in formals of function types, and the formals and locals for function
32393239 * definitions. *)
32403240
3241- method pVDeclPhony : unit -> varinfo -> bool -> doc
3242- (* * Invoked for each variable declaration. Note that variable
3243- * declarations are all the [GVar], [GVarDecl], [GFun], all the [varinfo]
3244- * in formals of function types, and the formals and locals for function
3245- * definitions. *)
3246-
32473241 method pVar : varinfo -> doc
32483242 (* * Invoked on each variable use. *)
32493243
@@ -3346,32 +3340,14 @@ class defaultCilPrinterClass : cilPrinter = object (self)
33463340
33473341 (* variable declaration *)
33483342 method pVDecl () (v :varinfo ) =
3349- if not v.vhasdeclinstruction then
3350- let stom, rest = separateStorageModifiers v.vattr in
3351- (* First the storage modifiers *)
3352- text (if v.vinline then " __inline " else " " )
3353- ++ d_storage () v.vstorage
3354- ++ (self#pAttrs () stom)
3355- ++ (self#pType (Some (text v.vname)) () v.vtype)
3356- ++ text " "
3357- ++ self#pAttrs () rest
3358- else
3359- text " "
3360-
3361-
3362- (* variable declaration *)
3363- method pVDeclPhony () (v :varinfo ) ph =
3364- if ph || not v.vhasdeclinstruction then
3365- let stom, rest = separateStorageModifiers v.vattr in
3366- (* First the storage modifiers *)
3367- text (if v.vinline then " __inline " else " " )
3368- ++ d_storage () v.vstorage
3369- ++ (self#pAttrs () stom)
3370- ++ (self#pType (Some (text v.vname)) () v.vtype)
3371- ++ text " "
3372- ++ self#pAttrs () rest
3373- else
3374- text " "
3343+ let stom, rest = separateStorageModifiers v.vattr in
3344+ (* First the storage modifiers *)
3345+ text (if v.vinline then " __inline " else " " )
3346+ ++ d_storage () v.vstorage
3347+ ++ (self#pAttrs () stom)
3348+ ++ (self#pType (Some (text v.vname)) () v.vtype)
3349+ ++ text " "
3350+ ++ self#pAttrs () rest
33753351
33763352 (* ** L-VALUES ***)
33773353 method pLval () (lv :lval ) = (* lval (base is 1st field) *)
@@ -3626,10 +3602,13 @@ class defaultCilPrinterClass : cilPrinter = object (self)
36263602 ++ text printInstrTerminator
36273603
36283604 end
3629- | VarDecl (varinfo ,l ) ->
3630- self#pLineDirective l
3631- ++ self#pVDeclPhony () varinfo true
3632- ++ chr ';'
3605+ | VarDecl (v , l ) ->
3606+ self#pLineDirective l
3607+ ++ self#pVDecl () v
3608+ ++ (match v.vinit.init with
3609+ | None -> text " ;"
3610+ | Some i -> text " = " ++
3611+ self#pInit () i ++ text " ;" )
36333612 (* In cabs2cil we have turned the call to builtin_va_arg into a
36343613 * three-argument call: the last argument is the address of the
36353614 * destination *)
@@ -3813,15 +3792,21 @@ class defaultCilPrinterClass : cilPrinter = object (self)
38133792
38143793 method private pStmtNext (next : stmt ) () (s : stmt ) =
38153794 (* print the labels *)
3816- ((docList ~sep: line (fun l -> self#pLabel () l)) () s.labels)
3817- (* print the statement itself. If the labels are non-empty and the
3818- * statement is empty, print a semicolon *)
3819- ++
3820- (if s.skind = Instr [] && s.labels <> [] then
3821- text " ;"
3822- else
3823- (if s.labels <> [] then line else nil)
3824- ++ self#pStmtKind next () s.skind)
3795+ let labels = ((docList ~sep: line (fun l -> self#pLabel () l)) () s.labels) in
3796+ if s.skind = Instr [] && s.labels <> [] then
3797+ (* If the labels are non-empty and the statement is empty, print a semicolon *)
3798+ labels ++ text " ;"
3799+ else
3800+ let pre =
3801+ if s.labels <> [] then
3802+ (match s.skind with
3803+ | Instr (VarDecl(_ )::_ )-> text " ;" (* first instruction is VarDecl, insert semicolon *)
3804+ | _ -> nil)
3805+ ++ line
3806+ else
3807+ nil (* no labels, no new line needed *)
3808+ in
3809+ labels ++ pre ++ self#pStmtKind next () s.skind
38253810
38263811 method private pLabel () = function
38273812 Label (s , _ , true ) -> text (s ^ " : " )
@@ -4248,7 +4233,7 @@ class defaultCilPrinterClass : cilPrinter = object (self)
42484233 | None -> self#pVDecl () vi ++ text " ;"
42494234 | Some i -> self#pVDecl () vi ++ text " = " ++
42504235 self#pInit () i ++ text " ;" )
4251- () f.slocals)
4236+ () ( List. filter ( fun v -> not v.vhasdeclinstruction) f.slocals) )
42524237 ++ line ++ line
42534238 (* the body *)
42544239 ++ ((* remember the declaration *) currentFormals < - f.sformals;
0 commit comments