diff options
| author | Patrick Schönberger | 2021-08-02 14:43:11 +0200 |
|---|---|---|
| committer | Patrick Schönberger | 2021-08-02 14:43:11 +0200 |
| commit | 8aeae09e74b46ca52866f22b48f55fecdf27b849 (patch) | |
| tree | c129a883278585a2fdfbab6bea7d47d9df1bcee2 /src/check.h | |
| parent | 9f5457a18f551d261e4bd380ea16a52dc5b04cf9 (diff) | |
| download | toc-8aeae09e74b46ca52866f22b48f55fecdf27b849.tar.gz toc-8aeae09e74b46ca52866f22b48f55fecdf27b849.zip | |
type modifiers, parenthesized expressions, chained access expressions
Diffstat (limited to 'src/check.h')
| -rw-r--r-- | src/check.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/check.h b/src/check.h new file mode 100644 index 0000000..9e6797f --- /dev/null +++ b/src/check.h @@ -0,0 +1,49 @@ +#pragma once
+
+#include "repr.h"
+
+bool checkStmt(
+ const Stmt & s,
+ std::vector<Struct> structs,
+ std::vector<Function> funcs,
+ std::vector<Variable> vars)
+{
+ // switch (s.type) {
+ // case StmtType::Assign:
+ // if (!checkVar(s._assign.))
+ // }
+ return true;
+}
+
+bool checkFunction(
+ const Function & f,
+ std::vector<Struct> structs,
+ std::vector<Function> funcs,
+ std::vector<Variable> vars)
+{
+ vars.insert(vars.end(), f.parameters.begin(), f.parameters.end());
+ vars.insert(vars.end(), f.body.variables.begin(), f.body.variables.end());
+ for (auto s : f.body.statements) {
+ if (!checkStmt(s, structs, funcs, vars))
+ return false;
+ }
+ return true;
+}
+
+bool checkProgram(const Program & p)
+{
+ for (auto f : p.functions) {
+ if (!checkFunction(f, p.structs, p.functions, p.variables))
+ return false;
+ }
+ for (auto s : p.structs) {
+ std::vector<Variable> vars = p.variables;
+ for (auto v : s.members)
+ vars.push_back(v);
+ for (auto f : s.methods) {
+ if (!checkFunction(f, p.structs, p.functions, vars))
+ return false;
+ }
+ }
+ return true;
+}
\ No newline at end of file |
