mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
enumchecks not working
This commit is contained in:
parent
5fd7942173
commit
45f8c5aa88
@ -57,7 +57,7 @@ using namespace dev;
|
|||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
CompilerStack::CompilerStack(ReadFile::Callback const& _readFile):
|
CompilerStack::CompilerStack(ReadFile::Callback const& _readFile):
|
||||||
m_readFile(_readFile), m_success(false) {}
|
m_readFile(_readFile), m_stackState(Empty) {}
|
||||||
|
|
||||||
void CompilerStack::setRemappings(vector<string> const& _remappings)
|
void CompilerStack::setRemappings(vector<string> const& _remappings)
|
||||||
{
|
{
|
||||||
@ -79,7 +79,6 @@ void CompilerStack::setRemappings(vector<string> const& _remappings)
|
|||||||
|
|
||||||
void CompilerStack::reset(bool _keepSources)
|
void CompilerStack::reset(bool _keepSources)
|
||||||
{
|
{
|
||||||
m_success = false;
|
|
||||||
if (_keepSources)
|
if (_keepSources)
|
||||||
for (auto sourcePair: m_sources)
|
for (auto sourcePair: m_sources)
|
||||||
sourcePair.second.reset();
|
sourcePair.second.reset();
|
||||||
@ -94,6 +93,7 @@ void CompilerStack::reset(bool _keepSources)
|
|||||||
m_sourceOrder.clear();
|
m_sourceOrder.clear();
|
||||||
m_contracts.clear();
|
m_contracts.clear();
|
||||||
m_errors.clear();
|
m_errors.clear();
|
||||||
|
m_stackState = Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerStack::addSource(string const& _name, string const& _content, bool _isLibrary)
|
bool CompilerStack::addSource(string const& _name, string const& _content, bool _isLibrary)
|
||||||
@ -102,6 +102,7 @@ bool CompilerStack::addSource(string const& _name, string const& _content, bool
|
|||||||
reset(true);
|
reset(true);
|
||||||
m_sources[_name].scanner = make_shared<Scanner>(CharStream(_content), _name);
|
m_sources[_name].scanner = make_shared<Scanner>(CharStream(_content), _name);
|
||||||
m_sources[_name].isLibrary = _isLibrary;
|
m_sources[_name].isLibrary = _isLibrary;
|
||||||
|
m_stackState = SourcesSet;
|
||||||
return existed;
|
return existed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,9 +115,10 @@ void CompilerStack::setSource(string const& _sourceCode)
|
|||||||
bool CompilerStack::parse()
|
bool CompilerStack::parse()
|
||||||
{
|
{
|
||||||
//reset
|
//reset
|
||||||
|
if(m_stackState < SourcesSet)
|
||||||
|
return false;
|
||||||
m_errors.clear();
|
m_errors.clear();
|
||||||
ASTNode::resetID();
|
ASTNode::resetID();
|
||||||
m_success = false;
|
|
||||||
|
|
||||||
if (SemVerVersion{string(VersionString)}.isPrerelease())
|
if (SemVerVersion{string(VersionString)}.isPrerelease())
|
||||||
{
|
{
|
||||||
@ -148,14 +150,20 @@ bool CompilerStack::parse()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Error::containsOnlyWarnings(m_errors);
|
if (Error::containsOnlyWarnings(m_errors))
|
||||||
|
{
|
||||||
|
m_stackState = ParsingSuccessful;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerStack::analyze()
|
bool CompilerStack::analyze()
|
||||||
{
|
{
|
||||||
if (m_sources.empty())
|
if (m_stackState < SourcesSet)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("There are no sources to be analyzed."));
|
return false;
|
||||||
|
//BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No Sources Set to be analyzed."));
|
||||||
resolveImports();
|
resolveImports();
|
||||||
|
|
||||||
bool noErrors = true;
|
bool noErrors = true;
|
||||||
@ -240,8 +248,13 @@ bool CompilerStack::analyze()
|
|||||||
noErrors = false;
|
noErrors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_success = noErrors;
|
if (noErrors)
|
||||||
return m_success;
|
{
|
||||||
|
m_stackState = AnalysisSuccessful;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerStack::parse(string const& _sourceCode)
|
bool CompilerStack::parse(string const& _sourceCode)
|
||||||
@ -263,7 +276,7 @@ bool CompilerStack::parseAndAnalyze(std::string const& _sourceCode)
|
|||||||
|
|
||||||
vector<string> CompilerStack::contractNames() const
|
vector<string> CompilerStack::contractNames() const
|
||||||
{
|
{
|
||||||
if (!m_success)
|
if (m_stackState != AnalysisSuccessful)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
||||||
vector<string> contractNames;
|
vector<string> contractNames;
|
||||||
for (auto const& contract: m_contracts)
|
for (auto const& contract: m_contracts)
|
||||||
@ -274,7 +287,7 @@ vector<string> CompilerStack::contractNames() const
|
|||||||
|
|
||||||
bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> const& _libraries)
|
bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> const& _libraries)
|
||||||
{
|
{
|
||||||
if (!m_success)
|
if (m_stackState < AnalysisSuccessful)
|
||||||
if (!parseAndAnalyze())
|
if (!parseAndAnalyze())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -288,6 +301,7 @@ bool CompilerStack::compile(bool _optimize, unsigned _runs, map<string, h160> co
|
|||||||
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
|
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
|
||||||
compileContract(*contract, compiledContracts);
|
compileContract(*contract, compiledContracts);
|
||||||
this->link();
|
this->link();
|
||||||
|
m_stackState = CompilationSuccessful;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +449,7 @@ Json::Value const& CompilerStack::interface(string const& _contractName) const
|
|||||||
|
|
||||||
Json::Value const& CompilerStack::metadata(string const& _contractName, DocumentationType _type) const
|
Json::Value const& CompilerStack::metadata(string const& _contractName, DocumentationType _type) const
|
||||||
{
|
{
|
||||||
if (!m_success)
|
if (m_stackState == CompilationSuccessful)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
||||||
|
|
||||||
return metadata(contract(_contractName), _type);
|
return metadata(contract(_contractName), _type);
|
||||||
@ -443,7 +457,7 @@ Json::Value const& CompilerStack::metadata(string const& _contractName, Document
|
|||||||
|
|
||||||
Json::Value const& CompilerStack::metadata(Contract const& _contract, DocumentationType _type) const
|
Json::Value const& CompilerStack::metadata(Contract const& _contract, DocumentationType _type) const
|
||||||
{
|
{
|
||||||
if (!m_success)
|
if (m_stackState != CompilationSuccessful)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
||||||
|
|
||||||
solAssert(_contract.contract, "");
|
solAssert(_contract.contract, "");
|
||||||
@ -474,7 +488,7 @@ Json::Value const& CompilerStack::metadata(Contract const& _contract, Documentat
|
|||||||
|
|
||||||
string const& CompilerStack::onChainMetadata(string const& _contractName) const
|
string const& CompilerStack::onChainMetadata(string const& _contractName) const
|
||||||
{
|
{
|
||||||
if (!m_success)
|
if (m_stackState != CompilationSuccessful)
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
|
||||||
|
|
||||||
return contract(_contractName).onChainMetadata;
|
return contract(_contractName).onChainMetadata;
|
||||||
|
@ -236,6 +236,13 @@ private:
|
|||||||
mutable std::unique_ptr<std::string const> sourceMapping;
|
mutable std::unique_ptr<std::string const> sourceMapping;
|
||||||
mutable std::unique_ptr<std::string const> runtimeSourceMapping;
|
mutable std::unique_ptr<std::string const> runtimeSourceMapping;
|
||||||
};
|
};
|
||||||
|
enum State {
|
||||||
|
Empty,
|
||||||
|
SourcesSet,
|
||||||
|
ParsingSuccessful,
|
||||||
|
AnalysisSuccessful,
|
||||||
|
CompilationSuccessful
|
||||||
|
};
|
||||||
|
|
||||||
/// Loads the missing sources from @a _ast (named @a _path) using the callback
|
/// Loads the missing sources from @a _ast (named @a _path) using the callback
|
||||||
/// @a m_readFile and stores the absolute paths of all imports in the AST annotations.
|
/// @a m_readFile and stores the absolute paths of all imports in the AST annotations.
|
||||||
@ -276,7 +283,6 @@ private:
|
|||||||
/// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
|
/// list of path prefix remappings, e.g. mylibrary: github.com/ethereum = /usr/local/ethereum
|
||||||
/// "context:prefix=target"
|
/// "context:prefix=target"
|
||||||
std::vector<Remapping> m_remappings;
|
std::vector<Remapping> m_remappings;
|
||||||
bool m_success;
|
|
||||||
std::map<std::string const, Source> m_sources;
|
std::map<std::string const, Source> m_sources;
|
||||||
std::shared_ptr<GlobalContext> m_globalContext;
|
std::shared_ptr<GlobalContext> m_globalContext;
|
||||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes;
|
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes;
|
||||||
@ -285,6 +291,7 @@ private:
|
|||||||
std::string m_formalTranslation;
|
std::string m_formalTranslation;
|
||||||
ErrorList m_errors;
|
ErrorList m_errors;
|
||||||
bool m_metadataLiteralSources = false;
|
bool m_metadataLiteralSources = false;
|
||||||
|
State m_stackState = Empty;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,11 @@ bool containsAtMostWarnings(Json::Value const& _compilerResult)
|
|||||||
BOOST_REQUIRE(error.isObject());
|
BOOST_REQUIRE(error.isObject());
|
||||||
BOOST_REQUIRE(error["severity"].isString());
|
BOOST_REQUIRE(error["severity"].isString());
|
||||||
if (error["severity"].asString() != "warning")
|
if (error["severity"].asString() != "warning")
|
||||||
|
{
|
||||||
|
cout << error << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user