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

Annotation of /trunk/ascend/compiler/when.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2318 - (hide annotations) (download) (as text)
Tue Dec 14 06:27:47 2010 UTC (11 years, 8 months ago) by jpye
File MIME type: text/x-csrc
File size: 3966 byte(s)
removing some unneeded #includes of 'slist.h'.
1 aw0a 1 /*
2     * WHEN List Implementation
3     * by Vicente Rico-Ramirez
4     * 7/96
5     * Version: $Revision: 1.11 $
6     * Version control file: $RCSfile: when.c,v $
7     * Date last modified: $Date: 1997/07/29 15:52:56 $
8     * Last modified by: $Author: rv2a $
9     *
10     * This file is part of the Ascend Language Interpreter.
11     *
12     * Copyright (C) 1996 Vicente Rico-Ramirez
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 along
25     * with the program; if not, write to the Free Software Foundation, Inc., 675
26     * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
27     */
28 jpye 2318 #include <stdio.h>
29     #include <assert.h>
30    
31 jpye 2018 #include <ascend/utilities/ascConfig.h>
32     #include <ascend/utilities/ascMalloc.h>
33 johnpye 1211
34 johnpye 399 #include "functype.h"
35 johnpye 669 #include "expr_types.h"
36 johnpye 399 #include "stattypes.h"
37     #include "sets.h"
38     #include "exprs.h"
39     #include "slist.h"
40     #include "vlist.h"
41     #include "when.h"
42 aw0a 1
43 johnpye 709 #define WMALLOC(x) x = ASC_NEW(struct WhenList)
44 aw0a 1
45     #ifndef lint
46     static CONST char WhenRCSid[] = "$Id: when.c,v 1.11 1997/07/29 15:52:56 rv2a Exp $";
47     #endif
48    
49    
50     #ifdef THIS_IS_AN_UNUSED_FUNCTION
51     static
52     int SetNodeIsTrue(struct Set *s)
53     {
54     CONST struct Expr *e;
55     assert(s && (SetType(s)==0));
56     e = GetSingleExpr(s);
57     assert(e && (ExprType(e)==e_boolean) && (NextExpr(e)==NULL));
58     return ExprBValue(e);
59     }
60     #endif /* THIS_IS_AN_UNUSED_FUNCTION */
61    
62    
63     struct WhenList *CreateWhen(struct Set *set, struct StatementList *sl)
64     {
65     register struct WhenList *result;
66     WMALLOC(result);
67     result->slist = sl;
68     result->values =set;
69     result->next = NULL;
70     return result;
71     }
72    
73     struct WhenList *ReverseWhenCases(struct WhenList *w)
74     {
75     register struct WhenList *next,*previous=NULL;
76     if (w==NULL) return w;
77     while (1) { /* loop until broken */
78     next = w->next;
79     w->next = previous;
80     if (next==NULL) return w;
81     previous = w;
82     w = next;
83     }
84     }
85    
86     struct WhenList *LinkWhenCases(struct WhenList *w1, struct WhenList *w2)
87     {
88     register struct WhenList *p;
89     p = w1;
90     while (p->next!=NULL) p = p->next;
91     p->next = w2;
92     return w1;
93     }
94    
95     struct WhenList *NextWhenCaseF(struct WhenList *w)
96     {
97     assert(w!=NULL);
98     return w->next;
99     }
100    
101     struct Set *WhenSetListF(struct WhenList *w)
102     {
103     assert(w!=NULL);
104     return w->values;
105     }
106    
107    
108     struct StatementList *WhenStatementListF(struct WhenList *w)
109     {
110     assert(w!=NULL);
111     return w->slist;
112     }
113    
114     void DestroyWhenNode(struct WhenList *w)
115     {
116     register struct Set *set;
117     if (w!=NULL){
118     set = w->values;
119     if (w->values) {
120     if (set->next == NULL) {
121     DestroySetNodeByReference(w->values);
122     }
123     else {
124     DestroySetListByReference(w->values);
125     }
126     }
127     DestroyStatementList(w->slist);
128     w->next = NULL;
129     ascfree((char *)w);
130     }
131     }
132    
133     void DestroyWhenList(struct WhenList *w)
134     {
135     register struct WhenList *next;
136     while (w!=NULL){
137     next = NextWhenCase(w);
138     DestroyWhenNode(w);
139     w = next;
140     }
141     }
142    
143     struct WhenList *CopyWhenNode(struct WhenList *w)
144     {
145     register struct WhenList *result;
146     assert(w!=NULL);
147     WMALLOC(result);
148     if (w->values) result->values = CopySetByReference(w->values);
149     else result->values = w->values;
150     result->slist = CopyListToModify(w->slist);
151     result->next = NULL;
152     return result;
153     }
154    
155     struct WhenList *CopyWhenList(struct WhenList *w)
156     {
157     register struct WhenList *head=NULL,*p;
158     if (w!=NULL) {
159     p = head = CopyWhenNode(w);
160     w = w->next;
161     while(w!=NULL){
162     p->next = CopyWhenNode(w);
163     p = p->next;
164     w = w->next;
165     }
166     }
167     return head;
168     }
169    
170    
171    
172    
173    
174    
175    
176    
177    

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