| 181 | }; |
| 182 | |
| 183 | void PreprocessFile::DescriptiveErrorListener::syntaxError( |
| 184 | Recognizer* recognizer, Token* offendingSymbol, size_t line, |
| 185 | size_t charPositionInLine, const std::string& msg, std::exception_ptr e) { |
| 186 | SymbolId msgId = m_pp->registerSymbol(msg); |
| 187 | |
| 188 | if (m_pp->m_macroInfo) { |
| 189 | std::string lineText(m_pp->getMacroBody()); |
| 190 | for (uint32_t i = 0; i < charPositionInLine; i++) lineText += " "; |
| 191 | lineText += "^-- " + m_macroContext + ":" + std::to_string(line) + ":" + |
| 192 | std::to_string(charPositionInLine) + ":"; |
| 193 | msgId = m_pp->registerSymbol(msg + "," + lineText); |
| 194 | Location loc(m_pp->getMacroInfo()->m_fileId, |
| 195 | m_pp->getMacroInfo()->m_startLine + line - 1, |
| 196 | charPositionInLine, msgId); |
| 197 | Location extraLoc(m_pp->getIncluderFileId(m_pp->getIncluderLine()), |
| 198 | m_pp->getIncluderLine(), 0); |
| 199 | Error err(ErrorDefinition::PP_MACRO_SYNTAX_ERROR, loc, extraLoc); |
| 200 | m_pp->addError(err); |
| 201 | } else { |
| 202 | FileSystem* fileSystem = FileSystem::getInstance(); |
| 203 | if (m_fileContent.empty()) { |
| 204 | fileSystem->readLines(m_fileId, m_fileContent); |
| 205 | } |
| 206 | |
| 207 | std::string lineText; |
| 208 | if (!m_fileContent.empty() && (line <= m_fileContent.size())) { |
| 209 | lineText = m_fileContent[line - 1]; |
| 210 | if (!lineText.empty()) { |
| 211 | if (lineText.back() != '\n') { |
| 212 | lineText += "\n"; |
| 213 | } |
| 214 | lineText.append(charPositionInLine, ' '); |
| 215 | StrAppend(&lineText, "^-- ", fileSystem->toPath(m_fileId), ":", line, |
| 216 | ":", charPositionInLine, ":"); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | Location loc2(m_pp->registerSymbol(lineText)); |
| 221 | |
| 222 | Location loc(m_pp->getFileId(line), line, charPositionInLine, msgId); |
| 223 | Error err(ErrorDefinition::PP_SYNTAX_ERROR, loc, loc2); |
| 224 | m_pp->addError(err); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void PreprocessFile::DescriptiveErrorListener::reportAmbiguity( |
| 229 | Parser* recognizer, const antlr4::dfa::DFA& dfa, size_t startIndex, |
nothing calls this directly
no test coverage detected