File tree 3 files changed +25
-0
lines changed
3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ Language Features:
4
4
5
5
6
6
Compiler Features:
7
+ * Constant Evaluator: Support for constants referenced by member access expressions.
7
8
8
9
9
10
Bugfixes:
Original file line number Diff line number Diff line change 27
27
#include < libsolidity/ast/TypeProvider.h>
28
28
#include < liblangutil/ErrorReporter.h>
29
29
30
+ #include < range/v3/algorithm/find_if.hpp>
31
+
30
32
#include < limits>
31
33
32
34
using namespace solidity ;
@@ -407,3 +409,24 @@ void ConstantEvaluator::endVisit(TupleExpression const& _tuple)
407
409
if (!_tuple.isInlineArray () && _tuple.components ().size () == 1 )
408
410
m_values[&_tuple] = evaluate (*_tuple.components ().front ());
409
411
}
412
+
413
+ void ConstantEvaluator::endVisit (MemberAccess const & _memberAccess)
414
+ {
415
+ if (auto const * parentIdentifier = dynamic_cast <Identifier const *>(&_memberAccess.expression ()))
416
+ {
417
+ if (auto const * contract = dynamic_cast <ContractDefinition const *>(parentIdentifier->annotation ().referencedDeclaration ))
418
+ {
419
+ auto contractVariables = contract->stateVariables ();
420
+ auto variable = ranges::find_if (
421
+ contractVariables,
422
+ [&](VariableDeclaration const * _variable) { return _variable->name () == _memberAccess.memberName (); }
423
+ );
424
+
425
+ if (
426
+ variable != ranges::end (contractVariables) &&
427
+ (*variable)->isConstant ()
428
+ )
429
+ m_values[&_memberAccess] = evaluate (**variable);
430
+ }
431
+ }
432
+ }
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ class ConstantEvaluator: private ASTConstVisitor
79
79
void endVisit (Literal const & _literal) override ;
80
80
void endVisit (Identifier const & _identifier) override ;
81
81
void endVisit (TupleExpression const & _tuple) override ;
82
+ void endVisit (MemberAccess const & _memberAcess) override ;
82
83
83
84
langutil::ErrorReporter& m_errorReporter;
84
85
// / Current recursion depth.
You can’t perform that action at this time.
0 commit comments