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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations) (download) (as text)
Sat Nov 13 16:45:56 2004 UTC (15 years, 2 months ago) by aw0a
File MIME type: text/x-csrc
File size: 4463 byte(s)
moving things to base/generic
1 aw0a 1 /*
2     * Ascend Instance External Vars Functions
3     * by Kirk Abbott
4     * 1995
5     * Version: $Revision: 1.7 $
6     * Version control file: $RCSfile: extinst.c,v $
7     * Date last modified: $Date: 1997/07/18 12:29:34 $
8     * Last modified by: $Author: mthomas $
9     *
10     * This file is part of the Ascend Language Interpreter.
11     *
12     * Copyright (C) 1995 Kirk Andre' Abbott
13     *
14     * The Ascend Language Interpreter is free software; you can redistribute
15     * it and/or modify it under the terms of the GNU General Public License as
16     * published by the Free Software Foundation; either version 2 of the
17     * License, or (at your option) any later version.
18     *
19     * The Ascend Language Interpreter is distributed in hope that it will be
20     * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22     * General Public License for more details.
23     *
24     * You should have received a copy of the GNU General Public License
25     * along with the program; if not, write to the Free Software Foundation,
26     * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27     * COPYING.
28     *
29     */
30     #include <stdarg.h>
31     #include "utilities/ascConfig.h"
32     #include "compiler/compiler.h"
33     #include "utilities/ascPanic.h"
34     #include "utilities/ascMalloc.h"
35     #include "general/list.h"
36     #include "compiler/instance_enum.h"
37     #include "compiler/fractions.h"
38     #include "compiler/dimen.h"
39     #include "compiler/functype.h"
40     #include "compiler/types.h"
41     #include "compiler/instquery.h"
42     #include "compiler/instance_types.h"
43     #include "compiler/instmacro.h"
44     #include "compiler/cmpfunc.h"
45     #include "compiler/extinst.h"
46    
47     #ifndef lint
48     static CONST char ExtInstModuleID[] = "$Id: extinst.c,v 1.7 1997/07/18 12:29:34 mthomas Exp $";
49     #endif
50    
51     /*********************************************************************\
52     External Relations Table
53     \*********************************************************************/
54    
55     struct Instance **g_ExtVariablesTable = NULL;
56    
57     static
58     void InitExtVariablesTable(void)
59     {
60     int c;
61     if (g_ExtVariablesTable==NULL) {
62     g_ExtVariablesTable = (struct Instance **)
63     ascmalloc(MAX_EXTRELATIONS*sizeof(struct Instance *));
64     for (c=0;c<MAX_EXTRELATIONS;c++) {
65     g_ExtVariablesTable[c] = NULL;
66     }
67     }
68     }
69    
70     static
71     struct gl_list_t *LookupVarInTable(struct Instance *inst)
72     {
73     int c;
74     struct Instance **hndl = g_ExtVariablesTable;
75     struct gl_list_t *hndl_list = NULL;
76     if (!inst)
77     return NULL;
78     if (g_ExtVariablesTable) {
79     hndl_list = gl_create(7L);
80     for(c=0;c<MAX_EXTRELATIONS;c++) {
81     if (hndl[c] == NULL) {
82     break;
83     }
84     if (hndl[c] == inst) {
85     gl_append_ptr(hndl_list,(VOIDPTR)&hndl[c]);
86     }
87     }
88     if (gl_length(hndl_list))
89     return hndl_list;
90     else{
91     gl_destroy(hndl_list);
92     return NULL;
93     }
94     }
95     return NULL;
96     }
97    
98     struct Instance **AddVarToTable(struct Instance *inst, int *added)
99     {
100     struct Instance **hndl;
101     int c=0;
102    
103     assert(inst!=NULL);
104     *added = 0;
105     if (g_ExtVariablesTable==NULL) {
106     InitExtVariablesTable();
107     hndl = g_ExtVariablesTable;
108     *hndl = inst;
109     *added = 1;
110     return (&hndl[0]);
111     }
112     hndl = g_ExtVariablesTable;
113     while (c<MAX_EXTRELATIONS) {
114     if (hndl[c]==inst) {
115     *added = 0;
116     return &hndl[c];
117     }
118     if (hndl[c]==NULL) { /* store in the first NULL position */
119     *added = 1;
120     hndl[c] = inst;
121     return &hndl[c];
122     }
123     c++;
124     }
125     Asc_Panic(2, NULL,
126     "MAX_EXTRELATIONS internal limit has just been exceeded.\n"
127     "Please report failure in AddVarToTable to :\n"
128     "%s\n", ASC_BIG_BUGMAIL);
129     exit(2);/* Needed to keep gcc from whining */
130     }
131    
132     /*
133     * This will be called only for models.
134     */
135     void FixExternalVars(struct Instance *old,struct Instance *new)
136     {
137     struct Instance **hndl;
138     struct gl_list_t *exists;
139     unsigned long len,c;
140     if (g_ExtVariablesTable==NULL)
141     return;
142     if (old==new)
143     return;
144     if ((old==NULL) || (new==NULL)) {
145     Asc_Panic(2, NULL,
146     "Internal error in FixExternalVars\n"
147     "Cannot handle NULL instances... exiting.\n");
148     }
149     exists = LookupVarInTable(old);
150     if (exists) {
151     len = gl_length(exists);
152     for (c=1;c<=len;c++) {
153     hndl = (struct Instance **)gl_fetch(exists,c);
154     *hndl = new;
155     }
156     gl_destroy(exists);
157     return;
158     }
159     return;
160     }
161    
162     void SetSimulationExtVars(struct Instance *i,struct Instance **extvars)
163     {
164     assert (i&&InstanceKind(i)==SIM_INST);
165     SIM_INST(i)->extvars = extvars;
166     }
167    
168    

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