|
| 1 | +//===------ArgsToFrontendOptionsConverter.h-- --------------------*-C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_FRONTEND_ARGSTOFRONTENDOPTIONSCONVERTER_H |
| 14 | +#define SWIFT_FRONTEND_ARGSTOFRONTENDOPTIONSCONVERTER_H |
| 15 | + |
| 16 | +#include "swift/AST/DiagnosticConsumer.h" |
| 17 | +#include "swift/AST/DiagnosticEngine.h" |
| 18 | +#include "swift/Frontend/FrontendOptions.h" |
| 19 | +#include "swift/Option/Options.h" |
| 20 | +#include "llvm/Option/ArgList.h" |
| 21 | + |
| 22 | +#include <vector> |
| 23 | + |
| 24 | +namespace swift { |
| 25 | + |
| 26 | +class ArgsToFrontendOptionsConverter { |
| 27 | +private: |
| 28 | + DiagnosticEngine &Diags; |
| 29 | + const llvm::opt::ArgList &Args; |
| 30 | + FrontendOptions &Opts; |
| 31 | + |
| 32 | + Optional<const std::vector<std::string>> |
| 33 | + cachedOutputFilenamesFromCommandLineOrFilelist; |
| 34 | + |
| 35 | + void handleDebugCrashGroupArguments(); |
| 36 | + |
| 37 | + void computeDebugTimeOptions(); |
| 38 | + bool computeFallbackModuleName(); |
| 39 | + bool computeModuleName(); |
| 40 | + bool computeOutputFilenames(); |
| 41 | + void computeDumpScopeMapLocations(); |
| 42 | + void computeHelpOptions(); |
| 43 | + void computeImplicitImportModuleNames(); |
| 44 | + void computeImportObjCHeaderOptions(); |
| 45 | + void computeLLVMArgs(); |
| 46 | + void computePlaygroundOptions(); |
| 47 | + void computePrintStatsOptions(); |
| 48 | + void computeTBDOptions(); |
| 49 | + |
| 50 | + void setUnsignedIntegerArgument(options::ID optionID, unsigned max, |
| 51 | + unsigned &valueToSet); |
| 52 | + |
| 53 | + FrontendOptions::ActionType determineRequestedAction() const; |
| 54 | + |
| 55 | + bool setUpForSILOrLLVM(); |
| 56 | + |
| 57 | + /// Determine the correct output filename when none was specified. |
| 58 | + /// |
| 59 | + /// Such an absence should only occur when invoking the frontend |
| 60 | + /// without the driver, |
| 61 | + /// because the driver will always pass -o with an appropriate filename |
| 62 | + /// if output is required for the requested action. |
| 63 | + bool deriveOutputFilenameFromInputFile(); |
| 64 | + |
| 65 | + /// Determine the correct output filename when a directory was specified. |
| 66 | + /// |
| 67 | + /// Such a specification should only occur when invoking the frontend |
| 68 | + /// directly, because the driver will always pass -o with an appropriate |
| 69 | + /// filename if output is required for the requested action. |
| 70 | + bool deriveOutputFilenameForDirectory(StringRef outputDir); |
| 71 | + |
| 72 | + std::string determineBaseNameOfOutput() const; |
| 73 | + |
| 74 | + void deriveOutputFilenameFromParts(StringRef dir, StringRef base); |
| 75 | + |
| 76 | + void determineSupplementaryOutputFilenames(); |
| 77 | + |
| 78 | + /// Returns the output filenames on the command line or in the output |
| 79 | + /// filelist. If there |
| 80 | + /// were neither -o's nor an output filelist, returns an empty vector. |
| 81 | + ArrayRef<std::string> getOutputFilenamesFromCommandLineOrFilelist(); |
| 82 | + |
| 83 | + bool checkForUnusedOutputPaths() const; |
| 84 | + |
| 85 | + std::vector<std::string> readOutputFileList(StringRef filelistPath) const; |
| 86 | + |
| 87 | +public: |
| 88 | + ArgsToFrontendOptionsConverter(DiagnosticEngine &Diags, |
| 89 | + const llvm::opt::ArgList &Args, |
| 90 | + FrontendOptions &Opts) |
| 91 | + : Diags(Diags), Args(Args), Opts(Opts) {} |
| 92 | + |
| 93 | + bool convert(); |
| 94 | +}; |
| 95 | + |
| 96 | +} // namespace swift |
| 97 | + |
| 98 | +#endif /* SWIFT_FRONTEND_ARGSTOFRONTENDOPTIONSCONVERTER_H */ |
0 commit comments