diff options
author | Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr> | 2002-02-01 13:13:33 +0000 |
---|---|---|
committer | Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr> | 2002-02-01 13:13:33 +0000 |
commit | 5d577dfbe664c3a9ac3619bd4b64ea2784ea8d5e (patch) | |
tree | 2349a25065709af2548560ea01aadb0f74882938 /camlp4/ocaml_src/lib/token.ml | |
parent | b34f0042d9ff7bec62a5ef56b76ee54e2412c930 (diff) |
-
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4340 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'camlp4/ocaml_src/lib/token.ml')
-rw-r--r-- | camlp4/ocaml_src/lib/token.ml | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/camlp4/ocaml_src/lib/token.ml b/camlp4/ocaml_src/lib/token.ml index b20ff8af7..379fdd0ce 100644 --- a/camlp4/ocaml_src/lib/token.ml +++ b/camlp4/ocaml_src/lib/token.ml @@ -36,23 +36,26 @@ let lexer_text (con, prm) = ;; let locerr () = invalid_arg "Lexer: location function";; -let loct_create () = ref (Array.create 1024 None);; -let loct_func loct i = +let loct_create () = ref (Array.create 1024 None), ref false;; +let loct_func (loct, ov) i = match - if i < 0 || i >= Array.length !loct then None + if i < 0 || i >= Array.length !loct then + if !ov then Array.unsafe_get !loct (Array.length !loct - 1) else None else Array.unsafe_get !loct i with Some loc -> loc | _ -> locerr () ;; -let loct_add loct i loc = +let loct_add (loct, ov) i loc = if i >= Array.length !loct then - begin - let new_tmax = Array.length !loct * 2 in + let new_tmax = Array.length !loct * 2 in + if new_tmax < Sys.max_array_length then let new_loct = Array.create new_tmax None in - Array.blit !loct 0 new_loct 0 (Array.length !loct); loct := new_loct - end; - !loct.(i) <- Some loc + Array.blit !loct 0 new_loct 0 (Array.length !loct); + loct := new_loct; + !loct.(i) <- Some loc + else ov := true + else !loct.(i) <- Some loc ;; let make_stream_and_location next_token_loc = |