Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005159OCamlfor Camlp4 use 15:062015-12-11 19:07
ReporterHendrik Tews 
Assigned Todoligez 
PlatformOSOS Version
Product Version3.12.0 
Target VersionFixed in Version3.13.0+dev 
Summary0005159: wrong location after line directive
DescriptionAfter line directives the offsets in the camlp4 locations are wrong.
For instance for a file containing the following two lines

# 1 ""
let a = 5

the location for the StVal node is

file = (OK)
start line = 1 (OK)
start bol = 11 (should be 0)
start offset = 11 (should be 0)
end line = 1 (OK)
end bol = ee (should be 0)
end offset = 20 (should be 9)
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
doligez (administrator)
2010-10-12 11:46
edited on: 2010-10-12 11:46

What makes you think it should be 0 ? The regular compiler does the same thing as camlp4.
These offsets are from the start of the lexbuf, not from the start of an embedded (and possibly nonexistent) file.

Hendrik Tews (reporter)
2010-10-12 23:08

The documentation says that Loc.start_off "Returns the number of
characters from the begining of the file of the begining of this
location" and because file_name="" and in the let is at
position 0 start_off should return 0.
doligez (administrator)
2010-10-13 16:03

Hm. The documentation needs to be rewritten in a less ambiguous way.
In this case, "the file" is your two-line file that contains the # and the let
(i.e. the real file that OCaml is parsing).

In any case, I don't think you should rely on anything else than the
difference between offset and bol.
Hendrik Tews (reporter)
2010-10-18 09:56

doligez wrote:

    Hm. The documentation needs to be rewritten in a less ambiguous way.

I don't see any ambiguity, there is only one file, which name is
returned by Loc.file_name.

    In any case, I don't think you should rely on anything else than the
    difference between offset and bol.

You mean file_name and start/stop_line may return invalid values?
Why are these functions present then?

How would you report an error location with only the difference
between offset and bol? Something like

  File unknown, line unknown, characters 8-9:
  Error: ...

doligez (administrator)
2010-10-19 14:09

Hendrik Tews wrote:

  I don't see any ambiguity, there is only one file, which name is
  returned by Loc.file_name.

Actually, there is only one file, the one that OCaml is parsing (your two-line
file that starts with '# 1 ""'). The fact that you're interpreting it differently
definitely indicates ambiguity.

  You mean file_name and start/stop_line may return invalid values?
  Why are these functions present then?

No, I mean as far as offset and bol are concerned, only the difference is
significant. Of course you can use the file name and line number.
doligez (administrator)
2012-02-10 10:08

Fixed by rewording the documentation to refer to the lexbuf rather than "the file".

Fixed in trunk [3.13.0] (commit 12144).
Hendrik Tews (reporter)
2012-02-10 10:40

May I suggest to update the documentation in camlp4/Camlp4/
as well? There Loc.start_off is still specified to return the
number of characters from the beginning of the file.

I would further suggest to add a note to camlp4/Camlp4/ stating:

Note that character numbers in locations refer to character
numbers in the parsed character stream, while line numbers refer
to line numbers in the source file. The source file and the
parsed character stream differ, for instance, when the parsed
character stream contains a line number directive. The line
number directive will only update the file-name field and the
line-number field of the position. It makes therefore no sense to
use character numbers with the source file if the sources contain
line number directives.
doligez (administrator)
2012-02-13 18:46

Done in trunk [3.13.0] (commit 12150)

- Issue History
Date Modified Username Field Change
2010-09-29 15:06 Hendrik Tews New Issue
2010-09-29 15:06 Hendrik Tews Status new => assigned
2010-09-29 15:06 Hendrik Tews Assigned To => ertai
2010-10-12 11:46 doligez Note Added: 0005679
2010-10-12 11:46 doligez Note Edited: 0005679
2010-10-12 23:08 Hendrik Tews Note Added: 0005681
2010-10-13 16:03 doligez Note Added: 0005682
2010-10-13 16:03 doligez Assigned To ertai => doligez
2010-10-18 09:56 Hendrik Tews Note Added: 0005683
2010-10-19 14:09 doligez Note Added: 0005685
2012-02-10 10:08 doligez Note Added: 0006910
2012-02-10 10:08 doligez Status assigned => closed
2012-02-10 10:08 doligez Resolution open => fixed
2012-02-10 10:08 doligez Fixed in Version => 3.13.0+dev
2012-02-10 10:40 Hendrik Tews Note Added: 0006911
2012-02-10 10:40 Hendrik Tews Status closed => feedback
2012-02-10 10:40 Hendrik Tews Resolution fixed => reopened
2012-02-13 18:46 doligez Note Added: 0006918
2012-02-13 18:46 doligez Status feedback => resolved
2012-02-13 18:46 doligez Resolution reopened => fixed
2015-12-11 19:07 xleroy Status resolved => closed
2016-02-08 12:49 doligez Category Camlp4 => for Camlp4 use [^]
2016-02-08 12:50 doligez Category for Camlp4 use [^] => for Camlp4 use [^]

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker