Parent Directory | Revision Log

Revision **502** -
(**show annotations**)
(**download**)
(**as text**)

*Tue Apr 18 12:57:30 2006 UTC*
(14 years, 5 months ago)
by *johnpye*

File MIME type: text/x-chdr

File size: 9359 byte(s)

File MIME type: text/x-chdr

File size: 9359 byte(s)

Added check to see that YACC runs OK. Fixing build with MSVC++ 2005. All builds now except for some problems in the SWIG-generated code.

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 | #include <compiler/compiler.h> |

85 | #include <compiler/instance_name.h> |

86 | |

87 | /* Parent routines */ |

88 | |

89 | extern unsigned long NumberParents(CONST struct Instance *i); |

90 | /**< |

91 | * Return the number of parents that instance i has. |

92 | * DummyInstances have no parents, apparently. |

93 | */ |

94 | |

95 | extern struct Instance *InstanceParent(CONST struct Instance *i, unsigned long n); |

96 | /**< |

97 | * Return a pointer to parent number n. Parents are numbered from |

98 | * 1 to NumberParents(i). 0(zero) is not a valid parent number. |

99 | * DummyInstances have no parents, apparently. |

100 | */ |

101 | |

102 | extern unsigned long SearchForParent(CONST struct Instance *i, |

103 | CONST struct Instance *p); |

104 | /**< |

105 | * Look in instance "i"'s parent list for parent "p". If "p" is not |

106 | * found, it will return 0; otherwise, it will return the parent number of |

107 | * "p" in instance "i"'s parent list. |

108 | * DummyInstance never has parents, it thinks. |

109 | */ |

110 | |

111 | extern void DeleteParent(struct Instance *i, unsigned long pos); |

112 | /**< |

113 | * Remove parent in pos from i's parent list. |

114 | * DummyInstance just reduces its reference count. |

115 | */ |

116 | |

117 | extern struct InstanceName ParentsName(CONST struct Instance *p, |

118 | CONST struct Instance *c); |

119 | /**< |

120 | * This will returns parent "p"'s name for "c". This assumes that |

121 | * "c" is actually a child of "p", and it will return a bad value if |

122 | * "c" is not a child of "p". Note this is actually a combination of |

123 | * ChildIndex and ChildName defined below. It is defined separately |

124 | * because it will be call alot. This is not a fast routine taking time |

125 | * proportional to the number of children p has. |

126 | * DummyInstance may have several names and which you get is arbitrary |

127 | * because you aren't supposed to care about dummy instances. |

128 | */ |

129 | |

130 | extern void AddParent(struct Instance *i, struct Instance *p); |

131 | /**< |

132 | * This will add parent "p" to instance "i"'s parent list. This only |

133 | * creates the link from "i" to "p"; it doesn't create the link from |

134 | * "p" to "i" which must be done with the routines below. |

135 | * This doesn't <-***** |

136 | * check if p is already a parent of "i"; you should know that it isn't |

137 | * before calling this. |

138 | * Exception: |

139 | * Every reference to DummyInstance should call this, and since |

140 | * SearchForParent will always say that p is not a parent of dummy, |

141 | * things work out ok. |

142 | */ |

143 | |

144 | /* Children routines */ |

145 | |

146 | ASC_DLLSPEC(unsigned long) NumberChildren(CONST struct Instance *i); |

147 | /**< |

148 | * Return the number of children that instance i has. |

149 | */ |

150 | |

151 | |

152 | ASC_DLLSPEC(struct Instance*) InstanceChild(CONST struct Instance *i, |

153 | unsigned long n); |

154 | /**< |

155 | * Return a pointer to children number n. Do not confuse the child number |

156 | * n with an integer index. The two numbers may have no correlation. |

157 | * Child number range from 1 to NumberChildren(i). 0(zero) is not a valid |

158 | * child number. |

159 | * May exit on improper i. |

160 | */ |

161 | |

162 | ASC_DLLSPEC(struct InstanceName) ChildName(CONST struct Instance *i, unsigned long n); |

163 | /**< |

164 | * Returns the name of the n'th child of i. Assumes that i has an |

165 | * n'th child. |

166 | */ |

