| 113 | } |
| 114 | |
| 115 | void SourceReferenceFormatter::printSourceLocation(SourceReference const& _ref) |
| 116 | { |
| 117 | if (_ref.position.line < 0) |
| 118 | { |
| 119 | if (_ref.sourceName.empty()) |
| 120 | return; // Nothing we can print here |
| 121 | |
| 122 | frameColored() << "-->"; |
| 123 | m_stream << ' ' << _ref.sourceName << '\n'; |
| 124 | return; // No line available, nothing else to print |
| 125 | } |
| 126 | |
| 127 | std::string line = std::to_string(_ref.position.line + 1); // one-based line number as string |
| 128 | std::string leftpad = std::string(line.size(), ' '); |
| 129 | |
| 130 | // line 0: source name |
| 131 | m_stream << leftpad; |
| 132 | frameColored() << "-->"; |
| 133 | m_stream << ' ' << _ref.sourceName << ':' << line << ':' << (_ref.position.column + 1) << ":\n"; |
| 134 | |
| 135 | std::string_view text = _ref.text; |
| 136 | |
| 137 | if (m_charStreamProvider.charStream(_ref.sourceName).isImportedFromAST()) |
| 138 | return; |
| 139 | |
| 140 | if (!_ref.multiline) |
| 141 | { |
| 142 | size_t const locationLength = static_cast<size_t>(_ref.endColumn - _ref.startColumn); |
| 143 | |
| 144 | // line 1: |
| 145 | m_stream << leftpad << ' '; |
| 146 | frameColored() << '|'; |
| 147 | m_stream << '\n'; |
| 148 | |
| 149 | // line 2: |
| 150 | frameColored() << line << " |"; |
| 151 | |
| 152 | m_stream << ' ' << text.substr(0, static_cast<size_t>(_ref.startColumn)); |
| 153 | highlightColored() << text.substr(static_cast<size_t>(_ref.startColumn), locationLength); |
| 154 | m_stream << text.substr(static_cast<size_t>(_ref.endColumn)) << '\n'; |
| 155 | |
| 156 | // line 3: |
| 157 | m_stream << leftpad << ' '; |
| 158 | frameColored() << '|'; |
| 159 | |
| 160 | m_stream << ' ' << replaceNonTabs(text.substr(0, static_cast<size_t>(_ref.startColumn)), ' '); |
| 161 | diagColored() << ( |
| 162 | locationLength == 0 ? |
| 163 | "^" : |
| 164 | replaceNonTabs(text.substr(static_cast<size_t>(_ref.startColumn), locationLength), '^') |
| 165 | ); |
| 166 | m_stream << '\n'; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | // line 1: |
| 171 | m_stream << leftpad << ' '; |
| 172 | frameColored() << '|'; |
nothing calls this directly
no test coverage detected