Skip to content

Instantly share code, notes, and snippets.

@vitaut
Last active March 22, 2016 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitaut/0aae222c71f24c287dc6 to your computer and use it in GitHub Desktop.
Save vitaut/0aae222c71f24c287dc6 to your computer and use it in GitHub Desktop.
#include "mp/nl-reader.h"
enum Expr {OTHER, CONST};
struct ExprCounter : mp::NullNLHandler<Expr> {
int num_divs;
ExprCounter() : num_divs(0) {}
Expr OnBinary(mp::expr::Kind kind, Expr lhs, Expr rhs) {
if (kind == mp::expr::DIV && rhs != CONST)
++num_divs;
}
Expr OnNumericConstant(double value) { return CONST; }
};
int main(int argc, char **argv) {
for (int i = 1; i < argc; ++i) {
ExprCounter counter;
mp::ReadNLFile(argv[i], counter);
if (counter.num_divs != 0)
fmt::print("{}: {} divisions\n", argv[i], counter.num_divs);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment