/[ascend]/trunk/ascend/compiler/universal.c
ViewVC logotype

Contents of /trunk/ascend/compiler/universal.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2332 - (show annotations) (download) (as text)
Fri Dec 24 00:29:41 2010 UTC (9 years, 6 months ago) by jpye
File MIME type: text/x-csrc
File size: 4662 byte(s)
Cleaning lint from some compiler/*.c files, removing debug output from bintoken.c.
Working to debug strange results from command "ASCENDLIBRARY=~/ascend/models LD_LIBRARY_PATH=~/ascend test/test compiler_basics.init compiler_basics.parse_string_module compiler_basics.instantiate_string".
1 /*
2 * Universal Routines
3 * by Tom Epperly
4 * Created: 3/27/1990
5 * Version: $Revision: 1.7 $
6 * Version control file: $RCSfile: universal.c,v $
7 * Date last modified: $Date: 1997/07/18 12:36:19 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
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
31 #include <ascend/general/platform.h>
32
33 #include <ascend/general/panic.h>
34 #include <ascend/general/ascMalloc.h>
35 #include <ascend/general/list.h>
36
37
38 #include "expr_types.h"
39 #include "stattypes.h"
40 #include "child.h"
41 #include "type_desc.h"
42 #include "universal.h"
43
44
45 struct universal_rec {
46 struct TypeDescription *desc;
47 struct Instance *inst;
48 };
49
50 #define UNIVERSAL_TABLE_SIZE 15
51 struct UniversalTable *GlobalUniversalTable=NULL;
52
53 struct UniversalTable *CreateUniversalTable(void)
54 {
55 return gl_create(UNIVERSAL_TABLE_SIZE);
56 }
57
58
59 #ifdef THIS_IS_AN_UNUSED_FUNCTION
60 static
61 struct UniversalTable *MergeUniversalTable(struct gl_list_t *table1,
62 struct gl_list_t *table2)
63 {
64 (void)table1; /* stop gcc whine about unused varaible */
65 (void)table2; /* stop gcc whine about unused varaible */
66 return NULL;
67 }
68 #endif /* THIS_IS_AN_UNUSED_FUNCTION */
69
70
71 void DestroyUniversalTable(struct gl_list_t *table)
72 {
73 if (table) {
74 gl_free_and_destroy(table);
75 }
76 }
77
78 void SetUniversalTable(struct gl_list_t *table)
79 {
80 GlobalUniversalTable = table;
81 }
82
83 struct UniversalTable *GetUniversalTable(void)
84 {
85 return GlobalUniversalTable;
86 }
87
88 struct Instance *LookupInstance(struct gl_list_t *table,
89 struct TypeDescription *desc)
90 {
91 register unsigned long c;
92 register struct universal_rec *ptr;
93 if (table){
94 for(c=gl_length(table);c>=1;--c){
95 ptr = (struct universal_rec *)gl_fetch(table,c);
96 AssertAllocatedMemory(ptr,sizeof(struct universal_rec));
97 if (ptr->desc == desc) return ptr->inst;
98 }
99 }
100 return NULL;
101 }
102
103 void AddUniversalInstance(struct gl_list_t *table,
104 struct TypeDescription *desc,
105 struct Instance *inst)
106 {
107 struct universal_rec *ptr;
108 if (table){
109 ptr = (struct universal_rec *)ascmalloc(sizeof(struct universal_rec));
110 AssertAllocatedMemory(ptr,sizeof(struct universal_rec));
111 ptr->desc = desc;
112 ptr->inst = inst;
113 gl_append_ptr(table,(char *)ptr);
114 }
115 }
116
117 void RemoveUniversalInstance(struct gl_list_t *table, struct Instance *inst)
118 {
119 register unsigned long c;
120 register struct universal_rec *ptr;
121 if (table){
122 for(c=gl_length(table);c>=1;--c){
123 ptr = (struct universal_rec *)gl_fetch(table,c);
124 AssertAllocatedMemory(ptr,sizeof(struct universal_rec));
125 if (ptr->inst == inst){
126 gl_delete(table,c,1);
127 return;
128 }
129 }
130 }
131 }
132
133 void ChangeUniversalInstance(struct gl_list_t *table,
134 struct Instance *oldinst,
135 struct Instance *newinst)
136 {
137 register unsigned long c;
138 register struct universal_rec *ptr;
139 if (table){
140 for(c=gl_length(table);c>=1;--c){
141 ptr = (struct universal_rec *)gl_fetch(table,c);
142 AssertAllocatedMemory(ptr,sizeof(struct universal_rec));
143 if (ptr->inst == oldinst) {
144 ptr->inst = newinst;
145 }
146 }
147 }
148 }
149
150 unsigned long NumberTypes(struct gl_list_t *table)
151 {
152 if (table) {
153 return gl_length(table);
154 } else {
155 return 0;
156 }
157 }
158
159 struct Instance *GetInstance(struct gl_list_t *table, unsigned long int pos)
160 {
161 register struct universal_rec *ptr;
162 if (table){
163 ptr = (struct universal_rec *)gl_fetch(table,pos);
164 AssertAllocatedMemory(ptr,sizeof(struct universal_rec));
165 return ptr->inst;
166 } else {
167 return NULL;
168 }
169 }
170
171 struct TypeDescription *GetTypeDescription(struct gl_list_t *table,
172 unsigned long int pos)
173 {
174 register struct universal_rec *ptr;
175 if (table){
176 ptr = (struct universal_rec *)gl_fetch(table,pos);
177 AssertAllocatedMemory(ptr,sizeof(struct universal_rec));
178 return ptr->desc;
179 } else {
180 return NULL;
181 }
182 }

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