| 254 | } |
| 255 | |
| 256 | bool CompileSourceFile::postPreprocess_() { |
| 257 | FileSystem* const fileSystem = FileSystem::getInstance(); |
| 258 | if (m_commandLineParser->parseOnly()) { |
| 259 | m_ppResultFileId = fileSystem->copy(m_fileId, m_symbolTable); |
| 260 | return true; |
| 261 | } |
| 262 | std::string m_pp_result = m_pp->getPreProcessedFileContent(); |
| 263 | if (!m_text.empty()) { |
| 264 | m_parser = new ParseFile(m_pp_result, this, m_compilationUnit, |
| 265 | m_library); // unit test |
| 266 | } |
| 267 | if (!(m_commandLineParser->writePpOutput() || |
| 268 | m_commandLineParser->writePpOutputFileId())) { |
| 269 | return true; |
| 270 | } |
| 271 | |
| 272 | m_ppResultFileId = m_commandLineParser->writePpOutputFileId(); |
| 273 | if (!m_ppResultFileId) { |
| 274 | const std::string_view libraryName = m_library->getName(); |
| 275 | m_ppResultFileId = fileSystem->getPpOutputFile( |
| 276 | m_commandLineParser->fileunit(), m_fileId, libraryName, m_symbolTable); |
| 277 | } |
| 278 | |
| 279 | if (m_commandLineParser->lowMem() || m_commandLineParser->link()) { |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | const PathId ppResultDirId = |
| 284 | fileSystem->getParent(m_ppResultFileId, m_symbolTable); |
| 285 | if (!fileSystem->mkdirs(ppResultDirId)) { |
| 286 | Location loc(ppResultDirId); |
| 287 | Error err(ErrorDefinition::PP_CANNOT_CREATE_DIRECTORY, loc); |
| 288 | m_errors->addError(err); |
| 289 | return false; |
| 290 | } |
| 291 | if (!m_pp->usingCachedVersion() || !fileSystem->exists(m_ppResultFileId)) { |
| 292 | if (!fileSystem->writeContent(m_ppResultFileId, m_pp_result, true)) { |
| 293 | Location loc(m_ppResultFileId); |
| 294 | Error err(ErrorDefinition::PP_OPEN_FILE_FOR_WRITE, loc); |
| 295 | m_errors->addError(err); |
| 296 | return false; |
| 297 | } |
| 298 | } |
| 299 | return true; |
| 300 | } |
| 301 | |
| 302 | void CompileSourceFile::registerAntlrPpHandlerForId( |
| 303 | SymbolId id, PreprocessFile::AntlrParserHandler* pp) { |
nothing calls this directly
no test coverage detected