Commits

ccorrodi committed 5133f0d

print command section in debug, add exceptions

- debug.ml: print command section, ast should be printed completely now
- exception.ml: contains exceptions (currently TodoException for unimplemented
stuff and BadMatchException for when a pattern is matched that should never
be matched)
- lexer.mll: parse commands without newline
- ocamlmake.ml: throw BadMatchException

  • Participants
  • Parent commits cdeb6e2
  • Branches develop

Comments (0)

Files changed (6)

 DEBUG = 1
 FLAGS = -build-dir $(OBJDIR) -Is $(SRCDIRS)
 ifdef DEBUG
-  FLAGS += -cflags -annot
+  FLAGS += -cflags -annot,-g -lflags -g
 endif
 LIBBUILD = $(OCAMLBUILD) $(FLAGS)
 BUILD = $(OCAMLBUILD) $(FLAGS)
     TODO: This type should contain more information, see dep.h. *)
 type dependency = string
 
-(** Represent a rule as found in the "implicit rules" and "files" section. *)
+(** Represent a rule as found in the "implicit rules" and "files" section.
+
+    TODO 2012-10-29: Do we need to store r_next?
+    *)
 type rule = {
   r_next : rule option;
   r_targets : string list;
   database list
 
 (** {2 Constant Strings} *)
-(** Some doc string! *)
 let s_origin_default = "default"
 let s_origin_env = "environment"
 let s_origin_file = "makefile"
 (** {2 Output / Pretty Printing} *)
 (** Pretty print the command section. This is a valid make database section. *)
 let pp_commands (d : database) : string =
-  L.fold_right (fun cmd s -> (s_of_command cmd) ^ s) d.d_commands ""
+  L.fold_right (fun cmd s -> (s_of_command cmd) ^ "\n" ^ s) d.d_commands ""
 
 (** Pretty print the variable section. This is a valid make database section.
     *)
 let pp_files (d : database) : string =
   let file_strings = L.map s_of_rule d.d_files in
   String.concat "\n" file_strings
-

File src/debug.ml

 module L = List
 module S = Str
 module P = Pervasives
+open Exception
 open Ast
 
 (** {2 String Functions} *)
 
 
 (** {2 Debug} *)
+(** Return a string representation of the command section in the
+    given database. *)
+let debug_pp_commands (d : database) : string =
+  let debug_command (c : command) : string =
+    "command: " ^ (s_of_command c)
+  in
+  String.concat "\n" (L.map debug_command d.d_commands)
+
 (** Return a string containing the variable section of the given database,
     including all information from the variable type. *)
 let debug_pp_vars (d : database) : string =
   String.concat "\n" (L.map debug_var d.d_variables)
 
 (** Return a string with a pretty printed representation of the given rule. *)
-let debug_rule (r : rule) : string =
+let debug_pp_rule (r : rule) : string =
   let next =
     "Next: " ^
     match r.r_next with
 let debug_pp_rules (d : database) : string =
   let count = L.length d.d_implicit_rules in
   let cs = Printf.sprintf "# of implicit rules: %d\n" count in
-  let rules = String.concat "\n\n" (L.map debug_rule d.d_implicit_rules) in
+  let rules = String.concat "\n\n" (L.map debug_pp_rule d.d_implicit_rules) in
   cs ^ rules
 
 (** Return a string containing the files section of the given database. *)
 let debug_pp_files (d : database) : string =
   let count = L.length d.d_files in
   let cs = Printf.sprintf "# of files: %d\n" count in
-  let rules = String.concat "\n\n" (L.map debug_rule d.d_files) in
+  let rules = String.concat "\n\n" (L.map debug_pp_rule d.d_files) in
   cs ^ rules
 
 (** Return a pretty printed version of the database. *)
 let debug_database (d : database) : string =
+  let command_header = indent "Commands:" in
+  incr d_indent;
+  let commands = indent (debug_pp_commands d) in
+  decr d_indent;
+
   let var_header = indent "Variables:" in
   incr d_indent;
   let vars = indent (debug_pp_vars d) in
   let files = indent (debug_pp_files d) in
   decr d_indent;
 
-  String.concat "\n" [var_header; vars;
+  String.concat "\n" [command_header; commands;
+                      var_header; vars;
                       rule_header; rules;
                       file_header; files;
+                      ""
                      ]
 
 
   d_indent := 1;
   let dbs = String.concat "\n" (L.map debug_database a) in
   "AST:\n" ^ dbs
-

File src/exception.ml

+(** Exceptions
+
+    @file exception.ml
+    @author Claudio Corrodi
+    *)
+
+(** Raise a TodoException when an implementation is incomplete. *)
+exception TodoException
+
+(** Raise a BadMatchException when a pattern is matched that should never be
+    matched. *)
+exception BadMatchException

File src/lexer.mll

   | '#' [^'\n']* '\n'? {
     command_token lexbuf
   }
-  | [^'\n']* '\n'? as line {
+  | ([^'\n']* as line) '\n'? {
     COMMAND line :: command_token lexbuf
   }
   | eof {

File src/ocamlmake.ml

 module D = Debug
 module S = Str
 module L = List
+module Exn = Exception
 
 (** Convert input token list to "Lexing.lexbuf -> Parser.token", as this is
     the type we need as first argument to Parser.input.
         | cur :: [] ->
             [cur]
         | [] ->
-            (* this case should never happen *)
-            []
+            raise Exn.BadMatchException
       in
       new_rules
     in