SmallCC / src /

Full commit
(* This help to manage param *)

type 'a value = None | Some of 'a

exception NoValue
exception NotImplemented of string

let getValue v = match v with
    Some a  -> a
  | None    -> raise NoValue

(* Begin of the visitor class*)

class visitor =

    (* Complet this accept *)
  method acceptFunctionDefinition decspe dec dec_list cs =
    if (decspe <> None) then ();
    if (dec_list <> None) then ();

  method acceptTranslationUnit tu ed =
    if (tu <> None) then this#visitTranslationUnit (getValue tu);
    this#visitExternalDeclaration (getValue ed)

  method visitFunctionDefinition ast = match ast with
  	  Ast.FUN_spec_dec_list(decspe, dec, dec_list, cs)
      -> this#acceptFunctionDefinition (Some decspe) (Some dec) (Some dec_list) (Some cs)
	  | Ast.FUN_spec_dec(decspe, dec, cs)
      -> this#acceptFunctionDefinition (Some decspe) (Some dec) None (Some cs)
	  | Ast.FUN_dec_list(dec, dec_list, cs)
      -> this#acceptFunctionDefinition None (Some dec) (Some dec_list) (Some cs)
	  | Ast.FUN_dec(dec, cs)
      -> this#acceptFunctionDefinition None (Some dec) None (Some cs)

    (* Here i visite directly, but why not? *)
  method visitExternalDeclaration ast = match ast with
	    Ast.ED_fun_def(fd)  -> this#visitFunctionDefinition fd
	  | Ast.ED_dec(dec)     -> raise (NotImplemented "ED_dec")

  method visitTranslationUnit ast = match ast with
	    Ast.TU_dec(ed)      -> this#acceptTranslationUnit None (Some ed) 
	  | Ast.TU_tans(tu, ed) -> this#acceptTranslationUnit (Some tu) (Some ed)
	  | Ast.None            -> ()

class prettyPrintVisitor =
    inherit visitor as old

    method acceptFunctionDefinition a b c d =
      print_endline "Function";
      old#acceptFunctionDefinition a b c d