abouttreesummaryrefslogcommitdiff
path: root/src/check.h
blob: 091b646edc5953bf0ff9b345dc19bf0823295d8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

#include "repr.h"

bool checkStmt(
  const Stmt & s,
  std::vector<Namespace> namespaces,
  std::vector<Variable> vars)
{
  return true;
}

bool checkFunction(
  const Function & f,
  std::vector<Namespace> namespaces,
  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, namespaces, vars))
      return false;
  }
  return true;
}

bool checkProgram(const Program & p)
{
  for (auto f : p.functions)
  {
    if (!checkFunction(f, p.namespaces, 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.namespaces, vars))
        return false;
    }
  }
  return true;
}