mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Basic support to free constants
This commit is contained in:
@@ -51,27 +51,6 @@ SMTEncoder::SMTEncoder(smt::EncodingContext& _context):
|
||||
|
||||
bool SMTEncoder::analyze(SourceUnit const& _source)
|
||||
{
|
||||
set<SourceUnit const*, smt::EncodingContext::IdCompare> sources;
|
||||
sources.insert(&_source);
|
||||
for (auto const& source: _source.referencedSourceUnits(true))
|
||||
sources.insert(source);
|
||||
|
||||
bool analysis = true;
|
||||
for (auto source: sources)
|
||||
for (auto node: source->nodes())
|
||||
if (auto var = dynamic_pointer_cast<VariableDeclaration>(node))
|
||||
{
|
||||
m_errorReporter.warning(
|
||||
8195_error,
|
||||
var->location(),
|
||||
"Model checker analysis was not possible because file level constants are not supported."
|
||||
);
|
||||
analysis = false;
|
||||
}
|
||||
|
||||
if (!analysis)
|
||||
return false;
|
||||
|
||||
state().prepareForSourceUnit(_source);
|
||||
|
||||
return true;
|
||||
@@ -437,14 +416,9 @@ void SMTEncoder::endVisit(TupleExpression const& _tuple)
|
||||
auto values = applyMap(_tuple.components(), [this](auto const& component) -> optional<smtutil::Expression> {
|
||||
if (component)
|
||||
{
|
||||
if (auto varDecl = identifierToVariable(*component))
|
||||
return currentValue(*varDecl);
|
||||
else
|
||||
{
|
||||
if (!m_context.knownExpression(*component))
|
||||
if (!m_context.knownExpression(*component))
|
||||
createExpr(*component);
|
||||
return expr(*component);
|
||||
}
|
||||
return expr(*component);
|
||||
}
|
||||
return {};
|
||||
});
|
||||
@@ -1395,6 +1369,9 @@ void SMTEncoder::endVisit(IndexAccess const& _indexAccess)
|
||||
auto varDecl = identifierToVariable(*id);
|
||||
solAssert(varDecl, "");
|
||||
array = m_context.variable(*varDecl);
|
||||
|
||||
if (varDecl && varDecl->isConstant())
|
||||
m_context.addAssertion(currentValue(*varDecl) == expr(*id));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2599,6 +2576,7 @@ VariableDeclaration const* SMTEncoder::identifierToVariable(Expression const& _e
|
||||
solAssert(m_context.knownVariable(*varDecl), "");
|
||||
return varDecl;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -2913,6 +2891,15 @@ set<FunctionCall const*> SMTEncoder::collectABICalls(ASTNode const* _node)
|
||||
return ABIFunctions(_node).abiCalls;
|
||||
}
|
||||
|
||||
set<SourceUnit const*, ASTNode::CompareByID> SMTEncoder::sourceDependencies(SourceUnit const& _source)
|
||||
{
|
||||
set<SourceUnit const*, ASTNode::CompareByID> sources;
|
||||
sources.insert(&_source);
|
||||
for (auto const& source: _source.referencedSourceUnits(true))
|
||||
sources.insert(source);
|
||||
return sources;
|
||||
}
|
||||
|
||||
void SMTEncoder::createReturnedExpressions(FunctionCall const& _funCall, ContractDefinition const* _contextContract)
|
||||
{
|
||||
auto funDef = functionCallToDefinition(_funCall, currentScopeContract(), _contextContract);
|
||||
@@ -2978,6 +2965,14 @@ void SMTEncoder::collectFreeFunctions(set<SourceUnit const*, ASTNode::CompareByI
|
||||
}
|
||||
}
|
||||
|
||||
void SMTEncoder::createFreeConstants(set<SourceUnit const*, ASTNode::CompareByID> const& _sources)
|
||||
{
|
||||
for (auto source: _sources)
|
||||
for (auto node: source->nodes())
|
||||
if (auto var = dynamic_cast<VariableDeclaration const*>(node.get()))
|
||||
createVariable(*var);
|
||||
}
|
||||
|
||||
smt::SymbolicState& SMTEncoder::state()
|
||||
{
|
||||
return m_context.state();
|
||||
|
||||
Reference in New Issue
Block a user