Skip to content

Commit ab5d8e9

Browse files
author
grogers
committed
add support for include statements
1 parent ec730d9 commit ab5d8e9

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

crossref.erl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,9 @@
22

33
-export([build/3]).
44

5-
-define(CSCOPE_VERSION, 15).
6-
7-
%-define(DEFINEBEGIN, $\#).
8-
%-define(DEFINEEND, $\)).
9-
-define(FUNCTIONCALL, $`).
10-
-define(FUNCTIONDEFBEGIN, $\$).
11-
-define(FUNCTIONDEFEND, $}).
12-
%-define(INCLUDE, $~).
13-
-define(NEWFILE, $@).
14-
%-define(RECORDDEF, $s).
15-
5+
-include("crossref.hrl").
166

7+
-define(CSCOPE_VERSION, 15).
178

189
build(SrcDirs, IncDirs, SrcFiles) ->
1910
CscopeDb = "cscope.out",
@@ -72,7 +63,7 @@ build_crossref_of_file(Filename, AbsForms) ->
7263
%% Outputs a deep list suitable for writing to the crossref file
7364
form_to_crossref(Filename, Form) ->
7465
case erl_syntax:type(Form) of
75-
attribute -> []; %% @fixme ignore for now
66+
attribute -> attribute_to_crossref(Form);
7667
function -> function_to_crossref(Form);
7768

7869
error_marker ->
@@ -89,6 +80,18 @@ form_to_crossref(Filename, Form) ->
8980
[]
9081
end.
9182

83+
attribute_to_crossref(Attribute) ->
84+
case erl_syntax:atom_value(erl_syntax:attribute_name(Attribute)) of
85+
include ->
86+
StartStr = io_lib:format("~b -include(~n", [erl_syntax:get_pos(Attribute)]),
87+
[File] = erl_syntax:attribute_arguments(Attribute),
88+
IncludeStr = io_lib:format("\t~c\"~s~n", [?INCLUDE, erl_syntax:string_value(File)]),
89+
EndStr = "\").\n",
90+
[StartStr, IncludeStr, EndStr];
91+
92+
_ -> [] % ignore unused attributes
93+
end.
94+
9295
function_to_crossref(Function) ->
9396
StartStr = io_lib:format("~b ~n", [erl_syntax:get_pos(Function)]),
9497
FunctionName = erl_syntax:atom_name(erl_syntax:function_name(Function)),

crossref.hrl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-define(DEFINEBEGIN, $\#).
2+
-define(DEFINEEND, $\)).
3+
-define(FUNCTIONCALL, $`).
4+
-define(FUNCTIONDEFBEGIN, $\$).
5+
-define(FUNCTIONDEFEND, $}).
6+
-define(INCLUDE, $~).
7+
-define(NEWFILE, $@).
8+
-define(RECORDDEF, $s).

erlscope.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-module(erlscope).
22
-export([main/0]).
3-
-compile([export_all]).
43

54
main() ->
65
Filenames = get_files("cscope.files"),
@@ -14,7 +13,7 @@ get_files(Filename) ->
1413

1514
read_filenames_from(File, Acc) ->
1615
case file:read_line(File) of
17-
eof -> Acc;
16+
eof -> lists:reverse(Acc);
1817
{ok, Data} ->
1918
read_filenames_from(File, [string:strip(Data, both, $\n) | Acc])
2019
end.

0 commit comments

Comments
 (0)