Uses colors to analyze dependencies among sub expressions. More...
#include "colorize.h"
#include <set>
#include <algorithm>
#include "tlib.hh"
#include "signals.hh"
Go to the source code of this file.
Functions | |
static int | allocateColor (Tree exp) |
allocate a new unique color for exp | |
static void | colorize (Tree exp, int color) |
add color information to exp and all its subtrees | |
static void | uncolorize (Tree exp) |
remove color information | |
static void | listMultiColoredExp (Tree exp, set< Tree > &lst) |
list multicolored subexpressions of exp | |
void | splitDependance (const set< Tree > &exps, set< Tree > &post, set< Tree > &pre) |
Analyze a set of expressions to discover its dependencies that is subexpressions common to at least two of these expressions. | |
static void | addColor (Tree exp, int color) |
a color to the colors of exp | |
static bool | hasColor (Tree exp, int color) |
true if exp is already colored with color | |
static int | colorsCount (Tree exp) |
returns the number of colors of exp | |
static void | clearColors (Tree exp) |
remove the color property of exp | |
void | setColorProperty (Tree sig, set< int > *colorset) |
set the color-set property of sig | |
set< int > * | getColorProperty (Tree sig) |
retrieve the color-set property of sig | |
Variables | |
Tree | COLORPROPERTY = tree(symbol("ColorProperty")) |
Uses colors to analyze dependencies among sub expressions.
Definition in file colorize.cpp.
void addColor | ( | Tree | exp, | |
int | color | |||
) | [static] |
a color to the colors of exp
Add a color to the colorset of exp.
Create an empty coloset if needed.
sig | the signal we want to color | |
color | the color used |
Definition at line 154 of file colorize.cpp.
References getColorProperty(), and setColorProperty().
Referenced by colorize().
00155 { 00156 set<int>* cset = getColorProperty(exp); 00157 if (cset == 0) { 00158 cset = new set<int>(); 00159 setColorProperty(exp, cset); 00160 } 00161 cset->insert(color); 00162 }
int allocateColor | ( | Tree | exp | ) | [static] |
allocate a new unique color for exp
Allocate a unique color (an integer) for an expression.
by converting its address into an integer
Definition at line 59 of file colorize.cpp.
Referenced by splitDependance().
00060 { 00061 // return int(exp); 00062 static map<Tree,int> colorMap; 00063 static int nextFreeColor = 1; 00064 int& color = colorMap[exp]; 00065 if (!color) 00066 color = nextFreeColor++; 00067 return color; 00068 }
static void clearColors | ( | Tree | exp | ) | [static] |
remove the color property of exp
Count the number of colors of exp.
exp | the expression we want to count the colors |
Definition at line 203 of file colorize.cpp.
References getColorProperty().
Referenced by uncolorize().
00204 { 00205 set<int>* cset = getColorProperty(exp); 00206 if (cset != 0) { 00207 cset->clear(); 00208 } 00209 }
void colorize | ( | Tree | exp, | |
int | color | |||
) | [static] |
add color information to exp and all its subtrees
Add a color to all the expression tree.
Definition at line 73 of file colorize.cpp.
References addColor(), getSubSignals(), and hasColor().
Referenced by splitDependance().
00074 { 00075 if (! hasColor(exp, color)) { 00076 addColor(exp, color); 00077 vector<Tree> v; 00078 int n = getSubSignals(exp, v, false); 00079 for (int i=0; i<n; i++) colorize(v[i], color); 00080 } 00081 }
static int colorsCount | ( | Tree | exp | ) | [static] |
returns the number of colors of exp
Count the number of colors of exp.
exp | the expression we want to count the colors |
Definition at line 187 of file colorize.cpp.
References getColorProperty().
Referenced by listMultiColoredExp(), and uncolorize().
00188 { 00189 set<int>* cset = getColorProperty(exp); 00190 if (cset==0) { 00191 return 0; 00192 } else { 00193 return cset->size(); 00194 } 00195 }
set<int>* getColorProperty | ( | Tree | sig | ) |
retrieve the color-set property of sig
sig | the signal we want to know the color-set property |
Definition at line 135 of file colorize.cpp.
References getProperty(), and tree2ptr().
Referenced by addColor(), clearColors(), colorsCount(), and hasColor().
00136 { 00137 Tree tt; 00138 if (!getProperty(sig, COLORPROPERTY, tt)) { 00139 return 0; 00140 } else { 00141 return (set<int>*)tree2ptr(tt); 00142 } 00143 }
bool hasColor | ( | Tree | exp, | |
int | color | |||
) | [static] |
true if exp is already colored with color
Test if exp as color in its colorset.
sig | the signal we want to test | |
color | the color to test |
Definition at line 171 of file colorize.cpp.
References getColorProperty().
Referenced by colorize().
00172 { 00173 set<int>* cset = getColorProperty(exp); 00174 if (cset==0) { 00175 return false; 00176 } else { 00177 return cset->find(color) != cset->end(); 00178 } 00179 }
list multicolored subexpressions of exp
Make a set of the multicolored sub-expressions.
Definition at line 99 of file colorize.cpp.
References colorsCount(), and getSubSignals().
Referenced by splitDependance().
00100 { 00101 assert(colorsCount(exp) > 0); 00102 if (colorsCount(exp) > 1) { 00103 // we have found a multicolored expression 00104 lst.insert(exp); 00105 } else { 00106 // it is a monocolored expression 00107 // we search its subexpressions 00108 vector<Tree> v; 00109 int n = getSubSignals(exp, v, false); 00110 for (int i=0; i<n; i++) { 00111 listMultiColoredExp(v[i], lst); 00112 } 00113 } 00114 }
void setColorProperty | ( | Tree | sig, | |
set< int > * | colorset | |||
) |
set the color-set property of sig
sig | the signal we want to type | |
t | the type of the signal |
Definition at line 125 of file colorize.cpp.
References setProperty(), and tree().
Referenced by addColor().
00126 { 00127 setProperty(sig, COLORPROPERTY, tree((void*)colorset)); 00128 }
Analyze a set of expressions to discover its dependencies that is subexpressions common to at least two of these expressions.
exps | set of expressions to analyze | |
post | resulting set of post expressions | |
pre | resulting set of pre expressions |
Definition at line 28 of file colorize.cpp.
References allocateColor(), colorize(), listMultiColoredExp(), and uncolorize().
00029 { 00030 set<Tree>::const_iterator e; 00031 for (e= exps.begin(); e != exps.end(); e++) { 00032 colorize(*e, allocateColor(*e)); 00033 } 00034 00035 pre.clear(); 00036 for (e = exps.begin(); e != exps.end(); e++) { 00037 listMultiColoredExp(*e, pre); 00038 } 00039 00040 post.clear(); 00041 set_difference(exps.begin(), exps.end(), pre.begin(), pre.end(), inserter(post, post.begin())); 00042 00043 for (e = exps.begin(); e != exps.end(); e++) { 00044 uncolorize(*e); 00045 } 00046 }
void uncolorize | ( | Tree | exp | ) | [static] |
remove color information
Remove the colors of an expression tree.
Definition at line 86 of file colorize.cpp.
References clearColors(), colorsCount(), and getSubSignals().
Referenced by splitDependance().
00087 { 00088 if (colorsCount(exp) > 0) { 00089 clearColors(exp); 00090 vector<Tree> v; 00091 int n = getSubSignals(exp, v, false); 00092 for (int i=0; i<n; i++) uncolorize(v[i]); 00093 } 00094 }
Tree COLORPROPERTY = tree(symbol("ColorProperty")) |
Definition at line 118 of file colorize.cpp.