Commits

Corentin Derbois  committed a9efb33

Add main.c work!

  • Participants
  • Parent commits 535524f

Comments (0)

Files changed (2)

File src/prettyprint.ml

     
     inherit Visitor.visitor as old
 
-    method accept_function_definition a b c d =
-      print_endline ("Function: " ^ (this#getFuncName (Visitor.getValue b)));
-      old#accept_function_definition a b c d
+    method accept_primary_expression t = match t with
+	      Ast.PE_IDENTIFIER (a) -> print_string a
+	    | Ast.PE_CONSTANT (a) -> print_string a
+	    | Ast.PE_STRING_LITERAL (a) -> print_string a
+	    | Ast.PE_Expression (a) -> () (* FIXME *)
+
+    method accept_jump_statement t = match t with
+	      Ast.JS_GOTO (str)     -> print_endline ("goto " ^ str ^ ";")
+      | Ast.JS_CONTINUE     -> print_endline ("continue;")
+      | Ast.JS_BREAK        -> print_endline ("break;")
+      | Ast.JS_RETURN_NONE  -> print_endline ("return;")
+      | Ast.JS_RETURN (exp) ->
+          begin
+            print_string "return ";
+            this#visite_expression exp;
+            print_endline ";"
+          end
+
+    method accept_type_specifier t = match t with
+        Ast.TYPE_VOID -> print_string "void"
+	    | Ast.TYPE_CHAR -> print_string "char"
+	    | Ast.TYPE_SHORT -> print_string "short"
+	    | Ast.TYPE_INT -> print_string "int"
+	    | Ast.TYPE_LONG -> print_string "long"
+	    | Ast.TYPE_FLOAT -> print_string "float"
+	    | Ast.TYPE_DOUBLE -> print_string "double"
+	    | Ast.TYPE_SIGNED -> print_string "signed"
+	    | Ast.TYPE_UNSIGNED -> print_string "unsigned"
+	    | Ast.TYPE_struct(a) -> () (* FIXME *)
+	    | Ast.TYPE_enum(a) -> () (* FIXME *)
+	    | Ast.TYPE_TYPE_NAME -> () (* FIXME *)
+
+
+    method accept_compound_statement dl sl =
+      print_endline ("{");
+      old#accept_compound_statement dl sl;
+      print_endline ("}")
+
+    method accept_direct_declarator ast = match ast with
+	      Ast.DIDE_id (a) -> print_string a
+	    | Ast.DIDE_dec (a) -> raise (Visitor.NotImplemented "DIDE_dec")
+	    | Ast.DIDE_cro_const (a,b) -> raise (Visitor.NotImplemented "DIDE_cro_const")
+	    | Ast.DIDE_void_cro (a) -> raise (Visitor.NotImplemented "DIDE_void_cro")
+	    | Ast.DIDE_param_list (a,b) ->
+          begin
+            this#visite_direct_declarator a;
+            print_string "(";
+            this#visite_parameter_type_list b;
+            print_string ")"
+          end
+	    | Ast.DIDE_id_list (a,b) -> raise (Visitor.NotImplemented "DIDE_id_list")
+	    | Ast.DIDE_void_para (a) -> raise (Visitor.NotImplemented "DIDE_void_para")
+
 
   end
 

File src/visitor.ml

 (***************** Accept method for overriding ***********************)
 
     
-method accept_primary_expression = ()
+method accept_primary_expression (ast:Ast.primary_expression) = ()
 
 method accept_postfix_expression = ()
 	
 
 method accept_storage_class_specifier = ()
 
-method accept_type_specifier = ()
+method accept_type_specifier ast = ()
 
 method accept_struct_or_union_specifier = ()
 
 	
 method accept_declarator = ()
 
-method accept_direct_declarator = ()
+method accept_direct_declarator (ast:Ast.direct_declarator) =  ()
 
 method accept_pointer = ()
 
 
 method accept_labeled_statement = ()
 
-method accept_compound_statement = ()
+method accept_compound_statement dl sl =
+  if (dl <> None) then this#visite_declaration_list (getValue dl);
+  if (sl <> None) then this#visite_statement_list (getValue sl)
 
 method accept_declaration_list = ()
 
 
 method accept_iteration_statement = ()
 
-method accept_jump_statement = ()
+method accept_jump_statement (ast:Ast.jump_statement) = ()
 
     (* Complet this accept *)
 method accept_function_definition decspe dec dec_list cs =
-  ();
-  if (decspe <> None) then ();
-  if (dec_list <> None) then (); (* FIXME *)
-  ()
+  this#visite_declaration_specifiers (getValue decspe);
+  if (decspe <> None) then this#visite_declarator (getValue dec);
+  if (dec_list <> None) then this#visite_declaration_list (getValue dec_list);
+  this#visite_compound_statement (getValue cs)
 
   (* useless ? *)
 method accept_external_declaration = ()
 
 (************************ Visite method *******************************)
 
-method visite_primary_expression ast = match ast with
-	  Ast.PE_IDENTIFIER (a) -> ()
-	| Ast.PE_CONSTANT (a) -> ()
-	| Ast.PE_STRING_LITERAL (a) -> ()
-	| Ast.PE_Expression (a) -> ()
-	
+method visite_primary_expression ast = 
+  this#accept_primary_expression ast	
 
 method visite_postfix_expression ast = match ast with
-	  Ast.PE_pri_exp (a) -> ()
+	  Ast.PE_pri_exp (a) -> this#visite_primary_expression a
 	| Ast.PE_exp (a,b) -> ()
 	| Ast.PE_empty (a) -> ()
 	| Ast.PE_arg_exp_list (a,b) -> ()
 	
 
 method visite_unary_expression ast = match ast with
-	  Ast.UE_post_exp (a) -> ()
+	  Ast.UE_post_exp (a) -> this#visite_postfix_expression a
 	| Ast.UE_inc (a) -> ()
 	| Ast.UE_dec (a) -> ()
 	| Ast.UE_cast (a,b) -> ()
 	
 
 method visite_cast_expression ast = match ast with
-	  Ast.CA_unary_expression (a) -> ()
+	  Ast.CA_unary_expression (a) -> this#visite_unary_expression a
 	| Ast.CA_type (a,b) -> ()
 	
 
 method visite_multiplicative_expression ast = match ast with
-	  Ast.ME_exp (a) -> ()
+	  Ast.ME_exp (a) -> this#visite_cast_expression a
 	| Ast.ME_fois (a,b) -> ()
 	| Ast.ME_div (a,b) -> ()
 	| Ast.ME_pourcent (a,b) -> ()
 	
 
 method visite_additive_expression ast = match ast with
-	  Ast.AE_exp (a) -> ()
+	  Ast.AE_exp (a) -> this#visite_multiplicative_expression a
 	| Ast.AE_plus (a,b) -> ()
 	| Ast.AE_moin (a,b) -> ()
 	
 
 method visite_shift_expression ast = match ast with
-	  Ast.SE_exp (a) -> ()
+	  Ast.SE_exp (a) -> this#visite_additive_expression a
 	| Ast.SE_left (a,b) -> ()
 	| Ast.SE_right (a,b) -> ()
 	
 
 method visite_relational_expression ast = match ast with
-	  Ast.RE_exp (a) -> ()
+	  Ast.RE_exp (a) -> this#visite_shift_expression a
 	| Ast.RE_left (a,b) -> ()
 	| Ast.RE_right (a,b) -> ()
 	| Ast.RE_less (a,b) -> ()
 	
 
 method visite_equality_expression ast = match ast with
-	  Ast.EE_exp (a) -> ()
+	  Ast.EE_exp (a) -> this#visite_relational_expression a
 	| Ast.EE_eq (a,b) -> ()
 	| Ast.EE_ne (a,b) -> ()
 	
 
 method visite_and_expression ast = match ast with
-	  Ast.ANE_eq (a) -> ()
+	  Ast.ANE_eq (a) -> this#visite_equality_expression a
 	| Ast.ANE_and (a,b) -> ()
 	
 
 method visite_exclusive_or_expression ast = match ast with
-	  Ast.EXEX_and (a) -> ()
+	  Ast.EXEX_and (a) -> this#visite_and_expression a
 	| Ast.EXEX_circon (a,b) -> ()
 	
 
 method visite_inclusive_or_expression ast = match ast with
-	  Ast.INE_exp (a) -> ()
+	  Ast.INE_exp (a) -> this#visite_exclusive_or_expression a
 	| Ast.INE_pipe (a,b) -> ()
 	
 
 method visite_logical_and_expression ast = match ast with
-	  Ast.LAE_exp (a) -> ()
+	  Ast.LAE_exp (a) -> this#visite_inclusive_or_expression a
 	| Ast.LAE_and (a,b) -> ()
 	
 
 method visite_logical_or_expression ast = match ast with
-	  Ast.LOE_exp (a) -> ()
+	  Ast.LOE_exp (a) -> this#visite_logical_and_expression a
 	| Ast.LOE_or (a,b) -> ()
 	
 
 method visite_conditional_expression ast = match ast with
-	  Ast.COE_exp (a) -> ()
+	  Ast.COE_exp (a) -> this#visite_logical_or_expression a
 	| Ast.COE_int (a,b,c) -> ()
 	
 
 method visite_assignment_expression ast = match ast with
-	  Ast.ASE_exp (a) -> ()
+	  Ast.ASE_exp (a) -> this#visite_conditional_expression a
 	| Ast.ASE_op (a,b,c) -> ()
 	
 
 	
 
 method visite_expression ast = match ast with
-	  Ast.E_exp (a) -> ()
+	  Ast.E_exp (a) -> this#visite_assignment_expression a
 	| Ast.E_list (a,b) -> ()
 	
 
 	
 
 method visite_declaration_specifiers ast = match ast with
-	  Ast.DES_class (a) -> ()
-	| Ast.DES_class_dec (a,b) -> ()
-	| Ast.DES_type (a) -> ()
-	| Ast.DES_type_dec (a,b) -> ()
-	| Ast.DES_type_qua (a) -> ()
-	| Ast.DES_type_qua_dec (a,b) -> ()
+	  Ast.DES_class (a) ->  raise (NotImplemented "DES_class")
+	| Ast.DES_class_dec (a,b) ->  raise (NotImplemented "DES_class_dec")
+	| Ast.DES_type (a) ->  this#visite_type_specifier a
+	| Ast.DES_type_dec (a,b) ->  raise (NotImplemented "DES_type_dec")
+	| Ast.DES_type_qua (a) ->  raise (NotImplemented "DES_type_qua")
+	| Ast.DES_type_qua_dec (a,b) ->  raise (NotImplemented "DES_type_qua_dec")
 	
 
 method visite_init_declarator_list ast = match ast with
 
 	
 
-method visite_type_specifier ast = match ast with
-	  Ast.TYPE_VOID
-	| Ast.TYPE_CHAR
-	| Ast.TYPE_SHORT
-	| Ast.TYPE_INT
-	| Ast.TYPE_LONG
-	| Ast.TYPE_FLOAT
-	| Ast.TYPE_DOUBLE
-	| Ast.TYPE_SIGNED
-	| Ast.TYPE_UNSIGNED -> ()
-	| Ast.TYPE_struct(a) -> ()
-	| Ast.TYPE_enum(a) -> ()
-	| Ast.TYPE_TYPE_NAME -> ()
+method visite_type_specifier ast =
+  this#accept_type_specifier ast
 
 	
 
 	
 
 method visite_declarator ast = match ast with
-	  Ast.DECL_pointer (a,b) -> ()
-	| Ast.DECL_direct (a) -> ()
+	  Ast.DECL_pointer (a,b) -> raise (NotImplemented "DECL_pointer")
+	| Ast.DECL_direct (a) -> this#visite_direct_declarator a
 	
 
-method visite_direct_declarator ast = match ast with
-	  Ast.DIDE_id (a) -> ()
-	| Ast.DIDE_dec (a) -> ()
-	| Ast.DIDE_cro_const (a,b) -> ()
-	| Ast.DIDE_void_cro (a) -> ()
-	| Ast.DIDE_param_list (a,b) -> ()
-	| Ast.DIDE_id_list (a,b) -> ()
-	| Ast.DIDE_void_para (a) -> ()
-	
+method visite_direct_declarator ast =
+  this#accept_direct_declarator ast
 
 method visite_pointer ast = match ast with
 	  Ast.POINTER -> ()
 	| Ast.TQL_list (a,b) -> ()
 	
 
-
+(* FIXME must became a accept in pretty *)
 method visite_parameter_type_list ast = match ast with
-	  Ast.PTL_list (a) -> ()
-	| Ast.PTL_variatique (a) -> ()
+	  Ast.PTL_list (a) -> this#visite_parameter_list a
+	| Ast.PTL_variatique (a) -> raise (NotImplemented "PTL_variatique")
 	
 
 method visite_parameter_list ast = match ast with
-	  Ast.PALI_dec (a) -> ()
+	  Ast.PALI_dec (a) -> this#visite_parameter_declaration a
 	| Ast.PALI_list (a,b) -> ()
 	
 
 method visite_parameter_declaration ast = match ast with
-	  Ast.PADE_dec_spec (a,b) -> ()
-	| Ast.PADE_abs_spec (a,b) -> ()
-	| Ast.PADE_spec (a) -> ()
+	  Ast.PADE_dec_spec (a,b) -> raise (NotImplemented "PADE_dec_spec")
+	| Ast.PADE_abs_spec (a,b) -> raise (NotImplemented "PADE_abs_spec")
+	| Ast.PADE_spec (a) -> this#visite_declaration_specifiers a
 	
 
 method visite_identifier_list ast = match ast with
 	| Ast.DAD_para_void -> ()
 	| Ast.DAD_param_list (a) -> ()
 	| Ast.DAD_dec_param_void (a) -> ()
-	| Ast.DAD_dec_param (a,b) -> ()
+  | Ast.DAD_dec_param (a,b) -> ()
 	
 
 method visite_cinitializer ast = match ast with
 	
 
 method visite_statement ast = match ast with
-	  Ast.STAT_label (a) -> ()
-	| Ast.STAT_compound (a) -> ()
-	| Ast.STAT_exp (a) -> ()
-	| Ast.STAT_selection (a) -> ()
-	| Ast.STAT_iter (a) -> ()
-	| Ast.STAT_jump (a) -> ()
+	  Ast.STAT_label (a) -> raise (NotImplemented "STAT_label")
+	| Ast.STAT_compound (a) ->  raise (NotImplemented "STAT_compound")
+	| Ast.STAT_exp (a) -> raise (NotImplemented "STAT_exp")
+	| Ast.STAT_selection (a) -> raise (NotImplemented "STAT_selection")
+	| Ast.STAT_iter (a) -> raise (NotImplemented "STAT_iter")
+	| Ast.STAT_jump (a) -> this#visite_jump_statement a
 	
 
 method visite_labeled_statement ast = match ast with
 	    Ast.CS_NONE
       -> ()
     | Ast.CS_stat_list(sl)
-      -> raise (NotImplemented "CS_stat_list")
+      -> this#accept_compound_statement None (Some sl)
     | Ast.CS_dec_list(dl)
       -> raise (NotImplemented "CS_dec_list")
     | Ast.CS_dec_stat_list(dl, sl)
 	
 
 method visite_statement_list ast = match ast with
-	  Ast.STL_stat (a) -> ()
-	| Ast.STL_list (a,b) -> ()
+	  Ast.STL_stat (a) -> this#visite_statement a
+	| Ast.STL_list (a,b) -> raise (NotImplemented "STL_list")
 	
 
 method visite_expression_statement ast = match ast with
 	| Ast.ITER_for_exp (a,b,c,d) -> ()
 	
 
-method visite_jump_statement ast = match ast with
-	  Ast.JS_GOTO (a) -> ()
-	| Ast.JS_CONTINUE
-	| Ast.JS_BREAK
-  | Ast.JS_RETURN_NONE -> ()
-	| Ast.JS_RETURN (a) -> ()
+method visite_jump_statement ast =
+  this#accept_jump_statement ast
 	
 
 method visite_translation_unit ast = match ast with