Employ the union-find algorithm to reason the type constraints on ASTs of C++ 14 programs.
lambda.cc
#include <cstdio>
#include <cstdlib>
auto lambda(int n) {
auto x = getchar();
auto y = (int *)malloc(8);
*y = x;
auto z = *y;
return x;
}
recursive.cc
auto foo = [](auto x) {
return x;
};
auto bar = [](auto a, auto b) {
return a + b;
};
auto zip = [](auto f1) {
auto a = 2;
auto b = 3;
a = f1(a);
b = bar(a, b);
return bar;
};
auto test() {
auto f2 = zip(foo);
return f2(1, 2);
}
Manually write down the result of type constraints for each program, named as
H2_progName_StuFstName_StuID.txt, e.g., H2_lambda_Kojima_013038.txt ;
In each .txt file, the constraint of each top-level variable exactly one line
“[[%s]]\t%s\n” % (var_name, constraint);int main() { return 0 } at line 1, the output is [[main]] ()->int.auto *y = 3 at line 3, the output is [[y]] &int.P.S. Though it is optional, it is recommended to practice as a side-project if you do not understand how LLVM/Clang passes or checkers are built and how can they run like plugins.
Please refer to the following document to prepare the initial setup of clang AST-based environment.
Please refer to Clang AST quick tour for the details of Clang AST components.
The implementation only needs to cover the first program, outputting a .txt file as the result, named as
H2_progName_StuFstName_StuID.txt, e.g., H2_lambda_Kojima_013038.txt ;
Include all resulting files in a single directory named as H2_StuFstName_StuID, compress the directory and submit the package, e.g., H2_Mahiro_013038.tar.gz;
In each .txt file, the constraint of each top-level variable exactly one line
“[[%s]]\t%s\n” % (var_name, constraint);int main() { return 0 } at line 1, the output is [[main]] ()->int.auto *y = 3 at line 3, the output is [[y]] &int.