/[ascend]/trunk/base/generic/compiler/parentchild.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/parentchild.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1539 - (show annotations) (download) (as text)
Wed Jul 11 09:14:41 2007 UTC (15 years, 8 months ago) by jpye
File MIME type: text/x-chdr
File size: 9372 byte(s)
Debug info removed.
Comment about header files removed.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3 Copyright (C) 1996 Ben Allan
4 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
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, or (at your option)
9 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20 *//**
21 @file
22 Ascend Instance Tree Link Implementation.
23
24 General comments on parents:
25
26 - Parents are numbered from 1 up, so zero is never a valid
27 parent number
28
29 - Parent lists are kept sorted by address.
30
31 - The ordering of the parents list is not predictable in
32 any usefull way.
33
34 - The number of parents for a given instance can be modified
35 by ARE_THE_SAME's.
36
37 - The number of parents is NOT constant for a given type.
38
39 - Parent lists will contain no duplications.
40 (when AddParent is used correctly, that is.)
41
42 - DummyInstances don't track parents -- they play a reference
43 count game.
44
45 General comments on children:
46
47 - Children are number from 1 up, so zero is never a valid child
48 number.
49
50 - Children numbers will remain constant for a given type except
51 for arrays which can have varying numbers of children.
52
53 - Children numbers may or may not change will an instance is
54 refined.
55
56 - Children are always sorted in increasing order either
57 alphabetically or numerically depending on the type of
58 naming.
59
60 - Children don't know what their name is. Only a parent
61 knows the names of the children below it.
62
63 - DummyInstances have no children.
64
65 based on instance.c
66 *//*
67 by Tom Epperly 8/16/89, Ben Allan
68 Version: $Revision: 1.11 $
69 Version control file: $RCSfile: parentchild.h,v $
70 Date last modified: $Date: 1998/02/05 16:37:24 $
71 Last modified by: $Author: ballan $
72 */
73
74 #ifndef ASC_PARENTCHILD_H
75 #define ASC_PARENTCHILD_H
76
77 /** @addtogroup compiler Compiler
78 @{
79 */
80
81 #include <utilities/ascConfig.h>
82 #include <compiler/compiler.h>
83 #include <compiler/instance_enum.h>
84 #include <compiler/instance_name.h>
85
86 /* Parent routines */
87
88 ASC_DLLSPEC unsigned long NumberParents(CONST struct Instance *i);
89 /**<
90 * Return the number of parents that instance i has.
91 * DummyInstances have no parents, apparently.
92 */
93
94 ASC_DLLSPEC struct Instance *InstanceParent(CONST struct Instance *i, unsigned long n);
95 /**<
96 * Return a pointer to parent number n. Parents are numbered from
97 * 1 to NumberParents(i). 0(zero) is not a valid parent number.
98 * DummyInstances have no parents, apparently.
99 */
100
101 extern unsigned long SearchForParent(CONST struct Instance *i,
102 CONST struct Instance *p);
103 /**<
104 * Look in instance "i"'s parent list for parent "p". If "p" is not
105 * found, it will return 0; otherwise, it will return the parent number of
106 * "p" in instance "i"'s parent list.
107 * DummyInstance never has parents, it thinks.
108 */
109
110 extern void DeleteParent(struct Instance *i, unsigned long pos);
111 /**<
112 * Remove parent in pos from i's parent list.
113 * DummyInstance just reduces its reference count.
114 */
115
116 ASC_DLLSPEC struct InstanceName ParentsName(CONST struct Instance *p,
117 CONST struct Instance *c);
118 /**<
119 * This will returns parent "p"'s name for "c". This assumes that
120 * "c" is actually a child of "p", and it will return a bad value if
121 * "c" is not a child of "p". Note this is actually a combination of
122 * ChildIndex and ChildName defined below. It is defined separately
123 * because it will be call alot. This is not a fast routine taking time
124 * proportional to the number of children p has.
125 * DummyInstance may have several names and which you get is arbitrary
126 * because you aren't supposed to care about dummy instances.
127 */
128
129 extern void AddParent(struct Instance *i, struct Instance *p);
130 /**<
131 * This will add parent "p" to instance "i"'s parent list. This only
132 * creates the link from "i" to "p"; it doesn't create the link from
133 * "p" to "i" which must be done with the routines below.
134 * This doesn't <-*****
135 * check if p is already a parent of "i"; you should know that it isn't
136 * before calling this.
137 * Exception:
138 * Every reference to DummyInstance should call this, and since
139 * SearchForParent will always say that p is not a parent of dummy,
140 * things work out ok.
141 */
142
143 /* Children routines */
144
145 ASC_DLLSPEC unsigned long NumberChildren(CONST struct Instance *i);
146 /**<
147 * Return the number of children that instance i has.
148 */
149
150
151 ASC_DLLSPEC struct Instance*InstanceChild(CONST struct Instance *i,
152 unsigned long n);
153 /**<
154 * Return a pointer to children number n. Do not confuse the child number
155 * n with an integer index. The two numbers may have no correlation.
156 * Child number range from 1 to NumberChildren(i). 0(zero) is not a valid
157 * child number.
158 * May exit on improper i.
159 */
160
161 ASC_DLLSPEC struct InstanceName ChildName(CONST struct Instance *i, unsigned long n);
162 /**<
163 * Returns the name of the n'th child of i. Assumes that i has an
164 * n'th child.
165 */
166
167 ASC_DLLSPEC CONST struct Statement *ChildDeclaration(CONST struct Instance *i,
168 unsigned long n);
169 /**<
170 * Returns the declaration statement (IS_A,ALIASE,ARRAY) of the n'th child
171 * of i, if i has an n'th child. May return NULL under very odd circumstances.
172 * Does not return redeclarations (refinement) statements.
173 * i must not be NULL! The nth child may be NULL, but we don't care.
174 * (Note that as of 2/97 this function cannot return NULL because
175 * the ascend language is basetype safe semantically.)
176 */
177
178 extern CONST struct TypeDescription *ChildRefines(CONST struct Instance *i,
179 unsigned long n);
180 /**<
181 * Returns the type of the n'th child of i as determined at parse time.
182 * The nth child of the instance i doesn't need to exist yet. (may be null)
183 * The nth child of the instance will be of at least this type if the
184 * child is not an array.
185 * If the child is an array, the type returned here
186 * will be the type of the array elements as determined at parse time.
187 * This function may return NULL -- this merely means that at parse
188 * time we couldn't quite untwist the naming to determine a type.<br><br>
189 *
190 * Warning: Unselected parts will yield instances of type DUMMYINST
191 * instead of whatever type this returns.
192 */
193
194 ASC_DLLSPEC unsigned long ChildSearch(CONST struct Instance *i,
195 CONST struct InstanceName *name);
196 /**<
197 * This procedure will search instance i for a child that matches "name".
198 * It it is unsuccessful, it will return 0; otherwise, it will return the
199 * index of the child that matches. It is assumed that all children have
200 * unique names and that there is no need to worry about more than one child
201 * matching "name". This can be called on childless instance without
202 * error. The strings in the InstanceName must come from the symbol table.
203 */
204
205 ASC_DLLSPEC struct Instance*ChildByChar(CONST struct Instance *i,
206 symchar *str);
207 /**<
208 * This returns to the pointer to a child, c, of parent,p, named by str.
209 * str must be a simple name. If child not found, returns NULL.
210 * str must be from the symbol table. If AscFindSymbol(str)==NULL,
211 * then this function should not be called because NO instance
212 * can have a child with a name which is not in the symbol table.
213 */
214
215 /*
216 * extern unsigned long ChildSearchRegExp(); NOT IMPLEMENTED.
217 * unsigned long ChildSearchRegExp(i,name,start)
218 * struct Instance *i;
219 * char *name;
220 * unsigned long start;
221 *
222 * This is an unplanned extension to the initial implementation to add regular
223 * expression searches. The function will search from child number "start"
224 * to the first match. If no match is found, it will return 0; otherwise
225 * it will return the first match of the regular expression. Examples of
226 * regular expressions are:
227 * f* which means all strings starting with the letter f
228 * f? which means all two character long strings starting with
229 * f
230 */
231
232 ASC_DLLSPEC unsigned long ChildIndex(CONST struct Instance *i,
233 CONST struct Instance *child);
234 /**<
235 * This procedure searches through the child list of instance i for child.
236 * If it does not find a match, it returns 0; otherwise, it will return
237 * the child number of "child".
238 */
239
240 extern void StoreChildPtr(struct Instance *i,
241 unsigned long n,
242 struct Instance *child);
243 /**<
244 * Store the child pointer "child" in position n of i. This only creates
245 * the link from i to child, and not the back link which is created by
246 * add parent. Instance "i" cannot be a fundamental atom; atoms are
247 * created in a special way.
248 */
249
250 /* @} */
251
252 #endif /* ASC_PARENTCHILD_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22