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

Function toSolidityStr

libsolidity/formal/ExpressionFormatter.cpp:141–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141std::string toSolidityStr(smtutil::Expression const& _expr)
142{
143 auto const& op = _expr.name;
144
145 auto const& args = _expr.arguments;
146 auto strArgs = util::applyMap(args, [](auto const& _arg) { return toSolidityStr(_arg); });
147
148 // Constant or variable.
149 if (args.empty())
150 return op;
151
152 if (starts_with(op, "dt_accessor"))
153 return formatDatatypeAccessor(_expr, strArgs);
154
155 // Infix operators with format replacements.
156 static std::map<std::string, std::string> const infixOps{
157 {"and", "&&"},
158 {"or", "||"},
159 {"implies", "=>"},
160 {"=", "="},
161 {">", ">"},
162 {">=", ">="},
163 {"<", "<"},
164 {"<=", "<="},
165 {"+", "+"},
166 {"-", "-"},
167 {"*", "*"},
168 {"/", "/"},
169 {"div", "/"},
170 {"mod", "%"}
171 };
172 // Some of these (and, or, +, *) may have >= 2 arguments from z3.
173 if (infixOps.count(op) && args.size() >= 2)
174 return formatInfixOp(infixOps.at(op), strArgs);
175
176 static std::set<std::string> const arrayOps{"select", "store", "const_array"};
177 if (arrayOps.count(op))
178 return formatArrayOp(_expr, strArgs);
179
180 if (args.size() == 1)
181 return formatUnaryOp(_expr, strArgs);
182
183 // Other operators such as bv2int, int2bv may end up here.
184 return op + "(" + boost::algorithm::join(strArgs, ", ") + ")";
185}
186
187namespace
188{

Callers 1

collectInvariantsFunction · 0.85

Calls 9

applyMapFunction · 0.85
formatDatatypeAccessorFunction · 0.85
formatInfixOpFunction · 0.85
formatArrayOpFunction · 0.85
formatUnaryOpFunction · 0.85
atMethod · 0.80
emptyMethod · 0.45
countMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected