diff options
author | Son Ho | 2022-10-26 10:12:03 +0200 |
---|---|---|
committer | Son HO | 2022-10-26 10:42:07 +0200 |
commit | 7d6e7a5608327d24bf8574bda53dc031d3b91140 (patch) | |
tree | f13ed45792a440a75a9cdd54aa0b76d28854d687 /src/Meta.ml | |
parent | 7f2f06918e9326138097bc91a8cf1eb7a0af2a9d (diff) |
Add meta data with code locations to the various definitions
Diffstat (limited to 'src/Meta.ml')
-rw-r--r-- | src/Meta.ml | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Meta.ml b/src/Meta.ml new file mode 100644 index 00000000..cca6f047 --- /dev/null +++ b/src/Meta.ml @@ -0,0 +1,44 @@ +(** Meta data like code spans *) + +(** A line location *) +type loc = { + line : int; (** The (1-based) line number. *) + col : int; (** The (0-based) column offset. *) +} +[@@deriving show] + +type file_name = + | Virtual of string (** A remapped path (namely paths into stdlib) *) + | Local of string + (** A local path (a file coming from the current crate for instance) *) +[@@deriving show] + +(** Span data *) +type span = { file : file_name; beg_loc : loc; end_loc : loc } [@@deriving show] + +type meta = { + span : span; + (** The source code span. + + If this meta information is for a statement/terminator coming from a macro + expansion/inlining/etc., this span is (in case of macros) for the macro + before expansion (i.e., the location the code where the user wrote the call + to the macro). + + Ex: + ```text + // Below, we consider the spans for the statements inside `test` + + // the statement we consider, which gets inlined in `test` + VV + macro_rules! macro { ... st ... } // `generated_from_span` refers to this location + + fn test() { + macro!(); // <-- `span` refers to this location + } + ``` + *) + generated_from_span : span option; + (** Where the code actually comes from, in case of macro expansion/inlining/etc. *) +} +[@@deriving show] |