Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
bc1f453978
commit
c3aec878e5
3609 changed files with 342772 additions and 0 deletions
170
trunk/paradiseo-eo/doc/html/_sym_8cpp-source.html
Normal file
170
trunk/paradiseo-eo/doc/html/_sym_8cpp-source.html
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
||||
<title>EO: Sym.cpp Source File</title>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
||||
</head><body>
|
||||
<!-- Generated by Doxygen 1.3.9.1 -->
|
||||
<div class="qindex"> <form class="search" action="search.php" method="get">
|
||||
<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
|
||||
<div class="nav">
|
||||
<a class="el" href="dir_000007.html">contrib</a> / <a class="el" href="dir_000008.html">mathsym</a> / <a class="el" href="dir_000028.html">sym</a></div>
|
||||
<h1>Sym.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/* </span>
|
||||
00002 <span class="comment"> * Copyright (C) 2005 Maarten Keijzer</span>
|
||||
00003 <span class="comment"> *</span>
|
||||
00004 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
|
||||
00005 <span class="comment"> * it under the terms of version 2 of the GNU General Public License as </span>
|
||||
00006 <span class="comment"> * published by the Free Software Foundation. </span>
|
||||
00007 <span class="comment"> *</span>
|
||||
00008 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
|
||||
00009 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
||||
00010 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
||||
00011 <span class="comment"> * GNU General Public License for more details.</span>
|
||||
00012 <span class="comment"> *</span>
|
||||
00013 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
|
||||
00014 <span class="comment"> * along with this program; if not, write to the Free Software</span>
|
||||
00015 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
|
||||
00016 <span class="comment"> */</span>
|
||||
00017
|
||||
00018 <span class="preprocessor">#include <sstream></span>
|
||||
00019 <span class="preprocessor">#include <vector></span>
|
||||
00020
|
||||
00021 <span class="preprocessor">#include "Sym.h"</span>
|
||||
00022
|
||||
00023 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
|
||||
00024
|
||||
00025 <span class="keyword">typedef</span> UniqueNodeStats* (*NodeStatFunc)(Sym&);
|
||||
00026
|
||||
00027 UniqueNodeStats* (*Sym::factory)(<span class="keyword">const</span> Sym&) = 0;
|
||||
00028
|
||||
00029 SymMap Sym::dag(100000); <span class="comment">// reserve space for so many nodes</span>
|
||||
00030 std::vector<unsigned> Sym::token_count;
|
||||
00031
|
||||
00032
|
||||
00033 size_t get_size(<span class="keyword">const</span> SymVec& vec) {
|
||||
00034 size_t sz = 0;
|
||||
00035 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < vec.size(); ++i) {
|
||||
00036 sz += vec[i].size();
|
||||
00037 }
|
||||
00038 <span class="keywordflow">return</span> sz;
|
||||
00039 }
|
||||
00040
|
||||
00041 size_t get_depth(<span class="keyword">const</span> SymVec& vec) {
|
||||
00042 size_t dp = 1;
|
||||
00043 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < vec.size(); ++i) {
|
||||
00044 dp = std::max(dp, vec[i].depth());
|
||||
00045 }
|
||||
00046 <span class="keywordflow">return</span> dp;
|
||||
00047 }
|
||||
00048
|
||||
00049 Sym::Sym(token_t tok, <span class="keyword">const</span> SymVec& args_) : node(dag.end())
|
||||
00050 {
|
||||
00051 detail::SymKey key(tok, detail::SymArgs(args_));
|
||||
00052 detail::SymValue val;
|
||||
00053
|
||||
00054 node = dag.insert(pair<const detail::SymKey, detail::SymValue>(key, val)).first;
|
||||
00055
|
||||
00056 <span class="keywordflow">if</span> (__unchecked_refcount() == 0) { <span class="comment">// new node, set some stats </span>
|
||||
00057 node->second.size = 1 + get_size(args_);
|
||||
00058 node->second.depth = 1 + get_depth(args_);
|
||||
00059
|
||||
00060 <span class="comment">// token count</span>
|
||||
00061 <span class="keywordflow">if</span> (tok >= token_count.size()) {
|
||||
00062 token_count.resize(tok+1);
|
||||
00063 }
|
||||
00064
|
||||
00065 incref();
|
||||
00066 node->first.fixate();
|
||||
00067 <span class="comment">// call the factory function if available</span>
|
||||
00068 <span class="keywordflow">if</span> (factory) node->second.uniqueNodeStats = factory(*<span class="keyword">this</span>);
|
||||
00069
|
||||
00070 }
|
||||
00071 <span class="keywordflow">else</span> incref();
|
||||
00072 }
|
||||
00073
|
||||
00074 Sym::Sym(token_t tok, <span class="keyword">const</span> Sym& a) : node(dag.end()) {
|
||||
00075 SymVec args_; args_.push_back(a);
|
||||
00076 detail::SymKey key(tok, detail::SymArgs(args_));
|
||||
00077 detail::SymValue val;
|
||||
00078
|
||||
00079 node = dag.insert(pair<const detail::SymKey, detail::SymValue>(key, val)).first;
|
||||
00080
|
||||
00081 <span class="keywordflow">if</span> (__unchecked_refcount() == 0) { <span class="comment">// new node, set some stats </span>
|
||||
00082 node->second.size = 1 + get_size(args_);
|
||||
00083 node->second.depth = 1 + get_depth(args_);
|
||||
00084
|
||||
00085 <span class="comment">// token count</span>
|
||||
00086 <span class="keywordflow">if</span> (tok >= token_count.size()) {
|
||||
00087 token_count.resize(tok+1);
|
||||
00088 }
|
||||
00089
|
||||
00090 incref();
|
||||
00091 node->first.fixate();
|
||||
00092 <span class="comment">// call the factory function if available</span>
|
||||
00093 <span class="keywordflow">if</span> (factory) node->second.uniqueNodeStats = factory(*<span class="keyword">this</span>);
|
||||
00094 }
|
||||
00095 <span class="keywordflow">else</span> incref();
|
||||
00096 }
|
||||
00097
|
||||
00098 Sym::Sym(token_t tok) : node(dag.end()) {
|
||||
00099 detail::SymKey key(tok);
|
||||
00100 detail::SymValue val;
|
||||
00101 node = dag.insert(pair<const detail::SymKey, detail::SymValue>(key, val)).first;
|
||||
00102
|
||||
00103 <span class="keywordflow">if</span> (__unchecked_refcount() == 0) { <span class="comment">// new node, set some stats </span>
|
||||
00104 node->second.size = 1;
|
||||
00105 node->second.depth = 1;
|
||||
00106
|
||||
00107 <span class="comment">// token count</span>
|
||||
00108 <span class="keywordflow">if</span> (tok >= token_count.size()) {
|
||||
00109 token_count.resize(tok+1);
|
||||
00110 }
|
||||
00111
|
||||
00112 incref();
|
||||
00113
|
||||
00114 <span class="comment">// call the factory function if available</span>
|
||||
00115 <span class="keywordflow">if</span> (factory) node->second.uniqueNodeStats = factory(*<span class="keyword">this</span>);
|
||||
00116
|
||||
00117 }
|
||||
00118 <span class="keywordflow">else</span> incref();
|
||||
00119 }
|
||||
00120
|
||||
00121 std::pair<Sym,bool> insert_subtree_impl(<span class="keyword">const</span> Sym& cur, size_t w, <span class="keyword">const</span> Sym& nw) {
|
||||
00122 <span class="keywordflow">if</span> (w-- == 0) <span class="keywordflow">return</span> make_pair(nw, !(nw == cur));
|
||||
00123
|
||||
00124 <span class="keyword">const</span> SymVec& vec = cur.args();
|
||||
00125 std::pair<Sym,bool> result;
|
||||
00126 <span class="keywordtype">unsigned</span> i;
|
||||
00127
|
||||
00128 <span class="keywordflow">for</span> (i = 0; i < vec.size(); ++i) {
|
||||
00129 <span class="keywordflow">if</span> (w < vec[i].size()) {
|
||||
00130 result = insert_subtree_impl(vec[i], w, nw);
|
||||
00131 <span class="keywordflow">if</span> (result.second == <span class="keyword">false</span>) <span class="keywordflow">return</span> std::make_pair(cur, <span class="keyword">false</span>); <span class="comment">// unchanged</span>
|
||||
00132 <span class="keywordflow">break</span>;
|
||||
00133 }
|
||||
00134 w -= vec[i].size();
|
||||
00135 }
|
||||
00136 SymVec newvec = cur.args();
|
||||
00137 newvec[i] = result.first;
|
||||
00138 <span class="keywordflow">return</span> make_pair(Sym(cur.token(), newvec), <span class="keyword">true</span>);
|
||||
00139 }
|
||||
00140
|
||||
00141 Sym insert_subtree(<span class="keyword">const</span> Sym& cur, size_t w, <span class="keyword">const</span> Sym& nw) {
|
||||
00142 <span class="keywordflow">return</span> insert_subtree_impl(cur,w,nw).first;
|
||||
00143 }
|
||||
00144 Sym get_subtree(<span class="keyword">const</span> Sym& cur, size_t w) {
|
||||
00145 <span class="keywordflow">if</span> (w-- == 0) <span class="keywordflow">return</span> cur;
|
||||
00146
|
||||
00147 <span class="keyword">const</span> SymVec& vec = cur.args();
|
||||
00148 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < vec.size(); ++i) {
|
||||
00149 <span class="keywordflow">if</span> (w < vec[i].size()) <span class="keywordflow">return</span> get_subtree(vec[i], w);
|
||||
00150 w-=vec[i].size();
|
||||
00151 }
|
||||
00152 <span class="keywordflow">return</span> cur;
|
||||
00153 }
|
||||
00154
|
||||
00155
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:42 2006 for EO by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue