labels.cpp File Reference

#include "labels.hh"
#include "tlib.hh"
#include "boxes.hh"
#include "signals.hh"
Include dependency graph for labels.cpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Tree pathRoot ()
bool isPathRoot (Tree t)
Tree pathParent ()
bool isPathParent (Tree t)
Tree pathCurrent ()
bool isPathCurrent (Tree t)
static Tree encodeName (char g, const string &name)
 analyze name for "H:name" | "V:name" etc
static Tree label2path (const char *label)
 Analyzes a label and converts it as a path.
static Tree concatPath (Tree relpath, Tree abspath)
 Concatenate the relative path to the absolute path Note that the relpath is top-down while the abspath is bottom-up.
static Tree normalizeLabel (Tree label, Tree path)
Tree normalizePath (Tree path)

Variables

Sym PATHROOT = symbol ("/")
 Grammar for labels with pathnames ----------------------------------- <label> = <name> | <path> <name> <name> = [^/]+ <path> = <apath> | <rpath> <apath> = '/' | '/' <rpath> <rpath> = (<gname> '/')+ <gname> = ".." | "." | <gtype> <name> <gtype> = "h:" | "H:" | "v:" | V:" | "t:" | "T:".
Sym PATHPARENT = symbol ("..")
Sym PATHCURRENT = symbol (".")

Function Documentation

static Tree concatPath ( Tree  relpath,
Tree  abspath 
) [static]

Concatenate the relative path to the absolute path Note that the relpath is top-down while the abspath is bottom-up.

Definition at line 94 of file labels.cpp.

References cons(), hd(), isList(), isNil(), isPathCurrent(), isPathParent(), isPathRoot(), nil, and tl().

Referenced by normalizeLabel().

00095 {
00096     if (isList(relpath)) {
00097         Tree head = hd(relpath);
00098         if (isPathRoot(head)) {
00099             return concatPath(tl(relpath), nil);
00100         } else if (isPathParent(head)) {
00101             if (!isList(abspath)) { 
00102                 //cerr << "abspath : " << *abspath << endl; 
00103                 return concatPath(tl(relpath), hd(relpath));
00104             } else {
00105                 return concatPath(tl(relpath), tl(abspath));
00106             }
00107         } else if (isPathCurrent(head)) {
00108             return concatPath(tl(relpath), abspath);
00109         } else {
00110             return concatPath(tl(relpath), cons(head,abspath));
00111         }
00112     } else {
00113         assert(isNil(relpath));
00114         return abspath;
00115     }
00116 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree encodeName ( char  g,
const string &  name 
) [static]

analyze name for "H:name" | "V:name" etc

Definition at line 36 of file labels.cpp.

References cons(), and tree().

Referenced by label2path().

00037 {
00038     switch (g) {
00039         case 'v':
00040         case 'V': return cons(tree(0), tree(name));
00041 
00042         case 'h':
00043         case 'H': return cons(tree(1), tree(name));
00044 
00045         case 't':
00046         case 'T': return cons(tree(2), tree(name));
00047 
00048         default : return cons(tree(0), tree(name));
00049     }
00050 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool isPathCurrent ( Tree  t  ) 

Definition at line 28 of file labels.cpp.

References isTree().

Referenced by concatPath().

00028 { return isTree(t, PATHCURRENT); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool isPathParent ( Tree  t  ) 

Definition at line 24 of file labels.cpp.

References isTree().

Referenced by concatPath().

00024 { return isTree(t, PATHPARENT); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool isPathRoot ( Tree  t  ) 

Definition at line 20 of file labels.cpp.

References isTree().

Referenced by concatPath().

00020 { return isTree(t, PATHROOT); }

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree label2path ( const char *  label  )  [static]

Analyzes a label and converts it as a path.

Definition at line 57 of file labels.cpp.

References cons(), encodeName(), nil, pathParent(), pathRoot(), and tree().

Referenced by normalizeLabel().

00058 {
00059     if (label[0] == 0) {
00060         return cons(tree(""), nil);
00061 
00062     } else if (label[0] == '/') {
00063         return cons(pathRoot(), label2path(&label[1]));
00064 
00065     } else if ((label[0] == '.') && (label[1] == '/')) {
00066         return label2path(&label[2]);
00067 
00068     } else if ((label[0] == '.') && (label[1] == '.') && (label[2] == '/')) {
00069         return cons(pathParent(), label2path(&label[3]));
00070 
00071     } else if (label[1] == ':') {
00072         char    g = label[0];
00073         string  s;
00074         int     i = 2;
00075         while ((label[i] != 0) && (label[i] != '/')) {
00076             s.push_back(label[i]);
00077             i++;
00078         }
00079         if (label[i] == '/') i++;
00080         return cons(encodeName(g,s), label2path(&label[i]));
00081 
00082     } else {
00083         return cons(tree(label),nil);
00084     }
00085 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree normalizeLabel ( Tree  label,
Tree  path 
) [static]

Definition at line 119 of file labels.cpp.

References concatPath(), cons(), isList(), isSym(), label2path(), name(), and CTree::node().

Referenced by normalizePath().

00120 {
00121     // we suppose label = "../label" ou "name/label" ou "name"  
00122     //cout << "Normalize Label " << *label << " with path " << *path << endl;
00123     if (isList(label)) {
00124         return cons(label, path);
00125     } else {
00126         Sym s;
00127         assert (isSym(label->node(),&s));
00128         return concatPath(label2path(name(s)),path);
00129     }
00130 }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree normalizePath ( Tree  path  ) 

Definition at line 132 of file labels.cpp.

References hd(), isNil(), normalizeLabel(), normalizePath(), and tl().

Referenced by normalizePath(), and propagate().

00133 {
00134     //cout << "Normalize Path [[" << *path << "]]" << endl;
00135     Tree npath;
00136     if (isNil(path)) {
00137         npath = path;
00138     } else {
00139         npath = normalizeLabel(hd(path), normalizePath(tl(path)));
00140     }
00141     //cout << "              -> [[" << *npath << "]]" << endl;
00142     return npath;
00143 }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree pathCurrent (  ) 

Definition at line 27 of file labels.cpp.

References tree().

00027 { return tree(PATHCURRENT); }

Here is the call graph for this function:

Tree pathParent (  ) 

Definition at line 23 of file labels.cpp.

References tree().

Referenced by label2path().

00023 { return tree(PATHPARENT); }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree pathRoot (  ) 

Definition at line 19 of file labels.cpp.

References tree().

Referenced by label2path().

00019 { return tree(PATHROOT); }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Sym PATHCURRENT = symbol (".")

Definition at line 26 of file labels.cpp.

Sym PATHPARENT = symbol ("..")

Definition at line 22 of file labels.cpp.

Sym PATHROOT = symbol ("/")

Grammar for labels with pathnames ----------------------------------- <label> = <name> | <path> <name> <name> = [^/]+ <path> = <apath> | <rpath> <apath> = '/' | '/' <rpath> <rpath> = (<gname> '/')+ <gname> = ".." | "." | <gtype> <name> <gtype> = "h:" | "H:" | "v:" | V:" | "t:" | "T:".

Definition at line 18 of file labels.cpp.

Generated on Wed Apr 28 23:45:50 2010 for FAUST compiler by  doxygen 1.6.3