File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ Language Features:
44
55
66Compiler Features:
7+ *  Constant Evaluator: Support for constants referenced by member access expressions.
78
89
910Bugfixes:
Original file line number Diff line number Diff line change 2727#include  < libsolidity/ast/TypeProvider.h> 
2828#include  < liblangutil/ErrorReporter.h> 
2929
30+ #include  < range/v3/algorithm/find_if.hpp> 
31+ 
3032#include  < limits> 
3133
3234using  namespace  solidity ; 
@@ -407,3 +409,24 @@ void ConstantEvaluator::endVisit(TupleExpression const& _tuple)
407409	if  (!_tuple.isInlineArray () && _tuple.components ().size () == 1 )
408410		m_values[&_tuple] = evaluate (*_tuple.components ().front ());
409411}
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
7979	void  endVisit (Literal const & _literal) override ;
8080	void  endVisit (Identifier const & _identifier) override ;
8181	void  endVisit (TupleExpression const & _tuple) override ;
82+ 	void  endVisit (MemberAccess const & _memberAcess) override ;
8283
8384	langutil::ErrorReporter& m_errorReporter;
8485	// / Current recursion depth.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments