FAUST compiler  0.9.9.6b8
names.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 
30 #include "ppsig.hh"
31 #include "names.hh"
32 #include "property.hh"
33 #include "ppsig.hh"
34 #include "doc_Text.hh"
35 #include "Text.hh"
36 #include <assert.h>
37 
38 
39 // History
40 // 2009/09/08 : get/setDefNameProperty
41 
42 
43 extern int gMaxNameSize;
44 
45 
52 Tree DEFNAMEPROPERTY = tree(symbol("DEFNAMEPROPERTY"));
53 
55 {
56  //cerr << "setDefNameProperty : " << *id << " FOR " << t << "#" << boxpp(t) << endl;
57  setProperty(t, DEFNAMEPROPERTY, id);
58 }
59 
60 void setDefNameProperty(Tree t, const string& name)
61 {
62  //cerr << "setDefNameProperty : " << name << " FOR " << t << "#" << boxpp(t) << endl;
63  int n = (int)name.size();
64  int m = (gMaxNameSize>1023) ? 1023 : gMaxNameSize;
65  if (n > m) {
66  // the name is too long we reduce it to 2/3 of maxsize
67  char buf[1024];
68  int i = 0;
69  // copy first third
70  for (; i < m/3; i++) { buf[i] = name[i]; }
71  // add ...
72  buf[i++] = '.';
73  buf[i++] = '.';
74  buf[i++] = '.';
75  // copy last third
76  for (int c = n-m/3; c<n; c++, i++) { buf[i] = name[c]; }
77  buf[i] = 0;
78  setProperty(t, DEFNAMEPROPERTY, tree(buf));
79  } else {
80  setProperty(t, DEFNAMEPROPERTY, tree(name.c_str()));
81  }
82 
83 }
84 
86 {
87  //cerr << "getDefNameProperty of : " << t << endl;
88  return getProperty(t, DEFNAMEPROPERTY, id);
89 }
90 
91 
97 string defName2NickName (const string& defname)
98 {
99  return defname;
100 }
101 
102 Tree NICKNAMEPROPERTY = tree(symbol("NICKNAMEPROPERTY"));
103 
104 
108 void setSigNickname(Tree t, const string& id)
109 {
110  Tree s,d;
111  if (isSigFixDelay(t,s,d) && isZero(d)) {
112  setProperty(s, NICKNAMEPROPERTY, tree(id));
113  } else {
114  setProperty(t, NICKNAMEPROPERTY, tree(id));
115  }
116 }
117 
118 
123 {
124  bool r = getProperty(t, NICKNAMEPROPERTY, id);
125  return r;
126 }
127 
128 
129 
134 void setSigListNickName (Tree lsig, const string& nickname)
135 {
136  assert(isList(lsig));
137 
138  if (isNil(tl(lsig))) {
139  setSigNickname(hd(lsig), nickname);
140  } else {
141  int i=0;
142  while (!isNil(lsig)) {
143  setSigNickname(hd(lsig), subst("$0_$1", nickname, T(++i)));
144  lsig = tl(lsig);
145  }
146  }
147 }
148 
149 
150 
151 
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
void setSigListNickName(Tree lsig, const string &nickname)
set the nickname property of a list of signals.
Definition: names.cpp:134
bool isZero(Tree a)
Definition: signals.hh:188
Tree NICKNAMEPROPERTY
Definition: names.cpp:102
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:62
Tree DEFNAMEPROPERTY
Definition name property : a property to keep track of the definition name of an expression.
Definition: names.cpp:52
Tree hd(Tree l)
Definition: list.hh:133
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
bool isNil(Tree l)
Definition: list.hh:137
bool getSigNickname(Tree t, Tree &id)
Get the nickname property of a signal.
Definition: names.cpp:122
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
bool isList(Tree l)
Definition: list.hh:138
string T(char *c)
Definition: Text.cpp:158
string defName2NickName(const string &defname)
Convert a definition name (can be long) into a short nickname that can be used as an equation name in...
Definition: names.cpp:97
int gMaxNameSize
Definition: main.cpp:127
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
void setSigNickname(Tree t, const string &id)
Set the nickname property of a signal.
Definition: names.cpp:108
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
Definition: symbol.hh:95
Interface for names management.
Tree tl(Tree l)
Definition: list.hh:134
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423