variables.c File Reference

#include <stdlib.h>
#include "intersci-n.h"
#include <varargs.h>

Include dependency graph for variables.c:

Go to the source code of this file.

Data Structures

struct  btype
struct  ftype

Defines

#define ISNONSTACK(var)
#define FORNAME   128

Functions

int ShowVariables ()
int FixStackPositions ()
IVAR GetVar (char *name, int p)
IVAR GetExistVar (char *name)
int CreatePredefVar (char *name)
IVAR GetOutVar (char *name)
IVAR GetExistOutVar ()
IVAR CheckOutVar ()
void AddForName (IVAR ivar, char *name, char *cname, IVAR ivar1)
void AddForName1 (IVAR ivar, char *name, char *cname, IVAR ivar1)
void ForNameClean ()
void ChangeForName2 (va_alist)
void ChangeForName1 (VARPTR var, char *name)
int GetBasType (char *sname)
char * SGetSciType (int type)
int GetForType (char *type)
char * SGetForType (int type)
char * SGetForTypeAbrev (VARPTR var)
int SGetForDec (int type)
char * SGetCDec (int type)
char * SGetForTypeStack (VARPTR var)
char * SGetForTypeBConvert (VARPTR var)
char * SGetExtForTypeAbrev (VARPTR var)
char * SGetExtForTypeStack (VARPTR var)

Variables

static struct btype SType []
static struct ftype FType []


Define Documentation

#define FORNAME   128

Definition at line 382 of file variables.c.

Referenced by ChangeForName2().

#define ISNONSTACK ( var   ) 

Value:

( (var)->for_type == EXTERNAL \
   || ( (var)->for_type == CSTRINGV && (var)->is_sciarg == 0  && (var)->list_el == 0 ))

Definition at line 68 of file variables.c.

Referenced by FixStackPositions().


Function Documentation

void AddForName ( IVAR  ivar,
char*  name,
char*  cname,
IVAR  ivar1 
)

Definition at line 288 of file variables.c.

References l, malloc(), MAXARG, NULL, var, and variables.

00293 {
00294   VARPTR var;
00295   int l;
00296   var = variables[ivar-1];
00297   l = var->nfor_name;
00298   if (l == MAXARG) {
00299     printf("too many \"for_name\" for variable \"%s\"\n",var->name);
00300     printf("  augment constant \"MAXARG\" and recompile intersci\n");
00301     exit(1);
00302   }
00303   var->for_name[l] = (char *)malloc((unsigned)(strlen(name) + 1));
00304   if ( cname != NULL) 
00305     {
00306       var->C_name[l] = (char *)malloc((unsigned)(strlen(cname) + 1));
00307       strcpy(var->C_name[l],cname);
00308     }
00309   else 
00310     var->C_name[l] = NULL;
00311   var->for_name_orig[l] = ivar1;
00312   strcpy(var->for_name[l],name);
00313   var->nfor_name = l + 1;
00314 }

Here is the call graph for this function:

void AddForName1 ( IVAR  ivar,
char*  name,
char*  cname,
IVAR  ivar1 
)

Definition at line 323 of file variables.c.

References l, malloc(), MAXARG, NULL, pass, var, and variables.

00328 {
00329   VARPTR var;
00330   int l;
00331   var = variables[ivar-1];
00332   l = var->nfor_name;
00333   if ( pass == 0 && var->kp_state == -1 ) 
00334     {
00335       var->kp_state = var->nfor_name ;
00336     }
00337   if (l == MAXARG) {
00338     printf("too many \"for_name\" for variable \"%s\"\n",var->name);
00339     printf("  augment constant \"MAXARG\" and recompile intersci\n");
00340     exit(1);
00341   }
00342   var->for_name[l] = (char *)malloc((unsigned)(strlen(name) + 1));
00343   if ( cname != NULL) 
00344     {
00345       var->C_name[l] = (char *)malloc((unsigned)(strlen(cname) + 1));
00346       strcpy(var->C_name[l],cname);
00347     }
00348 
00349   else 
00350     var->C_name[l] = NULL;
00351   var->for_name_orig[l] = ivar1;
00352   strcpy(var->for_name[l],name);
00353   var->nfor_name = l + 1;
00354 }

Here is the call graph for this function:

void ChangeForName1 ( VARPTR  var,
char*  name 
)

