| 1 |
/* |
| 2 |
* ascFreeAllVars.c |
| 3 |
* by Ben Allan |
| 4 |
* February 24, 1998 |
| 5 |
* Part of ASCEND |
| 6 |
* Version: $Revision: 1.4 $ |
| 7 |
* Version control file: $RCSfile: ascFreeAllVars.c,v $ |
| 8 |
* Date last modified: $Date: 1998/06/16 16:42:09 $ |
| 9 |
* Last modified by: $Author: mthomas $ |
| 10 |
* |
| 11 |
* This file is part of the Ascend Language Interpreter. |
| 12 |
* |
| 13 |
* Copyright (C) 1998 Carnegie Mellon University |
| 14 |
* |
| 15 |
* The Ascend Language Interpreter is free software; you can |
| 16 |
* redistribute it and/or modify it under the terms of the GNU |
| 17 |
* General Public License as published by the Free Software |
| 18 |
* Foundation; either version 2 of the License, or (at your option) |
| 19 |
* any later version. |
| 20 |
* |
| 21 |
* The Ascend Language Interpreter is distributed in hope that it |
| 22 |
* will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 23 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 24 |
* See the GNU General Public License for more details. |
| 25 |
* |
| 26 |
* You should have received a copy of the GNU General Public License |
| 27 |
* along with the program; if not, write to the Free Software |
| 28 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check |
| 29 |
* the file named COPYING. |
| 30 |
*/ |
| 31 |
|
| 32 |
#include <utilities/ascConfig.h> |
| 33 |
#include <utilities/ascPrint.h> |
| 34 |
#include <general/list.h> |
| 35 |
#include <compiler/compiler.h> |
| 36 |
#include <compiler/fractions.h> |
| 37 |
#include <compiler/dimen.h> |
| 38 |
#include <compiler/child.h> |
| 39 |
#include <compiler/type_desc.h> |
| 40 |
#include <compiler/symtab.h> |
| 41 |
#include <compiler/instance_enum.h> |
| 42 |
#include <compiler/instquery.h> |
| 43 |
#include <compiler/atomvalue.h> |
| 44 |
#include <compiler/visitinst.h> |
| 45 |
#include <compiler/extfunc.h> |
| 46 |
#include <compiler/parentchild.h> |
| 47 |
#include <compiler/library.h> |
| 48 |
#include <packages/ascFreeAllVars.h> |
| 49 |
|
| 50 |
|
| 51 |
/* |
| 52 |
* The following functions give an alternative |
| 53 |
* to the recursive clear procedure found in most |
| 54 |
* models. |
| 55 |
*/ |
| 56 |
|
| 57 |
struct cvpacket { |
| 58 |
struct TypeDescription *g_solver_var_type; |
| 59 |
symchar *fixed; |
| 60 |
}; |
| 61 |
|
| 62 |
static |
| 63 |
void Asc_ClearVars(struct Instance *i, struct cvpacket *cv) |
| 64 |
{ |
| 65 |
struct Instance *c; |
| 66 |
struct TypeDescription *type; |
| 67 |
|
| 68 |
type = InstanceTypeDesc(i); |
| 69 |
if ( GetBaseType(type) == real_type && |
| 70 |
type == MoreRefined(type,cv->g_solver_var_type) ) { |
| 71 |
c = ChildByChar(i,cv->fixed); |
| 72 |
if (c != NULL && InstanceKind(c)==BOOLEAN_INST) { |
| 73 |
SetBooleanAtomValue(c,FALSE,0); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
int Asc_ClearVarsInTree(struct Instance *i){ |
| 80 |
struct cvpacket cv; |
| 81 |
cv.g_solver_var_type = FindType(AddSymbol("solver_var")); |
| 82 |
if (cv.g_solver_var_type == NULL){ |
| 83 |
ERROR_REPORTER_HERE(ASC_PROG_ERROR,"CV.G_SOLVER_VAR_TYPE IS NULL"); |
| 84 |
return 1; |
| 85 |
}/*else{ |
| 86 |
ERROR_REPORTER_DEBUG("solver_var was found :)\n"); |
| 87 |
}*/ |
| 88 |
|
| 89 |
if (i==NULL){ |
| 90 |
ERROR_REPORTER_HERE(ASC_PROG_ERROR,"INSTANCE IS NULL"); |
| 91 |
return 1; |
| 92 |
} |
| 93 |
cv.fixed = AddSymbol("fixed"); |
| 94 |
VisitInstanceTreeTwo(i,(VisitTwoProc)Asc_ClearVars, 0, 0, &cv); |
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
int Asc_FreeAllVars( struct Instance *root, struct gl_list_t *arglist){ |
| 99 |
/* arglist is a list of gllist of instances */ |
| 100 |
if (arglist == NULL || |
| 101 |
gl_length(arglist) == 0L || |
| 102 |
gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 || |
| 103 |
gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) { |
| 104 |
/*ERROR_REPORTER_HERE(ASC_PROG_NOTE,"About to call ClearVarsInTree(root)");*/ |
| 105 |
return Asc_ClearVarsInTree(root); |
| 106 |
} else { |
| 107 |
/*ERROR_REPORTER_HERE(ASC_PROG_NOTE,"About to call ClearVarsInTree(arglist[1][1])\n");*/ |
| 108 |
return Asc_ClearVarsInTree((struct Instance *)gl_fetch( |
| 109 |
(struct gl_list_t *)gl_fetch(arglist,1),1)); |
| 110 |
} |
| 111 |
} |