summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHans Bolinder <hasse@erlang.org>2021-01-04 14:25:11 +0100
committerHans Bolinder <hasse@erlang.org>2021-01-26 11:57:13 +0100
commit98527dc0e5a7fce1e2a4d20380a5c39977297a6a (patch)
tree298beda1ba361b9437e18ad962fc58decebae8db /lib
parentbe940b12ec91b19b6d80a6ad8c6a93395df2808f (diff)
downloaderlang-98527dc0e5a7fce1e2a4d20380a5c39977297a6a.tar.gz
edoc: Correct handling of annotations of abstract code
Diffstat (limited to 'lib')
-rw-r--r--lib/edoc/src/edoc_extract.erl10
-rw-r--r--lib/edoc/src/edoc_specs.erl21
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/edoc/src/edoc_extract.erl b/lib/edoc/src/edoc_extract.erl
index e878fc1a39..e821c1931d 100644
--- a/lib/edoc/src/edoc_extract.erl
+++ b/lib/edoc/src/edoc_extract.erl
@@ -385,7 +385,7 @@ collect([F | Fs], Cs, Ss, Ts, Rs, As, Header, Mod) ->
comment ->
collect(Fs, [F | Cs], Ss, Ts, Rs, As, Header, Mod);
{function, Name} ->
- L = erl_syntax:get_pos(F),
+ L = get_line(F),
Export = ordsets:is_element(Name, Mod#module.exports),
Args = parameters(erl_syntax:function_clauses(F)),
collect(Fs, [], [], [], [],
@@ -394,7 +394,7 @@ collect([F | Fs], Cs, Ss, Ts, Rs, As, Header, Mod) ->
data = {comment_text(Cs),Ss,Ts,Rs}} | As],
Header, Mod);
{attribute, {module, _}} when Header =:= undefined ->
- L = erl_syntax:get_pos(F),
+ L = get_line(F),
collect(Fs, [], [], [], [], As,
#entry{name = module, line = L,
data = {comment_text(Cs),Ss,Ts,Rs}},
@@ -441,7 +441,7 @@ comment_text(Cs) ->
comment_text(Cs, []).
comment_text([C | Cs], Ss) ->
- L = erl_syntax:get_pos(C),
+ L = get_line(C),
comment_text(Cs, [#comment{line = L,
text = [remove_percent_chars(S)
|| S <- erl_syntax:comment_text(C)]}
@@ -449,6 +449,10 @@ comment_text([C | Cs], Ss) ->
comment_text([], Ss) ->
Ss.
+get_line(Tree) ->
+ Anno = erl_syntax:get_pos(Tree),
+ erl_anno:line(Anno).
+
%% @doc Replaces leading `%' characters by spaces. For example, `"%%%
%% foo" -> "\s\s\s foo"', but `"% % foo" -> "\s % foo"', since the
%% second `%' is preceded by whitespace.
diff --git a/lib/edoc/src/edoc_specs.erl b/lib/edoc/src/edoc_specs.erl
index 9b5050a7c2..8c2fb8ee50 100644
--- a/lib/edoc/src/edoc_specs.erl
+++ b/lib/edoc/src/edoc_specs.erl
@@ -47,8 +47,9 @@ type(Form, TypeDocs) ->
case Data0 of
{R, Fs} ->
record = Name,
- L = erl_syntax:get_pos(Form),
- {{record, R}, {type, L, record, [{atom,L,R} | Fs]}, [], ""};
+ Anno = erl_syntax:get_pos(Form),
+ {{record, R},
+ {type, Anno, record, [{atom,Anno,R} | Fs]}, [], ""};
{N,T,As} ->
type = tag(Name),
Doc0 =
@@ -137,11 +138,11 @@ find_type_docs([F | Fs], Cs, Fun) ->
try get_name_and_last_line(F) of
{Name, LastTypeLine} ->
C0 = erl_syntax:comment(["% @type f(). "]),
- C1 = erl_syntax:set_pos(C0, LastTypeLine),
+ C1 = erl_syntax:set_pos(C0, anno(LastTypeLine)),
%% Postcomments before the dot after the typespec are ignored.
C2 = [C1 | [C ||
C <- erl_syntax:get_postcomments(F),
- erl_syntax:get_pos(C) >= LastTypeLine]],
+ get_tree_line(C) >= LastTypeLine]],
C3 = collect_comments(Fs, LastTypeLine),
#tag{data = Doc0} = Fun(lists:reverse(C2 ++ C3), LastTypeLine),
case strip(Doc0) of % Strip away "f(). \n"
@@ -158,7 +159,7 @@ find_type_docs([F | Fs], Cs, Fun) ->
collect_comments([], _Line) ->
[];
collect_comments([F | Fs], Line) ->
- L1 = erl_syntax:get_pos(F),
+ L1 = get_tree_line(F),
if
L1 =:= Line + 1;
L1 =:= Line -> % a separate postcomment
@@ -175,6 +176,13 @@ collect_comments([F | Fs], Line) ->
%% by a -type attribute and the include statement is followed by a
%% comment (which is not meant to be documentation of the type).
+anno(Location) ->
+ erl_anno:new(Location).
+
+get_tree_line(Tree) ->
+ Anno = erl_syntax:get_pos(Tree),
+ erl_anno:line(Anno).
+
is_comment(F) ->
erl_syntax_lib:analyze_form(F) =:= comment.
@@ -190,7 +198,8 @@ strip([_ | S]) ->
get_name_and_last_line(F) ->
{Name, Data} = analyze_type_attribute(F),
type = edoc_specs:tag(Name),
- Attr = {attribute, erl_syntax:get_pos(F), Name, Data},
+ Anno = erl_syntax:get_pos(F),
+ Attr = {attribute, Anno, Name, Data},
Fun = fun(A) ->
Line = get_line(A),
case get('$max_line') of