From 842b01bae4f611619a61f4d1c587501ebf44b35d Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Sun, 15 Feb 2009 22:23:07 +0000 Subject: [PATCH] some random work --- src/ast/simplify-visitor.cc | 16 ++++++++++++++-- src/ast/simplify-visitor.hh | 5 +++++ src/ast/type-checker-visitor.cc | 24 ++++++++++++++++++++++++ src/ast/type-checker-visitor.hh | 1 + src/ast/type-checking.doch | 11 +++++++++++ src/ozulis.hh | 10 ++++++++++ 6 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/ast/type-checking.doch diff --git a/src/ast/simplify-visitor.cc b/src/ast/simplify-visitor.cc index 0bffb3f..6970d2b 100644 --- a/src/ast/simplify-visitor.cc +++ b/src/ast/simplify-visitor.cc @@ -51,7 +51,7 @@ namespace ast /// @todo use a garbage collector std::vector * newList = new std::vector(); - BOOST_FOREACH(Node * node, (*block.instrs)) + BOOST_FOREACH (Node * node, (*block.instrs)) { assert(node); simplifications_.clear(); @@ -61,6 +61,7 @@ namespace ast //delete node; } //delete block.instrs; + block.instrs = newList; } @@ -100,7 +101,7 @@ namespace ast SIMPLIFY_BINARY_EXP(LtEqExp) SIMPLIFY_BINARY_EXP(GtExp) SIMPLIFY_BINARY_EXP(GtEqExp) - + SIMPLIFY_BINARY_EXP(AddExp) SIMPLIFY_BINARY_EXP(SubExp) SIMPLIFY_BINARY_EXP(MulExp) @@ -153,6 +154,17 @@ namespace ast delete &node; } + /** + * @internal + * develop the cast, and simplify it + */ + void + SimplifyVisitor::visit(CastExp & node) + { + node.exp->accept(*this); + //assert(false); + } + void SimplifyVisitor::visit(Label & node) { diff --git a/src/ast/simplify-visitor.hh b/src/ast/simplify-visitor.hh index ab097b3..0edeba8 100644 --- a/src/ast/simplify-visitor.hh +++ b/src/ast/simplify-visitor.hh @@ -61,6 +61,8 @@ namespace ast virtual void visit(Block & node); //virtual void visit(Function & node); + virtual void visit(CastExp & node); + virtual void visit(Label & node); virtual void visit(Goto & node); @@ -68,8 +70,11 @@ namespace ast std::string currentId() const; std::string nextId(); + /// @brief the new list of 3 address instructions std::vector simplifications_; + /// @brief the child which replace the previously visited node Exp * replacement_; + /// @brief the next id for register count int nextId_; }; } diff --git a/src/ast/type-checker-visitor.cc b/src/ast/type-checker-visitor.cc index c190c9e..366f862 100644 --- a/src/ast/type-checker-visitor.cc +++ b/src/ast/type-checker-visitor.cc @@ -24,6 +24,7 @@ namespace ast } while (0) ADD_CAST_TABLE_ENTRY(FloatType, IntegerType, castIntegerFloat); + //ADD_CAST_TABLE_ENTRY(IntegerType, IntegerType, castIntegerInteger); } TypeCheckerVisitor::~TypeCheckerVisitor() @@ -87,4 +88,27 @@ namespace ast castExp->type = ftype; return castExp; } + + // CastExp * +// TypeCheckerVisitor::castIntegerFloat(Type * type1, +// Type * type2) +// { +// CastExp * castExp = new CastExp(); +// IntegerType * left; +// FloatType * right; + +// if (type1->nodeType == IntegerType::nodeTypeId()) +// { +// itype = reinterpret_cast (type1); +// ftype = reinterpret_cast (type2); +// } +// else +// { +// itype = reinterpret_cast (type2); +// ftype = reinterpret_cast (type1); +// } + +// castExp->type = ftype; +// return castExp; +// } } diff --git a/src/ast/type-checker-visitor.hh b/src/ast/type-checker-visitor.hh index 05fdaf4..85d8140 100644 --- a/src/ast/type-checker-visitor.hh +++ b/src/ast/type-checker-visitor.hh @@ -26,6 +26,7 @@ namespace ast CastExp * findCast(Type * type1, Type * type2); CastExp * castIntegerFloat(Type * type1, Type * type2); + //CastExp * castIntegerInteger(Type * type1, Type * type2); typedef std::pair castTableKey_t; typedef CastExp * diff --git a/src/ast/type-checking.doch b/src/ast/type-checking.doch new file mode 100644 index 0000000..1b24d86 --- /dev/null +++ b/src/ast/type-checking.doch @@ -0,0 +1,11 @@ +/** + * @page TypeChecking Type Checking + * + * @section Introduction + * The type checker have to ensure that types are correct. + * If it is possible, it may find an appropriate cast for the user. + * The type checker also have to find appropriate overloaded method. + * + * @section Implementation + * ast::TypeCheckerVisitor it the type checker. + */ diff --git a/src/ozulis.hh b/src/ozulis.hh index d998d91..048489b 100644 --- a/src/ozulis.hh +++ b/src/ozulis.hh @@ -2,4 +2,14 @@ * @mainpage Ozulis * @section Introduction * This is an experimental compiler for an undefined language. + * + * @section Modules + * @dot + * digraph example { + * node [shape=record, fontname=Helvetica, fontsize=10]; + * b [ label="class B" URL="\ref B"]; + * c [ label="class C" URL="\ref C"]; + * b -> c [ arrowhead="open", style="dashed" ]; + * } + * @enddot */ -- 2.11.4.GIT