diff --git a/src/passeCodeRatToTam.ml b/src/passeCodeRatToTam.ml index 622f9ee..7e78c15 100644 --- a/src/passeCodeRatToTam.ml +++ b/src/passeCodeRatToTam.ml @@ -5,7 +5,6 @@ struct open Tds open Ast open AstType - open AstPlacement open Type open Code @@ -27,19 +26,16 @@ let rec getTailleAvant aff n = (res + (getTaille t), false) ) (0, false) l_typstr in tai - | _ -> failwith "TODO or not TODO" + | _ -> failwith "Internal Error" end - | Attribut(aff2, info) -> (** (A.c).x - avec A = (1 2 (3 4) 5) = (a b c d) - avec c = (x y) - ici A ~ aff2 | c ~ info | x ~ n *) + | Attribut(aff2, info) -> begin match info_ast_to_info info with - | InfoVar(n2, _, _, _) -> + | InfoVar(_, _, _, _) -> let t2 = getType aff2 in let aff_gen = Ident (info_to_info_ast (InfoVar("", t2, 0, ""))) in getTailleAvant aff_gen n - | _ -> failwith "adaidadj" + | _ -> failwith "Internal Error" end and getType aff = @@ -49,7 +45,7 @@ and getType aff = begin match info_ast_to_info info with | InfoVar(_, t, _, _) -> t - | _ -> failwith "prooblemo" + | _ -> failwith "Internal Error" end | Attribut(aff2, info) -> begin @@ -66,9 +62,9 @@ and getType aff = res ) Undefined l_typstr in t2 - | _ -> failwith "pas ok" + | _ -> failwith "Internal Error" end - | _ -> failwith "sproblematik" + | _ -> failwith "Internal Error" end and getTailleAttribut aff n = @@ -85,7 +81,7 @@ and getTailleAttribut aff n = else res ) l_typstr 0 - | _ -> failwith "TODO' or not TODO'" + | _ -> failwith "Internal Error" end | Attribut(_, _) -> getTaille (getType aff) @@ -96,7 +92,7 @@ and getBase aff = begin match info_ast_to_info i with | InfoVar(_, _, base, _) -> base - | _ -> failwith "spa bon" + | _ -> failwith "Internal Error" end | Attribut(a,i) -> begin @@ -106,7 +102,7 @@ and getBase aff = let ita = getTailleAvant aff n in let res = ib + ita in res - | _ -> failwith "v vhjbhki" + | _ -> failwith "Internal Error" end and getReg aff = @@ -116,7 +112,7 @@ and getReg aff = begin match info_ast_to_info i with | InfoVar(_, _, _, reg) -> reg - | _ -> failwith "spa bon" + | _ -> failwith "Internal Error" end | Attribut(a,_) -> getReg a @@ -138,7 +134,7 @@ and analyse_code_affectable a = match info_ast_to_info i with | InfoVar(_, t, base, reg) -> "LOAD (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n" | InfoConst(_,v) -> "LOADL " ^ (string_of_int v) ^ "\n" - | _ -> failwith "w-wtf bwo y-you okay -.-" + | _ -> failwith "Internal Error" end | Attribut(_, _) -> @@ -154,7 +150,7 @@ and analyse_code_expression e = | InfoFun(nom,_,_) -> (List.fold_right (fun e res -> analyse_code_expression e ^ res) le "") ^ "CALL (ST) " ^ nom ^ "\n" - | _ -> failwith "eeeeencore un pb" + | _ -> failwith "Internal Error" end | Booleen(b) -> @@ -201,7 +197,7 @@ and analyse_code_expression e = begin match info_ast_to_info i with | InfoVar(_, _, base, _) -> "LOADL " ^ (string_of_int base) ^ "\n" - | _ -> failwith "on a un pb" + | _ -> failwith "Internal Error" end | Tuple(l_expr) -> List.fold_right (fun e res -> analyse_code_expression e ^ res) l_expr "" @@ -217,7 +213,7 @@ and analyse_code_instruction i taille_return taille_args taille_var = "PUSH " ^ (string_of_int (getTaille t)) ^ "\n" ^ analyse_code_expression e ^ "STORE (" ^ (string_of_int (getTaille t)) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n" - | _ -> failwith "match non exautique" + | _ -> failwith "Internal Error" end | Affectation(a, e) -> @@ -229,7 +225,7 @@ and analyse_code_instruction i taille_return taille_args taille_var = | InfoVar (_, t, base, reg) -> (analyse_code_expression e) ^ "STORE (" ^ string_of_int (getTaille t) ^ ") " ^ (string_of_int base) ^ "[" ^ reg ^ "]\n" - | _ -> failwith "Erreur interne : symbole non reconnnu" + | _ -> failwith "Internal Error" end | Dref(a, t) -> @@ -246,9 +242,9 @@ and analyse_code_instruction i taille_return taille_args taille_var = | InfoVar(n, _, _, _) -> (analyse_code_expression e) ^ "STORE (" ^ (string_of_int (getTailleAttribut a n)) ^ ") " ^ (string_of_int (getBase a)) ^ "[" ^ reg ^ "]\n" - | _ -> failwith "toujours pas bonn" + | _ -> failwith "Internal Error" end - | _ -> failwith "toujours pas bon" + | _ -> failwith "Internal Error" end end @@ -321,20 +317,20 @@ and analyse_code_instruction i taille_return taille_args taille_var = "LOADL ' '\n" ^ "SUBR COut\n" ,taille + (getTaille t)) - | _ -> failwith "peut pas print des non printable, ofc" + | _ -> failwith "Internal Error" ) ("LOADL ' '\nSUBR COut\n", base) l_t in res end - | _ -> failwith "toujours pas bon ca" + | _ -> failwith "Internal Error" in - let rec affichage_expression e t = + let affichage_expression e t = let l_typstr = match t with | Struct(l_typstr) -> l_typstr - | _ -> failwith "wowowowow" + | _ -> failwith "Internal Error" in - let l_t, l_s = List.split l_typstr in + let l_t, _ = List.split l_typstr in match e with | Tuple(l_e) -> List.fold_right ( @@ -346,7 +342,7 @@ and analyse_code_instruction i taille_return taille_args taille_var = | Rat -> AffichageRat(e) | Pointeur(_) -> AffichagePointeur(e) | Struct(_) -> AffichageStruct(e, t) - | _ -> failwith "peut pas print des non printable, duh" + | _ -> failwith "Internal Error" in "LOADL ' '\n" ^ "SUBR COut\n" ^ @@ -357,21 +353,21 @@ and analyse_code_instruction i taille_return taille_args taille_var = | Affectable(a) -> begin match a with - | Dref(a,t) -> failwith "ok1" + | Dref(_, _) -> failwith "Internal Error" | Ident(i) -> begin match info_ast_to_info i with | InfoVar(_, t, base, reg) -> affichage base reg t - | _ -> failwith "spa bon" + | _ -> failwith "Internal Error" end - | Attribut(a2,i) -> + | Attribut(_, i) -> match info_ast_to_info i with - | InfoVar(n, t, _, _) -> + | InfoVar(_, t, _, _) -> let base = getBase a in let reg = getReg a in affichage base reg t - | _ -> failwith "zifj" + | _ -> failwith "Internal Error" end | AppelFonction(i, le) -> begin @@ -393,16 +389,16 @@ and analyse_code_instruction i taille_return taille_args taille_var = | Rat -> AffichageRat(Nothing) | Pointeur(_) -> AffichagePointeur(Nothing) | Struct(l_ts) -> AffichageStruct(Tuple(List.map (fun _ -> Nothing) l_ts), t) - | _ -> failwith "peut pas print des non printable, duuuh" + | _ -> failwith "Internal Error" in "LOADL ' '\n" ^ "SUBR COut\n" ^ (analyse_code_instruction i "0" "0" "0") ^ res ) l_typstr "LOADL ' '\nSUBR COut\n" *) - | _ -> failwith "bizreement pas ok" + | _ -> failwith "Internal Error" end - | _ -> failwith "spa cool ca" + | _ -> failwith "Internal Error" in "LOADL '{'\n" ^ @@ -416,20 +412,19 @@ and analyse_code_instruction i taille_return taille_args taille_var = let etiq2 = getEtiquette () in (analyse_code_expression e) ^ "JUMPIF (0) " ^ etiq1 ^ "\n" ^ - (analyse_code_bloc b1 taille_return taille_args taille_var) ^ + (analyse_code_bloc b1 taille_return taille_args) ^ "JUMP " ^ etiq2 ^ "\n" ^ etiq1 ^ "\n" ^ - (analyse_code_bloc b2 taille_return taille_args taille_var) ^ + (analyse_code_bloc b2 taille_return taille_args) ^ etiq2 ^ "\n" | TantQue(e, b) -> - let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) b 0) in let etiq_while = getEtiquette () in let etiq_fin = getEtiquette () in etiq_while ^ "\n" ^ (analyse_code_expression e) ^ "JUMPIF (0) " ^ etiq_fin ^ "\n" ^ - (analyse_code_bloc b taille_return taille_args taille_var) ^ + (analyse_code_bloc b taille_return taille_args) ^ "JUMP " ^ etiq_while ^ "\n" ^ etiq_fin ^ "\n" @@ -440,7 +435,7 @@ and analyse_code_instruction i taille_return taille_args taille_var = | Empty -> "" -and analyse_code_bloc bloc taille_return taille_args taille_var = +and analyse_code_bloc bloc taille_return taille_args = let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) bloc 0) in List.fold_right ( fun i res -> (analyse_code_instruction i taille_return taille_args taille_var) ^ res @@ -450,19 +445,18 @@ and analyse_code_bloc bloc taille_return taille_args taille_var = and analyse_code_fonction (AstPlacement.Fonction(info, _, bloc)) = match info_ast_to_info info with | InfoFun(name, t, l_t) -> - let taille_var = string_of_int (List.fold_right (fun e res -> taille_variables_declarees e + res) bloc 0) in let taille_return = string_of_int (getTaille t) in let taille_args = string_of_int (List.fold_right (fun e res -> getTaille e + res) l_t 0) in name ^ "\n" ^ - (analyse_code_bloc bloc taille_return taille_args taille_var) ^ + (analyse_code_bloc bloc taille_return taille_args) ^ "HALT\n" - | _ -> failwith "spa normal" + | _ -> failwith "Internal Error" let analyser (AstPlacement.Programme(fonctions, prog)) = let code = getEntete () in let code = code ^ List.fold_right (fun e res -> (analyse_code_fonction e) ^ res) fonctions "" in let code = code ^ "main\n" in - let code = code ^ (analyse_code_bloc prog "0" "0" "0") in + let code = code ^ (analyse_code_bloc prog "0" "0") in code ^ "\nHALT" end diff --git a/src/passePlacementRat.ml b/src/passePlacementRat.ml index 18bb6d0..9e58bb4 100644 --- a/src/passePlacementRat.ml +++ b/src/passePlacementRat.ml @@ -4,7 +4,6 @@ struct open Tds open Ast - open AstType open AstPlacement open Type @@ -21,7 +20,7 @@ let rec analyse_placement_instruction i base reg = let taille = getTaille t in modifier_adresse_info base reg info; taille - | _ -> failwith "wtf frère" + | _ -> failwith "Internal Error" end | AstType.Conditionnelle(_, b1, b2) -> @@ -49,7 +48,7 @@ and analyse_placement_fonction (AstType.Fonction(info, l_typinfo, bloc)) = | InfoVar(_,t,_,_) -> modifier_adresse_info (res_q - (getTaille t)) "LB" x; res_q - (getTaille t) - | _ -> failwith "pas normal" + | _ -> failwith "Internal Error" end ) l_typinfo 0 in let _ = analyse_placement_bloc 3 "LB" bloc in diff --git a/src/passeTdsRat.ml b/src/passeTdsRat.ml index e6b2c8e..2b75bc3 100644 --- a/src/passeTdsRat.ml +++ b/src/passeTdsRat.ml @@ -11,7 +11,23 @@ struct type t1 = Ast.AstSyntax.programme type t2 = Ast.AstTds.programme - +(* + recherche_type: + tds -> typ -> typ + Description: + Permet d'obtenir le type d'un typedef + Parameters: + - tds : la table des symboles que l'on souhaite cherche + - t : le type que l'on cherche + Returns: + Le type d'un typedef + Pre-conditions: + - True + Post-conditions: + - True + Exceptions: + - IdentifiantNonDeclare +*) let rec recherche_type tds t = match t with | TIdent(t_nom) -> @@ -22,19 +38,33 @@ let rec recherche_type tds t = begin match info_ast_to_info i with | InfoType(_, t2) -> recherche_type tds t2 - | _ -> failwith "un truc louche ca" + | _ -> failwith "Internal Error" end end - | _ -> - begin - match t with - | Struct (l_typstr) -> + | Struct (l_typstr) -> let n_l_typstr = (List.map (fun (t, n) -> (recherche_type tds t, n)) l_typstr) in Struct n_l_typstr - | _ -> t - end - + | _ -> t +(* + analyse_tds_affectable: + tds -> AstSyntax.affectable -> bool -> AstTds.affectable + Description: + Transforme les affectable de l'AstSyntax en AstTds + Parameters: + - tds : la table des symboles courante + - a : l'affectable à analyser + - modif : permet de savoir s'il sagit d'un affectable dans une expression ou dans une affectation + Returns: + Un nouvel AstTds.affectable + Pre-conditions: + - True + Post-conditions: + - True + Exceptions: + - IdentifiantNonDeclare + - MauvaiseUtilisationIdentifiant +*) let rec analyse_tds_affectable tds a modif = match a with | AstSyntax.Dref new_aff -> @@ -52,21 +82,38 @@ let rec analyse_tds_affectable tds a modif = | InfoConst _ -> begin if modif then - failwith "bah non en fait" + failwith "Internal Error" else AstTds.Ident(info) end - | InfoFun _ -> raise (MauvaiseUtilisationIdentifiant(n)) + | InfoFun _ -> (* On ne peut pas utiliser une fonction comme affectable *) + raise (MauvaiseUtilisationIdentifiant(n)) + | _ -> failwith "Internal Error" end end | AstSyntax.Attribut(aff, str) -> + (* + extraction_info: + affectable -> info_ast + Description: + Extrait l'info d'un affectable + Parameters: + - aff : Affectable dont on veut extraire l'info + Returns: + L'info de l'affectable + Pre-conditions: + - True + Post-conditions: + - True + *) let rec extraction_info aff = match aff with | Dref(aff2) -> extraction_info aff2 | Ident(info) -> info - | Attribut(aff2, info) -> info + | Attribut(_, info) -> info in + let n_aff = analyse_tds_affectable tds aff modif in let info = extraction_info n_aff in match info_ast_to_info info with @@ -77,60 +124,69 @@ let rec analyse_tds_affectable tds a modif = let t = List.fold_right (fun (t, n) res -> if str = n then t else res) l_att Undefined in if t != Undefined then AstTds.Attribut(n_aff, info_to_info_ast (InfoVar(str, t, 0, ""))) - else + else (** L'attribut ne correspond à aucun attribut du struct *) raise (MauvaiseUtilisationIdentifiant str) - | _ -> - let _ = print_endline (string_of_type t) in - raise (MauvaiseUtilisationIdentifiant str) - end + | _ -> (** Il faut que l'objet sur le quel on appelle l'attribut soit un struct *) + raise (MauvaiseUtilisationIdentifiant str) + end (** Ce ne peut etre qu'un InfoVar *) | _ -> raise (MauvaiseUtilisationIdentifiant str) -(* analyse_tds_expression : AstSyntax.expression -> AstTds.expression *) -(* Paramètre tds : la table des symboles courante *) -(* Paramètre e : l'expression à analyser *) -(* Vérifie la bonne utilisation des identifiants et tranforme l'expression -en une expression de type AstTds.expression *) -(* Erreur si mauvaise utilisation des identifiants *) +(* + analyse_tds_affectable: + tds -> AstSyntax.expression -> AstTds.expression + Description: + Vérifie la bonne utilisation des identifiants et transforme les expressions de l'AstSyntax en AstTds + Parameters: + - tds : la table des symboles courante + - e : l'expression à analyser + Returns: + Une nouvelle AstTds.expression + Pre-conditions: + - True + Post-conditions: + - True + Exceptions: + - IdentifiantNonDeclare + - MauvaiseUtilisationIdentifiant +*) let rec analyse_tds_expression tds e = match e with | AstSyntax.AppelFonction(str, l_expr) -> begin match chercherGlobalement tds str with - (* L'identifiant est déja déclaré *) - | None -> raise (IdentifiantNonDeclare str) + + | None -> (* L'identifiant est déja déclaré *) + raise (IdentifiantNonDeclare str) | Some info -> match (info_ast_to_info info) with - | InfoFun(_, _, _) -> + | InfoFun(_, _, _) -> let nl_expr = List.map (fun e -> analyse_tds_expression tds e) l_expr in AstTds.AppelFonction(info, nl_expr) - (* L'identifiant ne fait pas référence à une fonction, on lève ue exception *) - | _ -> raise (MauvaiseUtilisationIdentifiant str) + | _ -> (* L'identifiant ne fait pas référence à une fonction, on lève une exception *) + raise (MauvaiseUtilisationIdentifiant str) end - | AstSyntax.Booleen(b) -> - begin - AstTds.Booleen(b) - end - | AstSyntax.Entier(i) -> - begin - AstTds.Entier(i) - end + | AstSyntax.Booleen(b) -> AstTds.Booleen(b) + + | AstSyntax.Entier(i) -> AstTds.Entier(i) + | AstSyntax.Unaire(u, expr) -> - begin - let new_expr = analyse_tds_expression tds expr in - AstTds.Unaire (u, new_expr) - end + let new_expr = analyse_tds_expression tds expr in + AstTds.Unaire (u, new_expr) + | AstSyntax.Binaire(b, expr_1, expr_2) -> - begin - let new_expr_1 = analyse_tds_expression tds expr_1 in - let new_expr_2 = analyse_tds_expression tds expr_2 in - AstTds.Binaire(b, new_expr_1, new_expr_2) - end + let new_expr_1 = analyse_tds_expression tds expr_1 in + let new_expr_2 = analyse_tds_expression tds expr_2 in + AstTds.Binaire(b, new_expr_1, new_expr_2) + | AstSyntax.Affectable(a) -> AstTds.Affectable(analyse_tds_affectable tds a false) + | AstSyntax.Null -> AstTds.Null + | AstSyntax.NewType(t) -> AstTds.NewType(t) + | AstSyntax.Adresse(n) -> let info = chercherGlobalement tds n in begin @@ -144,22 +200,37 @@ let rec analyse_tds_expression tds e = | _ -> raise (MauvaiseUtilisationIdentifiant(n)) end end + | AstSyntax.Tuple(le) -> let n_le = List.map (fun e -> analyse_tds_expression tds e) le in AstTds.Tuple(n_le) -let rec analyse_tds_typedef tds (AstSyntax.TypeDef(n, t)) = + +(* + analyse_tds_typedef: + tds -> AstSyntax.typedef -> AstTds.instruction + Description: + Transforme les typedef de l'AstSyntax en AstTds.instructions + Parameters: + - tds : la table des symboles courante + - td : le typedef à analyser + Returns: + Une nouvelle AstTds.affectable + Pre-conditions: + - True + Post-conditions: + - True + Exceptions: + - DoubleDeclaration +*) +let analyse_tds_typedef tds (AstSyntax.TypeDef(n, t)) = begin match chercherLocalement tds n with - | None -> - (* L'identifiant n'est pas trouvé dans la tds locale, - il n'a donc pas été déclaré dans le bloc courant *) - (* Ajout dans la tds de la constante *) + | None -> (* L'identifiant n'est pas trouvé dans la tds locale du bloc, on ajoute donc dans la tds la constante *) ajouter tds n (info_to_info_ast (InfoType (n, t))); Empty - | Some _ -> - (* L'identifiant est trouvé dans la tds locale, - il a donc déjà été déclaré dans le bloc courant *) + + | Some _ -> (* L'identifiant est trouvé dans la tds locale, il a donc double déclaration *) raise (DoubleDeclaration n) end @@ -169,109 +240,130 @@ let rec analyse_tds_typedef tds (AstSyntax.TypeDef(n, t)) = (* Vérifie la bonne utilisation des identifiants et tranforme l'instruction en une instruction de type AstTds.instruction *) (* Erreur si mauvaise utilisation des identifiants *) +(* + analyse_tds_typedef: + tds -> AstSyntax.typedef -> AstTds.instruction + Description: + Transforme les typedef de l'AstSyntax en AstTds.instructions + Parameters: + - tds : la table des symboles courante + - td : le typedef à analyser + Returns: + Une nouvelle AstTds.affectable + Pre-conditions: + - True + Post-conditions: + - True + Exceptions: + - DoubleDeclaration +*) let rec analyse_tds_instruction tds i = match i with | AstSyntax.Declaration (t, n, e) -> begin match chercherLocalement tds n with - | None -> + | None -> (* L'identifiant n'est pas trouvé dans la tds locale, il n'a donc pas été déclaré dans le bloc courant *) let nt = recherche_type tds t in - (* L'identifiant n'est pas trouvé dans la tds locale, - il n'a donc pas été déclaré dans le bloc courant *) - (* Vérification de la bonne utilisation des identifiants dans l'expression *) - (* et obtention de l'expression transformée *) + + (* Vérification de la bonne utilisation des identifiants dans l'expression et obtention de l'expression transformée *) let ne = analyse_tds_expression tds e in + (* Création de l'information associée à l'identfiant *) let info = InfoVar (n, nt, 0, "") in + (* Création du pointeur sur l'information *) let ia = info_to_info_ast info in + (* Ajout de l'information (pointeur) dans la tds *) ajouter tds n ia; - (* Renvoie de la nouvelle déclaration où le nom a été remplacé par l'information - et l'expression remplacée par l'expression issue de l'analyse *) - + + (* Renvoie de la nouvelle déclaration où le nom a été remplacé par l'information et l'expression remplacée par l'expression issue de l'analyse *) AstTds.Declaration (nt, ia, ne) - | Some _ -> - (* L'identifiant est trouvé dans la tds locale, - il a donc déjà été déclaré dans le bloc courant *) + + | Some _ -> (* L'identifiant est trouvé dans la tds locale, il a donc déjà été déclaré dans le bloc courant *) raise (DoubleDeclaration n) end + | AstSyntax.Affectation (aff, e) -> begin let ne = analyse_tds_expression tds e in let n_a = analyse_tds_affectable tds aff false in match aff with - | Dref a -> - Affectation (n_a, ne) - - | Ident(n) -> - begin - match chercherGlobalement tds n with - | None -> - (* L'identifiant n'est pas trouvé dans la tds globale. *) - raise (IdentifiantNonDeclare n) - | Some info -> - (* L'identifiant est trouvé dans la tds globale, - il a donc déjà été déclaré. L'information associée est récupérée. *) - begin - match info_ast_to_info info with - | InfoVar _ -> - (* Renvoie de la nouvelle affectation où le nom a été remplacé par l'information - et l'expression remplacée par l'expression issue de l'analyse *) - Affectation (n_a, ne) - | _ -> - (* Modification d'une constante ou d'une fonction *) - raise (MauvaiseUtilisationIdentifiant n) - end - end - | Attribut(aff2, n) -> - begin - (** RAF *) - Affectation(n_a, ne) - end + | Dref _ -> + Affectation (n_a, ne) + + | Ident(n) -> + begin + match chercherGlobalement tds n with + | None -> (* L'identifiant n'est pas trouvé dans la tds globale. *) + raise (IdentifiantNonDeclare n) + + | Some info -> (* L'identifiant est trouvé dans la tds globale, il a donc déjà été déclaré. L'information associée est récupérée. *) + begin + match info_ast_to_info info with + | InfoVar _ -> (* Renvoie de la nouvelle affectation où le nom a été remplacé par l'information et l'expression remplacée par l'expression issue de l'analyse *) + Affectation (n_a, ne) + + | _ -> (* Modification d'une constante ou d'une fonction *) + raise (MauvaiseUtilisationIdentifiant n) + end + end + | Attribut(_, _) -> (* RAF *) + Affectation(n_a, ne) end + | AstSyntax.Constante (n,v) -> begin match chercherLocalement tds n with - | None -> - (* L'identifiant n'est pas trouvé dans la tds locale, - il n'a donc pas été déclaré dans le bloc courant *) - (* Ajout dans la tds de la constante *) - ajouter tds n (info_to_info_ast (InfoConst (n,v))); - (* Suppression du noeud de déclaration des constantes devenu inutile *) - Empty - | Some _ -> - (* L'identifiant est trouvé dans la tds locale, - il a donc déjà été déclaré dans le bloc courant *) + | None -> (* L'identifiant n'est pas trouvé dans la tds locale, il n'a donc pas été déclaré dans le bloc courant *) + + (* Ajout dans la tds de la constante *) + ajouter tds n (info_to_info_ast (InfoConst (n,v))); + + (* Suppression du noeud de déclaration des constantes devenu inutile *) + Empty + + | Some _ -> (* L'identifiant est trouvé dans la tds locale, il a donc déjà été déclaré dans le bloc courant *) raise (DoubleDeclaration n) end + | AstSyntax.Affichage e -> - (* Vérification de la bonne utilisation des identifiants dans l'expression *) - (* et obtention de l'expression transformée *) + (* Vérification de la bonne utilisation des identifiants dans l'expression et obtention de l'expression transformée *) let ne = analyse_tds_expression tds e in + (* Renvoie du nouvel affichage où l'expression remplacée par l'expression issue de l'analyse *) Affichage (ne) + | AstSyntax.Conditionnelle (c,t,e) -> (* Analyse de la condition *) let nc = analyse_tds_expression tds c in + (* Analyse du bloc then *) let tast = analyse_tds_bloc tds t in + (* Analyse du bloc else *) let east = analyse_tds_bloc tds e in + (* Renvoie la nouvelle structure de la conditionnelle *) Conditionnelle (nc, tast, east) + | AstSyntax.TantQue (c,b) -> (* Analyse de la condition *) let nc = analyse_tds_expression tds c in + (* Analyse du bloc *) let bast = analyse_tds_bloc tds b in + (* Renvoie la nouvelle structure de la boucle *) TantQue (nc, bast) + | AstSyntax.Retour (e) -> (* Analyse de l'expression *) let ne = analyse_tds_expression tds e in Retour (ne) + | AstSyntax.LocalTypeDef(td) -> + (* Analyse du typedef *) analyse_tds_typedef tds td @@ -309,9 +401,6 @@ let analyse_tds_fonction maintds (AstSyntax.Fonction(t, str, l_typstr, bloc)) = | Some _ -> raise (DoubleDeclaration str) | None -> begin - (* Info de l'identifiant de la fonction *) - let info = Tds.InfoVar(str, Undefined, 0, "") in - (* Copie de la tds globale dans la tds locale au bloc *) let tds_bloc = creerTDSFille maintds in diff --git a/src/passeTypeRat.ml b/src/passeTypeRat.ml index 0e4b64a..26a7794 100644 --- a/src/passeTypeRat.ml +++ b/src/passeTypeRat.ml @@ -18,15 +18,14 @@ let rec analyse_type_affectable a = begin match (analyse_type_affectable a) with | (na, Pointeur t) -> (AstType.Dref(na, t), t) - | _ -> failwith "jsp koi mettre ici" + | _ -> failwith "Internal Error" end | AstTds.Ident(info) -> begin match info_ast_to_info info with | InfoVar(_, t, _, _) -> (AstType.Ident(info), t) | InfoConst _ -> (AstType.Ident(info), Int) - | InfoFun _ -> failwith "c chelou frr" - | InfoType _ -> failwith "c koi le pb encore" + | _ -> failwith "Internal Error" end | AstTds.Attribut(aff, info) -> begin @@ -34,7 +33,7 @@ let rec analyse_type_affectable a = match info_ast_to_info info with | InfoVar(_, t, _, _) -> (AstType.Attribut(n_aff, info), t) - | _ -> failwith "heuuuu wtf, c cringe" + | _ -> failwith "Internal Error" end @@ -55,7 +54,7 @@ let rec analyse_type_expression e = (AstType.AppelFonction(info, n_l_expr), t) else raise (TypesParametresInattendus(l_type_fun, l_type)) - | _ -> failwith "pas normal" + | _ -> failwith "Internal Error" end | AstTds.Unaire(u, expr) -> @@ -105,7 +104,7 @@ let rec analyse_type_expression e = | InfoVar(_, t, _, _) -> let _ = modifier_type_info (Pointeur(t)) info in (AstType.Adresse(info), Pointeur(t)) - | _ -> failwith "FAIII with" + | _ -> failwith "Internal Error" end | AstTds.Tuple(l_expr) -> @@ -135,8 +134,8 @@ let rec analyse_type_instruction opt i = | Dref a -> begin match (analyse_type_affectable a) with - | (na, Pointeur t) -> AstType.Affectation(na, ne) - | _ -> failwith "jsp koi mettre ici" + | (na, Pointeur _) -> AstType.Affectation(na, ne) + | _ -> failwith "Internal Error" end | AstTds.Ident info -> begin @@ -146,7 +145,7 @@ let rec analyse_type_instruction opt i = AstType.Affectation(AstType.Ident(info), ne) else raise (TypeInattendu(nt, t)) - | _ -> failwith "wut" + | _ -> failwith "Internal Error" end | AstTds.Attribut(aff2, info) -> begin @@ -157,7 +156,7 @@ let rec analyse_type_instruction opt i = AstType.Affectation(Attribut(na, info), ne) else raise (TypeInattendu(nt, t)) - | _ -> failwith "pas bon du tout" + | _ -> failwith "Internal Error" end end @@ -170,7 +169,7 @@ let rec analyse_type_instruction opt i = | Bool -> AstType.AffichageBool(ne) | Pointeur _ -> AstType.AffichagePointeur(ne) | Struct _ -> AstType.AffichageStruct(ne, nt) - | _ -> failwith "un truc chelou" + | _ -> failwith "Internal Error" end | AstTds.Conditionnelle (e, b1, b2) -> @@ -203,7 +202,7 @@ let rec analyse_type_instruction opt i = AstType.Retour(ne) else raise (TypeInattendu(nt, t)) - | None -> failwith "Pas de return dans le main" + | None -> failwith "Internal Error" end | AstTds.Empty -> AstType.Empty @@ -244,7 +243,7 @@ let analyse_type_fonction opt (AstTds.Fonction(t, info, l_typinfo, bloc)) = end else raise (TypeInattendu(t, t_ret)) - | None -> failwith "Il faut un return dans une fonction" + | None -> failwith "Internal Error" (* analyser : AstTds.ast -> AstType.ast *) diff --git a/src/printerAst.ml b/src/printerAst.ml index c6d4ecc..9840214 100644 --- a/src/printerAst.ml +++ b/src/printerAst.ml @@ -55,6 +55,7 @@ struct match a with | AstSyntax.Dref(n) -> (string_of_affectable n) | AstSyntax.Ident(n) -> n ^ " " + | _ -> "" (* Conversion des expressions *) let rec string_of_expression e = @@ -69,6 +70,7 @@ struct | Fraction -> "["^(string_of_expression e1)^"/"^(string_of_expression e2)^"] " | _ -> (string_of_expression e1)^(string_of_binaire b)^(string_of_expression e2)^" " end + |_ -> "" let string_of_typedef (TypeDef(n, t)) = n ^ "->" ^ (string_of_type t) ^ "\n"