167 | |

168 | extern CONST struct Statement *ChildDeclaration(CONST struct Instance *i, |

169 | unsigned long n); |

170 | /**< |

171 | * Returns the declaration statement (IS_A,ALIASE,ARRAY) of the n'th child |

172 | * of i, if i has an n'th child. May return NULL under very odd circumstances. |

173 | * Does not return redeclarations (refinement) statements. |

174 | * i must not be NULL! The nth child may be NULL, but we don't care. |

175 | * (Note that as of 2/97 this function cannot return NULL because |

176 | * the ascend language is basetype safe semantically.) |

177 | */ |

178 | |

179 | extern CONST struct TypeDescription *ChildRefines(CONST struct Instance *i, |

180 | unsigned long n); |

181 | /**< |

182 | * Returns the type of the n'th child of i as determined at parse time. |

183 | * The nth child of the instance i doesn't need to exist yet. (may be null) |

184 | * The nth child of the instance will be of at least this type if the |

185 | * child is not an array. |

186 | * If the child is an array, the type returned here |

187 | * will be the type of the array elements as determined at parse time. |

188 | * This function may return NULL -- this merely means that at parse |

189 | * time we couldn't quite untwist the naming to determine a type.<br><br> |

190 | * |

191 | * Warning: Unselected parts will yield instances of type DUMMYINST |

192 | * instead of whatever type this returns. |

193 | */ |

194 | |

195 | extern unsigned long ChildSearch(CONST struct Instance *i, |

196 | CONST struct InstanceName *name); |

197 | /**< |

198 | * This procedure will search instance i for a child that matches "name". |

199 | * It it is unsuccessful, it will return 0; otherwise, it will return the |

200 | * index of the child that matches. It is assumed that all children have |

201 | * unique names and that there is no need to worry about more than one child |

202 | * matching "name". This can be called on childless instance without |

203 | * error. The strings in the InstanceName must come from the symbol table. |

204 | */ |

205 | |

206 | ASC_DLLSPEC(struct Instance*) ChildByChar(CONST struct Instance *i, |

207 | symchar *str); |

208 | /**< |

209 | * This returns to the pointer to a child, c, of parent,p, named by str. |

210 | * str must be a simple name. If child not found, returns NULL. |

211 | * str must be from the symbol table. If AscFindSymbol(str)==NULL, |

212 | * then this function should not be called because NO instance |

213 | * can have a child with a name which is not in the symbol table. |

214 | */ |

215 | |

216 | /* |

217 | * extern unsigned long ChildSearchRegExp(); NOT IMPLEMENTED. |

218 | * unsigned long ChildSearchRegExp(i,name,start) |

219 | * struct Instance *i; |

220 | * char *name; |

221 | * unsigned long start; |

222 | * |

223 | * This is an unplanned extension to the initial implementation to add regular |

224 | * expression searches. The function will search from child number "start" |

225 | * to the first match. If no match is found, it will return 0; otherwise |

226 | * it will return the first match of the regular expression. Examples of |

227 | * regular expressions are: |

228 | * f* which means all strings starting with the letter f |

229 | * f? which means all two character long strings starting with |

230 | * f |

231 | */ |

232 | |

233 | extern unsigned long ChildIndex(CONST struct Instance *i, |

234 | CONST struct Instance *child); |

235 | /**< |

236 | * This procedure searches through the child list of instance i for child. |

237 | * If it does not find a match, it returns 0; otherwise, it will return |

238 | * the child number of "child". |

239 | */ |

240 | |

241 | extern void StoreChildPtr(struct Instance *i, |

242 | unsigned long n, |

243 | struct Instance *child); |

244 | /**< |

245 | * Store the child pointer "child" in position n of i. This only creates |

246 | * the link from i to child, and not the back link which is created by |

247 | * add parent. Instance "i" cannot be a fundamental atom; atoms are |

248 | * created in a special way. |

249 | */ |

250 | |

251 | #endif /* ASC_PARENTCHILD_H */ |

john.pye@anu.edu.au | ViewVC Help |

Powered by ViewVC 1.1.22 |