Definition at line 414 of file variables.c.

References i, l, and pos.

Referenced by ChangeForName2(), CreDIMFOREXT(), CreSTRINGMAT(), GetPOLYNOM(), and GetSTRINGMAT().

00417 {
00418   int l,pos=0;
00419   l = var->nfor_name;
00420   if ( l  != 0)
00421     { 
00422       int i;
00423       for ( i=0 ; i < l ; i++) 
00424         {
00425           if ( var->for_name_orig[i] == var->stack_position ) 
00426             { 
00427               pos = i ; break;
00428             }
00429         }
00430     }
00431   var->for_name[pos] = (char *)malloc((unsigned)(strlen(name) + 1));
00432   strcpy(var->for_name[pos],name);
00433   if ( pos != 0) 
00434     {
00435       int xx;
00436       char *loc = var->for_name[pos];
00437       var->for_name[pos] =       var->for_name[0];
00438       var->for_name[0] = loc;
00439       xx= var->for_name_orig[pos];
00440       var->for_name_orig[pos] =       var->for_name_orig[0];
00441       var->for_name_orig[0] = xx;
00442     }
00443   /* we keep the C name  var->C_name[0] = NULL; */
00445   if (l == 0) var->nfor_name = 1;
00446 }

Here is the caller graph for this function:

void ChangeForName2 ( va_alist   ) 

Definition at line 395 of file variables.c.

References ChangeForName1(), and FORNAME.

Referenced by CreCommon(), CreIMATRIX(), CrePOINTER(), CreSPARSE(), GetCom(), GetIMATRIX(), GetPOINTER(), GetSPARSE(), OptMATRIX(), and WriteOptArgPhase2().

00397 {
00398   char forbuf[FORNAME];
00399   va_list ap;
00400 #ifdef __STDC__ 
00401   va_start(ap,format);
00402 #else 
00403   char *format;
00404   VARPTR varptr;
00405   va_start(ap);
00406   varptr = va_arg(ap, VARPTR );
00407   format = va_arg(ap, char *);
00408 #endif
00409   vsprintf(forbuf,format,ap);
00410   ChangeForName1(varptr,forbuf);
00411   va_end(ap);
00412 }

Here is the call graph for this function:

Here is the caller graph for this function:

IVAR CheckOutVar (  ) 

Definition at line 261 of file variables.c.

References i, nVariable, str, and variables.

Referenced by WriteOutput().

00262 {
00263   int i;
00264   char str[4];
00265   strcpy(str,"out");
00266   for (i = 0; i < nVariable; i++) {
00267     if (strcmp(variables[i]->name,str) == 0)
00268       return(i+1);
00269   }
00270   return 0;
00271 }

Here is the caller graph for this function:

int CreatePredefVar ( char *  name  ) 

Definition at line 184 of file variables.c.

References GetVar(), num, PREDEF, var, and variables.

00186 {
00187   VARPTR var;
00188   if (strcmp(name,"err")  == 0 
00189       || strcmp(name,"rhs") == 0 
00190       || strcmp(name,"lhs") == 0 
00191       || strcmp(name,"fname") == 0)
00192     {
00193       int num ;
00194       num=GetVar(name,1);
00195       var = variables[num-1];
00196       var->for_type = PREDEF;
00197       return(num);
00198     }
00199   return(-1);
00200 }

Here is the call graph for this function:

int FixStackPositions (  ) 

Definition at line 71 of file variables.c.

References i, icre, ISNONSTACK, j, nVariable, var::stack_position, var, and variables.

Referenced by Generate().

00072 {
00073   int i;
00074   VARPTR var,var1;
00075   for (i = nVariable-1 ; i >= 0; i--) 
00076     {
00077       int j;
00078       var = variables[i];
00079       if ( ISNONSTACK(var) )
00080         {
00081           icre--;
00082           for ( j = 0 ; j < nVariable ; j++ ) 
00083             {
00084               var1 = variables[j];
00085               if ( var1->stack_position > var->stack_position 
00086                    && ! (ISNONSTACK(var1)))
00087                 var1->stack_position--;
00088             }
00089         }
00090     }
00091   return 0;
00092 }

Here is the caller graph for this function:

void ForNameClean (  ) 

Definition at line 362 of file variables.c.

References i, nVariable, var, and variables.

