Permalink
Browse files

add file to pathing annotations so line numbers appear in the asm

  • Loading branch information...
1 parent c13d8d7 commit 0da66c2c33166ef39854ab24b4e8741033568445 @ericbmerritt ericbmerritt committed Jan 3, 2012
View
@@ -2,9 +2,13 @@
%% ==========================================
-module(jxa_annot).
--export([new/0,
- add/3,
- get/2]).
+-export([new/1,
+ add/4,
+ get/2,
+ get_type/2,
+ get_line/2,
+ get_line/3,
+ get_idx/2]).
%%=============================================================================
%% Types
@@ -21,17 +25,20 @@
%% We store the annotations in an ec_dictionary structure. This
%% initial dictionary is backed by ec_dict, however, this may change
%% in the future.
--spec new() -> annotations().
-new() ->
- ec_dictionary:new(ec_dict).
+-spec new(string()) -> annotations().
+new(Filename) ->
+ ec_dictionary:add('__filename__', Filename, ec_dictionary:new(ec_dict)).
%% #### add
%%
%% Given a pre created path, an annotation and the annotations object
%% we add the annotation at that path.
--spec add(jxa_path:path(), term(), annotations()) -> annotations().
-add(Path, Annots, Annotations) ->
- ec_dictionary:add(Path, Annots, Annotations).
+-spec add(jxa_path:path(), term(), term(),
+ annotations()) -> annotations().
+add(Path, Type, Idx={Line, _}, Annotations) ->
+ Filename = ec_dictionary:get('__filename__', Annotations),
+ ec_dictionary:add(Path, {Type, Idx, [Line, {file, Filename}]},
+ Annotations).
%% #### get
%%
@@ -41,6 +48,25 @@ add(Path, Annots, Annotations) ->
get(Path, Annotations) ->
ec_dictionary:get(Path, Annotations).
+get_line(Path, Annotations) ->
+ {_, _, LineAnnotations} = jxa_annot:get(Path, Annotations),
+ LineAnnotations.
+
+get_line(Path, Extra, Annotations) when is_list(Extra) ->
+ {_, _, LineAnnotations} = jxa_annot:get(Path, Annotations),
+ Extra ++ LineAnnotations;
+get_line(Path, Extra, Annotations) ->
+ {_, _, LineAnnotations} = jxa_annot:get(Path, Annotations),
+ [Extra | LineAnnotations].
+
+get_idx(Path, Annotations) ->
+ {_, Idx, _} = jxa_annot:get(Path, Annotations),
+ Idx.
+
+get_type(Path, Annotations) ->
+ {Type, _, _} = ec_dictionary:get(Path, Annotations),
+ Type.
+
%%=============================================================================
%% Internal Functions
%%=============================================================================
View
@@ -12,16 +12,16 @@
%% Public API
%%=============================================================================
comp(Path0, Ctx0, [binary | Args]) ->
- {_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
- jxa_ctx:annots(Ctx0)),
+ Annots = jxa_annot:get_line(jxa_path:path(Path0),
+ jxa_ctx:annots(Ctx0)),
{Ctx1, Bitstrings} = mk_binary(jxa_path:incr(Path0), Ctx0, Args),
- {Ctx1, cerl:ann_c_binary([Line], Bitstrings)}.
+ {Ctx1, cerl:ann_c_binary(Annots, Bitstrings)}.
comp_pattern(Path0, Acc0={Ctx0, _}, [binary | Args]) ->
- {_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
- jxa_ctx:annots(Ctx0)),
+ Annots = jxa_annot:get_line(jxa_path:path(Path0),
+ jxa_ctx:annots(Ctx0)),
{Acc1, Bitstrings} = mk_pattern_binary(jxa_path:incr(Path0), Acc0, Args),
- {Acc1, cerl:ann_c_binary([Line], Bitstrings)}.
+ {Acc1, cerl:ann_c_binary(Annots, Bitstrings)}.
%%=============================================================================
%% Private Functions
@@ -30,16 +30,19 @@ mk_pattern_binary(Path0, Acc0, Args) ->
{_, Acc3, BSAcc} =
lists:foldl(fun([Var | Pairs0], {Path1, Acc1={Ctx0, _}, BSAcc}) ->
Path2 = jxa_path:add(Path1),
- {_, Idx={Line, _}} =
- jxa_annot:get(jxa_path:add_path(Path2),
- jxa_ctx:annots(Ctx0)),
+ Annots =
+ jxa_annot:get_line(jxa_path:add_path(Path2),
+ jxa_ctx:annots(Ctx0)),
{{Ctx1, PG}, CerlVar} =
jxa_clause:comp_pattern(Path2, Acc1, Var),
Desc = resolve_defaults(
convert(Pairs0,
#bitstring{var=CerlVar})),
case Desc of
invalid ->
+ Idx =
+ jxa_annot:get_idx(jxa_path:add_path(Path2),
+ jxa_ctx:annots(Ctx0)),
?JXA_THROW({invalid_bistring_spec, Idx});
_ ->
ok
@@ -50,35 +53,38 @@ mk_pattern_binary(Path0, Acc0, Args) ->
Ctx1,
Desc#bitstring.size),
Unit = Desc#bitstring.unit,
- Type = cerl:ann_c_atom([Line],
+ Type = cerl:ann_c_atom(Annots,
Desc#bitstring.type),
Flags =
- cerl:ann_make_list([Line],
- [cerl:ann_c_atom([Line],
+ cerl:ann_make_list(Annots,
+ [cerl:ann_c_atom(Annots,
Desc#bitstring.signedness),
- cerl:ann_c_atom([Line],
+ cerl:ann_c_atom(Annots,
Desc#bitstring.endianness)]),
{jxa_path:incr(Path1),
{Ctx2, PG},
- [cerl:ann_c_bitstr([Line],
+ [cerl:ann_c_bitstr(Annots,
Desc#bitstring.var,
Size,
Unit,
Type,
Flags) | BSAcc]};
(Var, {Path1, Acc1={Ctx0, _}, BSAcc})
when is_atom(Var) orelse is_integer(Var) ->
- {_, Idx={Line, _}} =
- jxa_annot:get(jxa_path:add_path(Path1),
- jxa_ctx:annots(Ctx0)),
+ Annots =
+ jxa_annot:get_line(jxa_path:add_path(Path1),
+ jxa_ctx:annots(Ctx0)),
{{Ctx1, PG}, CerlVar} =
jxa_clause:comp_pattern(Path1, Acc1,
Var),
Desc = resolve_defaults(#bitstring{var=CerlVar}),
case Desc of
invalid ->
+ Idx =
+ jxa_annot:get_idx(jxa_path:add_path(Path1),
+ jxa_ctx:annots(Ctx0)),
?JXA_THROW({invalid_bistring_spec, Idx});
_ ->
ok
@@ -90,26 +96,26 @@ mk_pattern_binary(Path0, Acc0, Args) ->
Desc#bitstring.size),
Unit = Desc#bitstring.unit,
- Type = cerl:ann_c_atom([Line],
+ Type = cerl:ann_c_atom(Annots,
Desc#bitstring.type),
Flags =
- cerl:ann_make_list([Line],
- [cerl:ann_c_atom([Line],
+ cerl:ann_make_list(Annots,
+ [cerl:ann_c_atom(Annots,
Desc#bitstring.signedness),
- cerl:ann_c_atom([Line],
+ cerl:ann_c_atom(Annots,
Desc#bitstring.endianness)]),
{jxa_path:incr(Path1),
{Ctx2, PG},
- [cerl:ann_c_bitstr([Line],
+ [cerl:ann_c_bitstr(Annots,
Desc#bitstring.var,
Size,
Unit,
Type,
Flags) | BSAcc]};
(_, {Path1, {Ctx0, _}, _Acc}) ->
- {_, Idx} =
- jxa_annot:get(jxa_path:add_path(Path1),
- jxa_ctx:annots(Ctx0)),
+ Idx =
+ jxa_annot:get_idx(jxa_path:add_path(Path1),
+ jxa_ctx:annots(Ctx0)),
?JXA_THROW({invalid_bitstring, Idx})
end,
{Path0, Acc0, []},
@@ -121,16 +127,19 @@ mk_binary(Path0, Ctx0, Args) ->
{_, Ctx3, Acc} =
lists:foldl(fun([Var | Pairs0], {Path1, Ctx1, Acc}) ->
Path2 = jxa_path:add(Path1),
- {_, Idx={Line, _}} =
- jxa_annot:get(jxa_path:add_path(Path2),
- jxa_ctx:annots(Ctx0)),
+ Annots =
+ jxa_annot:get_line(jxa_path:add_path(Path2),
+ jxa_ctx:annots(Ctx0)),
{Ctx2, CerlVar} =
jxa_expression:comp(Path2, Ctx1, Var),
Desc = resolve_defaults(
convert(Pairs0,
#bitstring{var=CerlVar})),
case Desc of
invalid ->
+ Idx =
+ jxa_annot:get_idx(jxa_path:add_path(Path2),
+ jxa_ctx:annots(Ctx0)),
?JXA_THROW({invalid_bistring_spec, Idx});
_ ->
ok
@@ -141,34 +150,37 @@ mk_binary(Path0, Ctx0, Args) ->
Ctx2,
Desc#bitstring.size),
Unit = Desc#bitstring.unit,
- Type = cerl:ann_c_atom([Line],
+ Type = cerl:ann_c_atom(Annots,
Desc#bitstring.type),
Flags =
- cerl:ann_make_list([Line],
- [cerl:ann_c_atom([Line],
+ cerl:ann_make_list(Annots,
+ [cerl:ann_c_atom(Annots,
Desc#bitstring.signedness),
- cerl:ann_c_atom([Line],
+ cerl:ann_c_atom(Annots,
Desc#bitstring.endianness)]),
{jxa_path:incr(Path2),
Ctx3,
- [cerl:ann_c_bitstr([Line],
+ [cerl:ann_c_bitstr(Annots,
Desc#bitstring.var,
Size,
Unit,
Type,
Flags) | Acc]};
(Var, {Path1, Ctx1, Acc})
when is_atom(Var) orelse is_integer(Var) ->
- {_, Idx={Line, _}} =
- jxa_annot:get(jxa_path:add_path(Path1),
- jxa_ctx:annots(Ctx0)),
+ Annots =
+ jxa_annot:get_line(jxa_path:add_path(Path1),
+ jxa_ctx:annots(Ctx0)),
{Ctx2, CerlVar} =
jxa_expression:comp(Path1, Ctx1, Var),
Desc = resolve_defaults(#bitstring{var=CerlVar}),
case Desc of
invalid ->
+ Idx =
+ jxa_annot:get_line(jxa_path:add_path(Path1),
+ jxa_ctx:annots(Ctx0)),
?JXA_THROW({invalid_bistring_spec, Idx});
_ ->
ok
@@ -179,29 +191,29 @@ mk_binary(Path0, Ctx0, Args) ->
Ctx2,
Desc#bitstring.size),
Unit = Desc#bitstring.unit,
- Type = cerl:ann_c_atom([Line],
+ Type = cerl:ann_c_atom(Annots,
Desc#bitstring.type),
Flags =
- cerl:ann_make_list([Line],
- [cerl:ann_c_atom([Line],
+ cerl:ann_make_list(Annots,
+ [cerl:ann_c_atom(Annots,
Desc#bitstring.signedness),
- cerl:ann_c_atom([Line],
+ cerl:ann_c_atom(Annots,
Desc#bitstring.endianness)]),
{jxa_path:incr(Path1),
Ctx3,
- [cerl:ann_c_bitstr([Line],
+ [cerl:ann_c_bitstr(Annots,
Desc#bitstring.var,
Size,
Unit,
Type,
Flags) | Acc]};
(_, {Path1, _Ctx1, _Acc}) ->
- {_, Idx} =
- jxa_annot:get(jxa_path:add_path(Path1),
- jxa_ctx:annots(Ctx0)),
+ Idx =
+ jxa_annot:get_idx(jxa_path:add_path(Path1),
+ jxa_ctx:annots(Ctx0)),
?JXA_THROW({invalid_bitstring, Idx})
end,
{Path0, Ctx0, []},
Oops, something went wrong.

0 comments on commit 0da66c2

Please sign in to comment.