Ast2Cpp Class Reference

#include <Translation.h>

Inheritance diagram for Ast2Cpp:

Inheritance graph
[legend]
Collaboration diagram for Ast2Cpp:

Collaboration graph
[legend]

Detailed Description

Definition at line 76 of file Translation.h.


Public Member Functions

 Ast2Cpp ()
virtual ~Ast2Cpp ()
virtual StringBuffer operator() (const tree< AstNode > &, const MapClasses *classes=0, const MapVariables *vars=0, const MapFunctions *func=0, const MapAssignments *assigns=0, const MapVarEquivalent *equiv=0)

Constructor & Destructor Documentation

Ast2Cpp::Ast2Cpp (  )  [inline]

Definition at line 79 of file Translation.h.

00079 {}

virtual Ast2Cpp::~Ast2Cpp (  )  [inline, virtual]

Definition at line 80 of file Translation.h.

00080 {}


Member Function Documentation

StringBuffer Ast2Cpp::operator() ( const tree< AstNode > &  tr,
const MapClasses classes = 0,
const MapVariables vars = 0,
const MapFunctions func = 0,
const MapAssignments assigns = 0,
const MapVarEquivalent equiv = 0 
) [virtual]

Implements Translation.

Definition at line 457 of file Translation.cpp.

References addClassCpp(), addFunctionCpp(), tree< T, tree_node_allocator >::begin(), classVarNames, cppheader, CPPHEADERSIZE, tree< T, tree_node_allocator >::end(), StringBuffer::format(), StringBuffer::insert_begin(), varname(), and writeSiblingsCPP().

00459 {
00460     StringBuffer buffer, beg;
00461     classVarNames.clear();
00462 
00463     for (unsigned i=0;i<CPPHEADERSIZE;i++) {
00464         beg << (cppheader[i]);
00465     }
00466 
00467     // Add the classes definitions
00468     for (tree<AstNode>::iterator iter=tr.begin();iter!=tr.end();++iter) {
00469         if (iter->getType() == "unticked_class_declaration_statement")
00470             addClassCpp(iter, tr, buffer);
00471     }
00472 
00473     // Add the function definitions
00474     for (tree<AstNode>::iterator iter=tr.begin();iter!=tr.end();++iter)
00475     {
00476         if (iter->getType() == "unticked_function_declaration_statement")
00477         {
00478             addFunctionCpp(iter, tr, buffer);
00479         }
00480     }
00481 
00482     // Add the main
00483     buffer << ("\n\nint main() {\n");
00484     //cout << "Main" << endl;
00485     writeSiblingsCPP(tr, tr.begin(), buffer,false,false,true);
00486     buffer << ("return 0;\n}\n\n");
00487 
00488     // Add all variables as global
00489     for(MapVariables::const_iterator iter = vars->begin(); iter != vars->end(); ++iter) {
00490         if (find(classVarNames.begin(),classVarNames.end(),varname(iter->first)) == classVarNames.end()) {
00491             string def = "PhpObject " + varname(iter->first) + ";\n";
00492             beg << (def);
00493         }
00494     }
00495     beg << ("\n");
00496 
00497     buffer.format();
00498     buffer.insert_begin(beg);
00499     return buffer;
00500 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Wed Feb 27 20:31:37 2008 for php.ast.svn.src. by  doxygen 1.5.3