intmacr2tree.h

Go to the documentation of this file.
00001 /**************************************************/
00002 /* intmacr2tree.h                                 */
00003 /* Functions used for macr2tree() Scilab function */
00004 /* Copyright INRIA                                */
00005 /* V.C. - 2004                                    */
00006 /**************************************************/
00007 
00008 /* Generic header files */
00009 #include <string.h>
00010 #include <stdio.h>
00011 #include <math.h>
00012 #include "machine.h"
00013 #include "stack-c.h" /* stack-def.h, stack1.h, stack2.h, stack3.h included */
00014 #include "Funtab.h"
00015 
00016 /**********************/
00017 /* External functions */
00018 /**********************/
00019 
00020 /* Defined in SCI/modules/core/src/c/str2sci.c */
00021 extern void str2sci(char** x,int n,int m); /* Write a C-string in Scilab stack */
00022 
00023 /* Defined in SCI/modules/core/src/fortran/itosci.f */
00024 extern void C2F(itosci)(int *intptr,int *nbrows,int *nbcols); /* Write a int in Scilab stack */
00025 
00026 /* Defined in SCI/modules/core/src/fortran/dtosci.f */
00027 extern void C2F(dtosci)(double *dbleptr,int *nbrows,int *nbcols); /* Write a double in Scilab stack */
00028 
00029 /* Defined in SCI/modules/core/src/fortran/cvname.f */
00030 extern int C2F(cvnamel)(int *id,char *str,int *jobptr,int *str_len); 
00031 /* *jobptr==0: Get Scilab codes from C-string */
00032 /* *jobptr==1: Get C-string from Scilab codes */
00033 
00034 /* Defined in SCI/routines/system/mklist.f */
00035 extern int C2F(mklist)(int *nbitems); 
00036 extern int C2F(mktlist)(int *nbitems); 
00037 
00038 /* Some useful definitions unexistant in stack-c.h */
00039 #define idstk(x,y) (C2F(vstk).idstk+(x-1)+(y-1)*nsiz)
00040 #define CvNameL(id,str,jobptr,str_len) C2F(cvnamel)(id,str,jobptr,str_len);
00041 #define CvStr(n,line,str,jobptr,str_len) C2F(cvstr)(n,line,str,jobptr,str_len);
00042 
00043 /**********************/
00044 /* Internal functions */
00045 /**********************/
00046 
00047 /****************************************************************
00048  Function name: macr2tree
00049  Decription:
00050  Create on Scilab stack a "tree" composed of imbricated lists
00051  and tlists using Scilab pseudo codes of Scilab macro
00052  Resulting "tree" is a new representation for Scilab macro
00053  Particularly useful for M2SCI
00054  Tree is emuled by a "program" tlist:
00055   tlist(["program","name","outputs","inputs","statements","nblines"],..
00056                    macro_name,..
00057                            list_of_output_variable_tlists,..
00058                                      list_of_intput_variable_tlists,..
00059                                              list_of_macro_statements,..
00060                                                            total_number_of_lines_in_macro)
00061  Input:
00062   - fname: name of calling function for error message
00063  Output:
00064   - No output
00065  Returned value:
00066   - 0 if execution succeeds
00067   - not null if execution fails
00068 ****************************************************************/
00069 int C2F(macr2tree) _PARAMS((char *fname, unsigned long fname_len));
00070 
00071 /****************************************************************
00072  Function name: CreateVariableTList
00073  Decription:
00074  Create on Scilab stack a "variable" tlist:
00075   tlist(["variable","name"],variable_name)
00076  Input:
00077   - varname: pointer to a char array
00078     varname[0]=pointer to variable name (ASCII character string)
00079  Output:
00080   - No output
00081  Returned value:
00082   - 0 if execution succeeds
00083   - not null if execution fails
00084 ****************************************************************/
00085 static int CreateVariableTList(char **varname);
00086 
00087 /****************************************************************
00088  Function name: CreateEOLList
00089  Decription:
00090  Create on Scilab stack a "EOL" list:
00091   list("EOL")
00092  Input:
00093   - No input
00094  Output:
00095   - No output
00096  Returned value:
00097   - 0 if execution succeeds
00098   - not null if execution fails
00099 ****************************************************************/
00100 static int CreateEOLList(void);
00101 
00102 /****************************************************************
00103  Function name: AddVar
00104  Decription:
00105  Add a variable name in variable name table called varnames
00106  (varnames is global variable for file intmacr2tree.c)
00107  Input:
00108   - name: name of variable to add to table
00109  Output:
00110   - No output
00111  Returned value:
00112   - 0 if execution succeeds
00113   - not null if execution fails
00114 ****************************************************************/
00115 static int AddVar(char *name);
00116 
00117 /****************************************************************
00118  Function name: IsDefinedVar
00119  Decription:
00120  Search for a variable name in variable name table called "varnames"
00121  ("varnames" is global variable for file intmacr2tree.c)
00122  Input:
00123   - name: name of variable to add to table
00124  Output:
00125   - No output
00126  Returned value:
00127   - -1 if variable not does not exists in "varnames"
00128   - if variable already exists in "varnames", returned value is 
00129     equal to index where variable was find
00130 ****************************************************************/
00131 static int IsDefinedVar(char *name);
00132 
00133 /****************************************************************
00134  Function name: GetInstruction
00135  Decription: 
00136  Create on Scilab stack an INSTRUCTION tlist:
00137       tlist(["equal","expression","lhs"],...)
00138    OR tlist(["for","expression","statements"],...)
00139    OR tlist(["while","expression","statements"],...)
00140    OR tlist(["selectcase","expression","cases","else"],...)
00141    OR tlist(["ifthenelse","expression","then","elseifs","else"],...)
00142  See CreateEqualTList and GetControlInstruction
00143  Input:
00144   - data: pointer to compiled macro code
00145   - index: index of current integer in data
00146   - nblines: pointer to number of lines in macro
00147  Output:
00148   - nblines: pointer to number of lines in macro
00149   - addinstr:
00150      0 if just a part of statement (For example "variable")
00151      1 if statement to add to list (For example "equal")
00152  Returned value:
00153   - 0 if execution succeeds
00154   - not null if execution fails
00155 ****************************************************************/
00156 static int GetInstruction(int *data,int *index,int *nblines,int *addinstr);
00157 
00158 /****************************************************************
00159  Function name: GetControlInstruction
00160  Decription: 
00161  Create on Scilab stack an CONTROL INSTRUCTION tlist:
00162       tlist(["for","expression","statements"],...)
00163    OR tlist(["while","expression","statements"],...)
00164    OR tlist(["selectcase","expression","cases","else"],...)
00165    OR tlist(["ifthenelse","expression","then","elseifs","else"],...)
00166  Input:
00167   - data: pointer to compiled macro code
00168   - index: index of current integer in data
00169   - nblines: pointer to number of lines in macro
00170  Output:
00171   - nblines: pointer to number of lines in macro
00172  Returned value:
00173   - 0 if execution succeeds
00174   - not null if execution fails
00175 ****************************************************************/
00176 static int GetControlInstruction(int *data,int *index,int *nblines);
00177 
00178 /****************************************************************
00179  Function name: CreateCsteTList
00180  Decription: 
00181  Create on Scilab stack a "cste" tlist:
00182    tlist(["cste","value"],constant_value)
00183  Input:
00184   - type: type of constant ("number","string","code23" or "emptymatrix")
00185   - data: pointer to compiled macro code
00186   - index: index of current integer in data
00187  Output:
00188   - No output
00189  Returned value:
00190   - 0 if execution succeeds
00191   - not null if execution fails
00192 ****************************************************************/
00193 static int CreateCsteTList(char *type,int *data,int *index);
00194 
00195 /****************************************************************
00196  Function name: CreateOperationTList
00197  Decription: 
00198  Create on Scilab stack an "operation" tlist:
00199    tlist(["operation","operands","operator"],list_of_operands,operator_symbol)
00200  Input:
00201   - data: pointer to compiled macro code
00202   - index: index of current integer in data
00203  Output:
00204   - No output
00205  Returned value:
00206   - 0 if execution succeeds
00207   - not null if execution fails
00208 ****************************************************************/
00209 static int CreateOperationTList(int *data,int *index);
00210 
00211 /****************************************************************
00212  Function name: CreateFuncallTList
00213  Decription: 
00214  Create on Scilab stack a "funcall" tlist:
00215    tlist(["funcall","rhs","name","lhsnb"],function_name,list_of_rhs,list_of_lhs,number_of_lhs)
00216  Input:
00217   - fromwhat: from what it has to be made ("funptr","datacode" or "macro")
00218   - data: pointer to compiled macro code
00219   - index: index of current integer in data
00220  Output:
00221   - No output
00222  Returned value:
00223   - 0 if execution succeeds
00224   - not null if execution fails
00225 ****************************************************************/
00226 static int CreateFuncallTList(char *fromwhat,int *data,int *index);
00227 
00228 /****************************************************************
00229  Function name: CreateEqualTList
00230  Decription: 
00231  Create on Scilab stack an "equal" tlist:
00232    tlist(["equal","expression","lhs"],left_part_of_equal,list_of_lhs)
00233  Input:
00234   - fromwhat: from what it has to be made ("code29","code1" or "forexpr")
00235   - data: pointer to compiled macro code
00236   - index: index of current integer in data
00237  Output:
00238   - No output
00239  Returned value:
00240   - 0 if execution succeeds
00241   - not null if execution fails
00242 ****************************************************************/
00243 static int CreateEqualTList(char *fromwhat,int *data,int *index);
00244 
00245 /****************************************************************
00246  Function name: CreateRecursiveIndexList
00247  Decription: 
00248   Create on Scilab stack a list for recursive insertion or extraction
00249   First list item is a matrix which contains number of row/column indexes
00250  Input:
00251   - data: pointer to compiled macro code
00252   - index: index of current integer in data
00253  Output:
00254   - No output
00255  Returned value:
00256   - 0 if execution succeeds
00257   - not null if execution fails
00258 ****************************************************************/
00259 
00260 static int CreateCommentTList(int *data,int *index);
00261 /****************************************************************
00262  Function name:  CreateCommentTList
00263  Decription: 
00264   Create on Scilab stack a "comment" tlist:
00265   tlist(["comment","text"],text_of_comment)
00266  Input:
00267   - data: pointer to compiled macro code
00268   - index: index of current integer in data
00269  Output:
00270   - No output
00271  Returned value:
00272   - 0 if execution succeeds
00273   - not null if execution fails
00274 
00275 ****************************************************************/
00276 static int CreateRecursiveIndexList(int *data,int *index);
00277 
00278 /****************************************************************
00279 
00280  Function name: VCopyObj
00281  Decription: 
00282   Copy an object in Scilab stack
00283  Input:
00284   - fname: name of calling function for error message
00285   - orig: position of object to copy
00286   - dest: position where object has to be copied
00287   - fname_length: length of character string fname
00288  Output:
00289   - No output
00290  Returned value:
00291   - 0 if execution succeeds
00292   - not null if execution fails
00293 ****************************************************************/
00294 static int VCopyObj(char *fname,int *orig,int *dest,unsigned long fname_length);
00295 
00296 /****************************************************************
00297  Function name: complexity
00298  Decription: 
00299   Eval number of statements (which give addinstr==1 in GetInstruction)
00300   in a compiled macro code or a part of this code
00301  Input:
00302   - data: pointer to compiled macro code
00303   - index: index of current integer in data
00304   - lgth: length of code to eval
00305  Output:
00306   - No output
00307  Returned value:
00308   - number of list items corresponding to code
00309 ****************************************************************/
00310 int complexity(int *data,int *index,int *lgth);

Generated on Sun Mar 4 15:03:45 2007 for Scilab [trunk] by  doxygen 1.5.1