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