public final class SourceMapping extends Object
The point of this information is to keep track of where semantic
actions (see Extent
) end up in generated files, to be
able to translate features that rely on positions in generated
files (errors, markers, stacktrace information) back to the
corresponding positions in the source files if possible.
Modifier and Type | Class and Description |
---|---|
static class |
SourceMapping.Mapping
A mapping describes a link between the range
described by
SourceMapping.Mapping.offset and SourceMapping.Mapping.length
in the generated file and the region of the
same length starting at position SourceMapping.Mapping.origin
in the source file. |
static class |
SourceMapping.Origin
An instance of this class describes the origin of some region
of generated code in terms of the source region from which it
originated.
|
Constructor and Description |
---|
SourceMapping(String generated) |
Modifier and Type | Method and Description |
---|---|
void |
add(int offset,
int length,
LexBuffer.Position origin,
@Nullable CExtent extent)
Adds a new mapping to
this , describing that
the range starting at position offset and spanning
length bytes corresponds to the range of the same
length at position origin in the original source. |
void |
forEach(Consumer<? super SourceMapping.Mapping> consumer)
Iterates on all known mappings and
applies
consumer on each one |
@Nullable SourceMapping.Origin |
map(int offset,
int length)
Tries to map the region described by
offset
and length to the original source via the
mappings known in this instance. |
String |
toString() |
public SourceMapping(String generated)
generated
- a name describing the input being mapped
Constructs a fresh and empty SourceMapping
describing mapping regions of generated
to
regions of one or several original sourcespublic void add(int offset, int length, LexBuffer.Position origin, @Nullable CExtent extent)
this
, describing that
the range starting at position offset
and spanning
length
bytes corresponds to the range of the same
length at position origin
in the original source.
If the mapped region stems from expanding and instantiating
the source region, the structure of the instantiation is
given by extent
. Otherwise extent
must be
null
.
offset
- length
- origin
- extent
- public void forEach(Consumer<? super SourceMapping.Mapping> consumer)
consumer
on each oneconsumer
- public @Nullable SourceMapping.Origin map(int offset, int length)
offset
and length
to the original source via the
mappings known in this instance.
The returned origin does not necessarily match the given region's contents exactly, as the latter may be the result of instantiating holes in semantic actions.
offset
- length
- null
if
the described range is not entirely mapped in any of
these source mappingsSourceMapping.Origin