Skip to content

Instantly share code, notes, and snippets.

@koba-e964
Last active January 11, 2020 05:20
Show Gist options
  • Save koba-e964/5935629953a6a732ff4cf096c0d3bffb to your computer and use it in GitHub Desktop.
Save koba-e964/5935629953a6a732ff4cf096c0d3bffb to your computer and use it in GitHub Desktop.
制約と validator を自動で作る PoC

制約と validator 自動生成ツール

$ make test-gen-dsl
c++ -fsanitize=undefined -O2    test-gen-dsl.cpp   -o test-gen-dsl
$ ./test-gen-dsl doc
- $n$ は整数である.
- $m$ は整数である.
$ ./test-gen-dsl validator
long long int n = readLong();
long long int m = readLong();
  • $n$ は整数である.
  • $m$ は整数である.
#include <iostream>
using namespace std;
#define IS_INTEGER(varname) gen_integer(varname, mode);
void gen_integer(string varname, string mode) {
if (mode == "doc") {
cout << "- $" << varname << "$ は整数である." << endl;
}
if (mode == "validator") {
cout << "long long int " << varname << " = readLong();" << endl;
}
}
void gen_code(string mode) {
IS_INTEGER("n");
IS_INTEGER("m");
}
int main(int argc, char **argv) {
if (argc != 2) {
cerr << "ushitapunichiakunw" << endl;
return 1;
}
// doc か validator のどちらか
string mode = argv[1];
gen_code(mode);
}
long long int n = readLong();
long long int m = readLong();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment