aboutsummaryrefslogtreecommitdiffstats
path: root/solc/CommandLineInterface.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-04-19 23:45:36 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-21 06:22:23 +0800
commit4566b4b336c2e572aeb98b174cabb110b454921a (patch)
tree70aa8b10b7d41d46353203a399f34695db96c959 /solc/CommandLineInterface.cpp
parented64c849f57b9aeed1eda4563f0d4340013420ef (diff)
downloaddexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.tar
dexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.tar.gz
dexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.tar.bz2
dexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.tar.lz
dexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.tar.xz
dexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.tar.zst
dexon-solidity-4566b4b336c2e572aeb98b174cabb110b454921a.zip
Pass readFileCallback to StandardCompiler in CLI
Diffstat (limited to 'solc/CommandLineInterface.cpp')
-rw-r--r--solc/CommandLineInterface.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index 49dfd0b5..2bfd0bf2 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -616,6 +616,37 @@ Allowed options)",
bool CommandLineInterface::processInput()
{
+ ReadFile::Callback fileReader = [this](string const& _path)
+ {
+ auto path = boost::filesystem::path(_path);
+ auto canonicalPath = boost::filesystem::canonical(path);
+ bool isAllowed = false;
+ for (auto const& allowedDir: m_allowedDirectories)
+ {
+ // If dir is a prefix of boostPath, we are fine.
+ if (
+ std::distance(allowedDir.begin(), allowedDir.end()) <= std::distance(canonicalPath.begin(), canonicalPath.end()) &&
+ std::equal(allowedDir.begin(), allowedDir.end(), canonicalPath.begin())
+ )
+ {
+ isAllowed = true;
+ break;
+ }
+ }
+ if (!isAllowed)
+ return ReadFile::Result{false, "File outside of allowed directories."};
+ else if (!boost::filesystem::exists(path))
+ return ReadFile::Result{false, "File not found."};
+ else if (!boost::filesystem::is_regular_file(canonicalPath))
+ return ReadFile::Result{false, "Not a valid file."};
+ else
+ {
+ auto contents = dev::contentsString(canonicalPath.string());
+ m_sourceCodes[path.string()] = contents;
+ return ReadFile::Result{true, contents};
+ }
+ };
+
if (m_args.count(g_argAllowPaths))
{
vector<string> paths;
@@ -632,7 +663,7 @@ bool CommandLineInterface::processInput()
getline(cin, tmp);
input.append(tmp + "\n");
}
- StandardCompiler compiler;
+ StandardCompiler compiler(fileReader);
cout << compiler.compile(input) << endl;
return true;
}
@@ -657,37 +688,6 @@ bool CommandLineInterface::processInput()
return link();
}
- ReadFile::Callback fileReader = [this](string const& _path)
- {
- auto path = boost::filesystem::path(_path);
- auto canonicalPath = boost::filesystem::canonical(path);
- bool isAllowed = false;
- for (auto const& allowedDir: m_allowedDirectories)
- {
- // If dir is a prefix of boostPath, we are fine.
- if (
- std::distance(allowedDir.begin(), allowedDir.end()) <= std::distance(canonicalPath.begin(), canonicalPath.end()) &&
- std::equal(allowedDir.begin(), allowedDir.end(), canonicalPath.begin())
- )
- {
- isAllowed = true;
- break;
- }
- }
- if (!isAllowed)
- return ReadFile::Result{false, "File outside of allowed directories."};
- else if (!boost::filesystem::exists(path))
- return ReadFile::Result{false, "File not found."};
- else if (!boost::filesystem::is_regular_file(canonicalPath))
- return ReadFile::Result{false, "Not a valid file."};
- else
- {
- auto contents = dev::contentsString(canonicalPath.string());
- m_sourceCodes[path.string()] = contents;
- return ReadFile::Result{true, contents};
- }
- };
-
m_compiler.reset(new CompilerStack(fileReader));
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); };
try