Translation.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002     This file is part of PHP-AST Project by Romain Gaucher (http://rgaucher.info).
00003 
00004     PHP-AST is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     PHP-AST/ORACLE is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with PHP-AST.  If not, see <http://www.gnu.org/licenses/>.
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     // Operators
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     // Print
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

Generated on Wed Feb 27 20:31:06 2008 for php.ast.svn.src. by  doxygen 1.5.3