vtkParse.y

Go to the documentation of this file.
00001 /*
00002  * $Id: vtkParse.y,v 1.4 2002/10/15 08:05:00 pfb Exp $
00003  */
00004 
00005 /*=========================================================================
00006 
00007   Program:   Visualization Toolkit
00008   Module:    $RCSfile: vtkParse.y,v $
00009   Language:  C++
00010   Date:      $Date: 2002/10/15 08:05:00 $
00011   Version:   $Revision: 1.4 $
00012 
00013 
00014 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00015 All rights reserved.
00016 
00017 Redistribution and use in source and binary forms, with or without
00018 modification, are permitted provided that the following conditions are met:
00019 
00020  * Redistributions of source code must retain the above copyright notice,
00021    this list of conditions and the following disclaimer.
00022 
00023  * Redistributions in binary form must reproduce the above copyright notice,
00024    this list of conditions and the following disclaimer in the documentation
00025    and/or other materials provided with the distribution.
00026 
00027  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00028    of any contributors may be used to endorse or promote products derived
00029    from this software without specific prior written permission.
00030 
00031  * Modified source versions must be plainly marked as such, and must not be
00032    misrepresented as being the original software.
00033 
00034 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00035 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00036 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00037 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00038 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00039 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00040 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00041 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00042 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00043 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00044 
00045 =========================================================================*/
00046 
00047 %{
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <string.h>
00051 #define yyerror(a) fprintf(stderr,"%s\n",a)
00052 #define yywrap() 1
00053 
00054 void output_function();
00055 
00056 /* vtkstrdup is not part of POSIX so we create our own */
00057 char *vtkstrdup(const char *in)
00058 {
00059   char *res = malloc(strlen(in)+1);
00060   strcpy(res,in);
00061   return res;
00062 }
00063 
00064 #include "vtkParse.h"
00065     
00066   FileInfo data;
00067   FunctionInfo *currentFunction;
00068 
00069   FILE *fhint;
00070   char temps[2048];
00071   int  in_public;
00072   int  in_protected;
00073   int  HaveComment;
00074   char CommentText[50000];
00075   int CommentState;
00076   int openSig;
00077   int invertSig;
00078   int sigAllocatedLength;
00079   
00080 #define YYMAXDEPTH 1000
00081 
00082   void checkSigSize(char *arg)
00083     {
00084     if (strlen(currentFunction->Signature) + strlen(arg) + 3 > 
00085         sigAllocatedLength)
00086       {
00087       currentFunction->Signature = (char *)
00088   realloc(currentFunction->Signature, sigAllocatedLength*2);
00089       sigAllocatedLength = sigAllocatedLength*2;
00090       }
00091     } 
00092   void preSig(char *arg)
00093     {
00094     if (!currentFunction->Signature)
00095       {
00096       currentFunction->Signature = (char*)malloc(2048);
00097       sigAllocatedLength = 2048; 
00098       sprintf(currentFunction->Signature,"%s",arg);
00099       }    
00100     else if (openSig)
00101       {
00102       char *tmp;
00103       checkSigSize(arg);
00104       tmp = vtkstrdup(currentFunction->Signature);
00105       sprintf(currentFunction->Signature,"%s%s",arg,tmp);
00106       free(tmp);
00107       }
00108     }
00109   void postSig(char *arg)
00110     {
00111     if (!currentFunction->Signature)
00112       {
00113       currentFunction->Signature = (char*)malloc(2048);
00114       sigAllocatedLength = 2048; 
00115       sprintf(currentFunction->Signature,"%s",arg);
00116       }    
00117     else if (openSig)
00118       {
00119       char *tmp;
00120       checkSigSize(arg);
00121       tmp = vtkstrdup(currentFunction->Signature);
00122       if (invertSig)
00123         {
00124         sprintf(currentFunction->Signature,"%s%s",arg,tmp);
00125         }
00126       else
00127         {
00128         sprintf(currentFunction->Signature,"%s%s",tmp,arg);
00129         }
00130       free(tmp);
00131       }
00132     }
00133   void delSig(void)
00134     {
00135     if (currentFunction->Signature)
00136       {
00137       free(currentFunction->Signature);
00138       currentFunction->Signature = NULL;
00139       }
00140     }
00141 %}
00142 
00143 %union{
00144   char *str;
00145   int   integer;
00146   }
00147 
00148 %token CLASS
00149 %token PUBLIC
00150 %token PRIVATE
00151 %token PROTECTED
00152 %token VIRTUAL
00153 %token <str> STRING
00154 %token <integer> NUM
00155 %token <str> ID
00156 %token INT
00157 %token FLOAT
00158 %token SHORT
00159 %token LONG
00160 %token DOUBLE
00161 %token VOID
00162 %token CHAR
00163 %token CLASS_REF
00164 %token OTHER
00165 %token CONST
00166 %token OPERATOR
00167 %token UNSIGNED
00168 %token FRIEND
00169 %token <str> VTK_ID
00170 %token STATIC
00171 %token VAR_FUNCTION
00172 %token ARRAY_NUM
00173 
00174 /* macro tokens */
00175 %token SetMacro
00176 %token GetMacro
00177 %token SetStringMacro
00178 %token GetStringMacro
00179 %token SetClampMacro
00180 %token SetObjectMacro
00181 %token SetReferenceCountedObjectMacro
00182 %token GetObjectMacro
00183 %token BooleanMacro
00184 %token SetVector2Macro
00185 %token SetVector3Macro
00186 %token SetVector4Macro
00187 %token SetVector6Macro
00188 %token GetVector2Macro
00189 %token GetVector3Macro
00190 %token GetVector4Macro
00191 %token GetVector6Macro
00192 %token SetVectorMacro
00193 %token GetVectorMacro
00194 %token ViewportCoordinateMacro
00195 %token WorldCoordinateMacro
00196 %token TypeMacro
00197 
00198 %%
00199 /*
00200  * Here is the start of the grammer
00201  */
00202 strt: maybe_other class_def maybe_other;
00203 
00204 class_def : CLASS VTK_ID 
00205       {
00206       data.ClassName = vtkstrdup($2);
00207       }
00208     optional_scope '{' class_def_body '}';
00209 
00210 class_def_body: class_def_item | class_def_item class_def_body;
00211 
00212 class_def_item: scope_type ':' | var
00213    | function | FRIEND function | macro ';' | macro;
00214 
00215 function: '~' func { preSig("~"); output_function(); } 
00216       | VIRTUAL '~' func { preSig("virtual ~"); output_function(); }
00217       | func 
00218          {
00219          output_function();
00220    }
00221       | type func 
00222          {
00223          currentFunction->ReturnType = $<integer>1;
00224          output_function();
00225    } 
00226       | VIRTUAL type func 
00227          {
00228          preSig("virtual ");
00229          currentFunction->ReturnType = $<integer>2;
00230          output_function();
00231    }
00232       | VIRTUAL func
00233          {
00234          preSig("virtual ");
00235          output_function();
00236    };
00237 
00238 func: func_beg { postSig(")"); } maybe_const { postSig(";"); openSig = 0; } 
00239       func_end
00240     {
00241       openSig = 1;
00242       currentFunction->Name = $<str>1; 
00243       fprintf(stderr,"   Parsed func %s\n",$<str>1); 
00244     }  
00245   | OPERATOR maybe_other_no_semi ';'
00246     { 
00247       currentFunction->IsOperator = 1; 
00248       fprintf(stderr,"   Converted operator\n"); 
00249     }
00250   | func_beg '=' NUM ';'
00251     { 
00252       postSig(") = 0;"); 
00253       currentFunction->Name = $<str>1; 
00254       fprintf(stderr,"   Parsed pure virtual func %s\n",$<str>1); 
00255       currentFunction->IsPureVirtual = 1; 
00256       data.IsAbstract = 1;
00257     };
00258 
00259 maybe_const: | CONST {postSig(" const");};
00260 
00261 func_beg: any_id '('  {postSig(" ("); } args_list ')';
00262 
00263 const_mod: CONST {postSig("const ");}
00264 
00265 static_mod: STATIC {postSig("static ");}
00266 
00267 any_id: VTK_ID {postSig($<str>1);} | ID {postSig($<str>1);};
00268 
00269 func_end: ';' 
00270     | '{' maybe_other '}' ';' 
00271     | '{' maybe_other '}'  
00272     | ':' maybe_other_no_semi ';';
00273 
00274 args_list: | more_args;
00275 
00276 more_args: arg { currentFunction->NumberOfArguments++;} 
00277   | arg { currentFunction->NumberOfArguments++; postSig(", ");} ',' more_args;
00278 
00279 arg: type 
00280     {
00281       currentFunction->ArgCounts[currentFunction->NumberOfArguments] = 0; 
00282       currentFunction->ArgTypes[currentFunction->NumberOfArguments] = 
00283   $<integer>1;} 
00284   | type var_id 
00285     {
00286       currentFunction->ArgCounts[currentFunction->NumberOfArguments] = 
00287   $<integer>2 / 10000; 
00288       currentFunction->ArgTypes[currentFunction->NumberOfArguments] = 
00289   $<integer>1 + $<integer>2 % 10000;
00290     } opt_var_assign
00291   | VAR_FUNCTION 
00292     { 
00293       postSig("void (*func)(void *) ");
00294       currentFunction->ArgCounts[currentFunction->NumberOfArguments] = 0; 
00295       currentFunction->ArgTypes[currentFunction->NumberOfArguments] = 5000;
00296     };
00297 
00298 opt_var_assign: | '=' float_num;
00299 
00300 var:  type var_id ';' {delSig();} | VAR_FUNCTION ';' {delSig();};
00301 
00302 var_id: any_id var_array { $<integer>$ = $<integer>2; };
00303 
00304 /*
00305  300 = [n] 
00306  600 = [n][m]
00307  900 = [n][m][l]
00308 */
00309 
00310 var_array: { $<integer>$ = 0; }
00311      | ARRAY_NUM { char temp[100]; sprintf(temp,"[%i]",$<integer>1); 
00312                    postSig(temp); } 
00313        var_array { $<integer>$ = 300 + 10000 * $<integer>1 + $<integer>3 % 1000; } 
00314      | '[' maybe_other_no_semi ']' var_array 
00315            { postSig("[]"); $<integer>$ = 300 + $<integer>4 % 1000; };
00316 
00317 type: const_mod type_red1 {$<integer>$ = 1000 + $<integer>2;} 
00318           | type_red1 {$<integer>$ = $<integer>1;}; 
00319           | static_mod type_red1 {$<integer>$ = 2000 + $<integer>2;}; 
00320           | static_mod const_mod type_red1 {$<integer>$ = 3000 + $<integer>3;}; 
00321 
00322 type_red1: type_red2 {$<integer>$ = $<integer>1;} 
00323          | type_red2 type_indirection 
00324              {$<integer>$ = $<integer>1 + $<integer>2;};
00325 
00326 /* 100 = &
00327    200 = &&
00328    300 = *
00329    400 = &*
00330    500 = *&
00331    700 = **
00332    */
00333 type_indirection: '&' { postSig("&"); $<integer>$ = 100;} 
00334                 | '*' { postSig("*"); $<integer>$ = 300;} 
00335                 | '&' type_indirection { $<integer>$ = 100 + $<integer>2;}
00336                 | '*' type_indirection { $<integer>$ = 400 + $<integer>2;};
00337 
00338 type_red2: UNSIGNED {postSig("unsigned ");} 
00339              type_primitive { $<integer>$ = 10 + $<integer>3;} 
00340                   | type_primitive { $<integer>$ = $<integer>1;};
00341 
00342 type_primitive: 
00343   FLOAT  { postSig("float "); $<integer>$ = 1;} | 
00344   VOID   { postSig("void "); $<integer>$ = 2;} | 
00345   CHAR   { postSig("char "); $<integer>$ = 3;} | 
00346   INT    { postSig("int "); $<integer>$ = 4;} | 
00347   SHORT  { postSig("short "); $<integer>$ = 5;} | 
00348   LONG   { postSig("long "); $<integer>$ = 6;} | 
00349   DOUBLE { postSig("double "); $<integer>$ = 7;} | 
00350   ID     {       
00351       char ctmpid[2048];
00352       sprintf(ctmpid,"%s ",$<str>1);
00353       postSig(ctmpid);
00354       $<integer>$ = 8;} |
00355   VTK_ID  
00356     { 
00357       char ctmpid[2048];
00358       sprintf(ctmpid,"%s ",$<str>1);
00359       postSig(ctmpid);
00360       $<integer>$ = 9; 
00361       currentFunction->ArgClasses[currentFunction->NumberOfArguments] =
00362         vtkstrdup($1); 
00363       /* store the string into the return value just in case we need it */
00364       /* this is a parsing hack because the first "type" parser will */
00365       /* possibly be ht ereturn type of the first argument */
00366       if ((!currentFunction->ReturnClass) && 
00367           (!currentFunction->NumberOfArguments)) 
00368         { 
00369         currentFunction->ReturnClass = vtkstrdup($1); 
00370         }
00371     };
00372 
00373 optional_scope: | ':' scope_list;
00374 
00375 scope_list: scope_type VTK_ID 
00376     { 
00377       data.SuperClasses[data.NumberOfSuperClasses] = vtkstrdup($2); 
00378       data.NumberOfSuperClasses++; 
00379     } 
00380   | scope_type VTK_ID 
00381     { 
00382       data.SuperClasses[data.NumberOfSuperClasses] = vtkstrdup($2); 
00383       data.NumberOfSuperClasses++; 
00384     } ',' scope_list;
00385 
00386 scope_type: PUBLIC {in_public = 1; in_protected = 0;} 
00387           | PRIVATE {in_public = 0; in_protected = 0;} 
00388           | PROTECTED {in_public = 0; in_protected = 1;};
00389 
00390 float_num: '-' float_prim | float_prim;
00391 
00392 float_prim: NUM {$<integer>$ = $1;} 
00393          | NUM '.' NUM {$<integer>$ = -1;} | any_id {$<integer>$ = -1;};
00394 
00395 macro:
00396   SetMacro '(' any_id ',' 
00397            {preSig("void Set"); postSig(" ("); } type_red2 ')'
00398    {
00399    postSig(");");
00400    sprintf(temps,"Set%s",$<str>3); 
00401    currentFunction->Name = vtkstrdup(temps);
00402    currentFunction->NumberOfArguments = 1;
00403    currentFunction->ArgTypes[0] = $<integer>6;
00404    currentFunction->ArgCounts[0] = 0;
00405    currentFunction->ReturnType = 2;
00406    output_function();
00407    }
00408 | GetMacro '('{postSig("Get");} any_id ',' {postSig(" ();"); invertSig = 1;} 
00409     type_red2 ')'
00410    { 
00411    sprintf(temps,"Get%s",$<str>4); 
00412    currentFunction->Name = vtkstrdup(temps);
00413    currentFunction->NumberOfArguments = 0;
00414    currentFunction->ReturnType = $<integer>7;
00415    output_function();
00416    }
00417 | SetStringMacro '(' {preSig("void Set");} any_id ')'
00418    {
00419    postSig(" (char *);"); 
00420    sprintf(temps,"Set%s",$<str>4); 
00421    currentFunction->Name = vtkstrdup(temps);
00422    currentFunction->NumberOfArguments = 1;
00423    currentFunction->ArgTypes[0] = 303;
00424    currentFunction->ArgCounts[0] = 0;
00425    currentFunction->ReturnType = 2;
00426    output_function();
00427    }
00428 | GetStringMacro '(' {preSig("char *Get");} any_id ')'
00429    { 
00430    postSig(" ();");
00431    sprintf(temps,"Get%s",$<str>4); 
00432    currentFunction->Name = vtkstrdup(temps);
00433    currentFunction->NumberOfArguments = 0;
00434    currentFunction->ReturnType = 303;
00435    output_function();
00436    }
00437 | SetClampMacro  '(' any_id ',' 
00438     {preSig("void Set"); postSig(" ("); } type_red2 
00439     {postSig(");"); openSig = 0;} ',' maybe_other_no_semi ')'
00440    { 
00441    char *local = vtkstrdup(currentFunction->Signature);
00442    sscanf (currentFunction->Signature, "%*s %*s (%s);", local);
00443    sprintf(temps,"Set%s",$<str>3); 
00444    currentFunction->Name = vtkstrdup(temps);
00445    currentFunction->NumberOfArguments = 1;
00446    currentFunction->ArgTypes[0] = $<integer>6;
00447    currentFunction->ArgCounts[0] = 0;
00448    currentFunction->ReturnType = 2;
00449    output_function();
00450 
00451    currentFunction->Signature = (char *)malloc(2048);
00452    sigAllocatedLength = 2048;
00453    sprintf(currentFunction->Signature,"%s Get%sMinValue ();",local,$<str>3);
00454    sprintf(temps,"Get%sMinValue",$<str>3);
00455    currentFunction->Name = vtkstrdup(temps);
00456    currentFunction->NumberOfArguments = 0;
00457    currentFunction->ReturnType = $<integer>6;
00458    output_function();
00459 
00460    currentFunction->Signature = (char *)malloc(2048);
00461    sigAllocatedLength = 2048;
00462    sprintf(currentFunction->Signature,"%s Get%sMaxValue ();",local,$<str>3);
00463    sprintf(temps,"Get%sMaxValue",$<str>3);
00464    currentFunction->Name = vtkstrdup(temps);
00465    currentFunction->NumberOfArguments = 0;
00466    currentFunction->ReturnType = $<integer>6;
00467    output_function();
00468    }
00469 | SetObjectMacro '(' any_id ',' 
00470   {preSig("void Set"); postSig(" ("); } type_red2 ')'
00471    { 
00472    postSig("*);");
00473    sprintf(temps,"Set%s",$<str>3); 
00474    currentFunction->Name = vtkstrdup(temps);
00475    currentFunction->NumberOfArguments = 1;
00476    currentFunction->ArgTypes[0] = 309;
00477    currentFunction->ArgCounts[0] = 1;
00478    currentFunction->ReturnType = 2;
00479    output_function();
00480    }
00481 | SetReferenceCountedObjectMacro '(' any_id ','   
00482    {preSig("void Set"); postSig(" ("); } type_red2 ')'
00483    { 
00484    postSig("*);");
00485    sprintf(temps,"Set%s",$<str>3); 
00486    currentFunction->Name = vtkstrdup(temps);
00487    currentFunction->NumberOfArguments = 1;
00488    currentFunction->ArgTypes[0] = 309;
00489    currentFunction->ArgCounts[0] = 1;
00490    currentFunction->ReturnType = 2;
00491    output_function();
00492    }
00493 | GetObjectMacro '(' {postSig("*Get");} any_id ',' 
00494    {postSig(" ();"); invertSig = 1;} type_red2 ')'
00495    { 
00496    sprintf(temps,"Get%s",$<str>4); 
00497    currentFunction->Name = vtkstrdup(temps);
00498    currentFunction->NumberOfArguments = 0;
00499    currentFunction->ReturnType = 309;
00500    output_function();
00501    }
00502 | BooleanMacro '(' any_id 
00503     {preSig("void "); postSig("On ();"); openSig = 0; } 
00504         ',' type_red2 ')'
00505    { 
00506    sprintf(temps,"%sOn",$<str>3); 
00507    currentFunction->Name = vtkstrdup(temps);
00508    currentFunction->NumberOfArguments = 0;
00509    currentFunction->ReturnType = 2;
00510    output_function();
00511    currentFunction->Signature = (char *)malloc(2048);
00512    sigAllocatedLength = 2048;
00513    sprintf(currentFunction->Signature,"void %sOff ();",$<str>3); 
00514    sprintf(temps,"%sOff",$<str>3); 
00515    currentFunction->Name = vtkstrdup(temps);
00516    currentFunction->NumberOfArguments = 0;
00517    output_function();
00518    }
00519 | SetVector2Macro '(' any_id ',' 
00520      {
00521      free (currentFunction->Signature);
00522      currentFunction->Signature = NULL;
00523      } 
00524       type_red2 ')'
00525    { 
00526    char *local = vtkstrdup(currentFunction->Signature);
00527    sprintf(currentFunction->Signature,"void Set%s (%s, %s);",$<str>3,
00528      local, local);
00529    sprintf(temps,"Set%s",$<str>3); 
00530    currentFunction->Name = vtkstrdup(temps);
00531    currentFunction->NumberOfArguments = 2;
00532    currentFunction->ArgTypes[0] = $<integer>6;
00533    currentFunction->ArgCounts[0] = 0;
00534    currentFunction->ArgTypes[1] = $<integer>6;
00535    currentFunction->ArgCounts[1] = 0;
00536    currentFunction->ReturnType = 2;
00537    output_function();
00538 
00539    currentFunction->Signature = (char *)malloc(2048);
00540    sigAllocatedLength = 2048;
00541    sprintf(currentFunction->Signature,"void Set%s (%s a[2]);",$<str>3,
00542      local);
00543    currentFunction->Name = vtkstrdup(temps);
00544    currentFunction->NumberOfArguments = 1;
00545    currentFunction->ArgTypes[0] = 300 + $<integer>6;
00546    currentFunction->ArgCounts[0] = 2;
00547    output_function();
00548    }
00549 | GetVector2Macro  '(' any_id ',' 
00550      {
00551      free (currentFunction->Signature);
00552      currentFunction->Signature = NULL;
00553      } 
00554       type_red2 ')'
00555    { 
00556    char *local = vtkstrdup(currentFunction->Signature);
00557    sprintf(currentFunction->Signature,"%s *Get%s ();",local, $<str>3);
00558    sprintf(temps,"Get%s",$<str>3); 
00559    currentFunction->Name = vtkstrdup(temps);
00560    currentFunction->NumberOfArguments = 0;
00561    currentFunction->ReturnType = 300 + $<integer>6;
00562    currentFunction->HaveHint = 1;
00563    currentFunction->HintSize = 2;
00564    output_function();
00565    }
00566 | SetVector3Macro '(' any_id ',' 
00567      {
00568      free (currentFunction->Signature);
00569      currentFunction->Signature = NULL;
00570      } 
00571       type_red2 ')'
00572    { 
00573    char *local = vtkstrdup(currentFunction->Signature);
00574    sprintf(currentFunction->Signature,"void Set%s (%s, %s, %s);",
00575      $<str>3, local, local, local);
00576    sprintf(temps,"Set%s",$<str>3); 
00577    currentFunction->Name = vtkstrdup(temps);
00578    currentFunction->NumberOfArguments = 3;
00579    currentFunction->ArgTypes[0] = $<integer>6;
00580    currentFunction->ArgCounts[0] = 0;
00581    currentFunction->ArgTypes[1] = $<integer>6;
00582    currentFunction->ArgCounts[1] = 0;
00583    currentFunction->ArgTypes[2] = $<integer>6;
00584    currentFunction->ArgCounts[2] = 0;
00585    currentFunction->ReturnType = 2;
00586    output_function();
00587 
00588    currentFunction->Signature = (char *)malloc(2048);
00589    sigAllocatedLength = 2048;
00590    sprintf(currentFunction->Signature,"void Set%s (%s a[3]);",$<str>3,
00591      local);
00592    currentFunction->Name = vtkstrdup(temps);
00593    currentFunction->NumberOfArguments = 1;
00594    currentFunction->ArgTypes[0] = 300 + $<integer>6;
00595    currentFunction->ArgCounts[0] = 3;
00596    output_function();
00597    }
00598 | GetVector3Macro  '(' any_id ','
00599      {
00600      free (currentFunction->Signature);
00601      currentFunction->Signature = NULL;
00602      } 
00603       type_red2 ')'
00604    { 
00605    char *local = vtkstrdup(currentFunction->Signature);
00606    sprintf(currentFunction->Signature,"%s *Get%s ();",local, $<str>3);
00607    sprintf(temps,"Get%s",$<str>3); 
00608    currentFunction->Name = vtkstrdup(temps);
00609    currentFunction->NumberOfArguments = 0;
00610    currentFunction->ReturnType = 300 + $<integer>6;
00611    currentFunction->HaveHint = 1;
00612    currentFunction->HintSize = 3;
00613    output_function();
00614    }
00615 | SetVector4Macro '(' any_id ',' 
00616      {
00617      free (currentFunction->Signature);
00618      currentFunction->Signature = NULL;
00619      } 
00620       type_red2 ')'
00621    { 
00622    char *local = vtkstrdup(currentFunction->Signature);
00623    sprintf(currentFunction->Signature,"void Set%s (%s, %s, %s, %s);",
00624      $<str>3, local, local, local, local);
00625    sprintf(temps,"Set%s",$<str>3); 
00626    currentFunction->Name = vtkstrdup(temps);
00627    currentFunction->NumberOfArguments = 4;
00628    currentFunction->ArgTypes[0] = $<integer>6;
00629    currentFunction->ArgCounts[0] = 0;
00630    currentFunction->ArgTypes[1] = $<integer>6;
00631    currentFunction->ArgCounts[1] = 0;
00632    currentFunction->ArgTypes[2] = $<integer>6;
00633    currentFunction->ArgCounts[2] = 0;
00634    currentFunction->ArgTypes[3] = $<integer>6;
00635    currentFunction->ArgCounts[3] = 0;
00636    currentFunction->ReturnType = 2;
00637    output_function();
00638 
00639    currentFunction->Signature = (char *)malloc(2048);
00640    sigAllocatedLength = 2048;
00641    sprintf(currentFunction->Signature,"void Set%s (%s a[4]);",$<str>3,
00642      local);
00643    currentFunction->Name = vtkstrdup(temps);
00644    currentFunction->NumberOfArguments = 1;
00645    currentFunction->ArgTypes[0] = 300 + $<integer>6;
00646    currentFunction->ArgCounts[0] = 4;
00647    output_function();
00648    }
00649 | GetVector4Macro  '(' any_id ','
00650      {
00651      free (currentFunction->Signature);
00652      currentFunction->Signature = NULL;
00653      } 
00654       type_red2 ')'
00655    { 
00656    char *local = vtkstrdup(currentFunction->Signature);
00657    sprintf(currentFunction->Signature,"%s *Get%s ();",local, $<str>3);
00658    sprintf(temps,"Get%s",$<str>3); 
00659    currentFunction->Name = vtkstrdup(temps);
00660    currentFunction->NumberOfArguments = 0;
00661    currentFunction->ReturnType = 300 + $<integer>6;
00662    currentFunction->HaveHint = 1;
00663    currentFunction->HintSize = 4;
00664    output_function();
00665    }
00666 | SetVector6Macro '(' any_id ','
00667      {
00668      free (currentFunction->Signature);
00669      currentFunction->Signature = NULL;
00670      } 
00671       type_red2 ')'
00672    { 
00673    char *local = vtkstrdup(currentFunction->Signature);
00674    sprintf(currentFunction->Signature,"void Set%s (%s, %s, %s, %s, %s, %s);",
00675      $<str>3, local, local, local, local, local, local);
00676    sprintf(temps,"Set%s",$<str>3); 
00677    currentFunction->Name = vtkstrdup(temps);
00678    currentFunction->NumberOfArguments = 6;
00679    currentFunction->ArgTypes[0] = $<integer>6;
00680    currentFunction->ArgCounts[0] = 0;
00681    currentFunction->ArgTypes[1] = $<integer>6;
00682    currentFunction->ArgCounts[1] = 0;
00683    currentFunction->ArgTypes[2] = $<integer>6;
00684    currentFunction->ArgCounts[2] = 0;
00685    currentFunction->ArgTypes[3] = $<integer>6;
00686    currentFunction->ArgCounts[3] = 0;
00687    currentFunction->ArgTypes[4] = $<integer>6;
00688    currentFunction->ArgCounts[4] = 0;
00689    currentFunction->ArgTypes[5] = $<integer>6;
00690    currentFunction->ArgCounts[5] = 0;
00691    currentFunction->ReturnType = 2;
00692    output_function();
00693 
00694    currentFunction->Signature = (char *)malloc(2048);
00695    sigAllocatedLength = 2048;
00696    sprintf(currentFunction->Signature,"void Set%s (%s a[6]);",$<str>3,
00697      local);
00698    currentFunction->Name = vtkstrdup(temps);
00699    currentFunction->NumberOfArguments = 1;
00700    currentFunction->ArgTypes[0] = 300 + $<integer>6;
00701    currentFunction->ArgCounts[0] = 6;
00702    output_function();
00703    }
00704 | GetVector6Macro  '(' any_id ','
00705      {
00706      free (currentFunction->Signature);
00707      currentFunction->Signature = NULL;
00708      } 
00709       type_red2 ')'
00710    { 
00711    char *local = vtkstrdup(currentFunction->Signature);
00712    sprintf(currentFunction->Signature,"%s *Get%s ();",local, $<str>3);
00713    sprintf(temps,"Get%s",$<str>3); 
00714    currentFunction->Name = vtkstrdup(temps);
00715    currentFunction->NumberOfArguments = 0;
00716    currentFunction->ReturnType = 300 + $<integer>6;
00717    currentFunction->HaveHint = 1;
00718    currentFunction->HintSize = 6;
00719    output_function();
00720    }
00721 | SetVectorMacro  '(' any_id ',' 
00722       {
00723       free (currentFunction->Signature);
00724       currentFunction->Signature = NULL;
00725       } 
00726      type_red2 ',' float_num ')'
00727    {
00728    char *local = vtkstrdup(currentFunction->Signature);
00729    sprintf(currentFunction->Signature,"void Set%s (%s [%i]);",$<str>3,
00730       local, $<integer>8);
00731      sprintf(temps,"Set%s",$<str>3); 
00732      currentFunction->Name = vtkstrdup(temps);
00733      currentFunction->ReturnType = 2;
00734      currentFunction->NumberOfArguments = 1;
00735      currentFunction->ArgTypes[0] = 300 + $<integer>6;
00736      currentFunction->ArgCounts[0] = $<integer>8;
00737      output_function();
00738    }
00739 | GetVectorMacro  '(' any_id ',' 
00740      {
00741      free (currentFunction->Signature);
00742      currentFunction->Signature = NULL;
00743      } 
00744      type_red2 ',' float_num ')'
00745    { 
00746    char *local = vtkstrdup(currentFunction->Signature);
00747    sprintf(currentFunction->Signature,"%s *Get%s ();",local, $<str>3);
00748    sprintf(temps,"Get%s",$<str>3); 
00749    currentFunction->Name = vtkstrdup(temps);
00750    currentFunction->NumberOfArguments = 0;
00751    currentFunction->ReturnType = 300 + $<integer>6;
00752    currentFunction->HaveHint = 1;
00753    currentFunction->HintSize = $<integer>8;
00754    output_function();
00755    }
00756 | ViewportCoordinateMacro '(' any_id ')'
00757    { 
00758      sprintf(currentFunction->Signature,"vtkCoordinate *Get%sCoordinate ();",
00759        $<str>3);
00760 
00761      sprintf(temps,"Get%sCoordinate",$<str>3); 
00762      currentFunction->Name = vtkstrdup(temps);
00763      currentFunction->NumberOfArguments = 0;
00764      currentFunction->ReturnType = 309;
00765      currentFunction->ReturnClass = vtkstrdup("vtkCoordinate");
00766      output_function();
00767 
00768      currentFunction->Signature = (char *)malloc(2048);
00769      sigAllocatedLength = 2048;
00770      sprintf(currentFunction->Signature,"void Set%s (float, float);",
00771        $<str>3);
00772      sprintf(temps,"Set%s",$<str>3); 
00773      currentFunction->Name = vtkstrdup(temps);
00774      currentFunction->NumberOfArguments = 2;
00775      currentFunction->ArgTypes[0] = 1;
00776      currentFunction->ArgCounts[0] = 0;
00777      currentFunction->ArgTypes[1] = 1;
00778      currentFunction->ArgCounts[1] = 0;
00779      currentFunction->ReturnType = 2;
00780      output_function();
00781 
00782      currentFunction->Signature = (char *)malloc(2048);
00783      sigAllocatedLength = 2048;
00784      sprintf(currentFunction->Signature,"void Set%s (float a[2]);",
00785        $<str>3);
00786      currentFunction->Name = vtkstrdup(temps);
00787      currentFunction->NumberOfArguments = 1;
00788      currentFunction->ArgTypes[0] = 301;
00789      currentFunction->ArgCounts[0] = 2;
00790      output_function();
00791      
00792      currentFunction->Signature = (char *)malloc(2048);
00793      sigAllocatedLength = 2048;
00794      sprintf(currentFunction->Signature,"float *Get%s ();", $<str>3);
00795      sprintf(temps,"Get%s",$<str>3); 
00796      currentFunction->Name = vtkstrdup(temps);
00797      currentFunction->NumberOfArguments = 0;
00798      currentFunction->ReturnType = 301;
00799      currentFunction->HaveHint = 1;
00800      currentFunction->HintSize = 2;
00801      output_function();
00802    }
00803 | WorldCoordinateMacro '(' any_id ')'
00804    { 
00805      sprintf(currentFunction->Signature,"vtkCoordinate *Get%sCoordinate ();",
00806        $<str>3);
00807 
00808      sprintf(temps,"Get%sCoordinate",$<str>3); 
00809      currentFunction->Name = vtkstrdup(temps);
00810      currentFunction->NumberOfArguments = 0;
00811      currentFunction->ReturnType = 309;
00812      currentFunction->ReturnClass = vtkstrdup("vtkCoordinate");
00813      output_function();
00814 
00815      currentFunction->Signature = (char *)malloc(2048);
00816      sigAllocatedLength = 2048;
00817      sprintf(currentFunction->Signature,"void Set%s (float, float, float);",
00818        $<str>3);
00819      sprintf(temps,"Set%s",$<str>3); 
00820      currentFunction->Name = vtkstrdup(temps);
00821      currentFunction->NumberOfArguments = 3;
00822      currentFunction->ArgTypes[0] = 1;
00823      currentFunction->ArgCounts[0] = 0;
00824      currentFunction->ArgTypes[1] = 1;
00825      currentFunction->ArgCounts[1] = 0;
00826      currentFunction->ArgTypes[2] = 1;
00827      currentFunction->ArgCounts[2] = 0;
00828      currentFunction->ReturnType = 2;
00829      output_function();
00830 
00831      currentFunction->Signature = (char *)malloc(2048);
00832      sigAllocatedLength = 2048;
00833      sprintf(currentFunction->Signature,"void Set%s (float a[3]);",
00834        $<str>3);
00835      currentFunction->Name = vtkstrdup(temps);
00836      currentFunction->NumberOfArguments = 1;
00837      currentFunction->ArgTypes[0] = 301;
00838      currentFunction->ArgCounts[0] = 3;
00839      output_function();
00840      
00841      currentFunction->Signature = (char *)malloc(2048);
00842      sigAllocatedLength = 2048;
00843      sprintf(currentFunction->Signature,"float *Get%s ();", $<str>3);
00844      sprintf(temps,"Get%s",$<str>3); 
00845      currentFunction->Name = vtkstrdup(temps);
00846      currentFunction->NumberOfArguments = 0;
00847      currentFunction->ReturnType = 301;
00848      currentFunction->HaveHint = 1;
00849      currentFunction->HintSize = 3;
00850      output_function();
00851    }
00852 | TypeMacro '(' any_id ',' any_id ')'
00853    { 
00854    currentFunction->Signature = (char *)malloc(2048);
00855    sigAllocatedLength = 2048;
00856    sprintf(currentFunction->Signature, "const char *GetClassName ();");
00857    sprintf(temps,"GetClassName"); 
00858    currentFunction->Name = vtkstrdup(temps);
00859    currentFunction->NumberOfArguments = 0;
00860    currentFunction->ReturnType = 1303;
00861    output_function();
00862 
00863    currentFunction->Signature = (char *)malloc(2048);
00864    sigAllocatedLength = 2048;
00865    sprintf(currentFunction->Signature,
00866            "int IsA (const char *name);");
00867    sprintf(temps,"IsA"); 
00868    currentFunction->Name = vtkstrdup(temps);
00869    currentFunction->NumberOfArguments = 1;
00870    currentFunction->ArgTypes[0] = 1303;
00871    currentFunction->ArgCounts[0] = 0;
00872    currentFunction->ReturnType = 4;
00873    output_function();
00874    }
00875 ;
00876 
00877 /*
00878  * These just eat up misc garbage
00879  */
00880 maybe_other : | other_stuff maybe_other;
00881 maybe_other_no_semi : | other_stuff_no_semi maybe_other_no_semi;
00882 
00883 other_stuff : ';' | other_stuff_no_semi;
00884 
00885 other_stuff_no_semi : OTHER | braces | parens | '*' | '=' | ':' | ',' | '.'
00886    | STRING | type_red2 | NUM | CLASS_REF | '&' | brackets | CONST 
00887    | OPERATOR | '-' | '~' | STATIC | ARRAY_NUM;
00888 
00889 braces: '{' maybe_other '}';
00890 parens: '(' maybe_other ')';
00891 brackets: '[' maybe_other ']';
00892 
00893 %%
00894 #include <string.h>
00895 #include "vtkParse.lex.c"
00896 
00897 /* initialize the structure */
00898 void InitFunction(FunctionInfo *func)
00899 {
00900   func->Name = NULL;
00901   func->NumberOfArguments = 0;
00902   func->ArrayFailure = 0;
00903   func->IsPureVirtual = 0;
00904   func->IsPublic = 0;
00905   func->IsOperator = 0;
00906   func->HaveHint = 0;
00907   func->HintSize = 0;
00908   func->ReturnType = 2;
00909   func->ReturnClass = NULL;
00910   func->Comment = NULL;
00911   func->Signature = NULL;
00912   sigAllocatedLength = 0;
00913   openSig = 1;
00914   invertSig = 0;
00915 }
00916 
00917 /* when the cpp file doesn't have enough info use the hint file */
00918 void look_for_hint()
00919 {
00920   char h_cls[80];
00921   char h_func[80];
00922   int  h_type;
00923   int  h_value;
00924 
00925   /* reset the position */
00926   rewind(fhint);
00927 
00928   /* first find a hint */
00929   while (fscanf(fhint,"%s %s %i %i",h_cls,h_func,&h_type,&h_value) != EOF)
00930     {
00931     if ((!strcmp(h_cls,data.ClassName))&&
00932   currentFunction->Name &&
00933   (!strcmp(h_func,currentFunction->Name))&&
00934   (h_type == currentFunction->ReturnType))
00935       {
00936       currentFunction->HaveHint = 1;
00937       currentFunction->HintSize = h_value;
00938       }
00939     }
00940 }
00941 
00942 /* a simple routine that updates a few variables */
00943 void output_function()
00944 {
00945   int i;
00946 
00947   /* a void argument is the same as no arguements */
00948   if (currentFunction->ArgTypes[0]%1000 == 2) 
00949     {
00950     currentFunction->NumberOfArguments = 0;
00951     }
00952 
00953   currentFunction->IsPublic = in_public;
00954   currentFunction->IsProtected = in_protected;
00955   
00956   /* look for VAR FUNCTIONS */
00957   if (currentFunction->NumberOfArguments
00958       && (currentFunction->ArgTypes[0] == 5000))
00959     {
00960     if (currentFunction->NumberOfArguments == 2)
00961       {
00962       currentFunction->NumberOfArguments = 1;
00963       }
00964     else
00965       {
00966       currentFunction->ArrayFailure = 1;
00967       }
00968     }
00969   
00970   /* is it a delete function */
00971   if (currentFunction->Name && !strcmp("Delete",currentFunction->Name))
00972     {
00973     data.HasDelete = 1;
00974     }
00975 
00976 
00977   /* if we need a return type hint and dont currently have one */
00978   /* then try to find one */
00979   if (!currentFunction->HaveHint)
00980     {
00981     switch (currentFunction->ReturnType%1000)
00982       {
00983       case 301: case 302: case 307:
00984       case 304: case 305: case 306: case 313:
00985         look_for_hint();
00986   break;
00987       }
00988     }
00989 
00990   /* reject multi-dimensional arrays from wrappers */
00991   for (i = 0; i < currentFunction->NumberOfArguments; i++)
00992     {
00993     if ((currentFunction->ArgTypes[i]%1000)/100 == 6 ||
00994         (currentFunction->ArgTypes[i]%1000)/100 == 9)
00995       {
00996       currentFunction->ArrayFailure = 1;
00997       }
00998     }
00999 
01000   if (HaveComment)
01001     {
01002     currentFunction->Comment = vtkstrdup(CommentText);
01003     }
01004   
01005   data.NumberOfFunctions++;
01006   currentFunction = data.Functions + data.NumberOfFunctions;
01007   InitFunction(currentFunction);
01008 }
01009 
01010 extern void vtkParseOutput(FILE *,FileInfo *);
01011 
01012 int main(int argc,char *argv[])
01013   {
01014   FILE *fin;
01015   int ret;
01016   
01017   if (argc < 4 || argc > 5)
01018     {
01019     fprintf(stderr,"Usage: %s input_file hint_file is_concrete\n",argv[0]);
01020     exit(1);
01021     }
01022   
01023   if (!(fin = fopen(argv[1],"r")))
01024     {
01025     fprintf(stderr,"Error opening input file %s\n",argv[1]);
01026     exit(1);
01027     }
01028 
01029   if (!(fhint = fopen(argv[2],"r")))
01030     {
01031     fprintf(stderr,"Error opening hint file %s\n",argv[2]);
01032     exit(1);
01033     }
01034 
01035   data.FileName = argv[1];
01036   data.NameComment = NULL;
01037   data.Description = NULL;
01038   data.Caveats = NULL;
01039   data.SeeAlso = NULL;
01040   CommentState = 0;
01041   data.IsConcrete = atoi(argv[3]);
01042 
01043   currentFunction = data.Functions;
01044   InitFunction(currentFunction);
01045   
01046   yyin = fin;
01047   yyout = stdout;
01048   ret = yyparse();
01049   if (ret)
01050     {
01051     fprintf(stdout,
01052             "*** SYNTAX ERROR found in parsing the header file %s ***\n", 
01053             argv[1]);
01054     return ret;
01055     }
01056 
01057   if (argc == 5)
01058     {
01059     FILE *fout;
01060     if (!(fout = fopen(argv[4],"w")))
01061       {
01062       fprintf(stderr,"Error opening output file %s\n",argv[4]);
01063       exit(1);
01064       }
01065     vtkParseOutput(fout,&data);
01066     fclose (fout);
01067     }
01068   else
01069     {
01070     vtkParseOutput(stdout,&data);
01071     }
01072     return 0;
01073   }
01074 
01075 /*
01076  * $Log: vtkParse.y,v $
01077  * Revision 1.4  2002/10/15 08:05:00  pfb
01078  * Changed p/o to reflect pure virtual finction.
01079  *
01080  * Revision 1.3  2002/04/18 13:23:03  pfb
01081  * Updated to source from VTK V4.0.
01082  *
01083  * Revision 1.2  2001/07/12 14:48:12  pfb
01084  * Now includes vtkParse.lex.c instead of lex.yy.c.
01085  *
01086  *
01087  */
01088