00363 {
00364   VARPTR var;
00365   int i;
00366   for (i = 0; i < nVariable; i++) {
00367     var = variables[i];
00368     if ( var->kp_state != -1 ) 
00369       {
00370         var->nfor_name = var->kp_state ;
00371       }
00372   }
00373 }

int GetBasType ( char *  sname  ) 

Definition at line 486 of file variables.c.

References code, i, j, NULL, and SType.

00488 { 
00489   int i=0;
00490   while ( SType[i].sname != (char *) NULL)
00491     {
00492       int j ;
00493       j = strcmp(sname,SType[i].sname);
00494       if ( j == 0 ) 
00495         { 
00496           return(SType[i].code);
00497         }
00498       else 
00499         { 
00500           if ( j <= 0) 
00501             break;
00502           else i++;
00503         }
00504     }
00505   printf("the type of variable \"%s\" is unknown\n",sname);
00506   exit(1);
00507 }

IVAR GetExistOutVar (  ) 

Definition at line 246 of file variables.c.

References i, nVariable, str, and variables.

00247 {
00248   int i;
00249   char str[4];
00250   strcpy(str,"out");
00251   for (i = 0; i < nVariable; i++) {
00252     if (strcmp(variables[i]->name,str) == 0)
00253       return(i+1);
00254   }
00255   printf("variable \"out\" must exist\n");
00256   exit(1);
00257 }

IVAR GetExistVar ( char *  name  ) 

Definition at line 154 of file variables.c.

References i, nVariable, var, and variables.

00156 {
00157   int i;
00158   VARPTR var;
00159   if (strcmp(name,"out") == 0) {
00160     printf("the name of a variable which is not the output variable\n");
00161     printf("  of SCILAB function cannot be \"out\"\n");
00162     exit(1);
00163   }
00164   for (i = 0; i < nVariable; i++) {
00165     var = variables[i];
00166     if (strcmp(var->name,name) == 0) {
00167       /* always present */
00168       var->present = 1;
00169       return(i+1);
00170     }
00171   }
00172   i=CreatePredefVar(name);
00173   if ( i != -1) return(i);
00174   printf("variable \"%s\" must exist\n",name);
00175   exit(1);
00176 }

int GetForType ( char *  type  ) 

Definition at line 560 of file variables.c.

References code, EXTERNAL, fname, FType, i, j, and NULL.

00562 {
00563   int i=0;
00564   while ( FType[i].fname != (char *) NULL)
00565     {
00566       int j;
00567       j = strcmp(type,FType[i].fname);
00568       if ( j == 0 ) 
00569         { 
00570           return(FType[i].code);
00571         }
00572       else 
00573         { 
00574           if ( j <= 0) 
00575             break;
00576           else i++;
00577         }
00578     }
00579   return(EXTERNAL);
00580 }

IVAR GetOutVar ( char *  name  ) 

Definition at line 207 of file variables.c.

References malloc(), MAXVAR, nVariable, var, VarAlloc(), and variables.

00209 {
00210   VARPTR var;
00211   if (strcmp(name,"out") != 0) {
00212     printf("the name of output variable of SCILAB function\n");
00213     printf("  must be \"out\"\n");
00214     exit(1);
00215   }
00216   if (nVariable == MAXVAR) {
00217     printf("too many variables\n");
00218     printf("  augmente constant \"MAXVAR\" and recompile intersci\n");
00219     exit(1);
00220   }
00221   var = VarAlloc();
00222   if (var == 0) {
00223     printf("Running out of memory\n");
00224     exit(1);
00225   }
00226   var->name = (char *)malloc((unsigned)(strlen(name) + 1));
00227   strcpy(var->name,name);
00228   var->type = 0;
00229   var->length = 0;
00230   var->for_type = 0;
00231   var->equal = 0;
00232   var->nfor_name = 0;
00233   var->kp_state = -1;
00234   var->list_el = 0;
00235   var->opt_type = 0;
00236   var->present = 0;
00237   var->out_position = 0;
00238   var->stack_position = 0;
00239   variables[nVariable++] = var;
00240   return(nVariable);
00241 }

Here is the call graph for this function:

IVAR GetVar ( char *  name,
int  p 
)

Definition at line 103 of file variables.c.

References i, nVariable, var, and variables.

