00001
00002
00003 #ifndef translator_i_h
00004 #define translator_i_h
00005
00006 #include <iostream>
00007 #include <string>
00008 #include <cassert>
00009 #include <stack>
00010 #include "hash-aux.h"
00011 #include "sstring.h"
00012
00013
00014 #include <encoding.h>
00015
00016
00017
00018
00019 #include "ptree_program_visitor.h"
00020 #include "mangle.h"
00021 #include "source.h"
00022
00023 struct vrec
00024 {
00025 string name, basename, type, enctype, alloc;
00026 int number;
00027 };
00028
00029 class Translate_visitor : public Ptree_program_visitor<bool>
00030 {
00031 typedef Ptree_program_visitor<bool> Super;
00032 typedef hash_map<string,vrec> Var_map;
00033
00034 enum Func_what {Prologue, Epilogue};
00035
00036 Var_map _var;
00037 Mangle _sym;
00038
00039 int _value;
00040 int _number;
00041
00042 string _func;
00043 string _alloc;
00044 string _last_alloc;
00045
00046 bool _expecting_lvalue;
00047 stack<bool> _lvalue_stack;
00048
00049
00050 ostringstream _expr;
00051
00052 ostream* out;
00053
00054 public:
00055 Translate_visitor(Source* s);
00056
00057 virtual ~Translate_visitor();
00058
00059 private:
00060
00061
00062
00063 bool visit_function(Ptree* storagespec, Ptree* returntype, PtreeDeclarator* decl, PtreeBlock* block);
00064
00065 bool visit_name_declaration(Ptree* storagespec, Ptree* type, Ptree* decllist);
00066
00067 bool visit_return(PtreeReturnStatement* exp);
00068
00069 bool visit_exprstatement(PtreeExprStatement* exp);
00070
00071 bool visit_assign(PtreeAssignExpr* exp);
00072
00073 bool visit_infix(PtreeInfixExpr* exp);
00074
00075 bool visit_postfix(PtreePostfixExpr* exp);
00076
00077 bool visit_funcall(PtreeFuncallExpr* exp);
00078
00082 bool visit_name(Ptree* exp);
00083
00084 bool visit_leaf(Leaf* exp);
00085
00086
00087
00088
00089 void new_value(const string& val);
00090
00091 void new_variable(const string& name, const string& initializer);
00092
00093 void new_function_prologue(const string& name, const string& rettype);
00094
00095 void new_function_epilogue(const string& name, const string& value);
00096
00097 void new_state(const string& func);
00098
00099
00100
00101
00102 void push_lvalue();
00103
00104 void pop_lvalue();
00105 };
00106
00107 #endif // translator_i_h