FAUST compiler  0.9.9.6b8
Functions | Variables
labels.cpp File Reference
#include "labels.hh"
#include "compatibility.hh"
Include dependency graph for labels.cpp:

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 More...
 
static Tree label2path (const char *label)
 Analyzes a label and converts it as a path. More...
 
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. More...
 
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:" More...
 
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 95 of file labels.cpp.

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

Referenced by normalizeLabel().

96 {
97  if (isList(relpath)) {
98  Tree head = hd(relpath);
99  if (isPathRoot(head)) {
100  return concatPath(tl(relpath), nil);
101  } else if (isPathParent(head)) {
102  if (!isList(abspath)) {
103  //cerr << "abspath : " << *abspath << endl;
104  return concatPath(tl(relpath), hd(relpath));
105  } else {
106  return concatPath(tl(relpath), tl(abspath));
107  }
108  } else if (isPathCurrent(head)) {
109  return concatPath(tl(relpath), abspath);
110  } else {
111  return concatPath(tl(relpath), cons(head,abspath));
112  }
113  } else {
114  assert(isNil(relpath));
115  return abspath;
116  }
117 }
bool isPathParent(Tree t)
Definition: labels.cpp:25
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
bool isPathRoot(Tree t)
Definition: labels.cpp:21
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
static Tree concatPath(Tree relpath, Tree abspath)
Concatenate the relative path to the absolute path Note that the relpath is top-down while the abspat...
Definition: labels.cpp:95
bool isPathCurrent(Tree t)
Definition: labels.cpp:29
Tree tl(Tree l)
Definition: list.hh:134

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 37 of file labels.cpp.

References cons(), and tree().

Referenced by label2path().

38 {
39  switch (g) {
40  case 'v':
41  case 'V': return cons(tree(0), tree(name));
42 
43  case 'h':
44  case 'H': return cons(tree(1), tree(name));
45 
46  case 't':
47  case 'T': return cons(tree(2), tree(name));
48 
49  default : return cons(tree(0), tree(name));
50  }
51 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

bool isPathCurrent ( Tree  t)

Definition at line 29 of file labels.cpp.

References isTree().

Referenced by concatPath().

29 { return isTree(t, PATHCURRENT); }
Sym PATHCURRENT
Definition: labels.cpp:27
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

Here is the call graph for this function:

Here is the caller graph for this function:

bool isPathParent ( Tree  t)

Definition at line 25 of file labels.cpp.

References isTree().

Referenced by concatPath().

25 { return isTree(t, PATHPARENT); }
Sym PATHPARENT
Definition: labels.cpp:23
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

Here is the call graph for this function:

Here is the caller graph for this function:

bool isPathRoot ( Tree  t)

Definition at line 21 of file labels.cpp.

References isTree().

Referenced by concatPath().

21 { return isTree(t, PATHROOT); }
Sym PATHROOT
Grammar for labels with pathnames
Definition: labels.cpp:19
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

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 58 of file labels.cpp.

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

Referenced by normalizeLabel().

59 {
60  if (label[0] == 0) {
61  return cons(tree(""), nil);
62 
63  } else if (label[0] == '/') {
64  return cons(pathRoot(), label2path(&label[1]));
65 
66  } else if ((label[0] == '.') && (label[1] == '/')) {
67  return label2path(&label[2]);
68 
69  } else if ((label[0] == '.') && (label[1] == '.') && (label[2] == '/')) {
70  return cons(pathParent(), label2path(&label[3]));
71 
72  } else if (label[1] == ':') {
73  char g = label[0];
74  string s;
75  int i = 2;
76  while ((label[i] != 0) && (label[i] != '/')) {
77  s.push_back(label[i]);
78  i++;
79  }
80  if (label[i] == '/') i++;
81  return cons(encodeName(g,s), label2path(&label[i]));
82 
83  } else {
84  return cons(tree(label),nil);
85  }
86 }
static Tree label2path(const char *label)
Analyzes a label and converts it as a path.
Definition: labels.cpp:58
static Tree encodeName(char g, const string &name)
analyze name for "H:name" | "V:name" etc
Definition: labels.cpp:37
Tree pathParent()
Definition: labels.cpp:24
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree pathRoot()
Definition: labels.cpp:20
Tree tree(const Node &n)
Definition: tree.hh:186
Tree nil
Definition: list.cpp:116

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 120 of file labels.cpp.

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

Referenced by normalizePath().

121 {
122  // we suppose label = "../label" ou "name/label" ou "name"
123  //cout << "Normalize Label " << *label << " with path " << *path << endl;
124  if (isList(label)) {
125  return cons(label, path);
126  } else {
127  Sym s;
128  assert (isSym(label->node(),&s));
129  return concatPath(label2path(name(s)),path);
130  }
131 }
static Tree label2path(const char *label)
Analyzes a label and converts it as a path.
Definition: labels.cpp:58
Tree cons(Tree a, Tree b)
Definition: list.hh:124
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isList(Tree l)
Definition: list.hh:138
bool isSym(const Node &n)
Definition: node.hh:199
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Symbols are unique objects with a name stored in a hash table.
Definition: symbol.hh:53
static Tree concatPath(Tree relpath, Tree abspath)
Concatenate the relative path to the absolute path Note that the relpath is top-down while the abspat...
Definition: labels.cpp:95

Here is the call graph for this function:

Here is the caller graph for this function:

Tree normalizePath ( Tree  path)

Definition at line 133 of file labels.cpp.

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

Referenced by normalizePath(), and realPropagate().

134 {
135  //cout << "Normalize Path [[" << *path << "]]" << endl;
136  Tree npath;
137  if (isNil(path)) {
138  npath = path;
139  } else {
140  npath = normalizeLabel(hd(path), normalizePath(tl(path)));
141  }
142  //cout << " -> [[" << *npath << "]]" << endl;
143  return npath;
144 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
static Tree normalizeLabel(Tree label, Tree path)
Definition: labels.cpp:120
Tree normalizePath(Tree path)
Definition: labels.cpp:133
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree pathCurrent ( )

Definition at line 28 of file labels.cpp.

References tree().

28 { return tree(PATHCURRENT); }
Sym PATHCURRENT
Definition: labels.cpp:27
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Tree pathParent ( )

Definition at line 24 of file labels.cpp.

References tree().

Referenced by label2path().

24 { return tree(PATHPARENT); }
Sym PATHPARENT
Definition: labels.cpp:23
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Tree pathRoot ( )

Definition at line 20 of file labels.cpp.

References tree().

Referenced by label2path().

20 { return tree(PATHROOT); }
Sym PATHROOT
Grammar for labels with pathnames
Definition: labels.cpp:19
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

Sym PATHCURRENT = symbol (".")

Definition at line 27 of file labels.cpp.

Sym PATHPARENT = symbol ("..")

Definition at line 23 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 19 of file labels.cpp.