00106 {
00107   int i;
00108   VARPTR var;
00109   if (strcmp(name,"out") == 0) {
00110     printf("the name of a variable which is not the output variable\n");
00111     printf("  of SCILAB function cannot be \"out\"\n");
00112     exit(1);
00113   }
00114   for (i = 0; i < nVariable; i++) {
00115     var = variables[i];
00116     if (strcmp(var->name,name) == 0) {
00117       var->present = var->present || p;
00118       return(i+1);
00119     }
00120   }
00121   if (nVariable == MAXVAR) {
00122     printf("too many variables\n");
00123     printf("  augment constant \"MAXVAR\" and recompile intersci\n");
00124     exit(1);
00125   }
00126   var = VarAlloc();
00127   if (var == 0) {
00128     printf("Running out of memory\n");
00129     exit(1);
00130   }
00131   var->name = (char *)malloc((unsigned)(strlen(name) + 1));
00132   strcpy(var->name,name);
00133   var->type = 0;
00134   var->length = 0;
00135   var->for_type = 0;
00136   var->equal = 0;
00137   var->nfor_name = 0;
00138   var->kp_state = -1;
00139   var->list_el = 0;
00140   var->opt_type = 0;
00141   var->present = p;
00142   var->out_position = 0;
00143   var->stack_position = 0;
00144   var->is_sciarg = 0;
00145   variables[nVariable++] = var;
00146   var->vpos = nVariable;
00147   return(nVariable);
00148 }

char* SGetCDec ( int  type  ) 

Definition at line 645 of file variables.c.

References code, FType, and i.

Referenced by OptMATRIX(), and WriteOptArg().

00647 {
00648   int i=0;
00649   while ( FType[i].code  != -1 ) 
00650     {
00651       if ( FType[i].code == type ) 
00652         return(FType[i].ctype);
00653       else 
00654         i++;
00655     }
00656   return("XXX");
00657 }

Here is the caller graph for this function:

char* SGetExtForTypeAbrev ( VARPTR  var  ) 

Definition at line 729 of file variables.c.

References BMATRIX.

Referenced by OutExtCommon(), and OutExtIMATRIX().

00731 {
00732   if ( var->type == BMATRIX ) 
00733     return("b");
00734   else 
00735     {
00736       if ( strcmp(var->fexternal,"cintf")==0) 
00737         return "i";
00738       else 
00739         return("d");
00740     }
00741 }

Here is the caller graph for this function:

char* SGetExtForTypeStack ( VARPTR  var  ) 

Definition at line 751 of file variables.c.

References BMATRIX, and FType.

Referenced by OutExtCommon(), and OutExtIMATRIX().

00753 {
00754   if ( var->type == BMATRIX ) 
00755     return(FType[1].st_name);
00756   else 
00757     return(FType[4].st_name);
00758 }

Here is the caller graph for this function:

int SGetForDec ( int  type  ) 

Definition at line 626 of file variables.c.

References code, FType, and i.

00628 {
00629   int i=0;
00630   while ( FType[i].code  != -1 ) 
00631     {
00632       if ( FType[i].code == type ) 
00633         return(FType[i].dec);
00634       else 
00635         i++;
00636     }
00637   return(-1);
00638 }

char* SGetForType ( int  type  ) 

Definition at line 587 of file variables.c.

References code, fname, FType, and i.

00589 {
00590   int i=0;
00591   while ( FType[i].code  != -1 ) 
00592     {
00593       if ( FType[i].code == type ) 
00594         return(FType[i].fname);
00595       else 
00596         i++;
00597     }
00598   return("External");
00599 }

char* SGetForTypeAbrev ( VARPTR  var  ) 

Definition at line 607 of file variables.c.

References code, FType, and i.

Referenced by CreCommon(), CreIMATRIX(), GetCom(), GetIMATRIX(), OptMATRIX(), OutCommon(), OutIMATRIX(), OutLISTarg(), WriteFunctionCode(), and WriteOptArg().

00609 {
00610   int i=0;
00611   while ( FType[i].code  != -1 ) 
00612     {
00613       if ( FType[i].code == var->for_type ) 
00614         return(FType[i].abrev);
00615       else 
00616         i++;
00617     }
00618   return("XX");
00619 }

Here is the caller graph for this function:

char* SGetForTypeBConvert ( VARPTR  var  ) 

Definition at line 697 of file variables.c.

References code, FType, and i.

