Skip to content

Commit b22f7c8

Browse files
davidpichardiefacebook-github-bot
authored andcommitted
Java source baby parser for class declaration locations
Reviewed By: mityal Differential Revision: D20919670 fbshipit-source-id: c7ceb517c
1 parent db96508 commit b22f7c8

File tree

5 files changed

+424
-38
lines changed

5 files changed

+424
-38
lines changed

infer/src/dune.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ let topl_stanzas =
129129
["(ocamllex ToplLexer)"; "(menhir (flags --unused-token INDENT --explain) (modules ToplParser))"]
130130

131131

132+
let java_sources_lexer = if java then ["(ocamllex jSourceFileInfo)"] else []
133+
132134
let flatten_sources_stanzas =
133135
List.map
134136
(fun source_dir ->
@@ -143,7 +145,7 @@ let flatten_sources_stanzas =
143145
(** The build stanzas to be passed to dune *)
144146
let stanzas =
145147
(env_stanza :: main_lib_stanza :: infer_exe_stanza :: infertop_stanza :: clang_lexer_stanzas)
146-
@ topl_stanzas @ flatten_sources_stanzas
148+
@ java_sources_lexer @ topl_stanzas @ flatten_sources_stanzas
147149

148150

149151
;;

infer/src/java/jFrontend.ml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,31 @@ let cache_classname cn =
132132

133133
let is_classname_cached cn = Sys.file_exists (path_of_cached_classname cn) = `Yes
134134

135+
let test_source_file_location source_file program cn node =
136+
let is_synthetic = function
137+
| Javalib.JInterface _ ->
138+
false
139+
| Javalib.JClass jc ->
140+
jc.Javalib.c_synthetic
141+
in
142+
if not (is_synthetic node) then
143+
match JClasspath.get_java_location program cn with
144+
| None ->
145+
L.(debug Capture Verbose)
146+
"WARNING SOURCE FILE PARSER: location not found for class %s in source file %s \n"
147+
(JBasics.cn_name cn)
148+
(SourceFile.to_abs_path source_file)
149+
| Some _ ->
150+
()
151+
152+
135153
(* Given a source file and a class, translates the code of this class.
136154
In init - mode, finds out whether this class contains initializers at all,
137155
in this case translates it. In standard mode, all methods are translated *)
138156
let create_icfg source_file program tenv icfg cn node =
139157
L.(debug Capture Verbose) "\tclassname: %s@." (JBasics.cn_name cn) ;
140158
if Config.dependency_mode && not (is_classname_cached cn) then cache_classname cn ;
159+
test_source_file_location source_file program cn node ;
141160
let translate m =
142161
let proc_name = JTransType.translate_method_name program tenv m in
143162
JClasspath.set_callee_translated program proc_name ;
@@ -194,19 +213,8 @@ let compute_source_icfg program tenv source_basename package_opt source_file =
194213
let select test procedure cn node =
195214
if test node then try procedure cn node with Bir.Subroutine -> ()
196215
in
197-
let set_java_location cn _node =
198-
let cn_name = JBasics.cn_name cn in
199-
let loc = JSourceFileInfo.class_name_location source_file cn_name in
200-
L.debug Capture Verbose "set_java_location %s with location %a@." cn_name Location.pp_file_pos
201-
loc ;
202-
JClasspath.set_java_location program cn loc
203-
in
204216
(* we must set the java location for all classes in the source file before translation *)
205-
let () =
206-
JBasics.ClassMap.iter
207-
(select (should_capture program package_opt source_basename) set_java_location)
208-
(JClasspath.get_classmap program)
209-
in
217+
JSourceFileInfo.collect_class_location program source_file ;
210218
let () =
211219
JBasics.ClassMap.iter
212220
(select

infer/src/java/jSourceFileInfo.ml

Lines changed: 0 additions & 13 deletions
This file was deleted.

infer/src/java/jSourceFileInfo.mli

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)