MCPcopy Create free account
hub / github.com/argotorg/solidity / simplify

Method simplify

libyul/optimiser/StructuralSimplifier.cpp:93–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93void StructuralSimplifier::simplify(std::vector<yul::Statement>& _statements)
94{
95 util::GenericVisitor visitor{
96 util::VisitorFallback<OptionalStatements>{},
97 [&](If& _ifStmt) -> OptionalStatements {
98 if (expressionAlwaysTrue(*_ifStmt.condition))
99 return {std::move(_ifStmt.body.statements)};
100 else if (expressionAlwaysFalse(*_ifStmt.condition))
101 return {std::vector<Statement>{}};
102 return {};
103 },
104 [&](Switch& _switchStmt) -> OptionalStatements {
105 if (std::optional<u256> const constExprVal = hasLiteralValue(*_switchStmt.expression))
106 return replaceConstArgSwitch(_switchStmt, constExprVal.value());
107 return {};
108 },
109 [&](ForLoop& _forLoop) -> OptionalStatements {
110 if (expressionAlwaysFalse(*_forLoop.condition))
111 return {std::move(_forLoop.pre.statements)};
112 return {};
113 }
114 };
115
116 util::iterateReplacing(
117 _statements,
118 [&](Statement& _stmt) -> OptionalStatements
119 {
120 OptionalStatements result = std::visit(visitor, _stmt);
121 if (result)
122 simplify(*result);
123 else
124 visit(_stmt);
125 return result;
126 }
127 );
128}

Callers

nothing calls this directly

Calls 6

expressionAlwaysTrueFunction · 0.85
expressionAlwaysFalseFunction · 0.85
hasLiteralValueFunction · 0.85
replaceConstArgSwitchFunction · 0.85
iterateReplacingFunction · 0.85
valueMethod · 0.45

Tested by

no test coverage detected