From 0170403fc67f25f2f45566d49e0368ac1ebb255b Mon Sep 17 00:00:00 2001 From: Guillotin Damien Date: Wed, 24 Nov 2021 19:22:01 +0100 Subject: [PATCH] tp2 DONE --- src/passeTdsRat.ml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/passeTdsRat.ml b/src/passeTdsRat.ml index 343f5af..ef48283 100644 --- a/src/passeTdsRat.ml +++ b/src/passeTdsRat.ml @@ -23,15 +23,24 @@ let rec analyse_tds_expression tds e = begin match chercherGlobalement tds str with | None -> raise (IdentifiantNonDeclare str) - | Some (InfoFun(str, typ, l_typ)) -> - let nl_expr = List.map (fun e -> analyse_tds_expression tds e) l_expr in - AstTds.AppelFonction((InfoFun(str, typ, l_typ)), nl_expr) + | Some info -> + match (info_ast_to_info info) with + | InfoFun(_, _, _) -> + let nl_expr = List.map (fun e -> analyse_tds_expression tds e) l_expr in + AstTds.AppelFonction(info, nl_expr) + | _ -> raise (MauvaiseUtilisationIdentifiant str) end | AstSyntax.Ident(str) -> begin match chercherGlobalement tds str with | None -> raise (IdentifiantNonDeclare str) - | Some info -> AstTds.Ident(info) + | Some info -> + match (info_ast_to_info info) with + | InfoVar(_, _, _, _) -> + AstTds.Ident(info) + | InfoConst(_, v) -> + AstTds.Entier(v) + | _ -> raise (MauvaiseUtilisationIdentifiant str) end | AstSyntax.Booleen(b) -> begin @@ -186,16 +195,21 @@ let analyse_tds_fonction maintds (AstSyntax.Fonction(t, str, l_typstr, bloc)) = | None -> begin let info = Tds.InfoVar(str, Undefined, 0, "") in - let tds_bloc = maintds in (* tds_bloc doit inclure les nouveaux éléments passés en paramètre *) - let unit_l = (List.map ( + let tds_bloc = creerTDSFille maintds in + let _ = (List.map ( fun (_, nom) -> - ajouter tds_bloc nom (info_to_info_ast (Tds.InfoVar(nom, Undefined, 0, ""))) + match chercherLocalement tds_bloc nom with + | None -> ajouter tds_bloc nom (info_to_info_ast (Tds.InfoVar(nom, Undefined, 0, ""))) + | Some _ -> raise (DoubleDeclaration nom) ) l_typstr) in + let _ = ajouter tds_bloc str (info_to_info_ast (Tds.InfoFun(str, t, (List.map (fun (t, _) -> t) l_typstr)))) in let new_bloc = analyse_tds_bloc tds_bloc bloc in let nl_typinfo = List.map ( fun (t, str2) -> ( t, info_to_info_ast (Tds.InfoVar(str2, Undefined, 0, "")) ) ) l_typstr in + let info_fun = InfoFun(str, t, (List.map (fun (t, _) -> t) l_typstr)) in + ajouter maintds str (info_to_info_ast info_fun); AstTds.Fonction(t, (info_to_info_ast info), nl_typinfo, new_bloc) end end