Skip to content

Commit

Permalink
Introduce --no-import-callback CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic committed Oct 13, 2023
1 parent 8820870 commit e2ea3fa
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Language Features:


Compiler Features:
* Commandline Interface: Add ``--no-import-callback`` option to disable the default file reader callback.
* Parser: Remove the experimental error recovery mode (``--error-recovery`` / ``settings.parserErrorRecovery``).
* Yul Optimizer: If ``PUSH0`` is supported, favor zero literals over storing zero values in variables.
* Yul Optimizer: Run the ``Rematerializer`` and ``UnusedPruner`` steps at the end of the default clean-up sequence.
Expand Down
10 changes: 7 additions & 3 deletions libsolidity/interface/UniversalCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,28 @@ namespace solidity::frontend
class UniversalCallback
{
public:
UniversalCallback(FileReader& _fileReader, SMTSolverCommand& _solver) :
UniversalCallback(FileReader* _fileReader, SMTSolverCommand& _solver) :
m_fileReader{_fileReader},
m_solver{_solver}
{}

frontend::ReadCallback::Callback callback()
{
return [this](std::string const& _kind, std::string const& _data) -> ReadCallback::Result {
if (!m_fileReader)
return ReadCallback::Result{false, "File reader callback is disabled."};
if (_kind == ReadCallback::kindString(ReadCallback::Kind::ReadFile))
return m_fileReader.readFile(_kind, _data);
return m_fileReader->readFile(_kind, _data);
else if (_kind == ReadCallback::kindString(ReadCallback::Kind::SMTQuery))
return m_solver.solve(_kind, _data);
solAssert(false, "Unknown callback kind.");
};
}

void disableFileReaderCallback() { m_fileReader = nullptr; }

private:
FileReader& m_fileReader;
FileReader* m_fileReader;
SMTSolverCommand& m_solver;
};

Expand Down
3 changes: 3 additions & 0 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ bool CommandLineInterface::parseArguments(int _argc, char const* const* _argv)
parser.parse(_argc, _argv);
m_options = parser.options();

if (m_options.input.noImportCallback)
m_universalCallback.disableFileReaderCallback();

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion solc/CommandLineInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CommandLineInterface
bool m_hasOutput = false;
FileReader m_fileReader;
SMTSolverCommand m_solverCommand{"eld"};
UniversalCallback m_universalCallback{m_fileReader, m_solverCommand};
UniversalCallback m_universalCallback{&m_fileReader, m_solverCommand};
std::optional<std::string> m_standardJsonInput;
std::unique_ptr<frontend::CompilerStack> m_compiler;
CommandLineOptions m_options;
Expand Down
9 changes: 9 additions & 0 deletions solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static std::string const g_strModelCheckerTimeout = "model-checker-timeout";
static std::string const g_strModelCheckerBMCLoopIterations = "model-checker-bmc-loop-iterations";
static std::string const g_strNone = "none";
static std::string const g_strNoOptimizeYul = "no-optimize-yul";
static std::string const g_strNoImportCallback = "no-import-callback";
static std::string const g_strOptimize = "optimize";
static std::string const g_strOptimizeRuns = "optimize-runs";
static std::string const g_strOptimizeYul = "optimize-yul";
Expand Down Expand Up @@ -224,6 +225,7 @@ bool CommandLineOptions::operator==(CommandLineOptions const& _other) const noex
input.includePaths == _other.input.includePaths &&
input.allowedDirectories == _other.input.allowedDirectories &&
input.ignoreMissingFiles == _other.input.ignoreMissingFiles &&
input.noImportCallback == _other.input.noImportCallback &&
output.dir == _other.output.dir &&
output.overwriteFiles == _other.output.overwriteFiles &&
output.evmVersion == _other.output.evmVersion &&
Expand Down Expand Up @@ -567,6 +569,10 @@ General Information)").c_str(),
g_strIgnoreMissingFiles.c_str(),
"Ignore missing files."
)
(
g_strNoImportCallback.c_str(),
"Disable the default file import callback."
)
;
desc.add(inputOptions);

Expand Down Expand Up @@ -1101,6 +1107,9 @@ void CommandLineParser::processArgs()
}
}

if (m_args.count(g_strNoImportCallback))
m_options.input.noImportCallback = true;

if (m_args.count(g_strAllowPaths))
{
std::vector<std::string> paths;
Expand Down
1 change: 1 addition & 0 deletions solc/CommandLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ struct CommandLineOptions
std::vector<boost::filesystem::path> includePaths;
FileReader::FileSystemPathSet allowedDirectories;
bool ignoreMissingFiles = false;
bool noImportCallback = false;
} input;

struct
Expand Down

0 comments on commit e2ea3fa

Please sign in to comment.