00699 {
00700   int i=0;
00701   while ( FType[i].code  != -1 ) 
00702     {
00703       if ( FType[i].code == var->for_type ) 
00704         {
00705           if ( FType[i].b_convert[0] == 'X' ) 
00706             {
00707               printf("incompatibility between Scilab and Fortran type for variable \"%s\"\n",
00708                      var->name);   
00709               exit(1);
00710             }
00711           return(FType[i].b_convert);
00712         }
00713       else 
00714         i++;
00715     }
00716   printf("Unknown Fortran type for variable \"%s\"\n", var->name);   
00717   exit(1);
00718 }

char* SGetForTypeStack ( VARPTR  var  ) 

Definition at line 665 of file variables.c.

References code, FType, and i.

Referenced by CreCommon(), CreIMATRIX(), GetCom(), GetIMATRIX(), OptMATRIX(), WriteOptArg(), and WriteOptArgPhase2().

00667 {
00668   int i=0;
00669   while ( FType[i].code  != -1 ) 
00670     {
00671       if ( FType[i].code == var->for_type ) 
00672         {
00673           if ( FType[i].st_name[0] == 'X' ) 
00674             {
00675               printf("incompatibility between Scilab and Fortran type for variable \"%s\"\n",
00676                      var->name);   
00677               exit(1);
00678             }
00679           return(FType[i].st_name);
00680         }
00681       else 
00682         i++;
00683     }
00684   printf("Unknown Fortran type for variable \"%s\"\n", var->name);   
00685   exit(1);
00686 }

Here is the caller graph for this function:

char* SGetSciType ( int  type  ) 

Definition at line 514 of file variables.c.

References code, i, and SType.

00516 {
00517   int i=0;
00518   while ( SType[i].code  != -1 ) 
00519     {
00520       if ( SType[i].code == type ) 
00521         return(SType[i].sname);
00522       else 
00523         i++;
00524     }
00525   return("unknown");
00526 }

int ShowVariables (  ) 

Definition at line 9 of file variables.c.

References i, j, var::name, nVariable, SGetForType(), SGetSciType(), var, and variables.

00010 {
00011   int i;
00012   VARPTR var;
00013   for (i = 0; i < nVariable; i++) 
00014     {
00015       int j;
00016       var = variables[i];
00017       fprintf(stderr,"==============variable %d : name %s\n",i+1,var->name);
00018       fprintf(stderr,"type %s<->%s\n",SGetSciType(var->type),
00019               SGetForType(var->for_type));
00020       fprintf(stderr,"elts : [");
00021       for (j=0 ; j < var->length ; j++) 
00022         {
00023           fprintf(stderr,"{var %d:%s}",var->el[j],
00024                   variables[var->el[j]-1]->name);
00025         }
00026       fprintf(stderr,"]\n");
00027       /* fprintf(stderr," name of external function when type is  char *fexternal[MAXNAM]; 
00028          external 
00029       */
00030       fprintf(stderr," ?  equal %d\n",var->equal);
00031       fprintf(stderr,"for_names [");
00032       if ( var->nfor_name != 0) 
00033         {
00034           for (j=0 ; j < var->nfor_name ; j++) 
00035             {
00036               fprintf(stderr,"{%s:%d}",var->for_name[j],
00037                       var->for_name_orig[j]);
00038               if ( j != var->nfor_name-1) fprintf(stderr,",");
00039             }
00040         }
00041       fprintf(stderr,"]\n");
00042       fprintf(stderr," position in a list %d\n",var->list_el);
00043       if ( var->list_el > 0 )
00044         fprintf(stderr," List name %s\n",var->list_name);
00045       fprintf(stderr," type of optional variable %d\n",var->opt_type);
00046       if ( var->opt_type != 0)
00047         fprintf(stderr," name or value default for optional variable %s\n",
00048                 var->opt_name);
00049       fprintf(stderr," 1 if the variable is really present %d\n",var->present);
00050       fprintf(stderr,"sciarg %d, rhs %d, lhs %d\n",
00051               var->is_sciarg,
00052               var->stack_position,
00053               var->out_position);
00054     }
00055   return 0;
00056 }

Here is the call graph for this function:


Variable Documentation

struct ftype FType[] [static]

struct btype SType[] [static]


Generated on Sun Mar 4 16:08:53 2007 for Scilab [trunk] by  doxygen 1.5.1