]> gitweb.ps.run Git - toc/blob - src/check.h
add namespace, private struct member grammar, change bracket style
[toc] / src / check.h
1 #pragma once\r
2 \r
3 #include "repr.h"\r
4 \r
5 bool checkStmt(\r
6   const Stmt & s,\r
7   std::vector<Struct> structs,\r
8   std::vector<Function> funcs,\r
9   std::vector<Variable> vars)\r
10 {\r
11   return true;\r
12 }\r
13 \r
14 bool checkFunction(\r
15   const Function & f,\r
16   std::vector<Struct> structs,\r
17   std::vector<Function> funcs,\r
18   std::vector<Variable> vars)\r
19 {\r
20   vars.insert(vars.end(), f.parameters.begin(), f.parameters.end());\r
21   vars.insert(vars.end(), f.body.variables.begin(), f.body.variables.end());\r
22   for (auto s : f.body.statements)\r
23   {\r
24     if (!checkStmt(s, structs, funcs, vars))\r
25       return false;\r
26   }\r
27   return true;\r
28 }\r
29 \r
30 bool checkProgram(const Program & p)\r
31 {\r
32   for (auto f : p.functions)\r
33   {\r
34     if (!checkFunction(f, p.structs, p.functions, p.variables))\r
35       return false;\r
36   }\r
37   for (auto s : p.structs)\r
38   {\r
39     std::vector<Variable> vars = p.variables;\r
40     for (auto v : s.members)\r
41       vars.push_back(v);\r
42     for (auto f : s.methods)\r
43     {\r
44       if (!checkFunction(f, p.structs, p.functions, vars))\r
45         return false;\r
46     }\r
47   }\r
48   return true;\r
49 }