/[ascend]/trunk/ascend/compiler/link.h
ViewVC logotype

Contents of /trunk/ascend/compiler/link.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2642 - (show annotations) (download) (as text)
Tue Oct 2 09:31:20 2012 UTC (5 years, 8 months ago) by jpye
File MIME type: text/x-chdr
File size: 9931 byte(s)
separate bug 567 and 564, avoid a name clash, eliminate duplicate FindInsts (Dante Stroe?)
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//** @file
20 Link table methods. GSOC project by Dante Stroe.
21 *//*
22 by Dante Stroe
23 Created: 07/07/2009
24 */
25
26
27 #include <ascend/general/platform.h>
28 #include <ascend/general/list.h>
29 #include "slist.h"
30 #include "statement.h"
31 #include "stattypes.h"
32 #include "instance_enum.h"
33 #include "find.h"
34 #include <stdio.h>
35
36 /**
37 Entry in the Link table (which is in fact a list) associated with each
38 model TypeDescription and/or model Instance
39 */
40 struct link_entry_t {
41 enum LinkKind link_type;
42 union {
43 struct Statement * statptr; /**< Pointer to the declarative statement */
44 struct VariableList * vl;
45 } u;
46 struct gl_list_t *instances_cache; /**< (cache) pointer to the list of instances that are linked*/
47 symchar* key_cache; /**< key that defines the linked instances */
48 unsigned int length; /**< Number of instances in the linked_instances list. */
49 unsigned long capacity; /**< Capacity of the link entry, in terms of the number of the instances that can be linked. */
50 unsigned int flags; /**< Status flags.used to differentiate between LINK statements
51 in the declarative part(FIXED) and the ones in the methods (not fied). */
52
53 };
54
55 extern struct gl_list_t *getLinkTypes (struct Instance *model, int recursive);
56 /**<
57 @param model - the scope Instance of the LINK (should be a model)
58 @param recursive - the child instances of the scope Instance are also scanned for LINK types
59
60 @return a gl_list with symchars that represent all the distinct LINK keys in the link_table(s)
61 */
62
63 extern struct gl_list_t *getLinks (struct Instance *model, symchar *key, int recursive);
64 /**<
65 @param model - the scope Instance of the LINK (should be a model)
66 @param key - pointer to the symchar of the key we are looking for in all the LINKs
67 @param recursive - the child instances of the scope Instance are also scanned for the given LINK key
68
69 @return a gl_list with link entries (link_entry_t *) that hold all the LINKs that have the the given LINK key
70 */
71
72 extern struct gl_list_t *getLinksReferencing (struct Instance *model, symchar* key, struct Instance *targetInstance, int recursive);
73 /**<
74 @param model the scope Instance of the LINKs (should be a model)
75 @param key pointer to the symchar of the key we are looking for in all the LINKs
76 @param targetInstance pointer to the instance we looking for inside the
77 variable lists of the LINK tables
78 @param recursive the child instances of the scope Instance are also
79 scanned for the given LINK key and target instance
80
81 @return a gl_list with link entries (link_entry_t *) that hold all the LINKs
82 that have the the given LINK key and the target instance
83 */
84
85 extern void addLinkEntry(struct Instance *model, symchar *key, struct gl_list_t *instances,struct Statement *stat, unsigned int declarative);
86 /**<
87 @param model the scope Instance of the LINK (should be a model)
88 @param key pointer to the symchar of the key we are adding to the LINK table
89 @param instances pointer to the list of instances that are "LINK-ed" by "key"
90 @param stat pointer to the Statement object that was executed for this LINK
91 @param declarative 1 if the statement was in the declarative part of the model
92 0 if in the Methods (decides whether the LINK entry is added to
93 the TypeDescription LINK table or to the ModelInstance one.
94 @return void (probably should return 1 in case of success and 0 otherwise)
95
96 Called by the LINK statements, both in the declarative and non-declarative part;
97 */
98
99
100 extern void removeLinkEntry(struct Instance *model, symchar *key, struct VariableList *vlist);
101 /**<
102 @param model the scope Instance of the LINK (should be a model)
103 @param key pointer to the symchar of the key we are removing from the LINK table
104 @param vlist variable list that hold the names of the instances that should be unlinked
105
106 @return void (probably should return 1 in case of success and 0 otherwise)
107
108 Called by the UNLINK statement in the non-declarative part (METHODS). Current
109 implementation requires that the UNLINK paramters in the statements should
110 match the parameters of a previous LINK statement in the non-declarative part.
111 */
112
113 extern void ignoreDeclLinkEntry(struct Instance *model, symchar *key, struct VariableList *vlist);
114 /**<
115 @param model the scope Instance of the LINK (should be a model)
116 @param key pointer to the symchar of the key we are removing from the LINK table
117 @param vlist variable list that hold the names of the instances that should be unlinked
118
119 @return void (probably should return 1 in case of success and 0 otherwise)
120
121 Called by the executeLNK function, when the key in a declarative LINK statement
122 is 'ignore', and is used to ignore the link entry
123 */
124
125
126 extern void removeNondeclarativeLinkEntry(struct Instance *model, symchar *key, int recursive);
127 /**<
128 @param model the scope Instance of the LINKs (should be a model)
129 @param key pointer to the symchar of the key we are removing from the LINK table
130 @param recursive the child instances of the scope Instance are also scanned
131 for the given LINK key (if key is null all are removed)
132 @return void (probably should return 1 in case of success and 0 otherwise)
133 */
134
135
136 extern CONST struct gl_list_t *getLinkInstances(struct Instance *model, struct link_entry_t *link_entry, int status);
137 /**<
138 @param model the scope Instance of the LINK (should be a model)
139 @param link_entry pointer to a link_entry in some link_table
140 @param status Find status of the instances in the LINK (TODO not yet impl)
141
142 @return gl_list with all the instances that are LINK-ed by the given LINK entry
143 */
144
145
146 extern CONST struct gl_list_t *getLinkInstancesFlat(struct Instance *model, struct link_entry_t *link_entry, int status);
147 /**<
148 @param model the scope Instance of the LINK (should be a model)
149 @param link_entry pointer to a link_entry in some link_table
150 @param status Find status of the instances in the LINK (TODO not yet impl)
151
152 @return gl_list with all the instances that are LINK-ed by the given LINK entry
153 */
154
155
156 extern struct gl_list_t *getLinkTableDeclarative(struct Instance *model);
157 /**<
158 @param model the scope Instance of the LINK (should be a model)
159
160 @return gl_list with all the LINK entries that are declarative for the given model
161 */
162
163
164 extern struct gl_list_t *getLinkTableProcedural(struct Instance *model);
165 /**<
166 @param model the scope Instance of the LINK (should be a model)
167
168 @return gl_list with all the LINK entries that are non-declarative for the given model
169 */
170
171 extern int isDeclarative(struct Instance* model, struct link_entry_t *link_entry);
172 /**<
173 @param model the scope Instance of the LINK (should be a model)
174 @param link_entry pointer to a link_entry in some link_table
175
176 @return 1 if the LINK entry is declarative (part of the TypeDescription
177 LINK table), 0 if the LINK entry is non-declarative (part of the ModelInstance LINK table)
178 */
179
180 extern void clearLinkCache(struct Instance* model);
181 /**<
182 @param model the scope Instance of the LINK (should be a model)
183
184 empty instance search optimization.
185 */
186
187 extern void populateLinkCache(struct Instance* model);
188 /**<
189 @param model the scope Instance of the LINK (should be a model)
190
191 fill instance search optimization.
192 */
193
194 extern int getOdeId(struct Instance *model,struct Instance *inst);
195 /**<
196 @param model the scope Instance of the LINK (should be a model)
197 @param inst the instance of the variable we are interested to find its differntial state
198
199 @return the ID of the derivative chain the variable belongs to, if any
200
201 Note: If the variable is algebraic or an independent variable the return value is 0
202 The Ids are integers that are intilized with their position in the list of 'ode' LINKs for each derivative chain
203 */
204
205 extern int getOdeType(struct Instance *model,struct Instance *inst);
206 /**<
207 @param model - the scope Instance of the LINK (should be a model)
208 @param inst - the instance of the variable we are interested to find its differntial state
209
210 @return- The order of the variable in the derivative chain to which it belongs, if any:
211 -1 - the variable instance is an independent variable
212 0 - the variable instance is not part of any derivative chain
213 1 - the variable instance is a state variable
214 2 - the variable instance is a first order derivative
215 3 - the variable instance is a second order derivative
216 etc.
217
218 Note: The values are taken from the position of the variables in the LINK instance list:
219 LINK('ode',dx_dt,x,t),where the first instance are the differential and derivative
220 variables in decreasing order and the last instance is always the independent variable.
221 */
222
223 /**
224 DS: Function used to test the above implmented functions.
225 FIXME It will be removed eventually
226 */
227 void TestingRoutine(struct Instance* model);
228
229 /* NOT EXTERN: internal use only in libascend */
230 struct gl_list_t *FindInsts(
231 struct Instance *inst, const struct VariableList *list, enum find_errors *err
232 );
233

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