]> gitweb.ps.run Git - toc/blob - src/check.h
pre change
[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<Namespace> namespaces,\r
8   std::vector<Variable> vars)\r
9 {\r
10   return true;\r
11 }\r
12 \r
13 bool checkFunction(\r
14   const Function & f,\r
15   std::vector<Namespace> namespaces,\r
16   std::vector<Variable> vars)\r
17 {\r
18   vars.insert(vars.end(), f.parameters.begin(), f.parameters.end());\r
19   vars.insert(vars.end(), f.body.variables.begin(), f.body.variables.end());\r
20   for (auto s : f.body.statements)\r
21   {\r
22     if (!checkStmt(s, namespaces, vars))\r
23       return false;\r
24   }\r
25   return true;\r
26 }\r
27 \r
28 bool checkProgram(const Program & p)\r
29 {\r
30   for (auto f : p.functions)\r
31   {\r
32     if (!checkFunction(f, p.namespaces, p.variables))\r
33       return false;\r
34   }\r
35   for (auto s : p.structs)\r
36   {\r
37     std::vector<Variable> vars = p.variables;\r
38     for (auto v : s.members)\r
39       vars.push_back(v);\r
40     for (auto f : s.methods)\r
41     {\r
42       if (!checkFunction(f, p.namespaces, vars))\r
43         return false;\r
44     }\r
45   }\r
46   return true;\r
47 }