cast bool -> float
[ozulis.git] / src / ast / type-checker-visitor.hh
bloba681e7ea08e30370240d0ad5b321b261563cf214
1 #ifndef AST_TYPE_CHECKER_VISITOR_HH
2 # define AST_TYPE_CHECKER_VISITOR_HH
4 # include <utility>
5 # include <map>
7 # include <ast/browse-visitor.hh>
9 namespace ast
11 /// @defgroup Visitors
12 /**
13 * @brief Check that all expressions are correct (type)
14 * @ingroup Visitors
16 class TypeCheckerVisitor : public BrowseVisitor
18 public:
19 TypeCheckerVisitor();
20 virtual ~TypeCheckerVisitor();
22 virtual void visit(AssignExp & node);
24 virtual void visit(AddExp & node);
25 virtual void visit(SubExp & node);
26 virtual void visit(MulExp & node);
27 virtual void visit(DivExp & node);
28 virtual void visit(ModExp & node);
30 virtual void visit(AndExp & node);
31 virtual void visit(OrExp & node);
32 virtual void visit(XorExp & node);
34 virtual void visit(ShlExp & node);
35 virtual void visit(AShrExp & node);
36 virtual void visit(LShrExp & node);
38 virtual void visit(EqExp & node);
39 virtual void visit(NeqExp & node);
40 virtual void visit(LtExp & node);
41 virtual void visit(LtEqExp & node);
42 virtual void visit(GtExp & node);
43 virtual void visit(GtEqExp & node);
45 virtual void visit(IdExp & node);
46 virtual void visit(CastExp & node);
48 virtual void visit(Symbol & node);
50 virtual void visit(File & node);
51 virtual void visit(Block & node);
53 public:
54 /// @todo move the cast part in an other place
55 typedef std::pair<id_t, id_t> castTableKey_t;
56 typedef CastExp * (*castTableValue_t)(Type * type1, Type * type2);
57 typedef std::map<castTableKey_t, castTableValue_t> castTable_t;
58 typedef BrowseVisitor super_t;
60 static CastExp * findCast(Type * type1, Type * type2);
62 private:
63 static CastExp * castBoolBool(Type * type1, Type * type2);
64 static CastExp * castBoolInteger(Type * type1, Type * type2);
65 static CastExp * castBoolFloat(Type * type1, Type * type2);
66 static CastExp * castBoolDouble(Type * type1, Type * type2);
67 static CastExp * castIntegerInteger(Type * type1, Type * type2);
68 static CastExp * castIntegerFloat(Type * type1, Type * type2);
69 static CastExp * castIntegerDouble(Type * type1, Type * type2);
70 static CastExp * castFloatFloat(Type * type1, Type * type2);
71 static CastExp * castFloatDouble(Type * type1, Type * type2);
75 static castTable_t castTable_;
76 Scope * scope_;
80 #endif /* !AST_TYPE_CHECKER_VISITOR_HH */