From dc9e9ba2f50ce881c3a77743663829d661363d51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Wed, 22 Feb 2012 22:43:32 +0100 Subject: [PATCH] Remove support for outdated libGrammar, replaced by Grammar2 --- configure | 4 -- src/OCamlDriver.cpp | 159 -------------------------------------------- src/grammar.ml | 104 ----------------------------- src/grammar.mli | 46 ------------- 4 files changed, 313 deletions(-) delete mode 100644 src/grammar.ml delete mode 100644 src/grammar.mli diff --git a/configure b/configure index f0540b7..e53f053 100755 --- a/configure +++ b/configure @@ -22,7 +22,6 @@ Conf.check "bp" (Conf.absolute) ("%s/../bp/libbp.a") (Sys.file_exists);; Conf.check "libcds" (Conf.absolute) ("%s/../libcds/lib/libcds.a") (Sys.file_exists);; Conf.check "XMLTree" (Conf.absolute) ("%s/../XMLTree/libXMLTree.a") (Sys.file_exists);; Conf.check "TextCollection" (Conf.absolute) ("%s/../TextCollection/libTextCollection.a") (Sys.file_exists);; -Conf.check "Grammar" (Conf.absolute) ("%s/../Grammar/libGrammar.a") (Sys.file_exists);; let libs_I= [ @@ -30,7 +29,6 @@ let libs_I= [ Conf.absolute "-I%s/../libcds/includes"; Conf.absolute "-I%s/../XMLTree"; Conf.absolute "-I%s/../TextCollection"; - Conf.absolute "-I%s/../Grammar"; Conf.absolute "-I%s/.."; ] @@ -39,13 +37,11 @@ let libs_L = [ Conf.absolute "-L%s/../libcds/lib"; Conf.absolute "-L%s/../XMLTree"; Conf.absolute "-L%s/../TextCollection"; - Conf.absolute "-L%s/../Grammar"; Conf.absolute "-L%s/.."; ] (* Order is relevant *) let libs_l = [ - "-lGrammar"; "-lXMLTree"; "-lTextCollection"; "-lbp"; diff --git a/src/OCamlDriver.cpp b/src/OCamlDriver.cpp index 7cf70c5..074dd1c 100644 --- a/src/OCamlDriver.cpp +++ b/src/OCamlDriver.cpp @@ -20,7 +20,6 @@ #include "XMLTree.h" #include "XMLTreeBuilder.h" -#include "Grammar.h" #include "Utils.h" #include "common_stub.hpp" @@ -32,8 +31,6 @@ #define XMLTREEBUILDER(x) (Obj_val(x)) -#define GRAMMAR(x) (Obj_val(x)) - #define TREENODEVAL(i) ((treeNode) (Int_val(i))) #define TAGVAL(i) ((TagType) (Int_val(i))) @@ -896,162 +893,6 @@ BV_QUERY(contains, Contains) BV_QUERY(lessthan, LessThan) - -//////////////////////////////////////////// Grammar stuff - -extern "C" value caml_grammar_load(value file, value load_bp) -{ - CAMLparam2(file, load_bp); - CAMLlocal1(result); - Grammar *grammar; - int f1 = Int_val(file); - int f2 = dup(f1); - FILE * fd = fdopen(f2, "r"); - if (fd == NULL) - CAMLRAISEMSG("Error opening grammar file"); - grammar = Grammar::load(fd, Bool_val(load_bp)); - fclose(fd); - result = sxsi_alloc_custom(); - Obj_val(result) = grammar; - CAMLreturn(result); -} - -extern "C" value caml_grammar_get_symbol_at(value grammar, value symbol, value preorder) -{ - CAMLparam3(grammar, symbol, preorder); - CAMLreturn(Val_long(GRAMMAR(grammar)->getSymbolAt(Long_val(symbol), Int_val(preorder)))); -} - -extern "C" value caml_grammar_first_child(value grammar, value rule, value pos) -{ - CAMLparam1(grammar); - CAMLreturn(Val_int(GRAMMAR(grammar)->firstChild(Long_val(rule), Int_val(pos)))); -} - -extern "C" value caml_grammar_next_sibling(value grammar, value rule, value pos) -{ - CAMLparam1(grammar); - CAMLreturn(Val_int(GRAMMAR(grammar)->nextSibling(Long_val(rule), Int_val(pos)))); -} - -extern "C" value caml_grammar_start_first_child(value grammar, value pos) -{ - CAMLparam1(grammar); - CAMLreturn(Val_int(GRAMMAR(grammar)->startFirstChild(Int_val(pos)))); -} - -extern "C" value caml_grammar_start_next_sibling(value grammar, value pos) -{ - CAMLparam1(grammar); - CAMLreturn(Val_int(GRAMMAR(grammar)->startNextSibling(Int_val(pos)))); -} - -extern "C" value caml_grammar_is_nil(value grammar, value rule) -{ - CAMLparam1(grammar); - CAMLreturn(Val_bool(GRAMMAR(grammar)->isNil(Long_val(rule)))); -} - -extern "C" value caml_grammar_get_tag(value grammar, value tag) -{ - CAMLparam1(grammar); - CAMLlocal1(res); - const char * s = (GRAMMAR(grammar)->getTagName(Long_val(tag))).c_str(); - res = caml_copy_string(s); - CAMLreturn(res); -} - -extern "C" value caml_grammar_get_id1(value grammar, value rule) -{ - CAMLparam1(grammar); - CAMLreturn(Val_long(GRAMMAR(grammar)->getID1(Long_val(rule)))); -} - -extern "C" value caml_grammar_get_id2(value grammar, value rule) -{ - CAMLparam1(grammar); - CAMLreturn(Val_long(GRAMMAR(grammar)->getID2(Long_val(rule)))); -} - -extern "C" value caml_grammar_get_param_pos(value grammar, value rule) -{ - CAMLparam1(grammar); - CAMLreturn(Val_int(GRAMMAR(grammar)->getParamPos(Long_val(rule)))); -} - -extern "C" value caml_grammar_translate_tag(value grammar, value tag) -{ - CAMLparam1(grammar); - CAMLreturn(Val_int(GRAMMAR(grammar)->translateTag(Int_val(tag)))); -} - -extern "C" value caml_grammar_register_tag(value grammar, value str) -{ - CAMLparam2(grammar, str); - char * s = String_val(str); - CAMLreturn(Val_int(GRAMMAR(grammar)->getTagID(s))); -} - -extern "C" value caml_grammar_nil_id(value grammar) -{ - CAMLparam1(grammar); - CAMLreturn(Val_long((GRAMMAR(grammar)->getNiltagid()) * 4 + 1)); -} - -extern "C" { -extern char *caml_young_end; -extern char *caml_young_start; -typedef char * addr; -#define Is_young(val) \ - ((addr)(val) < (addr)caml_young_end && (addr)(val) > (addr)caml_young_start) - -} -extern "C" value caml_custom_is_young(value a){ - return Val_bool(Is_young(a)); -} - -extern "C" value caml_custom_array_blit(value a1, value ofs1, value a2, value ofs2, - value n) -{ - value * src, * dst; - intnat count; - - if (Is_young(a2)) { - /* Arrays of values, destination is in young generation. - Here too we can do a direct copy since this cannot create - old-to-young pointers, nor mess up with the incremental major GC. - Again, memmove takes care of overlap. */ - memmove(&Field(a2, Long_val(ofs2)), - &Field(a1, Long_val(ofs1)), - Long_val(n) * sizeof(value)); - return Val_unit; - } - /* Array of values, destination is in old generation. - We must use caml_modify. */ - count = Long_val(n); - if (a1 == a2 && Long_val(ofs1) < Long_val(ofs2)) { - /* Copy in descending order */ - for (dst = &Field(a2, Long_val(ofs2) + count - 1), - src = &Field(a1, Long_val(ofs1) + count - 1); - count > 0; - count--, src--, dst--) { - caml_modify(dst, *src); - } - } else { - /* Copy in ascending order */ - for (dst = &Field(a2, Long_val(ofs2)), src = &Field(a1, Long_val(ofs1)); - count > 0; - count--, src++, dst++) { - caml_modify(dst, *src); - } - } - /* Many caml_modify in a row can create a lot of old-to-young refs. - Give the minor GC a chance to run if it needs to. */ - //caml_check_urgent_gc(Val_unit); - return Val_unit; -} - - ////////////////////// BP extern "C" value caml_bitmap_create(value size) diff --git a/src/grammar.ml b/src/grammar.ml deleted file mode 100644 index e209281..0000000 --- a/src/grammar.ml +++ /dev/null @@ -1,104 +0,0 @@ -INCLUDE "utils.ml" -INCLUDE "debug.ml" -INCLUDE "trace.ml" - - -type t - -type node = [ `Grammar ] Node.t - -type p_type = [ `Parameter ] -type n_type = [ `NonTerminal ] -type t_type = [ `Terminal ] -type any_type = [ p_type | n_type | t_type ] -type symbol = [ any_type ] Node.t - -type p_symbol = p_type Node.t -type n_symbol = n_type Node.t -type t_symbol = t_type Node.t -type tn_symbol = [ n_type | t_type ] Node.t - -type partial = - Leaf of node - | Node of tn_symbol * partial array - - -external is_nil : t -> t_symbol -> bool = "caml_grammar_is_nil" -external nil_symbol : t -> t_symbol = "caml_grammar_nil_id" -external translate_tag : t -> Tag.t -> Tag.t = "caml_grammar_translate_tag" -external to_string : t -> Tag.t -> string = "caml_grammar_get_tag" -external register_tag : t -> string -> Tag.t = "caml_grammar_register_tag" - - - -let tag_operations t = { - Tag.tag = (fun s -> register_tag t s); - Tag.to_string = (fun s -> to_string t s); - Tag.translate = (fun s -> translate_tag t s); -} - -external get_symbol_at : t -> symbol -> node -> symbol = "caml_grammar_get_symbol_at" -external first_child : t -> symbol -> node -> node = "caml_grammar_first_child" -external next_sibling : t -> symbol -> node -> node = "caml_grammar_next_sibling" - -external start_first_child : t -> node -> node = "caml_grammar_start_first_child" -external start_next_sibling : t -> node -> node = "caml_grammar_start_next_sibling" - - -let is_non_terminal (n : [< any_type ] Node.t) = - let n = Node.to_int n in - n land 3 == 0 - -let is_terminal (n : [< any_type ] Node.t) = - let n = Node.to_int n in - n land 3 == 1 - -let is_parameter (n : [< any_type ] Node.t) = - let n = Node.to_int n in - n land 3 == 2 - - -let symbol_tag (n : t_symbol) = (Node.to_int n) lsr 2 -;; -let tag = symbol_tag -let get_tag g (n : t_symbol) = to_string g (symbol_tag n) -let symbol (n : n_symbol) = ((Node.to_int n) lsr 10) land 0x7ffffff -;; - - -external parameter : [< any_type ] Node.t -> p_symbol = "%identity" -external terminal : [< any_type ] Node.t -> t_symbol = "%identity" -external non_terminal : [< any_type ] Node.t -> n_symbol = "%identity" - -external get_id1 : t -> n_symbol -> tn_symbol = "caml_grammar_get_id1" -external get_id2 : t -> n_symbol -> tn_symbol = "caml_grammar_get_id2" -(*external get_param_pos : t -> n_symbol -> int = "caml_grammar_get_param_pos" *) -let get_param_pos (n : n_symbol) = - let n = Node.to_int n in - (n lsr 6) land 0xf - -let num_params (n : n_symbol) = - let n = Node.to_int n in - (n lsr 2) land 0xf - -let num_children (n : [< t_type | n_type ] Node.t ) = - if is_non_terminal n then - num_params (non_terminal n) - else - 2 - - -external load : Unix.file_descr -> bool -> t = "caml_grammar_load" - - -let load filename bp = - let fd = Unix.openfile filename [ Unix.O_RDONLY ] 0o600 in - let g = - try load fd bp with - | e -> (Unix.close fd; raise e) - in - Unix.close fd; - Tag.init (tag_operations g); - g - - diff --git a/src/grammar.mli b/src/grammar.mli deleted file mode 100644 index dcf0067..0000000 --- a/src/grammar.mli +++ /dev/null @@ -1,46 +0,0 @@ -type t - -type node = [ `Grammar ] Node.t - -type p_type = [ `Parameter ] -type n_type = [ `NonTerminal ] -type t_type = [ `Terminal ] -type any_type = [ p_type | n_type | t_type ] -type symbol = [ any_type ] Node.t - -type p_symbol = p_type Node.t -type n_symbol = n_type Node.t -type t_symbol = t_type Node.t -type tn_symbol = [ n_type | t_type ] Node.t - -type partial = - | Leaf of node - | Node of tn_symbol * partial array - - -val is_terminal : [< any_type ] Node.t -> bool -val is_non_terminal : [< any_type ] Node.t -> bool -val is_parameter : [< any_type ] Node.t -> bool - -external get_symbol_at : t -> symbol -> node -> symbol = "caml_grammar_get_symbol_at" -external first_child : t -> symbol -> node -> node = "caml_grammar_first_child" -external next_sibling : t -> symbol -> node -> node = "caml_grammar_next_sibling" -external start_first_child : t -> node -> node = "caml_grammar_start_first_child" -external start_next_sibling : t -> node -> node = "caml_grammar_start_next_sibling" -external parameter : [< any_type ] Node.t -> p_symbol = "%identity" -external terminal : [< any_type ] Node.t -> t_symbol = "%identity" -external non_terminal : [< any_type ] Node.t -> n_symbol = "%identity" -external get_id1 : t -> n_symbol -> tn_symbol = "caml_grammar_get_id1" -external get_id2 : t -> n_symbol -> tn_symbol = "caml_grammar_get_id2" -val get_param_pos : n_symbol -> int -external nil_symbol : t -> t_symbol = "caml_grammar_nil_id" -val num_params : n_symbol -> int -val num_children : [< t_type | n_type ] Node.t -> int -external is_nil : t -> t_symbol -> bool = "caml_grammar_is_nil" - -val tag : t_symbol -> Tag.t -val symbol : n_symbol -> int -val tag_operations : t -> Tag.operations - - -val load : string -> bool -> t -- 2.17.1