/[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 490 - (show annotations) (download) (as text)
Tue Apr 18 06:55:20 2006 UTC (13 years, 7 months ago) by johnpye
File MIME type: text/x-chdr
File size: 9292 byte(s)
Moved 'extern "C"' into the ASC_DLLSPEC macro.
Renamed .no.yacc and .no.flex files to have .c extension, so that SCons can tell what they are.
Working on getting things building on VC++, still some problems (maybe just issues with $PATH tho)./
1 /* ASCEND modelling environment
2 Copyright (C) 1996 Ben Allan
3 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
4 Copyright (C) 2006 Carnegie Mellon University
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 Requires:
68 #include "utilities/ascConfig.h"
69 #include "instance_enum.h"
70 #include "compiler.h"
71 *//*
72 by Tom Epperly & Ben Allan
73 8/16/89
74 Version: $Revision: 1.11 $
75 Version control file: $RCSfile: parentchild.h,v $
76 Date last modified: $Date: 1998/02/05 16:37:24 $
77 Last modified by: $Author: ballan $
78 */
79
80 #ifndef ASC_PARENTCHILD_H
81 #define ASC_PARENTCHILD_H
82
83 #include <utilities/ascConfig.h>
84
85 /* Parent routines */
86
87 extern unsigned long NumberParents(CONST struct Instance *i);
88 /**<
89 * Return the number of parents that instance i has.
90 * DummyInstances have no parents, apparently.
91 */
92
93 extern struct Instance *InstanceParent(CONST struct Instance *i, unsigned long n);
94 /**<
95 * Return a pointer to parent number n. Parents are numbered from
96 * 1 to NumberParents(i). 0(zero) is not a valid parent number.
97 * DummyInstances have no parents, apparently.
98 */
99
100 extern unsigned long SearchForParent(CONST struct Instance *i,
101 CONST struct Instance *p);
102 /**<
103 * Look in instance "i"'s parent list for parent "p". If "p" is not
104 * found, it will return 0; otherwise, it will return the parent number of
105 * "p" in instance "i"'s parent list.
106 * DummyInstance never has parents, it thinks.
107 */
108
109 extern void DeleteParent(struct Instance *i, unsigned long pos);
110 /**<
111 * Remove parent in pos from i's parent list.
112 * DummyInstance just reduces its reference count.
113 */
114
115 extern struct InstanceName ParentsName(CONST struct Instance *p,
116 CONST struct Instance *c);
117 /**<
118 * This will returns parent "p"'s name for "c". This assumes that
119 * "c" is actually a child of "p", and it will return a bad value if
120 * "c" is not a child of "p". Note this is actually a combination of
121 * ChildIndex and ChildName defined below. It is defined separately
122 * because it will be call alot. This is not a fast routine taking time
123 * proportional to the number of children p has.
124 * DummyInstance may have several names and which you get is arbitrary
125 * because you aren't supposed to care about dummy instances.
126 */
127
128 extern void AddParent(struct Instance *i, struct Instance *p);
129 /**<
130 * This will add parent "p" to instance "i"'s parent list. This only
131 * creates the link from "i" to "p"; it doesn't create the link from
132 * "p" to "i" which must be done with the routines below.
133 * This doesn't <-*****
134 * check if p is already a parent of "i"; you should know that it isn't
135 * before calling this.
136 * Exception:
137 * Every reference to DummyInstance should call this, and since
138 * SearchForParent will always say that p is not a parent of dummy,
139 * things work out ok.
140 */
141
142 /* Children routines */
143
144 ASC_DLLSPEC(unsigned long) NumberChildren(CONST struct Instance *i);
145 /**<
146 * Return the number of children that instance i has.
147 */
148
149
150 ASC_DLLSPEC(struct Instance*) InstanceChild(CONST struct Instance *i,
151 unsigned long n);
152 /**<
153 * Return a pointer to children number n. Do not confuse the child number
154 * n with an integer index. The two numbers may have no correlation.
155 * Child number range from 1 to NumberChildren(i). 0(zero) is not a valid
156 * child number.
157 * May exit on improper i.
158 */
159
160 ASC_DLLSPEC(struct InstanceName) ChildName(CONST struct Instance *i, unsigned long n);
161 /**<
162 * Returns the name of the n'th child of i. Assumes that i has an
163 * n'th child.
164 */
165
166 extern CONST struct Statement *ChildDeclaration(CONST struct Instance *i,
167 unsigned long n);
168 /**<
169 * Returns the declaration statement (IS_A,ALIASE,ARRAY) of the n'th child
170 * of i, if i has an n'th child. May return NULL under very odd circumstances.
171 * Does not return redeclarations (refinement) statements.
172 * i must not be NULL! The nth child may be NULL, but we don't care.
173 * (Note that as of 2/97 this function cannot return NULL because
174 * the ascend language is basetype safe semantically.)
175 */
176
177 extern CONST struct TypeDescription *ChildRefines(CONST struct Instance *i,
178 unsigned long n);
179 /**<
180 * Returns the type of the n'th child of i as determined at parse time.
181 * The nth child of the instance i doesn't need to exist yet. (may be null)
182 * The nth child of the instance will be of at least this type if the
183 * child is not an array.
184 * If the child is an array, the type returned here
185 * will be the type of the array elements as determined at parse time.
186 * This function may return NULL -- this merely means that at parse
187 * time we couldn't quite untwist the naming to determine a type.<br><br>
188 *
189 * Warning: Unselected parts will yield instances of type DUMMYINST
190 * instead of whatever type this returns.
191 */
192
193 extern unsigned long ChildSearch(CONST struct Instance *i,
194 CONST struct InstanceName *name);
195 /**<
196 * This procedure will search instance i for a child that matches "name".
197 * It it is unsuccessful, it will return 0; otherwise, it will return the
198 * index of the child that matches. It is assumed that all children have
199 * unique names and that there is no need to worry about more than one child
200 * matching "name". This can be called on childless instance without
201 * error. The strings in the InstanceName must come from the symbol table.
202 */
203
204 ASC_DLLSPEC(struct Instance*) ChildByChar(CONST struct Instance *i,
205 symchar *str);
206 /**<
207 * This returns to the pointer to a child, c, of parent,p, named by str.
208 * str must be a simple name. If child not found, returns NULL.
209 * str must be from the symbol table. If AscFindSymbol(str)==NULL,
210 * then this function should not be called because NO instance
211 * can have a child with a name which is not in the symbol table.
212 */
213
214 /*
215 * extern unsigned long ChildSearchRegExp(); NOT IMPLEMENTED.
216 * unsigned long ChildSearchRegExp(i,name,start)
217 * struct Instance *i;
218 * char *name;
219 * unsigned long start;
220 *
221 * This is an unplanned extension to the initial implementation to add regular
222 * expression searches. The function will search from child number "start"
223 * to the first match. If no match is found, it will return 0; otherwise
224 * it will return the first match of the regular expression. Examples of
225 * regular expressions are:
226 * f* which means all strings starting with the letter f
227 * f? which means all two character long strings starting with
228 * f
229 */
230
231 extern unsigned long ChildIndex(CONST struct Instance *i,
232 CONST struct Instance *child);
233 /**<
234 * This procedure searches through the child list of instance i for child.
235 * If it does not find a match, it returns 0; otherwise, it will return
236 * the child number of "child".
237 */
238
239 extern void StoreChildPtr(struct Instance *i,
240 unsigned long n,
241 struct Instance *child);
242 /**<
243 * Store the child pointer "child" in position n of i. This only creates
244 * the link from i to child, and not the back link which is created by
245 * add parent. Instance "i" cannot be a fundamental atom; atoms are
246 * created in a special way.
247 */
248
249 #endif /* ASC_PARENTCHILD_H */

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