Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
4041-Add-erl_anno-set_end_location-2.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 4041-Add-erl_anno-set_end_location-2.patch of Package erlang
From 16ead333a7704610fd3daf8de44d227faa941964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= <jonatanklosko@gmail.com> Date: Tue, 12 Nov 2024 14:00:03 +0800 Subject: [PATCH] Add erl_anno:set_end_location/2 --- lib/stdlib/src/erl_anno.erl | 51 +++++++++++++++++++++++------- lib/stdlib/test/erl_anno_SUITE.erl | 26 ++++++++++++++- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/lib/stdlib/src/erl_anno.erl b/lib/stdlib/src/erl_anno.erl index 3a64c221b4..ef47d5a4df 100644 --- a/lib/stdlib/src/erl_anno.erl +++ b/lib/stdlib/src/erl_anno.erl @@ -75,7 +75,7 @@ for manipulating annotations in abstract code. -export([column/1, end_location/1, file/1, generated/1, line/1, location/1, record/1, text/1]). -export([set_file/2, set_generated/2, set_line/2, set_location/2, - set_record/2, set_text/2]). + set_end_location/2, set_record/2, set_text/2]). %% To be used when necessary to avoid Dialyzer warnings. -export([to_term/1, from_term/1]). @@ -100,6 +100,7 @@ for manipulating annotations in abstract code. -type annotation() :: {'file', filename()} | {'generated', generated()} | {'location', location()} + | {'end_location', location()} | {'record', record()} | {'text', string()}. @@ -251,17 +252,27 @@ column(Anno) -> -spec end_location(Anno) -> location() | 'undefined' when Anno :: anno(). +end_location(Line) when ?ALINE(Line) -> + undefined; +end_location({Line, Column}) when ?ALINE(Line), ?ACOLUMN(Column) -> + undefined; end_location(Anno) -> - case text(Anno) of + case anno_info(Anno, end_location) of undefined -> - undefined; - Text -> - case location(Anno) of - {Line, Column} -> - end_location(Text, Line, Column); - Line -> - end_location(Text, Line) - end + case text(Anno) of + undefined -> + undefined; + Text -> + case location(Anno) of + {Line, Column} -> + end_location(Text, Line, Column); + Line -> + end_location(Text, Line) + end + end; + + Location -> + Location end. -spec file(Anno) -> filename() | 'undefined' when @@ -403,6 +417,13 @@ set_location({L, C}=Loc, {Line, Column}) when ?ALINE(Line), ?ACOLUMN(Column), set_location(Location, Anno) -> set(location, Location, Anno). +-spec set_end_location(Location, Anno) -> Anno when + Location :: location(), + Anno :: anno(). + +set_end_location(Location, Anno) -> + set(end_location, Location, Anno). + -spec set_record(Record, Anno) -> Anno when Record :: record(), Anno :: anno(). @@ -508,6 +531,10 @@ is_settable(location, Line) when ?LLINE(Line) -> true; is_settable(location, {Line, Column}) when ?LLINE(Line), ?LCOLUMN(Column) -> true; +is_settable(end_location, Line) when ?LLINE(Line) -> + true; +is_settable(end_location, {Line, Column}) when ?LLINE(Line), ?LCOLUMN(Column) -> + true; is_settable(record, Boolean) when Boolean; not Boolean -> true; is_settable(text, Text) -> diff --git a/lib/stdlib/test/erl_anno_SUITE.erl b/lib/stdlib/test/erl_anno_SUITE.erl index 71ea9c3e1e..bc95ee6582 100644 --- a/lib/stdlib/test/erl_anno_SUITE.erl +++ b/lib/stdlib/test/erl_anno_SUITE.erl @@ -131,6 +131,11 @@ end_location(_Config) -> test(1, [{text, "TEXT", [{end_location, 1}, {length, 4}]}, {text, "TEXT\n", [{end_location, 2}, {length, 5}]}, {text, "TEXT\ntxt", [{end_location, 2}, {length, 8}]}]), + test({1, 17}, [{end_location, {1, 21}, [{end_location, {1, 21}}]}, + {end_location, {2, 1}, [{end_location, {2, 1}}]}]), + test(1, [{end_location, 1, [{end_location, 1}]}, + {end_location, 2, [{end_location, 2}]}, + {end_location, {1, 2}, [{end_location, {1, 2}}]}]), ok. %% Test 'file'. @@ -396,6 +401,8 @@ anno_set(line, Value, Anno) -> erl_anno:set_line(Value, Anno); anno_set(location, Value, Anno) -> erl_anno:set_location(Value, Anno); +anno_set(end_location, Value, Anno) -> + erl_anno:set_end_location(Value, Anno); anno_set(record, Value, Anno) -> erl_anno:set_record(Value, Anno); anno_set(text, Value, Anno) -> @@ -463,6 +470,23 @@ primary_value(line, State) -> Line -> Line end}; +primary_value(end_location, State) -> + case lists:keyfind(end_location, 1, State) of + false -> + case lists:keyfind(text, 1, State) of + false -> + undefined; + {text, Text} -> + case lists:keyfind(location, 1, State) of + false -> + undefined; + {location, Location} -> + {end_location, erl_anno:end_location(erl_anno:set_text(Text, erl_anno:new(Location)))} + end + end; + Tuple -> + Tuple + end; primary_value(Item, State) -> case lists:keyfind(Item, 1, State) of false -> @@ -475,7 +499,7 @@ default() -> [{Tag, default_value(Tag)} || Tag <- default_items()]. primary_items() -> - [file, generated, line, location, record, text]. + [file, generated, line, location, end_location, record, text]. secondary_items() -> %% 'length' has not been implemented -- 2.43.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor