This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Another wrapper around graph_code, this time not to generate a prolog DB but to generate an emacs (or vi) TAGS file. Test Plan: $ cd ~/pfff; make tags then under emacs M-x List. TAB list all the functions in list.ml and selecting one jump to the right place. Reviewers: pieter Reviewed By: pieter CC: julienv, mathieubaudet, platform-diffs@lists, erling Differential Revision: https://phabricator.fb.com/D653086
- Loading branch information
pad
committed
Dec 10, 2012
1 parent
7ab93a4
commit c9ca26a
Showing
6 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
(* Yoann Padioleau | ||
* | ||
* Copyright (C) 2012 Facebook | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public License | ||
* version 2.1 as published by the Free Software Foundation, with the | ||
* special exception on linking described in file license.txt. | ||
* | ||
* This library is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file | ||
* license.txt for more details. | ||
*) | ||
open Common | ||
|
||
module G = Graph_code | ||
module E = Database_code | ||
|
||
(*****************************************************************************) | ||
(* Prelude *) | ||
(*****************************************************************************) | ||
(* Generating a set of TAGS from a graph_code. | ||
* | ||
* alternatives: | ||
* - could start from the prolog facts (themselves generated from graph_code) | ||
* to factorize some code, but for TAGS we are only interested | ||
* in position and the only predicate that matters, at/3, does not | ||
* actually contain enough information such as the byte offset in the file, | ||
* so let's copy paste for now. | ||
*) | ||
|
||
(*****************************************************************************) | ||
(* Helpers *) | ||
(*****************************************************************************) | ||
|
||
(*****************************************************************************) | ||
(* Main entry point *) | ||
(*****************************************************************************) | ||
|
||
(* quite similar to graph_code_prolog *) | ||
let defs_of_graph_code ?(verbose=false) g = | ||
|
||
(* we use the multi-values-to-same-key property of Hashtbl.add and | ||
* Hashtbl.find_all | ||
*) | ||
let hfile_to_tags = Hashtbl.create 101 in | ||
|
||
let hmemo_file_array = Hashtbl.create 101 in | ||
|
||
|
||
g +> G.iter_nodes (fun n -> | ||
let (str, kind) = n in | ||
(try | ||
let nodeinfo = G.nodeinfo n g in | ||
let file = nodeinfo.G.pos.Parse_info.file in | ||
let line = nodeinfo.G.pos.Parse_info.line in | ||
let text = | ||
try | ||
let array = Common.memoized hmemo_file_array file (fun () -> | ||
Common.cat_array file | ||
) | ||
in | ||
(* not sure why, but can't put an empty string for | ||
* tag_definition_text; Emacs is then getting really confused | ||
*) | ||
array.(line) | ||
with | ||
| Invalid_argument _out_of_bound -> | ||
pr2 (spf "PB accessing line %d of %s" line file); | ||
"" | ||
| Sys_error _no_such_file -> | ||
pr2 (spf "PB accessing file %s" file); | ||
"" | ||
in | ||
let tag = { Tags_file. | ||
tagname = str; | ||
line_number = nodeinfo.G.pos.Parse_info.line; | ||
byte_offset = nodeinfo.G.pos.Parse_info.charpos; | ||
kind = kind; | ||
tag_definition_text = text; | ||
} | ||
in | ||
Hashtbl.add hfile_to_tags file tag; | ||
(* when add a tag for List.foo, also add foo.List *) | ||
let reversed_tagname = | ||
Common.split "\\." str +> List.rev +> Common.join "." in | ||
Hashtbl.add hfile_to_tags file | ||
{ tag with Tags_file.tagname = reversed_tagname } | ||
|
||
with Not_found -> () | ||
) | ||
); | ||
Common.hkeys hfile_to_tags +> List.map (fun file -> | ||
file, | ||
Hashtbl.find_all hfile_to_tags file | ||
+> List.map (fun tag -> tag.Tags_file.byte_offset, tag) | ||
+> Common.sort_by_key_lowfirst | ||
+> List.map snd | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
val defs_of_graph_code: | ||
?verbose:bool -> | ||
Graph_code.graph -> | ||
(Common.filename * Tags_file.tag list) list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters