ssParse.y

Go to the documentation of this file.
00001 /* $Id: ssParse.y,v 1.11 2004/07/14 10:01:26 pfb Exp $ */
00002 
00003 /*=========================================================================
00004 
00005   Program:   Visualization Toolkit
00006   Module:    $RCSfile: ssParse.y,v $
00007   Language:  C++
00008   Date:      $Date: 2004/07/14 10:01:26 $
00009   Version:   $Revision: 1.11 $
00010 
00011 
00012 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00013 All rights reserved.
00014 
00015 Redistribution and use in source and binary forms, with or without
00016 modification, are permitted provided that the following conditions are met:
00017 
00018  * Redistributions of source code must retain the above copyright notice,
00019    this list of conditions and the following disclaimer.
00020 
00021  * Redistributions in binary form must reproduce the above copyright notice,
00022    this list of conditions and the following disclaimer in the documentation
00023    and/or other materials provided with the distribution.
00024 
00025  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00026    of any contributors may be used to endorse or promote products derived
00027    from this software without specific prior written permission.
00028 
00029  * Modified source versions must be plainly marked as such, and must not be
00030    misrepresented as being the original software.
00031 
00032 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00033 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00034 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00035 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00036 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00037 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00038 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00039 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00040 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00041 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042 
00043 =========================================================================*/
00044 
00049 %{
00050 #include <stdio.h>
00051 #include <stdlib.h>
00052 #include <string.h>
00053 /* #define yyerror(a) fprintf(stderr,"%s\n",a) */
00054 #define yywrap() 1
00055 
00056 #include "ssParse.h"
00057     
00058 #define YYDEBUG 1
00059 #define YYERROR_VERBOSE
00060 
00061 FileInfo data;
00062 FunctionInfo *currentFunction;
00063 
00064 FILE *fhint;
00065 char temps[2048];
00066 int  in_public;
00067 int  in_protected;
00068 int  HaveComment;
00069 char CommentText[50000];
00070 int CommentState;
00071 int openSig;
00072 int invertSig;
00073 int sigAllocatedLength;
00074   
00075 #define YYMAXDEPTH 1000
00076 
00077 /*----------------------------------------------------------------------------*/
00078 void checkSigSize(char *arg)
00079   {
00080   if (strlen(currentFunction->Signature) + strlen(arg) + 3 > sigAllocatedLength)
00081     {
00082     currentFunction->Signature = (char *)
00083       realloc(currentFunction->Signature, sigAllocatedLength * 2);
00084     sigAllocatedLength = sigAllocatedLength * 2;
00085     }
00086   } 
00087 
00088 /*----------------------------------------------------------------------------*/
00089 void preSig(char *arg)
00090   {
00091   if (!currentFunction->Signature)
00092     {
00093     currentFunction->Signature = (char *)malloc(2048);
00094     sigAllocatedLength = 2048; 
00095     sprintf(currentFunction->Signature, "%s", arg);
00096     }    
00097   else if (openSig)
00098     {
00099     char *tmp;
00100     checkSigSize(arg);
00101     tmp = strdup(currentFunction->Signature);
00102     sprintf(currentFunction->Signature,"%s%s", arg, tmp);
00103     free(tmp);
00104     }
00105   }
00106 
00107 /*----------------------------------------------------------------------------*/
00108 void postSig(char *arg)
00109   {
00110   if (!currentFunction->Signature)
00111     {
00112     currentFunction->Signature = (char *)malloc(2048);
00113     sigAllocatedLength = 2048; 
00114     sprintf(currentFunction->Signature, "%s", arg);
00115     }    
00116   else if (openSig)
00117     {
00118     char *tmp;
00119     checkSigSize(arg);
00120     tmp = strdup(currentFunction->Signature);
00121     if (invertSig)
00122       {
00123       sprintf(currentFunction->Signature, "%s%s", arg, tmp);
00124       }
00125     else
00126       {
00127       sprintf(currentFunction->Signature, "%s%s", tmp, arg);
00128       }
00129     free(tmp);
00130     }
00131   }
00132 
00133 /*----------------------------------------------------------------------------*/
00134 void delSig(void)
00135   {
00136   if (currentFunction->Signature)
00137     {
00138     free(currentFunction->Signature);
00139     currentFunction->Signature = NULL;
00140     }
00141   }
00142 
00143 %}
00144 
00145 %union{
00146   char *str;
00147   int   integer;
00148   }
00149 
00150 %token CLASS
00151 %token PUBLIC
00152 %token PRIVATE
00153 %token PROTECTED
00154 %token VIRTUAL
00155 %token <str> STRING
00156 %token <integer> NUM
00157 %token <str> ID
00158 %token INT
00159 %token FLOAT
00160 %token SHORT
00161 %token LONG
00162 %token DOUBLE
00163 %token VOID
00164 %token CHAR
00165 %token CLASS_REF
00166 %token OTHER
00167 %token CONST
00168 %token OPERATOR
00169 %token UNSIGNED
00170 %token FRIEND
00171 %token <str> VTK_ID
00172 %token STATIC
00173 %token VAR_FUNCTION
00174 %token ARRAY_NUM
00175 
00176 /* macro tokens */
00177 %token SetMacro
00178 %token GetMacro
00179 %token SetStringMacro
00180 %token GetStringMacro
00181 %token SetClampMacro
00182 %token SetObjectMacro
00183 %token SetReferenceCountedObjectMacro
00184 %token GetObjectMacro
00185 %token BooleanMacro
00186 %token SetVector2Macro
00187 %token SetVector3Macro
00188 %token SetVector4Macro
00189 %token SetVector6Macro
00190 %token GetVector2Macro
00191 %token GetVector3Macro
00192 %token GetVector4Macro
00193 %token GetVector6Macro
00194 %token SetVectorMacro
00195 %token GetVectorMacro
00196 %token ViewportCoordinateMacro
00197 %token WorldCoordinateMacro
00198 %token TypeMacro
00199 
00200 %%
00201 /*
00202  * Here is the start of the grammer
00203  */
00204 strt: maybe_other class_def maybe_other;
00205 
00206 class_def : CLASS VTK_ID 
00207       {
00208       data.ClassName = strdup($2);
00209       }
00210     optional_scope '{' class_def_body '}';
00211 
00212 class_def_body: class_def_item | class_def_item class_def_body;
00213 
00214 class_def_item: scope_type ':'
00215    | var
00216    | function 
00217    | FRIEND function 
00218    | macro ';' 
00219    | macro;
00220 
00221 function: '~' func 
00222          {
00223          preSig("~");
00224          output_function();
00225          } 
00226       | VIRTUAL '~' func { preSig("virtual ~"); output_function(); }
00227       | func 
00228          {
00229          output_function();
00230          }
00231       | type func 
00232          {
00233          currentFunction->ReturnType = $<integer>1;
00234          output_function();
00235          } 
00236       | VIRTUAL type func 
00237          {
00238          preSig("virtual ");
00239          currentFunction->ReturnType = $<integer>2;
00240          output_function();
00241          }
00242       | VIRTUAL func
00243          {
00244          preSig("virtual ");
00245          output_function();
00246          };
00247 
00248 func: func_beg 
00249         { 
00250         postSig(")");
00251         }
00252       maybe_const 
00253         {
00254         postSig(";");
00255         openSig = 0;
00256         } 
00257       func_end
00258         {
00259         openSig = 1;
00260         currentFunction->Name = $<str>1; 
00261         fprintf(stderr,"   Parsed func %s\n", $<str>1); 
00262         }  
00263       | OPERATOR maybe_other_no_semi ';'
00264         { 
00265         currentFunction->IsOperator = 1; 
00266         fprintf(stderr,"   Converted operator\n"); 
00267         }
00268       | func_beg '=' NUM ';'
00269         { 
00270         postSig(") = 0;"); 
00271         currentFunction->Name = $<str>1; 
00272         fprintf(stderr,"   Parsed pure virtual func %s\n", $<str>1); 
00273         currentFunction->IsPureVirtual = 1; 
00274         data.IsAbstract = 1;
00275         }
00276       ;
00277 
00278 maybe_const: 
00279        | CONST 
00280            {
00281            postSig(" const");
00282            }
00283        ;
00284 
00285 func_beg: any_id '('  
00286             {
00287             postSig(" ("); 
00288             } 
00289           args_list ')';
00290 
00291 const_mod: CONST 
00292              {
00293              postSig("const ");
00294              }
00295 
00296 static_mod: STATIC 
00297               {
00298               postSig("static ");
00299               }
00300 
00301 any_id: VTK_ID 
00302           {
00303           postSig($<str>1);
00304           }
00305         | ID
00306           {
00307           postSig($<str>1);
00308           };
00309 
00310 func_end: ';' 
00311     | '{' maybe_other '}' ';' 
00312     | '{' maybe_other '}'  
00313     | ':' maybe_other_no_semi ';';
00314 
00315 args_list: | more_args;
00316 
00317 more_args: arg
00318              {
00319              currentFunction->NumberOfArguments++;
00320              } 
00321          | arg
00322              {
00323              currentFunction->NumberOfArguments++; postSig(", ");
00324              }
00325            ',' more_args;
00326 
00327 arg: type 
00328        {
00329        currentFunction->ArgCounts[currentFunction->NumberOfArguments] = 0; 
00330        currentFunction->ArgTypes[currentFunction->NumberOfArguments] = 
00331        $<integer>1;
00332        } 
00333    | type var_id 
00334        {
00335        currentFunction->ArgCounts[currentFunction->NumberOfArguments] = 
00336        $<integer>2 / 10000; 
00337        currentFunction->ArgTypes[currentFunction->NumberOfArguments] = 
00338        $<integer>1 + $<integer>2 % 10000;
00339        /* fail if array is not const */
00340        if ((($<integer>2 % 10000) / 100) % 10 != 0 &&
00341             ($<integer>1 / 1000) != 1 )
00342          {
00343          currentFunction->ArrayFailure = 1;
00344          }
00345        }
00346      opt_var_assign
00347    | VAR_FUNCTION 
00348        { 
00349        postSig("void (*func)(void *) ");
00350        currentFunction->ArgCounts[currentFunction->NumberOfArguments] = 0; 
00351        currentFunction->ArgTypes[currentFunction->NumberOfArguments] = 5000;
00352        };
00353 
00354 opt_var_assign: | '=' float_num;
00355 
00356 var:  type var_id ';' 
00357         {
00358         delSig();
00359         } 
00360     | VAR_FUNCTION ';' 
00361         {
00362         delSig();
00363         };
00364 
00365 var_id: any_id var_array 
00366           {
00367           $<integer>$ = $<integer>2;
00368           };
00369 
00370 var_array: 
00371           {
00372           $<integer>$ = 0;
00373           }
00374       | ARRAY_NUM
00375           {
00376           char temp[100];
00377           sprintf(temp,"[%i]",$<integer>1); 
00378           postSig(temp);
00379           } 
00380         var_array 
00381           {
00382           $<integer>$ = 300 + 10000 * $<integer>1;
00383           } 
00384       | '[' maybe_other_no_semi ']' var_array 
00385           {
00386           postSig("[]"); $<integer>$ = 300;
00387           };
00388 
00389 type: const_mod type_red1
00390         {
00391         $<integer>$ = 1000 + $<integer>2;
00392         } 
00393     | type_red1
00394         {
00395         $<integer>$ = $<integer>1;
00396         }; 
00397     | static_mod type_red1 
00398         {
00399         $<integer>$ = 2000 + $<integer>2;
00400         }; 
00401     | static_mod const_mod type_red1 
00402         {
00403         $<integer>$ = 3000 + $<integer>3;
00404         }; 
00405 
00406 type_red1: type_red2 
00407              {
00408              $<integer>$ = $<integer>1;
00409              } 
00410          | type_red2 type_indirection 
00411              {
00412              $<integer>$ = $<integer>1 + $<integer>2;
00413              };
00414 
00415 /* 100 = &
00416    200 = &&
00417    300 = *
00418    400 = &*
00419    500 = *&
00420    700 = **
00421    */
00422 type_indirection: '&' 
00423                     {
00424                     postSig("&");
00425                     $<integer>$ = 100;
00426                     } 
00427                 | '*' 
00428                     {
00429                     postSig("*");
00430                     $<integer>$ = 300;
00431                     } 
00432                 | '&' type_indirection
00433                     {
00434                     $<integer>$ = 100 + $<integer>2;
00435                     }
00436                 | '*' type_indirection 
00437                     {
00438                     $<integer>$ = 400 + $<integer>2;
00439                     };
00440 
00441 type_red2: UNSIGNED 
00442              {
00443              postSig("unsigned ");
00444              } 
00445            type_primitive
00446              {
00447              $<integer>$ = 10 + $<integer>3;
00448              } 
00449          | type_primitive 
00450              {
00451              $<integer>$ = $<integer>1;
00452              };
00453 
00454 type_primitive: 
00455            FLOAT
00456              {
00457              postSig("float ");
00458              $<integer>$ = 1;
00459              }
00460          | VOID
00461              {
00462              postSig("void ");
00463              $<integer>$ = 2;
00464              }
00465          | CHAR  
00466              {
00467              postSig("char ");
00468              $<integer>$ = 3;
00469              }
00470          | INT    
00471              {
00472              postSig("int ");
00473              $<integer>$ = 4;
00474              } 
00475          | SHORT
00476              {
00477              postSig("short ");
00478              $<integer>$ = 5;
00479              }
00480          | LONG  
00481              {
00482              postSig("long ");
00483              $<integer>$ = 6;
00484              }
00485          | DOUBLE 
00486              {
00487              postSig("double ");
00488              $<integer>$ = 7;
00489              }
00490          | ID 
00491              {       
00492              char ctmpid[2048];
00493              sprintf(ctmpid, "%s ", $<str>1);
00494              postSig(ctmpid);
00495              $<integer>$ = 8;
00496              }
00497          | VTK_ID  
00498              { 
00499              char ctmpid[2048];
00500              sprintf(ctmpid, "%s ", $<str>1);
00501              postSig(ctmpid);
00502              $<integer>$ = 9; 
00503              currentFunction->ArgClasses[currentFunction->NumberOfArguments] =
00504              strdup($1); 
00505             /* store the string into the return value just in case we need it */
00506             /* this is a parsing hack because the first "type" parser will */
00507             /* possibly be the return type of the first argument */
00508              if ((!currentFunction->ReturnClass) && 
00509                  (!currentFunction->NumberOfArguments)) 
00510                { 
00511                currentFunction->ReturnClass = strdup($1); 
00512                }
00513              };
00514 
00515 optional_scope: | ':' scope_list;
00516 
00517 scope_list: scope_type VTK_ID 
00518               { 
00519               data.SuperClasses[data.NumberOfSuperClasses] = strdup($2); 
00520               data.NumberOfSuperClasses++; 
00521               } 
00522           | scope_type VTK_ID 
00523               { 
00524               data.SuperClasses[data.NumberOfSuperClasses] = strdup($2); 
00525               data.NumberOfSuperClasses++; 
00526               } ',' scope_list;
00527 
00528 scope_type: PUBLIC
00529               {
00530               in_public = 1;
00531               in_protected = 0;
00532               } 
00533           | PRIVATE 
00534               {
00535               in_public = 0;
00536               in_protected = 0;
00537               } 
00538           | PROTECTED 
00539               {
00540               in_public = 0;
00541               in_protected = 1;
00542               };
00543 
00544 float_num: '-' float_prim | float_prim;
00545 
00546 float_prim: NUM 
00547               {
00548               $<integer>$ = $1;
00549               } 
00550           | NUM '.' NUM 
00551               {
00552               $<integer>$ = -1;
00553               }
00554           | any_id 
00555               {
00556               $<integer>$ = -1;
00557               };
00558 
00559 macro:
00560   SetMacro '(' any_id ',' 
00561              {
00562              preSig("void Set");
00563              postSig(" ("); 
00564              }
00565            type_red2 ')'
00566              {
00567              postSig(");");
00568              sprintf(temps, "Set%s", $<str>3); 
00569              currentFunction->Name = strdup(temps);
00570              currentFunction->NumberOfArguments = 1;
00571              currentFunction->ArgTypes[0] = $<integer>6;
00572              currentFunction->ArgCounts[0] = 0;
00573              currentFunction->ReturnType = 2;
00574              output_function();
00575              }
00576          | GetMacro '('
00577              {
00578              postSig("Get");
00579              }
00580            any_id ',' 
00581              {
00582              postSig(" ();");
00583              invertSig = 1;
00584              } 
00585            type_red2 ')'
00586              { 
00587              sprintf(temps, "Get%s", $<str>4); 
00588              currentFunction->Name = strdup(temps);
00589              currentFunction->NumberOfArguments = 0;
00590              currentFunction->ReturnType = $<integer>7;
00591              output_function();
00592              }
00593          | SetStringMacro '(' 
00594              {
00595              preSig("void Set");
00596              }
00597            any_id ')'
00598              {
00599              postSig(" (char *);"); 
00600              sprintf(temps, "Set%s", $<str>4); 
00601              currentFunction->Name = strdup(temps);
00602              currentFunction->NumberOfArguments = 1;
00603              currentFunction->ArgTypes[0] = 303;
00604              currentFunction->ArgCounts[0] = 0;
00605              currentFunction->ReturnType = 2;
00606              output_function();
00607              }
00608          | GetStringMacro '(' 
00609              {
00610              preSig("char *Get");
00611              }
00612            any_id ')'
00613              { 
00614              postSig(" ();");
00615              sprintf(temps, "Get%s", $<str>4); 
00616              currentFunction->Name = strdup(temps);
00617              currentFunction->NumberOfArguments = 0;
00618              currentFunction->ReturnType = 303;
00619              output_function();
00620              }
00621          | SetClampMacro  '(' any_id ',' 
00622              {
00623              preSig("void Set");
00624              postSig(" ("); 
00625              }
00626            type_red2 
00627              {
00628              postSig(");");
00629              openSig = 0;
00630              }
00631            ',' maybe_other_no_semi ')'
00632              { 
00633              sprintf(temps, "Set%s", $<str>3); 
00634              currentFunction->Name = strdup(temps);
00635              currentFunction->NumberOfArguments = 1;
00636              currentFunction->ArgTypes[0] = $<integer>6;
00637              currentFunction->ArgCounts[0] = 0;
00638              currentFunction->ReturnType = 2;
00639              output_function();
00640              }
00641          | SetObjectMacro '(' any_id ',' 
00642              {
00643              preSig("void Set");
00644              postSig(" ("); 
00645              }
00646            type_red2 ')'
00647              { 
00648              postSig("*);");
00649              sprintf(temps, "Set%s", $<str>3); 
00650              currentFunction->Name = strdup(temps);
00651              currentFunction->NumberOfArguments = 1;
00652              currentFunction->ArgTypes[0] = 309;
00653              currentFunction->ArgCounts[0] = 1;
00654              currentFunction->ReturnType = 2;
00655              output_function();
00656              }
00657          | SetReferenceCountedObjectMacro '(' any_id ','   
00658              {
00659              preSig("void Set");
00660              postSig(" (");
00661              }
00662            type_red2 ')'
00663              { 
00664              postSig("*);");
00665              sprintf(temps, "Set%s", $<str>3); 
00666              currentFunction->Name = strdup(temps);
00667              currentFunction->NumberOfArguments = 1;
00668              currentFunction->ArgTypes[0] = 309;
00669              currentFunction->ArgCounts[0] = 1;
00670              currentFunction->ReturnType = 2;
00671              output_function();
00672              }
00673          | GetObjectMacro '(' 
00674              {
00675              postSig("*Get");
00676              }
00677            any_id ',' 
00678              {
00679              postSig(" ();")
00680              ; invertSig = 1;
00681              }
00682            type_red2 ')'
00683              { 
00684              sprintf(temps, "Get%s", $<str>4); 
00685              currentFunction->Name = strdup(temps);
00686              currentFunction->NumberOfArguments = 0;
00687              currentFunction->ReturnType = 309;
00688              output_function();
00689              }
00690          | BooleanMacro '(' any_id 
00691              {
00692              preSig("void ");
00693              postSig("On ();");
00694              openSig = 0;
00695              } 
00696         ',' type_red2 ')'
00697              { 
00698              sprintf(temps, "%sOn", $<str>3); 
00699              currentFunction->Name = strdup(temps);
00700              currentFunction->NumberOfArguments = 0;
00701              currentFunction->ReturnType = 2;
00702              output_function();
00703              currentFunction->Signature = (char *)malloc(2048);
00704              sigAllocatedLength = 2048;
00705              sprintf(currentFunction->Signature, "void %sOff ();", $<str>3); 
00706              sprintf(temps, "%sOff", $<str>3); 
00707              currentFunction->Name = strdup(temps);
00708              currentFunction->NumberOfArguments = 0;
00709              output_function();
00710              }
00711          | SetVector2Macro '(' any_id ',' 
00712              {
00713              free(currentFunction->Signature);
00714              currentFunction->Signature = NULL;
00715              } 
00716            type_red2 ')'
00717              { 
00718              char *local = strdup(currentFunction->Signature);
00719              sprintf(currentFunction->Signature,
00720                      "void Set%s (%s, %s);",
00721                      $<str>3,
00722                      local,
00723                      local);
00724              sprintf(temps, "Set%s", $<str>3); 
00725              currentFunction->Name = strdup(temps);
00726              currentFunction->NumberOfArguments = 2;
00727              currentFunction->ArgTypes[0] = $<integer>6;
00728              currentFunction->ArgCounts[0] = 0;
00729              currentFunction->ArgTypes[1] = $<integer>6;
00730              currentFunction->ArgCounts[1] = 0;
00731              currentFunction->ReturnType = 2;
00732              output_function();
00733 
00734              currentFunction->Signature = (char *)malloc(2048);
00735              sigAllocatedLength = 2048;
00736              sprintf(currentFunction->Signature,
00737                      "void Set%s (%s a[2]);",
00738                      $<str>3,
00739                      local);
00740              currentFunction->Name = strdup(temps);
00741              currentFunction->NumberOfArguments = 1;
00742              currentFunction->ArgTypes[0] = 300 + $<integer>6;
00743              currentFunction->ArgCounts[0] = 2;
00744              output_function();
00745              }
00746          | GetVector2Macro  '(' any_id ',' 
00747              {
00748              free(currentFunction->Signature);
00749              currentFunction->Signature = NULL;
00750              } 
00751            type_red2 ')'
00752              { 
00753              char *local = strdup(currentFunction->Signature);
00754              sprintf(currentFunction->Signature,
00755                      "%s *Get%s ();",
00756                      local,
00757                      $<str>3);
00758              sprintf(temps, "Get%s", $<str>3); 
00759              currentFunction->Name = strdup(temps);
00760              currentFunction->NumberOfArguments = 0;
00761              currentFunction->ReturnType = 300 + $<integer>6;
00762              currentFunction->HaveHint = 1;
00763              currentFunction->HintSize = 2;
00764              output_function();
00765              }
00766          | SetVector3Macro '(' any_id ',' 
00767              {
00768              free(currentFunction->Signature);
00769              currentFunction->Signature = NULL;
00770              } 
00771            type_red2 ')'
00772              { 
00773              char *local = strdup(currentFunction->Signature);
00774              sprintf(currentFunction->Signature,
00775                      "void Set%s (%s, %s, %s);",
00776                      $<str>3,
00777                      local,
00778                      local,
00779                      local);
00780              sprintf(temps, "Set%s", $<str>3); 
00781              currentFunction->Name = strdup(temps);
00782              currentFunction->NumberOfArguments = 3;
00783              currentFunction->ArgTypes[0] = $<integer>6;
00784              currentFunction->ArgCounts[0] = 0;
00785              currentFunction->ArgTypes[1] = $<integer>6;
00786              currentFunction->ArgCounts[1] = 0;
00787              currentFunction->ArgTypes[2] = $<integer>6;
00788              currentFunction->ArgCounts[2] = 0;
00789              currentFunction->ReturnType = 2;
00790              output_function();
00791 
00792              currentFunction->Signature = (char *)malloc(2048);
00793              sigAllocatedLength = 2048;
00794              sprintf(currentFunction->Signature,
00795                      "void Set%s (%s a[3]);",
00796                      $<str>3,
00797                      local);
00798              currentFunction->Name = strdup(temps);
00799              currentFunction->NumberOfArguments = 1;
00800              currentFunction->ArgTypes[0] = 300 + $<integer>6;
00801              currentFunction->ArgCounts[0] = 3;
00802              output_function();
00803              }
00804          | GetVector3Macro  '(' any_id ','
00805              {
00806              free (currentFunction->Signature);
00807              currentFunction->Signature = NULL;
00808              } 
00809            type_red2 ')'
00810              { 
00811              char *local = strdup(currentFunction->Signature);
00812              sprintf(currentFunction->Signature,
00813                      "%s *Get%s ();",
00814                      local,
00815                      $<str>3);
00816              sprintf(temps, "Get%s", $<str>3); 
00817              currentFunction->Name = strdup(temps);
00818              currentFunction->NumberOfArguments = 0;
00819              currentFunction->ReturnType = 300 + $<integer>6;
00820              currentFunction->HaveHint = 1;
00821              currentFunction->HintSize = 3;
00822              output_function();
00823              }
00824          | SetVector4Macro '(' any_id ',' 
00825              {
00826              free(currentFunction->Signature);
00827              currentFunction->Signature = NULL;
00828              } 
00829            type_red2 ')'
00830              { 
00831              char *local = strdup(currentFunction->Signature);
00832              sprintf(currentFunction->Signature,
00833                      "void Set%s (%s, %s, %s, %s);",
00834                      $<str>3,
00835                      local,
00836                      local,
00837                      local,
00838                      local);
00839              sprintf(temps, "Set%s", $<str>3); 
00840              currentFunction->Name = strdup(temps);
00841              currentFunction->NumberOfArguments = 4;
00842              currentFunction->ArgTypes[0] = $<integer>6;
00843              currentFunction->ArgCounts[0] = 0;
00844              currentFunction->ArgTypes[1] = $<integer>6;
00845              currentFunction->ArgCounts[1] = 0;
00846              currentFunction->ArgTypes[2] = $<integer>6;
00847              currentFunction->ArgCounts[2] = 0;
00848              currentFunction->ArgTypes[3] = $<integer>6;
00849              currentFunction->ArgCounts[3] = 0;
00850              currentFunction->ReturnType = 2;
00851              output_function();
00852 
00853              currentFunction->Signature = (char *)malloc(2048);
00854              sigAllocatedLength = 2048;
00855              sprintf(currentFunction->Signature,
00856                      "void Set%s (%s a[4]);",
00857                      $<str>3,
00858                      local);
00859              currentFunction->Name = strdup(temps);
00860              currentFunction->NumberOfArguments = 1;
00861              currentFunction->ArgTypes[0] = 300 + $<integer>6;
00862              currentFunction->ArgCounts[0] = 4;
00863              output_function();
00864              }
00865          | GetVector4Macro  '(' any_id ','
00866              {
00867              free(currentFunction->Signature);
00868              currentFunction->Signature = NULL;
00869              } 
00870            type_red2 ')'
00871              { 
00872              char *local = strdup(currentFunction->Signature);
00873              sprintf(currentFunction->Signature,
00874                      "%s *Get%s ();",
00875                      local,
00876                      $<str>3);
00877              sprintf(temps, "Get%s", $<str>3); 
00878              currentFunction->Name = strdup(temps);
00879              currentFunction->NumberOfArguments = 0;
00880              currentFunction->ReturnType = 300 + $<integer>6;
00881              currentFunction->HaveHint = 1;
00882              currentFunction->HintSize = 4;
00883              output_function();
00884              }
00885          | SetVector6Macro '(' any_id ','
00886              {
00887              free(currentFunction->Signature);
00888              currentFunction->Signature = NULL;
00889              } 
00890            type_red2 ')'
00891              { 
00892              char *local = strdup(currentFunction->Signature);
00893              sprintf(currentFunction->Signature,
00894                      "void Set%s (%s, %s, %s, %s, %s, %s);",
00895                      $<str>3,
00896                      local,
00897                      local,
00898                      local,
00899                      local,
00900                      local,
00901                      local);
00902              sprintf(temps, "Set%s", $<str>3); 
00903              currentFunction->Name = strdup(temps);
00904              currentFunction->NumberOfArguments = 6;
00905              currentFunction->ArgTypes[0] = $<integer>6;
00906              currentFunction->ArgCounts[0] = 0;
00907              currentFunction->ArgTypes[1] = $<integer>6;
00908              currentFunction->ArgCounts[1] = 0;
00909              currentFunction->ArgTypes[2] = $<integer>6;
00910              currentFunction->ArgCounts[2] = 0;
00911              currentFunction->ArgTypes[3] = $<integer>6;
00912              currentFunction->ArgCounts[3] = 0;
00913              currentFunction->ArgTypes[4] = $<integer>6;
00914              currentFunction->ArgCounts[4] = 0;
00915              currentFunction->ArgTypes[5] = $<integer>6;
00916              currentFunction->ArgCounts[5] = 0;
00917              currentFunction->ReturnType = 2;
00918              output_function();
00919 
00920              currentFunction->Signature = (char *)malloc(2048);
00921              sigAllocatedLength = 2048;
00922              sprintf(currentFunction->Signature,
00923                      "void Set%s (%s a[6]);",
00924                      $<str>3,
00925                      local);
00926              currentFunction->Name = strdup(temps);
00927              currentFunction->NumberOfArguments = 1;
00928              currentFunction->ArgTypes[0] = 300 + $<integer>6;
00929              currentFunction->ArgCounts[0] = 6;
00930              output_function();
00931              }
00932          | GetVector6Macro  '(' any_id ','
00933              {
00934              free(currentFunction->Signature);
00935              currentFunction->Signature = NULL;
00936              } 
00937            type_red2 ')'
00938              { 
00939              char *local = strdup(currentFunction->Signature);
00940              sprintf(currentFunction->Signature,
00941                      "%s *Get%s ();",
00942                      local,
00943                      $<str>3);
00944              sprintf(temps, "Get%s", $<str>3); 
00945              currentFunction->Name = strdup(temps);
00946              currentFunction->NumberOfArguments = 0;
00947              currentFunction->ReturnType = 300 + $<integer>6;
00948              currentFunction->HaveHint = 1;
00949              currentFunction->HintSize = 6;
00950              output_function();
00951              }
00952          | SetVectorMacro  '(' any_id ',' 
00953              {
00954              free(currentFunction->Signature);
00955              currentFunction->Signature = NULL;
00956              } 
00957            type_red2 ',' float_num ')'
00958              {
00959              char *local = strdup(currentFunction->Signature);
00960              sprintf(currentFunction->Signature,
00961                      "void Set%s (%s [%i]);",
00962                      $<str>3,
00963                      local,
00964                      $<integer>8);
00965              sprintf(temps, "Set%s", $<str>3); 
00966              currentFunction->Name = strdup(temps);
00967              currentFunction->ReturnType = 2;
00968              currentFunction->NumberOfArguments = 1;
00969              currentFunction->ArgTypes[0] = 300 + $<integer>6;
00970              currentFunction->ArgCounts[0] = $<integer>8;
00971              output_function();
00972              }
00973          | GetVectorMacro  '(' any_id ',' 
00974              {
00975              free(currentFunction->Signature);
00976              currentFunction->Signature = NULL;
00977              } 
00978            type_red2 ',' float_num ')'
00979              { 
00980              char *local = strdup(currentFunction->Signature);
00981              sprintf(currentFunction->Signature,
00982                      "%s *Get%s ();",
00983                      local,
00984                      $<str>3);
00985              sprintf(temps,"Get%s",$<str>3); 
00986              currentFunction->Name = strdup(temps);
00987              currentFunction->NumberOfArguments = 0;
00988              currentFunction->ReturnType = 300 + $<integer>6;
00989              currentFunction->HaveHint = 1;
00990              currentFunction->HintSize = $<integer>8;
00991              output_function();
00992              }
00993          | ViewportCoordinateMacro '(' any_id ')'
00994              { 
00995              char *local = strdup(currentFunction->Signature);
00996              sprintf(currentFunction->Signature,
00997                      "vtkCoordinate *Get%sCoordinate ();",
00998                      $<str>3);
00999 
01000              sprintf(temps,
01001                      "Get%sCoordinate",
01002                      $<str>3); 
01003              currentFunction->Name = strdup(temps);
01004              currentFunction->NumberOfArguments = 0;
01005              currentFunction->ReturnType = 309;
01006              currentFunction->ReturnClass = strdup("vtkCoordinate");
01007              output_function();
01008 
01009              currentFunction->Signature = (char *)malloc(2048);
01010              sigAllocatedLength = 2048;
01011              sprintf(currentFunction->Signature,
01012                      "void Set%s (float, float);",
01013                      $<str>3);
01014              sprintf(temps, "Set%s", $<str>3); 
01015              currentFunction->Name = strdup(temps);
01016              currentFunction->NumberOfArguments = 2;
01017              currentFunction->ArgTypes[0] = 1;
01018              currentFunction->ArgCounts[0] = 0;
01019              currentFunction->ArgTypes[1] = 1;
01020              currentFunction->ArgCounts[1] = 0;
01021              currentFunction->ReturnType = 2;
01022              output_function();
01023 
01024              currentFunction->Signature = (char *)malloc(2048);
01025              sigAllocatedLength = 2048;
01026              sprintf(currentFunction->Signature,
01027                      "void Set%s (float a[2]);",
01028                      $<str>3);
01029              currentFunction->Name = strdup(temps);
01030              currentFunction->NumberOfArguments = 1;
01031              currentFunction->ArgTypes[0] = 301;
01032              currentFunction->ArgCounts[0] = 2;
01033              output_function();
01034      
01035              currentFunction->Signature = (char *)malloc(2048);
01036              sigAllocatedLength = 2048;
01037              sprintf(currentFunction->Signature,
01038                      "float *Get%s ();",
01039                      $<str>3);
01040              sprintf(temps,"Get%s",$<str>3); 
01041              currentFunction->Name = strdup(temps);
01042              currentFunction->NumberOfArguments = 0;
01043              currentFunction->ReturnType = 301;
01044              currentFunction->HaveHint = 1;
01045              currentFunction->HintSize = 2;
01046              output_function();
01047              }
01048          | WorldCoordinateMacro '(' any_id ')'
01049              { 
01050              char *local = strdup(currentFunction->Signature);
01051              sprintf(currentFunction->Signature,
01052                      "vtkCoordinate *Get%sCoordinate ();",
01053                      $<str>3);
01054 
01055              sprintf(temps,
01056                      "Get%sCoordinate",
01057                      $<str>3); 
01058              currentFunction->Name = strdup(temps);
01059              currentFunction->NumberOfArguments = 0;
01060              currentFunction->ReturnType = 309;
01061              currentFunction->ReturnClass = strdup("vtkCoordinate");
01062              output_function();
01063 
01064              currentFunction->Signature = (char *)malloc(2048);
01065              sigAllocatedLength = 2048;
01066              sprintf(currentFunction->Signature,
01067                      "void Set%s (float, float, float);",
01068                      $<str>3);
01069              sprintf(temps, "Set%s", $<str>3); 
01070              currentFunction->Name = strdup(temps);
01071              currentFunction->NumberOfArguments = 3;
01072              currentFunction->ArgTypes[0] = 1;
01073              currentFunction->ArgCounts[0] = 0;
01074              currentFunction->ArgTypes[1] = 1;
01075              currentFunction->ArgCounts[1] = 0;
01076              currentFunction->ArgTypes[2] = 1;
01077              currentFunction->ArgCounts[2] = 0;
01078              currentFunction->ReturnType = 2;
01079              output_function();
01080 
01081              currentFunction->Signature = (char *)malloc(2048);
01082              sigAllocatedLength = 2048;
01083              sprintf(currentFunction->Signature,
01084                      "void Set%s (float a[3]);",
01085                      $<str>3);
01086              currentFunction->Name = strdup(temps);
01087              currentFunction->NumberOfArguments = 1;
01088              currentFunction->ArgTypes[0] = 301;
01089              currentFunction->ArgCounts[0] = 3;
01090              output_function();
01091      
01092              currentFunction->Signature = (char *)malloc(2048);
01093              sigAllocatedLength = 2048;
01094              sprintf(currentFunction->Signature,"float *Get%s ();", $<str>3);
01095              sprintf(temps, "Get%s", $<str>3); 
01096              currentFunction->Name = strdup(temps);
01097              currentFunction->NumberOfArguments = 0;
01098              currentFunction->ReturnType = 301;
01099              currentFunction->HaveHint = 1;
01100              currentFunction->HintSize = 3;
01101              output_function();
01102              }
01103          | TypeMacro '(' any_id ',' any_id ')'
01104              { 
01105              currentFunction->Signature = (char *)malloc(2048);
01106              sigAllocatedLength = 2048;
01107              sprintf(currentFunction->Signature,
01108                      "const char *GetClassName ();");
01109              sprintf(temps, "GetClassName"); 
01110              currentFunction->Name = strdup(temps);
01111              currentFunction->NumberOfArguments = 0;
01112              currentFunction->ReturnType = 1303;
01113              output_function();
01114 
01115              currentFunction->Signature = (char *)malloc(2048);
01116              sigAllocatedLength = 2048;
01117              sprintf(currentFunction->Signature,
01118                      "int IsA (const char *name);");
01119              sprintf(temps, "IsA"); 
01120              currentFunction->Name = strdup(temps);
01121              currentFunction->NumberOfArguments = 1;
01122              currentFunction->ArgTypes[0] = 1303;
01123              currentFunction->ArgCounts[0] = 0;
01124              currentFunction->ReturnType = 4;
01125              output_function();
01126              }
01127            ;
01128 
01129 /*
01130  * These just eat up misc garbage
01131  */
01132 maybe_other : | other_stuff maybe_other;
01133 maybe_other_no_semi : | other_stuff_no_semi maybe_other_no_semi;
01134 
01135 other_stuff : ';' | other_stuff_no_semi;
01136 
01137 other_stuff_no_semi : OTHER
01138                     | braces
01139                     | parens
01140                     | '*'
01141                     | '='
01142                     | ':'
01143                     | ','
01144                     | '.'
01145                     | STRING
01146                     | type_red2
01147                     | NUM
01148                     | CLASS_REF
01149                     | '&'
01150                     | brackets
01151                     | CONST 
01152                     | OPERATOR
01153                     | '-'
01154                     | '~'
01155                     | STATIC
01156                     | ARRAY_NUM
01157                     ;
01158 
01159 braces: '{' maybe_other '}';
01160 parens: '(' maybe_other ')';
01161 brackets: '[' maybe_other ']';
01162 
01163 %%
01164 #include <string.h>
01165 #include <unistd.h>
01166 // #include "ssParse.lex.c"
01167 
01168 extern FILE *yyin, *yyout;
01169 
01170 /* initialize the structure */
01171 void InitFunction(FunctionInfo *func)
01172   {
01173   func->Name = NULL;
01174   func->NumberOfArguments = 0;
01175   func->ArrayFailure = 0;
01176   func->IsPureVirtual = 0;
01177   func->IsPublic = 0;
01178   func->IsOperator = 0;
01179   func->HaveHint = 0;
01180   func->HintSize = 0;
01181   func->ReturnType = 2;
01182   func->ReturnClass = NULL;
01183   func->Comment = NULL;
01184   func->Signature = NULL;
01185   sigAllocatedLength = 0;
01186   openSig = 1;
01187   invertSig = 0;
01188   }
01189 
01190 /* when the cpp file doesn't have enough info use the hint file */
01191 void look_for_hint()
01192   {
01193   char h_cls[80];
01194   char h_func[80];
01195   int  h_type;
01196   int  h_value;
01197 
01198   /* reset the position */
01199   rewind(fhint);
01200 
01201   /* first find a hint */
01202   while (fscanf(fhint, "%s %s %i %i", h_cls, h_func, &h_type, &h_value) != EOF)
01203     {
01204     if ((!strcmp(h_cls, data.ClassName))         &&
01205         currentFunction->Name                    &&
01206         (!strcmp(h_func, currentFunction->Name)) &&
01207         (h_type == currentFunction->ReturnType))
01208       {
01209       currentFunction->HaveHint = 1;
01210       currentFunction->HintSize = h_value;
01211       }
01212     }
01213   }
01214 
01215 /* a simple routine that updates a few variables */
01216 void output_function()
01217   {
01218   /* a void argument is the same as no arguements */
01219   if (currentFunction->ArgTypes[0] % 1000 == 2) 
01220     {
01221     currentFunction->NumberOfArguments = 0;
01222     }
01223 
01224   currentFunction->IsPublic = in_public;
01225   currentFunction->IsProtected = in_protected;
01226   
01227   /* look for VAR FUNCTIONS */
01228   if (currentFunction->NumberOfArguments &&
01229       (currentFunction->ArgTypes[0] == 5000))
01230     {
01231     if (currentFunction->NumberOfArguments == 2)
01232       {
01233       currentFunction->NumberOfArguments = 1;
01234       }
01235     else
01236       {
01237       currentFunction->ArrayFailure = 1;
01238       }
01239     }
01240   
01241   /* is it a delete function */
01242   if (currentFunction->Name && !strcmp("Delete",currentFunction->Name))
01243     {
01244     data.HasDelete = 1;
01245     }
01246 
01247 
01248   /* if we need a return type hint and dont currently have one */
01249   /* then try to find one */
01250   if (!currentFunction->HaveHint)
01251     {
01252     switch (currentFunction->ReturnType%1000)
01253       {
01254       case 301: case 302: case 307:
01255       case 304: case 305: case 306: case 313:
01256         look_for_hint();
01257   break;
01258       }
01259     }
01260 
01261   if (HaveComment)
01262     {
01263     currentFunction->Comment = strdup(CommentText);
01264     }
01265   
01266   data.NumberOfFunctions++;
01267   currentFunction = data.Functions + data.NumberOfFunctions;
01268   InitFunction(currentFunction);
01269   }
01270 
01271 extern void vtkParseOutput(FILE *,FileInfo *);
01272 
01273 /*----------------------------------------------------------------------------*/
01274 int main(int argc,char *argv[])
01275   {
01276   FILE *fin, *fout;
01277   int ret;
01278   int c;
01279   char *inputfilename = NULL, *outputfilename = NULL;
01280   
01281   yydebug = 0;
01282 
01283   data.IsConcrete = 1;
01284   data.IsAbstract = 0;
01285   data.Package = "";
01286   data.FileName = "";
01287   while ((c = getopt(argc, argv, "dhv:i:p:c:w:")) != -1)
01288     {
01289     switch (c)
01290       {
01291       case 'h':
01292         fprintf(stderr, "Invocation:\n");
01293         fprintf(stderr,
01294                 "%s [-i hintfile] [-v 1|0] [-p package] [-c inputheader] [-w output]",
01295                 argv[0]);
01296         break;
01297       case 'v':
01298         data.IsConcrete = atoi(optarg);
01299         break;
01300       case 'i':
01301         if (!(fhint = fopen(optarg, "r")))
01302           {
01303           fprintf(stderr, "Error opening hint file %s\n", optarg);
01304           exit(1);
01305           }
01306         break;  
01307       case 'p':
01308         data.Package = optarg;
01309         break;
01310       case 'd':
01311         yydebug = 1;
01312         break;
01313       case 'c':   // The name of the input C header file.
01314         inputfilename = optarg;
01315         break;
01316       case 'w':   // The name of the output C wrap file.  
01317         outputfilename = optarg;
01318         break;
01319       }
01320     }
01321   
01322   if (outputfilename != NULL)
01323     {
01324     if (!(fout = fopen(outputfilename, "w")))
01325       {
01326       fprintf(stderr, "Error opening output file %s\n", outputfilename);
01327       exit(1);
01328       }
01329     }  
01330   else
01331     {
01332     fprintf(stderr, "No output file specified\n");
01333     exit(1);
01334     }
01335 
01336   if (inputfilename != NULL)
01337     {
01338     if (!(fin = fopen(inputfilename, "r")))
01339       {
01340       fprintf(stderr, "Error opening input file %s\n", inputfilename);
01341       exit(1);
01342       }
01343     data.FileName = inputfilename;  
01344     }  
01345   else
01346     {
01347     fprintf(stderr, "No input file specified\n");
01348     exit(1);
01349     }
01350 
01351   data.NameComment = NULL;
01352   data.Description = NULL;
01353   data.Caveats = NULL;
01354   data.SeeAlso = NULL;
01355   CommentState = 0;
01356 
01357   currentFunction = data.Functions;
01358   InitFunction(currentFunction);
01359   
01360   yyin = fin;
01361   yyout = stdout;
01362   ret = yyparse();
01363   if (ret)
01364     {
01365     fprintf(stdout,
01366             "*** SYNTAX ERROR found in parsing the header file %s ***\n", 
01367             inputfilename);
01368     return ret;
01369     }
01370   vtkParseOutput(fout, &data);
01371   return 0;
01372   }
01373 
01374 /*----------------------------------------------------------------------------*/
01375 void yyerror (char *s)
01376   {
01377   fprintf (stderr, "%s\n", s);
01378   }
01379 
01380 /*
01381  * $Log: ssParse.y,v $
01382  * Revision 1.11  2004/07/14 10:01:26  pfb
01383  * Cosmetic changes.
01384  *
01385  * Revision 1.10  2004/02/07 19:01:09  pfb
01386  * Require that class_def: parse a VTK_ID (it was this way some time in the
01387  * past).
01388  *
01389  * Revision 1.9  2004/02/05 14:22:07  pfb
01390  * More re-formating.
01391  *
01392  * Revision 1.8  2004/02/05 11:37:00  pfb
01393  * Re-formatted.
01394  *
01395  * Revision 1.7  2004/01/27 16:18:38  pfb
01396  * Modified to that ssParse.y and ssParse.l link together (as opposed to
01397  * include).
01398  *
01399  * Revision 1.6  2002/10/15 08:01:37  pfb
01400  * Change p/o to reflect oure virtual functions.
01401  *
01402  * Revision 1.5  2002/08/26 08:14:36  pfb
01403  * Added input and output filenames etc.
01404  *
01405  * Revision 1.4  2002/04/21 14:42:43  pfb
01406  * Added debug output.
01407  *
01408  * Revision 1.3  2001/07/17 15:43:40  pfb
01409  * Cleanup.
01410  *
01411  * Revision 1.2  2001/07/16 13:27:17  pfb
01412  * First pass.
01413  *
01414  * Revision 1.1  2001/07/12 15:32:34  pfb
01415  * Initial rev.
01416  *
01417  *
01418  */