1 /************************************************************************
2 ************************************************************************
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.
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.
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 ************************************************************************/
25 * Interface for names propagation.
32 #include "property.hh"
34 #include "doc_Text.hh"
40 // 2009/09/08 : get/setDefNameProperty
43 extern int gMaxNameSize
;
47 * Definition name property : a property to keep track of the definition name
48 * of an expression. Whenever an identifier is evaluated, it is attached as a
49 * property of its definitionObviously there is no perfect solution since a same
50 * definition quand be given to different names.
52 Tree DEFNAMEPROPERTY
= tree(symbol("DEFNAMEPROPERTY"));
54 void setDefNameProperty(Tree t
, Tree id
)
56 //cerr << "setDefNameProperty : " << *id << " FOR " << t << "#" << boxpp(t) << endl;
57 setProperty(t
, DEFNAMEPROPERTY
, id
);
60 void setDefNameProperty(Tree t
, const string
& name
)
62 //cerr << "setDefNameProperty : " << name << " FOR " << t << "#" << boxpp(t) << endl;
64 int m
= (gMaxNameSize
>1023) ? 1023 : gMaxNameSize
;
66 // the name is too long we reduce it to 2/3 of maxsize
70 for (; i
< m
/3; i
++) { buf
[i
] = name
[i
]; }
76 for (int c
= n
-m
/3; c
<n
; c
++, i
++) { buf
[i
] = name
[c
]; }
78 setProperty(t
, DEFNAMEPROPERTY
, tree(buf
));
80 setProperty(t
, DEFNAMEPROPERTY
, tree(name
.c_str()));
85 bool getDefNameProperty(Tree t
, Tree
& id
)
87 //cerr << "getDefNameProperty of : " << t << endl;
88 return getProperty(t
, DEFNAMEPROPERTY
, id
);
93 * Convert a definition name (can be long) into a short nickname
94 * that can be used as an equation name in latex
95 * @todo Simplify long definition names.
97 string
defName2NickName (const string
& defname
)
102 Tree NICKNAMEPROPERTY
= tree(symbol("NICKNAMEPROPERTY"));
106 * Set the nickname property of a signal
108 void setSigNickname(Tree t
, const string
& id
)
111 if (isSigFixDelay(t
,s
,d
) && isZero(d
)) {
112 setProperty(s
, NICKNAMEPROPERTY
, tree(id
));
114 setProperty(t
, NICKNAMEPROPERTY
, tree(id
));
120 * Get the nickname property of a signal
122 bool getSigNickname(Tree t
, Tree
& id
)
124 bool r
= getProperty(t
, NICKNAMEPROPERTY
, id
);
131 * set the nickname property of a list of signals. If the list
132 * contains more than one signal, adds an index to the nickname
134 void setSigListNickName (Tree lsig
, const string
& nickname
)
136 assert(isList(lsig
));
138 if (isNil(tl(lsig
))) {
139 setSigNickname(hd(lsig
), nickname
);
142 while (!isNil(lsig
)) {
143 setSigNickname(hd(lsig
), subst("$0_$1", nickname
, T(++i
)));