| 349 | } |
| 350 | |
| 351 | bool PreprocessFile::preprocess() { |
| 352 | m_result.clear(); |
| 353 | std::string macroName; |
| 354 | CommandLineParser* clp = getCompileSourceFile()->getCommandLineParser(); |
| 355 | FileSystem* const fileSystem = FileSystem::getInstance(); |
| 356 | Timer tmr; |
| 357 | bool precompiled = false; |
| 358 | SymbolId macroSignatureId; |
| 359 | if (m_macroBody.empty()) { |
| 360 | precompiled = Precompiled::getSingleton()->isFilePrecompiled( |
| 361 | m_fileId, getCompileSourceFile()->getSymbolTable()); |
| 362 | PPCache cache(this); |
| 363 | if (cache.restore(clp->lowMem() || clp->noCacheHash())) { |
| 364 | m_usingCachedVersion = true; |
| 365 | getCompilationUnit()->setCurrentTimeInfo(getFileId(0)); |
| 366 | if (m_debugAstModel && !precompiled) |
| 367 | std::cout << m_fileContent->printObjects(); |
| 368 | if (precompiled || clp->noCacheHash()) { |
| 369 | if (clp->debugCache()) { |
| 370 | std::cout << "PP CACHE USED FOR: " << PathIdPP(m_fileId) << std::endl; |
| 371 | } |
| 372 | return true; |
| 373 | } |
| 374 | if (!clp->parseOnly() && !clp->lowMem()) { |
| 375 | resetIncludeFileInfo(); |
| 376 | } |
| 377 | } |
| 378 | } else { |
| 379 | macroName = getSymbol(m_macroId); |
| 380 | macroSignatureId = getMacroSignature(); |
| 381 | } |
| 382 | if (clp->parseOnly() || clp->lowMem() || clp->link()) return true; |
| 383 | |
| 384 | m_antlrParserHandler = |
| 385 | m_macroBody.empty() |
| 386 | ? getCompileSourceFile()->getAntlrPpHandlerForId(m_fileId) |
| 387 | : getCompileSourceFile()->getAntlrPpHandlerForId(macroSignatureId); |
| 388 | |
| 389 | if (m_antlrParserHandler == nullptr) { |
| 390 | m_antlrParserHandler = new AntlrParserHandler(); |
| 391 | m_antlrParserHandler->m_clearAntlrCache = clp->lowMem(); |
| 392 | if (m_macroBody.empty()) { |
| 393 | if (m_debugPP) |
| 394 | std::cout << "PP PREPROCESS FILE: " << PathIdPP(m_fileId) << std::endl; |
| 395 | std::istream& stream = fileSystem->openForRead(m_fileId); |
| 396 | if (!stream.good()) { |
| 397 | if (m_includer == nullptr) { |
| 398 | Location loc(m_fileId); |
| 399 | Error err(ErrorDefinition::PP_CANNOT_OPEN_FILE, loc); |
| 400 | addError(err); |
| 401 | } else { |
| 402 | Location includeFile(m_includer->m_fileId, m_includerLine, 0, |
| 403 | (SymbolId)m_fileId); |
| 404 | Error err(ErrorDefinition::PP_CANNOT_OPEN_INCLUDE_FILE, includeFile); |
| 405 | addError(err); |
| 406 | } |
| 407 | return false; |
| 408 | } |