From 4d14d131ec9e59cbfbd5e82309655ea0411504af Mon Sep 17 00:00:00 2001 From: ygrek Date: Fri, 15 May 2009 09:44:35 +0300 Subject: [PATCH] minor --- gen.ml | 8 ++++++++ gen_cxx.ml | 37 ++++++++++++++----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/gen.ml b/gen.ml index 6e8c73c..d5b284a 100644 --- a/gen.ml +++ b/gen.ml @@ -63,9 +63,17 @@ let generate_code index stmt = S.generate_code index scheme params kind props end +let generate_header () = + S.comment "DO NOT EDIT MANUALLY"; + empty_line (); + S.comment "generated by sqlgg %s" Config.version; + empty_line () + let process stmts = + generate_header (); S.start_output (); List.iteri generate_code stmts; S.finish_output () end + diff --git a/gen_cxx.ml b/gen_cxx.ml index 1e088ee..00a4f1b 100644 --- a/gen_cxx.ml +++ b/gen_cxx.ml @@ -9,21 +9,19 @@ open Stmt open Gen open Sql -module Cxx = -struct - type value = string * string - type t = value list +module Values = struct - let to_string x = - String.concat ", " (List.map (fun (n,t) -> t ^ " " ^ n) x) +let to_string x = + String.concat ", " (List.map (fun (n,t) -> t ^ " " ^ n) x) - let inline x = - String.concat ", " (List.map (fun (n,t) -> n) x) +let inline x = + String.concat ", " (List.map (fun (n,t) -> n) x) - let quote = String.replace_chars (function '\n' -> "\\n\\\n" | '\r' -> "" | '"' -> "\\\"" | c -> String.make 1 c) - let quote s = "\"" ^ quote s ^ "\"" end +let quote = String.replace_chars (function '\n' -> "\\n\\\n" | '\r' -> "" | '"' -> "\\\"" | c -> String.make 1 c) +let quote s = "\"" ^ quote s ^ "\"" + let quote_comment_inline = String.replace_chars (function '\n' -> "\n// " | c -> String.make 1 c) let comment fmt = Printf.kprintf (indent_endline & quote_comment_inline & (^) "// ") fmt let open_curly () = output "{"; inc_indent () @@ -44,14 +42,6 @@ let in_namespace name f = empty_line (); result -let generate_header () = - comment "DO NOT EDIT MANUALLY"; - empty_line (); - comment "generated by sqlgg %s" Config.version; - empty_line (); - output "#pragma once"; - empty_line () - let name_of attr index = match attr.RA.name with | "" -> sprintf "_%u" index @@ -128,7 +118,7 @@ let output_params_binder index params = let values = params_to_values params in values >> make_const_values >> output_value_defs; empty_line (); - output "%s(%s)" name (values >> make_const_values >> Cxx.to_string); + output "%s(%s)" name (values >> make_const_values >> Values.to_string); output_value_inits values; open_curly (); close_curly ""; @@ -154,7 +144,7 @@ let generate_code index scheme params kind props = if (Option.is_some scheme_binder_name) then output "template"; let values = params_to_values params in let result = match scheme_binder_name with None -> [] | Some _ -> ["result","T&"] in - let all_params = Cxx.to_string + let all_params = Values.to_string (["db","typename Traits::connection"] @ result @ (make_const_values values)) in let name = choose_name props kind index in @@ -164,8 +154,8 @@ let generate_code index scheme params kind props = | Insert _ -> sql ^ " (" ^ (String.concat "," (List.map (fun _ -> "?") params)) ^ ")" | Select | Update _ | Delete _ | Create _ -> sql in - let sql = Cxx.quote sql in - let inline_params = Cxx.inline (make_const_values values) in + let sql = quote sql in + let inline_params =Values.inline (make_const_values values) in output "static bool %s(%s)" name all_params; open_curly (); begin match scheme_binder_name with @@ -177,7 +167,8 @@ let generate_code index scheme params kind props = empty_line () let start_output () = - generate_header (); + output "#pragma once"; + empty_line (); output "template "; start_struct "sqlgg" -- 2.11.4.GIT