diff --git a/infer/src/erlang/ErlangTranslator.ml b/infer/src/erlang/ErlangTranslator.ml new file mode 100644 index 000000000..ed3a754fb --- /dev/null +++ b/infer/src/erlang/ErlangTranslator.ml @@ -0,0 +1,26 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open! IStd +module Ast = ErlangAst + +let to_source_and_cfg module_ = + let source = + let extract_path = function + | {Ast.line= _; simple_form= File {path}} -> + Some path + | _ -> + None + in + match List.find_map ~f:extract_path module_ with + | None -> + SourceFile.invalid __FILE__ + | Some path -> + SourceFile.create path + in + let cfg = (* TODO *) Cfg.create () in + (source, cfg) diff --git a/infer/src/erlang/ErlangTranslator.mli b/infer/src/erlang/ErlangTranslator.mli new file mode 100644 index 000000000..515767014 --- /dev/null +++ b/infer/src/erlang/ErlangTranslator.mli @@ -0,0 +1,10 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open! IStd + +val to_source_and_cfg : ErlangAst.module_ -> SourceFile.t * Cfg.t diff --git a/infer/src/integration/Rebar3.ml b/infer/src/integration/Rebar3.ml index ca37501d6..91b64f98c 100644 --- a/infer/src/integration/Rebar3.ml +++ b/infer/src/integration/Rebar3.ml @@ -16,9 +16,14 @@ let run_rebar result_dir args = let parse_and_store result_dir = let process json = - let _ast = ErlangJsonParser.to_module json in - (* TODO: Translate to Sil, load source, call [SourceFiles.add]. *) - () + match ErlangJsonParser.to_module json with + | None -> + false + | Some ast -> + let source_file, cfg = ErlangTranslator.to_source_and_cfg ast in + let tenv = (* TODO: types *) Tenv.Global in + SourceFiles.add source_file cfg tenv None ; + true in let log error = L.progress "E: %s@." error in let read_one_ast json_file = @@ -26,7 +31,7 @@ let parse_and_store result_dir = L.progress "P: parsing %s@." json_file ; match Utils.read_safe_json_file json_file with | Ok json -> - process json + if not (process json) then L.debug Capture Verbose "Failed to parse %s@." json_file | Error error -> log error ) in