/[ascend]/trunk/base/generic/compiler/extinst.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/extinst.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 709 - (show annotations) (download) (as text)
Wed Jun 28 16:28:57 2006 UTC (13 years, 9 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3556 byte(s)
Monster commit!
Lots of recommenting and reorganising of external relations-related stuff.
Replaced a lot of ascmalloc and asccalloc calls with the new ASC_NEW* macros.
Fixed (?) the problem Art is having with icons in PyGTK.
Turned on -Wall in SConstruct and fixed up a stack of warnings.
Removed the redundant exit(2) from after Asc_Panic calls and added __attribute__((noreturn)).
Set doxygen to create callgraphs to level 2, updated doxyfile to version 1.4.7.
Fixed up building of extfntest.c.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3 Copyright (C) 1995 Kirk Andre Abbott
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 *//*
20 Ascend Instance External Vars Functions
21 by Kirk Abbott
22 Last in CVS $Revision: 1.7 $ $Date: 1997/07/18 12:29:34 $ $Author: mthomas $
23 */
24
25 #include <stdarg.h>
26 #include <utilities/ascConfig.h>
27 #include "compiler.h"
28 #include <utilities/ascPanic.h>
29 #include <utilities/ascMalloc.h>
30 #include <general/list.h>
31 #include "instance_enum.h"
32 #include "fractions.h"
33 #include "dimen.h"
34 #include "functype.h"
35 #include "expr_types.h"
36 #include "instquery.h"
37 #include "instance_types.h"
38 #include "instmacro.h"
39 #include "cmpfunc.h"
40 #include "extinst.h"
41
42 struct Instance **g_ExtVariablesTable = NULL;
43
44 static
45 void InitExtVariablesTable(void)
46 {
47 int c;
48 if (g_ExtVariablesTable==NULL) {
49 g_ExtVariablesTable = ASC_NEW_ARRAY(struct Instance *,MAX_EXTRELATIONS);
50 for (c=0;c<MAX_EXTRELATIONS;c++) {
51 g_ExtVariablesTable[c] = NULL;
52 }
53 }
54 }
55
56 static
57 struct gl_list_t *LookupVarInTable(struct Instance *inst)
58 {
59 int c;
60 struct Instance **hndl = g_ExtVariablesTable;
61 struct gl_list_t *hndl_list = NULL;
62 if (!inst)
63 return NULL;
64 if (g_ExtVariablesTable) {
65 hndl_list = gl_create(7L);
66 for(c=0;c<MAX_EXTRELATIONS;c++) {
67 if (hndl[c] == NULL) {
68 break;
69 }
70 if (hndl[c] == inst) {
71 gl_append_ptr(hndl_list,(VOIDPTR)&hndl[c]);
72 }
73 }
74 if (gl_length(hndl_list))
75 return hndl_list;
76 else{
77 gl_destroy(hndl_list);
78 return NULL;
79 }
80 }
81 return NULL;
82 }
83
84 struct Instance **AddVarToTable(struct Instance *inst, int *added)
85 {
86 struct Instance **hndl;
87 int c=0;
88
89 assert(inst!=NULL);
90 *added = 0;
91 if (g_ExtVariablesTable==NULL) {
92 InitExtVariablesTable();
93 hndl = g_ExtVariablesTable;
94 *hndl = inst;
95 *added = 1;
96 return (&hndl[0]);
97 }
98 hndl = g_ExtVariablesTable;
99 while (c<MAX_EXTRELATIONS) {
100 if (hndl[c]==inst) {
101 *added = 0;
102 return &hndl[c];
103 }
104 if (hndl[c]==NULL) { /* store in the first NULL position */
105 *added = 1;
106 hndl[c] = inst;
107 return &hndl[c];
108 }
109 c++;
110 }
111 Asc_Panic(2, __FUNCTION__, "MAX_EXTRELATIONS limit exceeded.");
112
113 }
114
115
116 void FixExternalVars(struct Instance *old,struct Instance *new){
117 struct Instance **hndl;
118 struct gl_list_t *exists;
119 unsigned long len,c;
120 if (g_ExtVariablesTable==NULL)
121 return;
122 if (old==new)
123 return;
124 if ((old==NULL) || (new==NULL)) {
125 Asc_Panic(2, __FUNCTION__,"Cannot handle NULL instances.");
126 }
127 exists = LookupVarInTable(old);
128 if (exists) {
129 len = gl_length(exists);
130 for (c=1;c<=len;c++) {
131 hndl = (struct Instance **)gl_fetch(exists,c);
132 *hndl = new;
133 }
134 gl_destroy(exists);
135 return;
136 }
137 return;
138 }
139
140 void SetSimulationExtVars(struct Instance *i,struct Instance **extvars)
141 {
142 assert (i&&InstanceKind(i)==SIM_INST);
143 SIM_INST(i)->extvars = extvars;
144 }
145

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