@@ -11,6 +11,16 @@ fun transform_type typ = if typ = HOLogic.intT then "int"
...
@@ -11,6 +11,16 @@ fun transform_type typ = if typ = HOLogic.intT then "int"
else if typ = HOLogic.unitT then "unit"
else if typ = HOLogic.unitT then "unit"
else error "Unknownvariabletype"
else error "Unknownvariabletype"
local open C_AbsEnv HOLogic in
fun get_hol_type (C_Env.Parsed ret) params = let
val base_type =the (C11_TypeSpec_2_CleanTyp.conv_cDeclarationSpecifier_typ (SOME ret))
fun transform_type ((C_Ast.CArrDeclr0 _)::R) base_type = listT (transform_type R base_type)
| transform_type [] base_type = base_type
in transform_type params base_type end
fun map_env_ident_to_identifier (name,(positions,_,data)) =
case #functionArgs data of C_Ast.None => C_AbsEnv.Identifier(name, if null positions then @{here} else hd positions,get_hol_type (#ret data) (#params data),Global)
|_=> Identifier(name, @{here},intT,FunctionCategory (Final, NONE)) (*this line is wrong because of different function types*)
end
fun declare_function idents name ast ret_ty recursive ctxt =
fun declare_function idents name ast ret_ty recursive ctxt =
let val param_idents = filter (fn i => case i of C_AbsEnv.Identifier(_,_,_, C_AbsEnv.Parameter f_name) => f_name = name |_=>false) idents
let val param_idents = filter (fn i => case i of C_AbsEnv.Identifier(_,_,_, C_AbsEnv.Parameter f_name) => f_name = name |_=>false) idents
...
@@ -71,19 +81,10 @@ fun declare_function idents name ast ret_ty recursive ctxt =
...
@@ -71,19 +81,10 @@ fun declare_function idents name ast ret_ty recursive ctxt =
local open C_AbsEnv HOLogic in
local open C_AbsEnv HOLogic in
fun handle_declarations translUnit ctxt =
fun handle_declarations translUnit ctxt =
(let
(let
fun get_hol_type (C_Env.Parsed ret) params = let
val base_type =the (C11_TypeSpec_2_CleanTyp.conv_cDeclarationSpecifier_typ (SOME ret))
fun transform_type ((C_Ast.CArrDeclr0 _)::R) base_type = listT (transform_type R base_type)
| transform_type [] base_type = base_type
in transform_type params base_type end
fun map_prev_idents (name,(positions,_,data)) =
case #functionArgs data of C_Ast.None => C_AbsEnv.Identifier(name, if null positions then @{here} else hd positions,get_hol_type (#ret data) (#params data),Global)
|_=> Identifier(name, @{here},intT,FunctionCategory (Final, NONE)) (*this line is wrong because of different function types*)
val env = (C_Module.Data_Last_Env.get ctxt)
val env = (C_Module.Data_Last_Env.get ctxt)
(*First we need to get all previously defined global vars and functions*)
(*First we need to get all previously defined global vars and functions*)
val m = (Symtab.dest (#idents(#var_table(env))))
val m = (Symtab.dest (#idents(#var_table(env))))
val prev_idents =map map_prev_idents m
val prev_idents =map map_env_ident_to_identifier m
(*the new identifiers are returned in reverse \<rightarrow> thus reverse *)
(*the new identifiers are returned in reverse \<rightarrow> thus reverse *)
val (new_idents, call_table) = C_AbsEnv.parseTranslUnitIdentifiers translUnit [] prev_idents Symtab.empty
val (new_idents, call_table) = C_AbsEnv.parseTranslUnitIdentifiers translUnit [] prev_idents Symtab.empty
...
@@ -121,6 +122,24 @@ fun handle_declarations_wrapper ast v2 ctxt =
...
@@ -121,6 +122,24 @@ fun handle_declarations_wrapper ast v2 ctxt =