00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __TRANSLATION_H
00019 #define __TRANSLATION_H
00020
00021 #include <string>
00022 #include <list>
00023 #include <iostream>
00024 #include "Utils.h"
00025
00026 class StringBuffer
00027 {
00028 std::string buffer;
00029 public:
00030 StringBuffer(){}
00031 StringBuffer(const StringBuffer& s) { buffer = s.buffer; }
00032 StringBuffer(const std::string& _first) { buffer += (_first); }
00033 StringBuffer(const unsigned n) { buffer += (to_string<unsigned>(n)); }
00034 ~StringBuffer(){}
00035
00036
00037 StringBuffer& operator=(const StringBuffer& b) {
00038 buffer = b.buffer;
00039 return *this;
00040 }
00041 StringBuffer& operator<<(const StringBuffer& s) {
00042 buffer += (s.buffer);
00043 return *this;
00044 }
00045 StringBuffer& operator<<(const std::string& s) {
00046 buffer += (s);
00047 return *this;
00048 }
00049 void endl() { buffer += "\n"; }
00050 void replace(const std::string& what, const std::string& with) {
00051 utils::replace(buffer, what, with);
00052 }
00053 void insert_begin(const StringBuffer& s) {
00054 std::string out = s.buffer + buffer;
00055 buffer = out;
00056 }
00057 void format();
00058 void write(const std::string& _fname);
00059
00060 friend std::ostream& operator<<(std::ostream& stream, const StringBuffer&);
00061 };
00062
00063 std::ostream& operator<<(std::ostream&, const StringBuffer&);
00064
00065 class Translation
00066 {
00067 public:
00068 Translation() {}
00069 virtual ~Translation() {}
00070 public:
00071 virtual StringBuffer operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0,
00072 const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0) = 0;
00073 };
00074
00075
00076 class Ast2Cpp : public Translation
00077 {
00078 public:
00079 Ast2Cpp() {}
00080 virtual ~Ast2Cpp() {}
00081 public:
00082 virtual StringBuffer operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0,
00083 const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00084 };
00085
00086 class Ast2Php : public Translation
00087 {
00088 public:
00089 Ast2Php() {}
00090 virtual ~Ast2Php() {}
00091 public:
00092 virtual StringBuffer operator()(const tree<AstNode>&, const MapClasses* classes = 0, const MapVariables* vars = 0,
00093 const MapFunctions *func = 0, const MapAssignments *assigns = 0, const MapVarEquivalent *equiv = 0);
00094 };
00095
00096
00097
00098 #endif