File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ struct LinesOfCode {
5050 std::optional<std::string> nextLineOfCode;
5151};
5252
53+ /* NOTE: position.hh recursively depends on source-path.hh -> source-accessor.hh
54+ -> hash.hh -> config.hh -> experimental-features.hh -> error.hh -> Pos.
55+ There are other such cycles.
56+ Thus, Pos has to be an incomplete type in this header. But since ErrorInfo/Trace
57+ have to refer to Pos, they have to use pointer indirection via std::shared_ptr
58+ to break the recursive header dependency.
59+ FIXME: Untangle this mess. Should there be AbstractPos as there used to be before
60+ 4feb7d9f71? */
5361struct Pos ;
5462
5563void printCodeLines (std::ostream & out,
Original file line number Diff line number Diff line change @@ -76,6 +76,17 @@ public:
7676 return PosIdx (1 + origin.offset + offset);
7777 }
7878
79+ /* *
80+ * Convert a byte-offset PosIdx into a Pos with line/column information.
81+ *
82+ * @param p Byte offset into the virtual concatenation of all parsed contents
83+ * @return Position
84+ *
85+ * @warning Very expensive to call, as this has to read the entire source
86+ * into memory each time. Call this only if absolutely necessary. Prefer
87+ * to keep PosIdx around instead of needlessly converting it into Pos by
88+ * using this lookup method.
89+ */
7990 Pos operator [](PosIdx p) const ;
8091
8192 Pos::Origin originOf (PosIdx p) const
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ struct Pos
5050
5151 explicit operator bool () const { return line > 0 ; }
5252
53+ /* TODO: Why std::shared_ptr<Pos> and not std::shared_ptr<const Pos>? */
5354 operator std::shared_ptr<Pos>() const ;
5455
5556 /* *
You can’t perform that action at this time.
0 commit comments