AstContainer.cpp File Reference

#include "AstContainer.h"
#include "Utils.h"
#include "Obfuscator.h"
#include "Translation.h"
#include "Metric.h"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <stdexcept>
#include <iomanip>
#include <stack>

Include dependency graph for AstContainer.cpp:

Go to the source code of this file.

Namespaces

namespace  std

Functions

string getContent (xmlNode *a_node)
ostream & operator<< (ostream &stream, const Ast &ast)
ostream & operator<< (ostream &stream, const tree< AstNode > &ast)
ostream & operator<< (ostream &stream, const tree< AstNode >::iterator &iter)
ostream & operator<< (ostream &stream, const VarBase &v)
void print_current_list (const list< VarBase > &plop)
string htmlentities (const string &str)
void writeSiblingsXML (const tree< AstNode > &t, const tree< AstNode >::iterator iRoot, ostream &stream)
void exportXML (const Ast &ast, const string &xmlName)


Function Documentation

void exportXML ( const Ast ast,
const string &  xmlName 
)

Definition at line 902 of file AstContainer.cpp.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::empty(), tree< T, tree_node_allocator >::end(), Ast::tr, and writeSiblingsXML().

00903 {
00904     if (ast.tr.empty()) {
00905         throw length_error("AstContainer::exportXML - The AST is empty");
00906         return;
00907     }
00908     ofstream stream(xmlName.c_str());
00909     if (!stream.is_open())
00910         return;
00911     // skip <root>
00912     for(tree<AstNode>::sibling_iterator iRoots = ast.tr.begin(); iRoots != ast.tr.end(); iRoots++) {
00913         writeSiblingsXML(ast.tr,iRoots,stream);
00914     }
00915     stream.close();
00916 }

Here is the call graph for this function:

string getContent ( xmlNode *  a_node  ) 

Definition at line 32 of file AstContainer.cpp.

References utils::replace().

Referenced by Ast::walk().

00032                                    {
00033     xmlChar *c = xmlNodeGetContent(a_node);
00034     string ret((char *)c);
00035     utils::replace(ret, "\n","");
00036     utils::replace(ret, "\r","");
00037     utils::replace(ret, "\b","");   
00038     xmlFree(c);
00039     return ret;
00040 }

Here is the call graph for this function:

Here is the caller graph for this function:

string htmlentities ( const string &  str  ) 

Definition at line 855 of file AstContainer.cpp.

Referenced by writeSiblingsXML().

00856 {
00857     string ret;
00858     for(string::const_iterator iter=str.begin();iter!=str.end();++iter) {
00859         switch (*iter) {
00860             case '&' : ret += "&amp;"; break;
00861             case '<' : ret += "&lt;"; break;
00862             case '>' : ret += "&gt;"; break;
00863             case '"' : ret += "&quot;"; break;
00864             default: ret += *iter; break;
00865         }
00866     }
00867     return ret;
00868 }

Here is the caller graph for this function:

ostream& operator<< ( ostream &  stream,
const VarBase v 
)

Definition at line 57 of file AstContainer.cpp.

References VarBase::index, and VarBase::name.

00057                                                        {
00058     if (v.index.length() < 1)
00059         stream << v.name;
00060     else
00061         stream << v.name << '[' << v.index << ']';
00062     return stream;
00063 }

ostream& operator<< ( ostream &  stream,
const tree< AstNode >::iterator &  iter 
)

Definition at line 52 of file AstContainer.cpp.

00052                                                                        {
00053     stream << iter.node;
00054     return stream;
00055 }

ostream& operator<< ( ostream &  stream,
const tree< AstNode > &  ast 
)

Definition at line 47 of file AstContainer.cpp.

00047                                                               {
00048     kptree::print_tree_bracketed<AstNode>(ast, stream);
00049     return stream;  
00050 }

ostream& operator<< ( ostream &  stream,
const Ast ast 
)

Definition at line 42 of file AstContainer.cpp.

References Ast::tr.

00042                                                      {
00043     kptree::print_tree_bracketed<AstNode>(ast.tr, stream);
00044     return stream;
00045 }

void print_current_list ( const list< VarBase > &  plop  ) 

Definition at line 116 of file AstContainer.cpp.

Referenced by Ast::trace().

00116                                                    {
00117     for (list<VarBase>::const_iterator iter = plop.begin(); iter != plop.end(); ++iter)
00118         cerr << *iter << " | ";
00119     cerr << endl;
00120 }

Here is the caller graph for this function:

void writeSiblingsXML ( const tree< AstNode > &  t,
const tree< AstNode >::iterator  iRoot,
ostream &  stream 
)

Definition at line 870 of file AstContainer.cpp.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::empty(), tree< T, tree_node_allocator >::end(), htmlentities(), and tree< T, tree_node_allocator >::number_of_children().

Referenced by exportXML().

00871 {
00872     if(t.empty()) 
00873         return;
00874     if (iRoot->getType() == "root") {
00875         tree<AstNode>::sibling_iterator iChildren = t.begin(iRoot);
00876         stream << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl;
00877         writeSiblingsXML(t,iChildren,stream);
00878     }
00879     else if (t.number_of_children(iRoot) == 0) {
00880         string type = iRoot->getType();
00881         stream << "<php:" << type << '>';
00882         if (iRoot->getValue().length() > 0)
00883             stream << htmlentities(iRoot->getValue());
00884         stream << "</php:" << type << '>' << endl;
00885     }
00886     else {
00887         string type = iRoot->getType();
00888         string xmlns="";
00889         if (type == "start")
00890             xmlns = " xmlns:php=\"http://php.net/csl\"";
00891         stream << "<php:" << type << xmlns << '>' << endl;
00892         int siblingNum;
00893         tree<AstNode>::sibling_iterator iChildren;
00894         for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren) 
00895         {
00896             writeSiblingsXML(t,iChildren,stream);
00897         }
00898         stream << "</php:" << type << '>' << endl;
00899     }
00900 }

Here is the call graph for this function:

Here is the caller graph for this function:


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