Changeset 253


Ignore:
Timestamp:
Mar 11, 2007, 11:31:49 PM (18 years ago)
Author:
cinc
Message:

First attempt on automatic parameter check for methods.

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

Legend:

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

    r212 r253  
    636636}
    637637
     638#if 0
     639static gchar* mySkipSpaces(char*  theString)
     640{
     641  if(!theString) /* Huh???*/
     642    return "";
     643
     644  while(*theString)
     645    theString++;
     646
     647  return theString
     648}
     649#endif
     650
     651#include <string.h>
     652/*
     653  This function extracts the return vlaue from the string which is created by
     654  the parameter check macro. The string is of the form:
     655
     656  "retval, parm1, parm2,..."
     657
     658 */
     659static gchar* VoyagerExtractRetValFromParmCheck(gchar* theString)
     660{
     661  gchar* ptr, *ptr2;
     662
     663  if(NULL==(ptr=strchr(theString, ',')))
     664    {
     665      /* No ',' so no parameters provided */
     666      return g_strdup(theString);
     667    }
     668  *ptr='\0';
     669  ptr2=g_strdup(theString);
     670  *ptr=',';
     671  return ptr2;
     672};
     673/*
     674  This functions puts constants into the header file. For Voyager we
     675  use constants to encode some special information e.g. the metaclass name
     676  or info about which parameters to check for methods. This information is
     677  marked by special strings in the constants name.
     678 */
    638679static void
    639680ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
     
    642683        IDL_tree ident;
    643684        IDL_tree typespec;
     685    gchar *ptr;
    644686
    645687        ident = IDL_CONST_DCL (tree).ident;
    646688        id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
    647689
    648         fprintf(ci->fh, "#ifndef %s\n", id);
    649         fprintf(ci->fh, "#define %s ", id);
    650 
    651         orbit_cbe_write_const(ci->fh,
    652                               IDL_CONST_DCL(tree).const_exp);
    653 
    654         typespec = orbit_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
    655         if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
    656             !IDL_TYPE_INTEGER (typespec).f_signed)
    657                 fprintf(ci->fh, "U");
    658 
    659         fprintf(ci->fh, "\n");
    660         fprintf(ci->fh, "#endif /* !%s */\n\n", id);
    661    
    662     /* Get the name of our explicit metaclass if any */
     690    ptr=strstr( id , NOM_PARMCHECK_STRING);
     691    /* Enable parameter check for a method */
     692    if(ptr)
     693      {
     694        gchar *retVal;
     695        *ptr='\0';
     696        //printf(" %d    --- > %s %s Params: %s\n",
     697        //__LINE__, id, IDL_IDENT(ident).str, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value);
     698        fprintf(ci->fh, "/* %s: %s line %d */\n", __FILE__, __FUNCTION__, __LINE__);
     699        fprintf(ci->fh, "/* Value: %s */\n", IDL_STRING(IDL_CONST_DCL(tree).const_exp).value);
     700        fprintf(ci->fh, "#ifndef %s_ParmCheck_h\n", id);
     701        fprintf(ci->fh, "#define %s_ParmCheck_h\n", id);
     702        retVal=VoyagerExtractRetValFromParmCheck(IDL_STRING(IDL_CONST_DCL(tree).const_exp).value);
     703        fprintf(ci->fh, "#define %s_retval %s\n", id, retVal);
     704        g_free(retVal);
     705        fprintf(ci->fh, "#endif /* !%s */\n\n", id);
     706        *ptr='_';
     707      }
     708    else
     709      {
     710        fprintf(ci->fh, "#ifndef %s\n", id);
     711        fprintf(ci->fh, "#define %s ", id);
     712       
     713        orbit_cbe_write_const(ci->fh,
     714                              IDL_CONST_DCL(tree).const_exp);
     715       
     716        typespec = orbit_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
     717        if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
     718            !IDL_TYPE_INTEGER (typespec).f_signed)
     719          fprintf(ci->fh, "U");
     720       
     721        fprintf(ci->fh, "\n");
     722        fprintf(ci->fh, "#endif /* !%s */\n\n", id);
     723      }
     724
    663725    if(IDLN_STRING==IDL_NODE_TYPE(IDL_CONST_DCL(tree).const_exp))
    664726      {
     727        /* Get the name of our explicit metaclass if any */
    665728        /* Our metaclass info is a string */
    666729        if(strstr( IDL_IDENT(ident).str, NOM_METACLASS_STRING))
     
    671734            //     __LINE__, id, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value, gsMetaClassName[ulCurInterface]);
    672735          }
    673       }
     736       }
    674737        g_free(id);
    675738}
     
    11931256    /* define method call as a macro */
    11941257    fprintf(of, "/* define method call as a macro */\n");
    1195     fprintf(of, "#define %s(vomSelf, ", id);
     1258    fprintf(of, "#ifdef %s_ParmCheck_h /* Parameter check */\n", id);
     1259    /* Forward declaration */
     1260    fprintf(of, "NOMEXTERN ");               
     1261    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 */
     1280    fprintf(of, "#define %s(nomSelf, ", id);
    11961281    /* add the parms */
    1197 
    11981282    op = tree;
    11991283    for(curitem = IDL_OP_DCL(tree).parameter_dcls;
     
    12081292    }
    12091293    tree=op;
    1210 
    1211     //   fprintf(of, "CORBA_Environment *ev) \\\n");
    12121294    fprintf(of, "ev) \\\n");
    1213     fprintf(of, "        (NOM_Resolve(vomSelf, %s, %s) \\\n", id2, id3);
    1214     fprintf(of, "        (vomSelf,");
     1295    fprintf(of, "        (parmCheckFunc_%s(nomSelf, ", id);
     1296    /* 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;
     1310
     1311    fprintf(of, "ev) ? \\\n");
     1312    fprintf(of, "        (NOM_Resolve(nomSelf, %s, %s) \\\n", id2, id3);
     1313    fprintf(of, "        (nomSelf,");
    12151314
    12161315    /* add the parms */
     
    12281327    }
    12291328    tree=op;
     1329    fprintf(of, "ev)) : %s_retval)\n", id);
     1330    fprintf(of, "#else\n");
     1331
     1332    /* Normal macro */
     1333    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");
     1349    fprintf(of, "ev) \\\n");
     1350    fprintf(of, "        (NOM_Resolve(nomSelf, %s, %s) \\\n", id2, id3);
     1351    fprintf(of, "        (nomSelf,");
     1352
     1353    /* 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;
    12301367
    12311368    // fprintf(of, "CORBA_Environment *ev))\n");
    12321369    fprintf(of, "ev))\n");
     1370    fprintf(of, "#endif\n");
    12331371    /* Method macro */
    12341372    fprintf(of, "#define _%s %s", id3 , id);
  • trunk/ORBit2-2.14.0/src/idl-compiler/orbit-idl-c-skelimpl.c

    r249 r253  
    4343  FILE *of;
    4444  IDL_tree tree;
    45   enum { PASS_VOYAGER_INSTANCE, PASS_VOYAGER_GETDATA, PASS_VOYAGER_CLSDATA,
     45  enum { PASS_VOYAGER_INSTANCE, PASS_VOYAGER_GETDATA, PASS_VOYAGER_CLSDATA, PASS_VOYAGER_PARMCHECK,
    4646         PASS_SERVANTS, PASS_PROTOS, PASS_EPVS, PASS_VEPVS,
    4747         PASS_IMPLSTUBS, PASS_VOYAGER_OVERRIDEN_METHODS, PASS_VOYAGER_OVERRIDEN_METHODTAB,
     
    6767  "Voyager GetData macros ",
    6868  "Voyager class data structures",
     69  "Voyager parameter check",
    6970  "App-specific servant structures",
    7071  "Implementation stub prototypes",
     
    328329}
    329330
     331/*
     332  The name of our meta class is encoded as a constant. We go over all the constants found during
     333  IDL parsing and check for a special marker string in the name.
     334 */
    330335static void
    331336VoyagerExtractMetaClass(CBESkelImplInfo *ski)
     
    343348      id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
    344349
    345 #if 0
    346       printf(" %d --- > %s %s %s, %s %d\n", __LINE__,
    347              id, IDL_IDENT(ident).str, IDL_IDENT(IDL_INTERFACE(intf).ident).str,
    348              passnames[ski->pass], IDL_NODE_TYPE(IDL_CONST_DCL(ski->tree).const_exp));
    349 #endif
    350 
    351350      if(IDLN_STRING==IDL_NODE_TYPE(IDL_CONST_DCL(ski->tree).const_exp))
    352351        {
     352          //  printf(" %d --- > %s\n", __LINE__,IDL_IDENT(ident).str);
    353353          /* Our metaclass info is a string */
    354354          if(strstr( IDL_IDENT(ident).str, NOM_METACLASS_STRING))
     
    358358              //    printf(" %d    --- > %s %s (%x)\n",
    359359              //     __LINE__, id, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value, gsMetaClassName[ulCurInterface]);
     360            }
     361        }
     362      g_free(id);
     363    }/* PASS_VOYAGER_...*/
     364}
     365
     366/*
     367  For methods which should have parameter checks (specified by a special macro in the IDL file)
     368  a constant string is specified. The method name is encoded in the constants name while the string
     369  holds all the info about the parameters to check.
     370  We go over all the constants found during IDL parsing and check for a special marker string in the
     371  name.
     372 */
     373static void
     374VoyagerCreateParamCheckFunctions(CBESkelImplInfo *ski)
     375{
     376  char    *id;
     377  IDL_tree ident;
     378  IDL_tree intf;
     379
     380
     381  if(PASS_VOYAGER_PARMCHECK==ski->pass)
     382    {
     383      ident = IDL_CONST_DCL (ski->tree).ident;
     384      intf = IDL_get_parent_node(ski->tree, IDLN_INTERFACE, NULL);
     385
     386      id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
     387
     388      if(IDLN_STRING==IDL_NODE_TYPE(IDL_CONST_DCL(ski->tree).const_exp))
     389        {
     390          gchar *ptr;
     391          //  printf(" %d --- > %s\n", __LINE__,IDL_IDENT(ident).str);
     392          /* Our parameter info is a string */
     393          ptr=strstr( id /*IDL_IDENT(ident).str*/, NOM_PARMCHECK_STRING);
     394          if(ptr)
     395            {
     396              *ptr='\0';
     397              //printf(" %d    --- > %s %s Params: %s\n",
     398              //__LINE__, id, IDL_IDENT(ident).str, IDL_STRING(IDL_CONST_DCL(ski->tree).const_exp).value);
     399              fprintf(ski->of, "#ifndef %s_ParmCheck\n", id);
     400              fprintf(ski->of, "#define %s_ParmCheck\n", id);
     401              fprintf(ski->of, "#endif\n");
     402              *ptr='_';
    360403            }
    361404        }
     
    411454                break;
    412455    case IDLN_CONST_DCL:
     456      /* Find the name of the metaclass for this class if any. */
    413457      VoyagerExtractMetaClass(ski);
     458      /* Create support function for parameter checks. */
     459      VoyagerCreateParamCheckFunctions(ski);
    414460      break;
    415461        default:
     
    776822        gstr=g_string_new(IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str);
    777823
    778         /* Check for our specailly marked NOM-only methods. Don't output them here, they are handled
     824        /* Check for our specially marked NOM-only methods. Don't output them here, they are handled
    779825           specially. */
    780826          if(!strstr(id, NOM_INSTANCEVAR_STRING) /*&& !strstr(id, NOM_OVERRIDE_STRING)*/)
     
    9541000            }
    9551001
    956             /* Output the parameter info */
     1002            /* Output the parameter info for runtime type information */
    9571003            if(!bOverriden)
    9581004              {
     
    9881034                fprintf(ski->of, "}};\n");
    9891035              }
     1036
     1037            /* Output a function for checking the parameters */
     1038            if(!bOverriden)
     1039              {
     1040                fprintf(ski->of, "#ifdef %s_ParmCheck\n", id);
     1041                fprintf(ski->of, "NOMEXTERN ");               
     1042                fprintf(ski->of, "gboolean NOMLINK parmCheckFunc_%s_%s(%s *nomSelf,\n",
     1043                        id2, IDL_IDENT(IDL_OP_DCL(ski->tree).ident).str, id2);               
     1044                op = ski->tree;
     1045                for(curitem = IDL_OP_DCL(ski->tree).parameter_dcls;
     1046                    curitem; curitem = IDL_LIST(curitem).next) {
     1047                  subski.tree = IDL_LIST(curitem).data;
     1048                  orbit_cbe_ski_process_piece(&subski);
     1049                }
     1050                       
     1051                if(IDL_OP_DCL(op).context_expr)
     1052                  fprintf(ski->of, "CORBA_Context ctx,\n");           
     1053                fprintf(ski->of, "CORBA_Environment *ev)");
     1054
     1055                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);
     1058                fprintf(ski->of, "  {\n");
     1059                fprintf(ski->of, "  g_message(\"Object is not valid\");\n");
     1060                fprintf(ski->of, "  return FALSE;\n");
     1061                fprintf(ski->of, "  }\n");
     1062                fprintf(ski->of, "  return TRUE;\n");
     1063                fprintf(ski->of, "}\n");
     1064                fprintf(ski->of, "#endif\n");
     1065              }
     1066
    9901067
    9911068            if(ptr!=NULL)
     
    13891466        break;
    13901467      }
     1468    case PASS_VOYAGER_PARMCHECK:
     1469      {
     1470                subski.tree = IDL_INTERFACE(ski->tree).body;
     1471        cbe_ski_do_list(&subski);
     1472                IDL_tree_traverse_parents(ski->tree, (GFunc)&cbe_ski_do_inherited_methods, ski);
     1473        break;
     1474      }
    13911475    case PASS_VOYAGER_CLASSINFO:
    13921476      {
  • trunk/ORBit2-2.14.0/src/idl-compiler/orbit-idl2.h

    r92 r253  
    3333#define NOM_INSTANCEVAR_STRING "__INSTANCEVAR__"
    3434#define NOM_METACLASS_STRING "METACLASS_TO_USE"
     35#define NOM_PARMCHECK_STRING "__PARMCHECK__"
    3536
    3637#endif
Note: See TracChangeset for help on using the changeset viewer.