20 #include "type_check.h"
27 #include "../ast/expression.hpp"
30 #define T(s) tyEnv->lookup(s)
36 if (*t1 ==
T(
"Integer")) {
37 if (*t2 ==
T(
"Integer") or *t2 ==
T(
"Real"))
41 }
else if (*t1 ==
T(
"Real")) {
42 if (*t2 ==
T(
"Integer") or *t2 ==
T(
"Real"))
65 throw "Type Error (0)";
79 throw "Type Error (1)";
83 throw "Type Error (2)";
85 throw "Error! (TypeCheck_::check_binop)";
91 switch (e->expressionType()) {
93 AST_Expression_BinOp b = e->getAsBinOp();
94 return check_binop(b->left(), b->right(), b->binopType());
97 AST_Expression_UMinus b = e->getAsUMinus();
100 throw "Type Error (3)";
104 AST_Expression_Output b = e->getAsOutput();
109 AST_Expression_If b = e->getAsIf();
113 if (!
check_equal(ct,
T(
"Boolean")))
throw "Type Error (4)";
120 AST_Expression_Call c = e->getAsCall();
121 if (
toStr(c->name()) ==
"sample")
return T(
"Boolean");
127 AST_Expression_ComponentReference b = e->getAsComponentReference();
129 VarInfo tt =
varEnv->lookup(
toStr(b->names()->front()));
132 cerr <<
"Var:" << b->names()->front() <<
":";
133 throw "Variable no existe (8)";
135 if (b->indexes()->front()->size() == 0)
139 AST_ExpressionListIterator exit;
140 foreach (exit, b->indexes()->front())
142 t = t->getAsArray()->arrayOf();
144 throw "Type Error (7)";
161 AST_Expression_BooleanNot b = e->getAsBooleanNot();
163 if (!
check_equal(t,
T(
"Boolean")))
throw "Type Error (6)";
167 throw "No implrementado aun! (check_expression)";