Changeset 254


Ignore:
Timestamp:
Mar 12, 2007, 10:37:06 PM (18 years ago)
Author:
cinc
Message:

More method parameter checking. Cleaned up some of the mess from yesterday.

Location:
trunk/ORBit2-2.14.0/src/idl-compiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ORBit2-2.14.0/src/idl-compiler/orbit-idl-c-headers.c

    r253 r254  
    166166    break;
    167167  }
    168 
    169168}
    170169
     
    671670  return ptr2;
    672671};
     672
    673673/*
    674674  This functions puts constants into the header file. For Voyager we
     
    688688        id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
    689689
     690    /* Enable parameter check for a method. This is done by putting a #define xxx
     691       at the top of the file. Checking code is sourrounded by #ifdef/#endif. */
    690692    ptr=strstr( id , NOM_PARMCHECK_STRING);
    691     /* Enable parameter check for a method */
    692693    if(ptr)
    693694      {
     
    696697        //printf(" %d    --- > %s %s Params: %s\n",
    697698        //__LINE__, id, IDL_IDENT(ident).str, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value);
     699        /* Print out the line for easy finding in this source file */
    698700        fprintf(ci->fh, "/* %s: %s line %d */\n", __FILE__, __FUNCTION__, __LINE__);
    699701        fprintf(ci->fh, "/* Value: %s */\n", IDL_STRING(IDL_CONST_DCL(tree).const_exp).value);
     702        /* Protect by #ifdef...*/
    700703        fprintf(ci->fh, "#ifndef %s_ParmCheck_h\n", id);
    701704        fprintf(ci->fh, "#define %s_ParmCheck_h\n", id);
     705        /* Default return code (provided by the macro) */
    702706        retVal=VoyagerExtractRetValFromParmCheck(IDL_STRING(IDL_CONST_DCL(tree).const_exp).value);
    703707        fprintf(ci->fh, "#define %s_retval %s\n", id, retVal);
     
    723727      }
    724728
     729    /* Get the name of our explicit metaclass if any. */
    725730    if(IDLN_STRING==IDL_NODE_TYPE(IDL_CONST_DCL(tree).const_exp))
    726731      {
    727         /* Get the name of our explicit metaclass if any */
    728732        /* Our metaclass info is a string */
    729733        if(strstr( IDL_IDENT(ident).str, NOM_METACLASS_STRING))
     
    731735            gsMetaClassName=g_string_new(NULL);
    732736            g_string_printf(gsMetaClassName, "%s", IDL_STRING(IDL_CONST_DCL(tree).const_exp).value);
    733             //    printf(" %d    --- > %s %s (%x)\n",
    734             //     __LINE__, id, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value, gsMetaClassName[ulCurInterface]);
     737            //printf(" %d    --- > %s %s (%x)\n",
     738            //__LINE__, id, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value, gsMetaClassName[ulCurInterface]);
    735739          }
    736740       }
     
    11561160          IDL_tree  sub;
    11571161
    1158           //fprintf(ioi->of, "#define %s_%s() \\\n        %s_%s()\n",
    1159           //      realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
    1160           //      id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
    11611162          fprintf(ioi->of, "#define %s_%s(nomSelf, ",
    11621163                  realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
     
    11851186}
    11861187
     1188/*
     1189  Output the typespecs and parameters of a new method.
     1190  Note that tree must be correctly chosen.
     1191 */
     1192static void
     1193doWriteTypespecAndParameters(FILE  *of, IDL_tree tree)
     1194{
     1195  IDL_tree curitem;
     1196
     1197  for(curitem = IDL_OP_DCL(tree).parameter_dcls;
     1198      curitem; curitem = IDL_LIST(curitem).next) {
     1199    IDL_tree tr;
     1200    tr = IDL_LIST(curitem).data;     
     1201    /*  Write list of params */
     1202    if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
     1203      {
     1204        fprintf(of, "        ");
     1205        orbit_cbe_write_param_typespec(of, tr);
     1206        fprintf(of, " %s,\n", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
     1207      }
     1208  }
     1209}
     1210
     1211/*
     1212  Output the parameters only of a new method.
     1213  Note that tree must be correctly chosen.
     1214 */
     1215static void
     1216doWriteParametersOnly(FILE  *of, IDL_tree tree)
     1217{
     1218  IDL_tree curitem;
     1219
     1220  for(curitem = IDL_OP_DCL(tree).parameter_dcls;
     1221      curitem; curitem = IDL_LIST(curitem).next) {
     1222    IDL_tree tr;
     1223    tr = IDL_LIST(curitem).data;     
     1224    /*  Write list of params */
     1225    if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
     1226      {
     1227        fprintf(of, " %s,", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
     1228      }
     1229  }
     1230}
     1231
     1232/*
     1233  This function does quite some real work. It puts all the info about an introduced method
     1234  into the *.h file. This includes convenience macros, strings specifying the method name
     1235  and macros for automatic checking of parameters.
     1236 */
    11871237static void
    11881238VoyagerOutputNewMethod(FILE  *of, IDL_tree tree, const char *nom_prefix)
     
    11951245        IDL_tree curitem, op;
    11961246        int level;
    1197     //  CBESkelImplInfo subski = *ski;
    11981247
    11991248    g_assert (IDL_NODE_TYPE(tree) == IDLN_OP_DCL);
     
    12241273      IDL_tree tr;
    12251274      tr = IDL_LIST(curitem).data;     
    1226       //orbit_cbe_ski_process_piece(&subski);
     1275
    12271276      /*  Write list of params */
    12281277      if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
     
    12541303    fprintf(of, "#define nomMNDef_%s \"%s\"\n", id,  id3);
    12551304    fprintf(of, "#define nomMNFullDef_%s \"%s:%s\"\n", id, id2, id3);
     1305
    12561306    /* define method call as a macro */
    12571307    fprintf(of, "/* define method call as a macro */\n");
    1258     fprintf(of, "#ifdef %s_ParmCheck_h /* Parameter check */\n", id);
    1259     /* Forward declaration */
     1308    fprintf(of, "#ifndef NOM_NO_PARAM_CHECK /* Parameter chack at all? */\n");
     1309    fprintf(of, "#ifdef %s_ParmCheck_h /* Extended parameter check enabled */\n", id);
     1310
     1311    /* Forward declaration of parameter test function */
    12601312    fprintf(of, "NOMEXTERN ");               
    12611313    fprintf(of, "gboolean NOMLINK parmCheckFunc_%s(%s *nomSelf, \n",id, id2);
    1262     op = tree;
    1263     for(curitem = IDL_OP_DCL(tree).parameter_dcls;
    1264         curitem; curitem = IDL_LIST(curitem).next) {
    1265       IDL_tree tr;
    1266       tr = IDL_LIST(curitem).data;     
    1267       /*  Write list of params */
    1268       if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
    1269         {
    1270           fprintf(of, "        ");
    1271           orbit_cbe_write_param_typespec(of, tr);
    1272           fprintf(of, " %s,\n", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
    1273         }
    1274     }
    1275     tree=op;
    1276     fprintf(of, "CORBA_Environment *ev)");
    1277     fprintf(of, ";\n");
    1278 
    1279     /* Macro to be used when parameters are checked */
     1314    /* Write parameter list including the type spec */
     1315    doWriteTypespecAndParameters(of, tree);
     1316    fprintf(of, "CORBA_Environment *ev);\n");
     1317
     1318    /* Macro to be used when several parameters are checked */
    12801319    fprintf(of, "#define %s(nomSelf, ", id);
    12811320    /* add the parms */
    1282     op = tree;
    1283     for(curitem = IDL_OP_DCL(tree).parameter_dcls;
    1284         curitem; curitem = IDL_LIST(curitem).next) {
    1285       IDL_tree tr;
    1286       tr = IDL_LIST(curitem).data;     
    1287       /*  Write list of params */
    1288       if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
    1289         {
    1290           fprintf(of, " %s,", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
    1291         }
    1292     }
    1293     tree=op;
     1321    doWriteParametersOnly(of, tree);
    12941322    fprintf(of, "ev) \\\n");
    12951323    fprintf(of, "        (parmCheckFunc_%s(nomSelf, ", id);
    12961324    /* Parameters for call */
    1297     op = tree;
    1298     for(curitem = IDL_OP_DCL(tree).parameter_dcls;
    1299         curitem; curitem = IDL_LIST(curitem).next) {
    1300       IDL_tree tr;
    1301       tr = IDL_LIST(curitem).data;     
    1302       //orbit_cbe_ski_process_piece(&subski);
    1303       /*  Write list of params */
    1304       if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
    1305         {
    1306           fprintf(of, " %s,", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
    1307         }
    1308     }
    1309     tree=op;
     1325    doWriteParametersOnly(of, tree);
    13101326
    13111327    fprintf(of, "ev) ? \\\n");
    13121328    fprintf(of, "        (NOM_Resolve(nomSelf, %s, %s) \\\n", id2, id3);
    13131329    fprintf(of, "        (nomSelf,");
    1314 
    13151330    /* add the parms */
    1316     op = tree;
    1317     for(curitem = IDL_OP_DCL(tree).parameter_dcls;
    1318         curitem; curitem = IDL_LIST(curitem).next) {
    1319       IDL_tree tr;
    1320       tr = IDL_LIST(curitem).data;     
    1321       //orbit_cbe_ski_process_piece(&subski);
    1322       /*  Write list of params */
    1323       if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
    1324         {
    1325           fprintf(of, " %s,", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
    1326         }
    1327     }
    1328     tree=op;
     1331    doWriteParametersOnly(of, tree);
    13291332    fprintf(of, "ev)) : %s_retval)\n", id);
    1330     fprintf(of, "#else\n");
     1333
     1334    /* else NOM_NO_PARAM_CHECK */
     1335    fprintf(of, "#else /* Extended parameter check */\n");
     1336
     1337    /* Check object only  */
     1338    fprintf(of, "#define %s(nomSelf, ", id);
     1339    /* add the parms */
     1340    doWriteParametersOnly(of, tree);
     1341    fprintf(of, "ev) \\\n");
     1342    fprintf(of, "        (objectCheckFunc_%s(nomSelf, ", id2);
     1343    fprintf(of, " \"%s\") ? \\\n", id);
     1344    fprintf(of, "        (NOM_Resolve(nomSelf, %s, %s) \\\n", id2, id3);
     1345    fprintf(of, "        (nomSelf,");
     1346    /* add the parms */
     1347    doWriteParametersOnly(of, tree);
     1348    fprintf(of, "ev)) : (");
     1349    orbit_cbe_write_param_typespec(of, tree);
     1350    fprintf(of, ") NULL)\n");
     1351    fprintf(of, "#endif\n");
     1352
     1353    /* No parameter check at all */
     1354    fprintf(of, "#else /* NOM_NO_PARAM_CHECK */\n");
    13311355
    13321356    /* Normal macro */
    13331357    fprintf(of, "#define %s(nomSelf, ", id);
    1334     /* add the parms */
    1335     op = tree;
    1336     for(curitem = IDL_OP_DCL(tree).parameter_dcls;
    1337         curitem; curitem = IDL_LIST(curitem).next) {
    1338       IDL_tree tr;
    1339       tr = IDL_LIST(curitem).data;     
    1340       /*  Write list of params */
    1341       if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
    1342         {
    1343           fprintf(of, " %s,", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
    1344         }
    1345     }
    1346     tree=op;
    1347 
    1348     //   fprintf(of, "CORBA_Environment *ev) \\\n");
     1358    doWriteParametersOnly(of, tree);
    13491359    fprintf(of, "ev) \\\n");
    13501360    fprintf(of, "        (NOM_Resolve(nomSelf, %s, %s) \\\n", id2, id3);
    13511361    fprintf(of, "        (nomSelf,");
    1352 
    13531362    /* add the parms */
    1354     op = tree;
    1355     for(curitem = IDL_OP_DCL(tree).parameter_dcls;
    1356         curitem; curitem = IDL_LIST(curitem).next) {
    1357       IDL_tree tr;
    1358       tr = IDL_LIST(curitem).data;     
    1359       //orbit_cbe_ski_process_piece(&subski);
    1360       /*  Write list of params */
    1361       if(IDL_NODE_TYPE(tr) == IDLN_PARAM_DCL)
    1362         {
    1363           fprintf(of, " %s,", IDL_IDENT(IDL_PARAM_DCL(tr).simple_declarator).str);
    1364         }
    1365     }
    1366     tree=op;
    1367 
    1368     // fprintf(of, "CORBA_Environment *ev))\n");
     1363    doWriteParametersOnly(of, tree);
    13691364    fprintf(of, "ev))\n");
    1370     fprintf(of, "#endif\n");
     1365    fprintf(of, "#endif\n"); /* Parameter check*/
     1366
    13711367    /* Method macro */
    13721368    fprintf(of, "#define _%s %s", id3 , id);
     
    13781374}
    13791375
     1376/* CW: probably some cleanup isn't too bad here... */
    13801377static void
    13811378ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
     
    14311428        case IDLN_OP_DCL:
    14321429          orbit_idl_check_oneway_op (cur);
    1433           /* orbit_cbe_op_write_proto(ci->fh, cur, "", FALSE); */
    14341430
    14351431          /* NOM allows method overriding. This is done using a macro which builds a method
     
    14591455              }
    14601456#else
     1457#if 0
     1458              /* 11.03.2007: We don't use attributes for now! */
    14611459              /* We put the attribute methods automatically into the *ClassStruct.
    14621460                 That's different to SOM where you have to put them in the releaseorder list
     
    14681466                fprintf(ci->fh, ";\n");
    14691467              }
     1468#endif
    14701469#endif
    14711470            }/* for() */
     
    14791478      fprintf(ci->fh, "} %sClassData;\n\n", id);
    14801479     
    1481 
    1482       /******* Print introduced method for possible postprocessing *******/
     1480      /******* Print generic object check function  *******/
     1481
     1482      fprintf(ci->fh, "NOMEXTERN gboolean NOMLINK objectCheckFunc_%s(%s *nomSelf, gchar* chrMethodName);\n\n", id, id);
     1483
     1484     
     1485      /******* Print introduced methods *******/
    14831486      for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
    14841487        IDL_tree cur;
     
    14951498              fprintf(ci->fh, "/*\n * NEW_METHOD: ");
    14961499              fprintf(ci->fh, "%s %s\n */\n", IDL_IDENT (IDL_OP_DCL (cur).ident).str, id );
    1497 
     1500              /* Do print... */
    14981501              VoyagerOutputNewMethod(ci->fh, cur, "");
    1499 
    15001502            }
    15011503          break;
  • trunk/ORBit2-2.14.0/src/idl-compiler/orbit-idl-c-skelimpl.c

    r253 r254  
    127127}
    128128
     129/*
     130  Worker function for outputting the name of a class introducing some method.
     131  Called by VoyagerOutputIntroducingClass();
     132 */
    129133static
    130 void VoyagerOutputIntroducingClass(IDL_tree curif, InheritedOutputInfo *ioi)
     134void VoyagerDoOutputIntroducingClass(IDL_tree curif, InheritedOutputInfo *ioi)
    131135{
    132136  char *id;
     
    160164  g_free(id);
    161165}
     166
     167/*
     168  Output the name of a class introducing an overriden method.
     169*/
     170static
     171void VoyagerOutputIntroducingClass(IDL_tree tmptree, CBESkelImplInfo *ski, GString *gstr)
     172{
     173  if(IDL_INTERFACE(tmptree).inheritance_spec) {
     174    InheritedOutputInfo ioi;
     175   
     176    ioi.of = ski->of;
     177    ioi.realif = tmptree;
     178    ioi.chrOverridenMethodName=gstr->str;
     179    IDL_tree_traverse_parents(IDL_INTERFACE(tmptree).inheritance_spec,
     180                              (GFunc)VoyagerDoOutputIntroducingClass, &ioi);
     181  }
     182}
     183
    162184
    163185static
     
    365387
    366388/*
     389  This function creates a define for methods with parameter check at the top of the *.ih file
     390  to enable the check function whichis sourrounded by '#ifdef/#endif.
     391  Note that this function does not create any checking code.
     392
    367393  For methods which should have parameter checks (specified by a special macro in the IDL file)
    368394  a constant string is specified. The method name is encoded in the constants name while the string
     
    372398 */
    373399static void
    374 VoyagerCreateParamCheckFunctions(CBESkelImplInfo *ski)
     400VoyagerCreateParamCheckDefines(CBESkelImplInfo *ski)
    375401{
    376402  char    *id;
     
    408434
    409435/*
     436  Output a generic function for checking the object pointer.
     437 */
     438static void
     439VoyagerCreateObjectCheckFunction(char *id2, CBESkelImplInfo *ski)
     440{
     441#if 0
     442  if(PASS_VOYAGER_PARMCHECK==ski->pass)
     443    {
     444
     445      char *id, *id2;
     446      IDL_tree curitem;
     447      int level;
     448      GString *gstr;
     449
     450      curitem = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, &level);
     451      g_assert(curitem);
     452
     453      id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(ski->tree).ident), "_", 0);   
     454      id2 = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curitem).ident), "_", 0);
     455
     456      gstr=g_string_new(IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
     457#endif
     458
     459      /* Output a function for checking the parameters. Note that we only
     460         check the object pointer. */
     461      fprintf(ski->of, "\n/* Function to check if an object is valid before calling a method on it */\n");
     462      fprintf(ski->of, "#ifndef NOM_NO_PARAM_CHECK\n");
     463      fprintf(ski->of, "NOMEXTERN ");               
     464      fprintf(ski->of, "gboolean NOMLINK objectCheckFunc_%s(%s *nomSelf, gchar* chrMethodName)\n",
     465              id2, id2);               
     466      fprintf(ski->of, "{\n");
     467     
     468      fprintf(ski->of, "if(!nomIsObj(nomSelf) || !_nomIsA(nomSelf , %sClassData.classObject, NULLHANDLE))\n", id2);
     469      fprintf(ski->of, "  {\n");
     470      fprintf(ski->of, "  nomPrintObjectPointerError(nomSelf, \"%s\", chrMethodName);\n", id2);
     471      fprintf(ski->of, "  g_message(\"Note that NULL is returned for the call (if the method returns a value). This may not be correct. Use the NOMPARMCHECK() macro to specify default return values for methods.\");\n");
     472      fprintf(ski->of, "  return FALSE;\n");
     473      fprintf(ski->of, "  }\n");
     474      fprintf(ski->of, "  return TRUE;\n");
     475      fprintf(ski->of, "}\n");
     476      fprintf(ski->of, "#endif\n");
     477      //      g_free(id); g_free(id2);
     478      // }   
     479}
     480
     481
     482/*
    410483  This function outputs the parameter type of methods without the 'const'
    411484  qualifier.
     
    416489    return;
    417490
    418   orbit_cbe_voyager_write_param_typespec(ski->of, ski->tree);
    419  
     491  orbit_cbe_voyager_write_param_typespec(ski->of, ski->tree); 
    420492}
    421493
     
    456528      /* Find the name of the metaclass for this class if any. */
    457529      VoyagerExtractMetaClass(ski);
    458       /* Create support function for parameter checks. */
    459       VoyagerCreateParamCheckFunctions(ski);
     530      /* Create enable defines for parameter checks. */
     531      VoyagerCreateParamCheckDefines(ski);
    460532      break;
    461533        default:
     
    924996                        id2, gstr->str);
    925997                /* Output name of introducing class */
     998#if 0
    926999                if(IDL_INTERFACE(tmptree).inheritance_spec) {
    9271000                  InheritedOutputInfo ioi;
     
    9331006                                            (GFunc)VoyagerOutputIntroducingClass, &ioi);
    9341007                }
     1008#endif
     1009                VoyagerOutputIntroducingClass(tmptree, ski, gstr);
    9351010                fprintf(ski->of, ":%s\";\n",gstr->str); /* Output the method name */
    9361011
     
    9681043                fprintf(ski->of, "((");
    9691044                /* Output name of introducing class */
     1045#if 0
    9701046                if(IDL_INTERFACE(tmptree).inheritance_spec) {
    9711047                  InheritedOutputInfo ioi;
     
    9771053                                            (GFunc)VoyagerOutputIntroducingClass, &ioi);
    9781054                }
     1055#endif
     1056                VoyagerOutputIntroducingClass(tmptree, ski, gstr);
    9791057                fprintf(ski->of, "*)nomSelf, ");
    980                 //fprintf(ski->of, "(nomSelf, ");
     1058
    9811059                if(IDL_INTERFACE(tmptree).inheritance_spec) {
    9821060                  InheritedOutputInfo ioi;
     
    10351113              }
    10361114
    1037             /* Output a function for checking the parameters */
     1115            /* Output a function for checking the parameters. Note that we only
     1116               check the object pointer for now. */
    10381117            if(!bOverriden)
    10391118              {
     
    10541133
    10551134                fprintf(ski->of, "{\n");
    1056                 fprintf(ski->of, "  g_message(\"%%s: parameter check for %%s...\", __FUNCTION__, _nomGetClassName(nomSelf, NULLHANDLE));\n");
    1057                 fprintf(ski->of, "if(!_nomIsA(nomSelf , %sClassData.classObject, NULLHANDLE))\n", id2);
     1135
     1136                fprintf(ski->of, "if(!nomIsObj(nomSelf) || !_nomIsA(nomSelf , %sClassData.classObject, NULLHANDLE))\n", id2);
    10581137                fprintf(ski->of, "  {\n");
    1059                 fprintf(ski->of, "  g_message(\"Object is not valid\");\n");
     1138                fprintf(ski->of, "  nomPrintObjectPointerError(nomSelf, \"%s\", \"%s\");\n", id2, id);
    10601139                fprintf(ski->of, "  return FALSE;\n");
    10611140                fprintf(ski->of, "  }\n");
     1141                fprintf(ski->of, "  g_message(\"%%s: parameter check for %%s...\", __FUNCTION__, _nomGetClassName(nomSelf, NULLHANDLE));\n");
    10621142                fprintf(ski->of, "  return TRUE;\n");
    10631143                fprintf(ski->of, "}\n");
     
    14701550                subski.tree = IDL_INTERFACE(ski->tree).body;
    14711551        cbe_ski_do_list(&subski);
     1552        /* Output parameter check defines */
    14721553                IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
     1554        /* Output generic object check function */
     1555        VoyagerCreateObjectCheckFunction(id, ski);
    14731556        break;
    14741557      }
Note: See TracChangeset for help on using the changeset viewer.