Skip to content

Commit

Permalink
feat: reactivate sql preproc, go to def/ref active in exec block
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoKaios committed Oct 16, 2024
1 parent 9c00487 commit b0b7364
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .drom

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dune-project

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions opam/cobol_typeck.opam
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ install: [
depends: [
"ocaml" {>= "4.14.0"}
"dune" {>= "2.8.0"}
"superbol_preprocs" {= version}
"sql_ast" {= version}
"cobol_unit" {= version}
"cobol_ptree" {= version}
"cobol_parser" {= version}
Expand Down
2 changes: 2 additions & 0 deletions opam/osx/cobol_typeck-osx.opam
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ install: [
depends: [
"ocaml" {>= "4.14.0"}
"dune" {>= "2.8.0"}
"superbol_preprocs-osx" {= version}
"sql_ast-osx" {= version}
"cobol_unit-osx" {= version}
"cobol_ptree-osx" {= version}
"cobol_parser-osx" {= version}
Expand Down
2 changes: 2 additions & 0 deletions opam/windows/cobol_typeck-windows.opam
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ install: [
depends: [
"ocaml" {>= "4.14.0"}
"dune" {>= "2.8.0"}
"superbol_preprocs-windows" {= version}
"sql_ast-windows" {= version}
"cobol_unit-windows" {= version}
"cobol_ptree-windows" {= version}
"cobol_parser-windows" {= version}
Expand Down
39 changes: 39 additions & 0 deletions src/lsp/cobol_lsp/lsp_lookup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,45 @@ let element_at_position ~uri pos group : element_at_position =
Visitor.skip_children @@
on_proc_name (qualname_at_pos ~filename qn pos) acc

method! fold_exec_block' exec_block acc =
let acc = match exec_block.payload with
| Superbol_preprocs.Generic.Generic_exec_block _ ->
acc
| Superbol_preprocs.Esql.Esql_exec_block esql ->
let cob_var_extractor_folder = object
inherit [Sql_ast.cobol_var list] Sql_ast.Visitor.folder
method! fold_cobol_var cob_var acc =
if List.exists (fun c -> Sql_ast.compare_cobol_var cob_var c == 0) acc
then Cobol_common.Visitor.skip acc
else Cobol_common.Visitor.skip (cob_var::acc)
end in
let cobol_vars =
Sql_ast.Visitor.fold_esql_instruction cob_var_extractor_folder
esql []
in
let string_name_opt = List.filter_map begin function
| Sql_ast.CobVarNotNull cobol_var_id
| CobVarCasted (cobol_var_id, _) ->
if Lsp_position.is_in_srcloc ~filename pos ~@cobol_var_id
then Some cobol_var_id
else None
| CobVarNullIndicator (cobol_var_id, _)
when Lsp_position.is_in_srcloc ~filename pos ~@cobol_var_id ->
Some cobol_var_id
| CobVarNullIndicator (_, cobol_var_id)
when Lsp_position.is_in_srcloc ~filename pos ~@cobol_var_id ->
Some cobol_var_id
| CobVarNullIndicator _ -> None
end cobol_vars
in
let acc = match string_name_opt with
| [name] -> on_data_name (Name name) acc
| _ -> acc
in acc
| _ -> acc
in
Visitor.skip_children acc

end group init |> result

(* --- *)
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/cobol_typeck/dune

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions src/lsp/cobol_typeck/package.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ kind = "library"
# name of a file to generate with the current version
gen-version = "version.ml"

# supported file generators are "ocamllex", "ocamlyacc" and "menhir"
# default is [ "ocamllex", "ocamlyacc" ]
# supported file generators are "ocamllex", "ocamlyacc" and "menhir"
# default is [ "ocamllex", "ocamlyacc" ]
# generators = [ "ocamllex", "menhir" ]

# menhir options for the package
Expand All @@ -42,7 +42,7 @@ gen-version = "version.ml"
# pack = "Mylib"

# preprocessing options
# preprocess = "per-module (((action (run ./toto.sh %{input-file})) mod))"
# preprocess = "per-module (((action (run ./toto.sh %{input-file})) mod))"
preprocess = "pps ppx_deriving.show ppx_deriving.ord"

# files to skip while updating at package level
Expand All @@ -51,28 +51,30 @@ skip = ["index.mld"]
# package library dependencies
# [dependencies]
# ez_file = ">=0.1 <1.3"
# base-unix = { libname = "unix", version = ">=base" }
# base-unix = { libname = "unix", version = ">=base" }
[dependencies]
cobol_ptree = "version"
cobol_common = "version"
cobol_data = "version"
cobol_parser = "version"
cobol_unit = "version"
superbol_preprocs = "version"
sql_ast = "version"

# package tools dependencies
[tools]
ppx_deriving = ">=5.2.1"

# package fields (depends on package skeleton)
#Examples:
# dune-stanzas = "(preprocess (pps ppx_deriving_encoding))"
# dune-libraries = "bigstring"
# dune-trailer = "(install (..))"
# opam-trailer = "pin-depends: [..]"
# no-opam-test = "yes"
# no-opam-doc = "yes"
# gen-opam = "some" | "all"
# dune-stanzas = "(flags (:standard (:include linking.sexp)))"
# static-clibs = "unix"
# dune-stanzas = "(preprocess (pps ppx_deriving_encoding))"
# dune-libraries = "bigstring"
# dune-trailer = "(install (..))"
# opam-trailer = "pin-depends: [..]"
# no-opam-test = "yes"
# no-opam-doc = "yes"
# gen-opam = "some" | "all"
# dune-stanzas = "(flags (:standard (:include linking.sexp)))"
# static-clibs = "unix"
[fields]
# ...
43 changes: 43 additions & 0 deletions src/lsp/cobol_typeck/typeck_procedure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,49 @@ let references ~(data_definitions: Cobol_unit.Types.data_definitions) procedure
in
Visitor.skip_children acc

method! fold_exec_block' exec_block acc =
let register_name name acc =
let qn = Cobol_ptree.Name name in
let loc = name.loc in
begin try
let bnd = Qualmap.find_binding qn data_definitions.data_items.named in
{ acc with
refs = Typeck_outputs.register_data_qualref
~loc bnd.full_qn acc.refs }
with
| Not_found ->
acc (* ignored for now, as we don't process all the DATA DIV. yet. *)
| Qualmap.Ambiguous (lazy matching_qualnames) ->
error acc @@ Ambiguous_data_name { given_qualname = qn &@ loc;
matching_qualnames }
end in
let acc = match exec_block.payload with
| Superbol_preprocs.Generic.Generic_exec_block _ ->
acc
| Superbol_preprocs.Esql.Esql_exec_block esql ->
let cob_var_extractor_folder = object
inherit [Sql_ast.cobol_var list] Sql_ast.Visitor.folder
method! fold_cobol_var cob_var acc =
if List.exists (fun c -> Sql_ast.compare_cobol_var cob_var c == 0) acc
then Cobol_common.Visitor.skip acc
else Cobol_common.Visitor.skip (cob_var::acc)
end in
let cobol_vars =
Sql_ast.Visitor.fold_esql_instruction cob_var_extractor_folder
esql []
in
List.fold_left begin fun acc -> function
| Sql_ast.CobVarNotNull cobol_var_id
| CobVarCasted (cobol_var_id, _) ->
register_name cobol_var_id acc
| CobVarNullIndicator (cobol_var_id, cobol_var_id_2) ->
register_name cobol_var_id acc |>
register_name cobol_var_id_2
end acc cobol_vars
| _ -> acc
in
Visitor.skip_children acc

end in

Cobol_unit.Visitor.fold_procedure visitor procedure init |> references
Expand Down
12 changes: 9 additions & 3 deletions src/lsp/sql_parser/sql_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ let parse text =
([], None) text
|> fst |> List.rev
in
let ast = Grammar.MenhirInterpreter.loop (supplier tokens) init_checkpoint in
(* Format.fprintf Format.std_formatter "\n%a\n" Sql_ast.Printer.pp ast; *)
ast
match tokens with
| Grammar.((EXECUTE, _, _) :: (SQL, _, _) :: (IGNORE, _, _) :: _)
| Grammar.((EXEC, _, _) :: (SQL, _, _) :: (IGNORE, _, _) :: _) ->
(* failsafe to avoid parsing potentially breaking SQL IGNORE sections *)
Sql_ast.Ignore []
| _ ->
let ast = Grammar.MenhirInterpreter.loop (supplier tokens) init_checkpoint in
(* Format.fprintf Format.std_formatter "\n%a\n" Sql_ast.Printer.pp ast; *)
ast

let parseString str =
let ast = Grammar.main Lexer.token str in
Expand Down
1 change: 0 additions & 1 deletion src/lsp/sql_preproc/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ let generate ~filename ~contents ~cobol_unit sql_statements =
:: (working_storage_section @ output cur_lines statements)
end
| EXEC_SQL_IGNORE { end_loc; begin_of_ignore_loc } ->
Printf.eprintf "%d,%d\n" begin_of_ignore_loc.line begin_of_ignore_loc.char;
begin if i = begin_loc.line
then [comment "ESQL IGNORED SECTION"]
else [] end
Expand Down
4 changes: 2 additions & 2 deletions src/lsp/superbol_preprocs/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ let exec_scanners =
exec_scanner_fallback = Generic.scanner; (* for now; TODO: Call.scanner? *)
(* NB: Kept empty for now (the LSP does not yet benefit from this
preprocessor) *)
exec_scanners = Cobol_preproc.Options.EXEC_MAP.empty;
(* exec_scanners = Cobol_preproc.Options.EXEC_MAP.singleton "SQL" Esql.scanner; *)
(* exec_scanners = Cobol_preproc.Options.EXEC_MAP.empty; *)
exec_scanners = Cobol_preproc.Options.EXEC_MAP.singleton "SQL" Esql.scanner;
}

let more scanners =
Expand Down

0 comments on commit b0b7364

Please sign in to comment.