[XDCTOOLS-216] Object_get__S functions may contain unreachable code; also reomved underscores from variable names
diff --git a/src/packages/xdc/services/intern/gen/Config.java b/src/packages/xdc/services/intern/gen/Config.java
index 45d51e5..306c7dc 100644
--- a/src/packages/xdc/services/intern/gen/Config.java
+++ b/src/packages/xdc/services/intern/gen/Config.java
@@ -2335,7 +2335,7 @@
glob.genTitleD("create");
glob.out.printf("%1Handle %1create(", glob.cname);
glob.genCreArgDecls(unit, Glob.Type$LCL, " ");
- glob.out.printf("const %1Params *__prms, %2 )\n{\n%+", glob.cname,
+ glob.out.printf("const %1Params *prms, %2 )\n{\n%+", glob.cname,
Glob.ERRARG);
glob.out.printf("%treturn (%1Handle)%2create(", glob.cname, dcname);
if (unit.hasCreateArgs()) {
@@ -2343,7 +2343,7 @@
glob.out.printf("%1, ", arg.getName());
}
}
- glob.out.printf("(const %1Params *)__prms, __eb);\n}\n%-", dcname);
+ glob.out.printf("(const %1Params *)prms, eb);\n}\n%-", dcname);
glob.genTitleD("delete");
glob.out.printf("void %1delete(%1Handle *instp)\n{\n%+",
@@ -2681,8 +2681,8 @@
String logCall = "%1L_create";
- glob.out.printf("%t%1Params __prms;\n", glob.cname);
- glob.out.printf("%t%1Object *__obj;\n", glob.cname);
+ glob.out.printf("%t%1Params prms;\n", glob.cname);
+ glob.out.printf("%t%1Object *obj;\n", glob.cname);
skip();
String iStat = "";
@@ -2696,14 +2696,14 @@
skip();
glob.out.printf("%t/* common instance initialization */\n");
- glob.out.printf("%t__obj = %1createObject__I(&%2Object__DESC__C, NULL, "
- + "&__prms, (xdc_CPtr)__paramsPtr, 0, __eb);\n", cs, glob.cname);
+ glob.out.printf("%tobj = %1createObject__I(&%2Object__DESC__C, NULL, "
+ + "&prms, (xdc_CPtr)__paramsPtr, 0, eb);\n", cs, glob.cname);
glob.out.printf(
- "%tif (__obj == NULL) {\n%+%treturn NULL;\n%-%t}\n\n");
+ "%tif (obj == NULL) {\n%+%treturn NULL;\n%-%t}\n\n");
if (mod.geti("$$dlgflag") == 1 || mod.geti("$$iobjflag") == 1) {
glob.out.printf("%t/* module-specific initialization */\n");
- glob.out.printf("%t%2%1Instance_init__%3(__obj, ", glob.cname,
+ glob.out.printf("%t%2%1Instance_init__%3(obj, ", glob.cname,
iStat, isBeforeRom(mod) ? "F" : "E");
if (unit.hasCreateArgs()) {
for (Decl.Arg arg : unit.getCreator().getArgs()) {
@@ -2711,7 +2711,7 @@
arg.getName());
}
}
- glob.out.printf("&__prms%1);\n", iInitErr ? ", __eb" : "");
+ glob.out.printf("&prms%1);\n", iInitErr ? ", eb" : "");
if (iInitErr) {
if ((pol & DELETE_POLICY) != 0) {
// glob.out.printf(
@@ -2720,12 +2720,11 @@
// + "&xdc_runtime_Error_IgnoreBlock)) {\n");
glob.out.printf("%tif (iStat) {\n%+");
glob.out.printf("%txdc_runtime_Core_deleteObject__I(&%1"
- + "Object__DESC__C, __obj, %2, iStat, 0);\n",
+ + "Object__DESC__C, obj, %2, iStat, 0);\n",
glob.cname, fs);
}
else {
- glob.out.printf(
- "%tif (xdc_runtime_Error_check(__eb)) {\n%+");
+ glob.out.printf("%tif (xdc_runtime_Error_check(eb)) {\n%+");
}
glob.out.printf("%treturn NULL;\n");
glob.out.printf("%-%t}\n\n");
@@ -2737,16 +2736,16 @@
if ((mask & L_LIFECYCLE) != 0) {
if (commonGeti(mod, "namedInstance") == 1) {
glob.out.printf(
- "%t%1write2(" + logCall + ", (xdc_IArg)__obj, (xdc_IArg)"
- + "(((%2Object__*)__obj)->__name));\n", los, glob.cname);
+ "%t%1write2(" + logCall + ", (xdc_IArg)obj, (xdc_IArg)"
+ + "(((%2Object__*)obj)->__name));\n", los, glob.cname);
}
else {
glob.out.printf("%t%1write2(" + logCall
- + ", (xdc_IArg)__obj, 0);\n", los);
+ + ", (xdc_IArg)obj, 0);\n", los);
}
}
- glob.out.printf("%treturn __obj;\n");
+ glob.out.printf("%treturn obj;\n");
glob.out.printf("%-}\n");
return;
}
@@ -2811,11 +2810,11 @@
if (useCase == 2) {
glob.out.printf("%t%1constructObject__I(&%2Object__DESC__C, __obj, "
+ "&__prms, (xdc_CPtr)__paramsPtr, 0, %3);\n", cs, glob.cname,
- iInitErr ? "__eb" : "NULL");
+ iInitErr ? "eb" : "NULL");
}
else if (useCase == 0) {
glob.out.printf("%t__obj = %1createObject__I(&%2Object__DESC__C,"
- + " NULL, &__prms, (xdc_CPtr)__paramsPtr, 0, __eb);\n", cs,
+ + " NULL, &__prms, (xdc_CPtr)__paramsPtr, 0, eb);\n", cs,
glob.cname);
glob.out.printf(
"%tif (__obj == NULL) {\n%+%treturn NULL;\n%-%t}\n\n");
@@ -2832,7 +2831,7 @@
arg.getName());
}
}
- glob.out.printf("&__prms%1);\n", iInitErr ? ", __eb" : "");
+ glob.out.printf("&__prms%1);\n", iInitErr ? ", eb" : "");
if (iInitErr) {
// glob.out.printf("%t__err = xdc_runtime_Error_check(__eb);\n");
if ((pol & DELETE_POLICY) != 0) {
@@ -2851,8 +2850,7 @@
glob.out.printf("%-%t}\n\n");
}
else if (useCase == 0) {
- glob.out.printf("%tif (xdc_runtime_Error_check(__eb)) {\n"
- + "%+");
+ glob.out.printf("%tif (xdc_runtime_Error_check(eb)) {\n%+");
glob.out.printf("%treturn NULL;\n");
glob.out.printf("%-%t}\n\n");
}
@@ -2901,14 +2899,14 @@
if (mod.geti("PROXY$") == 1) {
// Proxy__abstract
- glob.out.printf("\nxdc_Bool %1Proxy__abstract__S( void )\n{\n%+",
+ glob.out.printf("\nxdc_Bool %1Proxy__abstract__S(void)\n{\n%+",
glob.cname);
glob.out.printf("%treturn %1;\n}\n%-",
mod.geti("$$instflag") == 1
&& mod.geti("abstractInstances$") == 1 ? "1" : "0");
// Proxy__delegate
//490928 glob.out.printf("xdc_CPtr %1Proxy__delegate__S( void )\n{\n%+%treturn ", glob.cname);
- glob.out.printf("xdc_CPtr %1Proxy__delegate__S( void )\n{\n%+%treturn ", glob.cname);
+ glob.out.printf("xdc_CPtr %1Proxy__delegate__S(void)\n{\n%+%treturn ", glob.cname);
Value delmod = mod.getv("delegate$");
String dcname = glob.mkCname(delmod.gets("$name"));
if (commonGeti(delmod, "fxntab") == 1) {
@@ -3017,20 +3015,29 @@
glob.out.printf("xdc_Ptr %1Object__get__S(xdc_Ptr oa, xdc_Int i)\n{"
+ "\n%+", glob.cname);
glob.out.printf("%tif (oa) {\n%+%treturn ((%1Object__ *)oa) + i;\n%-%t}\n\n", glob.cname);
- glob.out.printf("%tif (%1Object__count__C == 0) {\n%+%treturn NULL;\n%-%t}\n\n", glob.cname);
-
- /* MISRA hack. //490928
- * The const in the cast below triggers TI compiler warning #193:
- * type qualifier is meaningless on cast type
- * we can hide this via
- * #ifdef __ti__
- * #pragma diag_suppress 193
- * #endif
+ /* We can detect that there are no static instances for this module, so
+ * we can return NULL without any further checks.
+ * Proxy modules and modules without instances are detected earlier in
+ * the function, so we don't have to check for them here.
*/
- glob.out.printf("%t/* the bogus 'const' in the cast suppresses Klocwork MISRA complaints */\n");
- glob.out.printf("%treturn ((%1Object__ * const)%1Object__table__C) + i;\n",
- glob.cname);
- glob.out.printf("}\n%-");
+ if (mod.getv("$instances").geti("length") == 0) {
+ glob.out.printf("%treturn NULL;\n%-%t}\n\n");
+ }
+ else {
+ /* MISRA hack. //490928
+ * The const in the cast below triggers TI compiler warning #193:
+ * type qualifier is meaningless on cast type
+ * we can hide this via
+ * #ifdef __ti__
+ * #pragma diag_suppress 193
+ * #endif
+ */
+ glob.out.printf("%t/* the bogus 'const' in the cast suppresses "
+ + "Klocwork MISRA complaints */\n");
+ glob.out.printf("%treturn ((%1Object__ * const)%1Object__table__C) "
+ + "+ i;\n", glob.cname);
+ glob.out.printf("}\n%-");
+ }
// Object__first
glob.genTitleD("Object__first__S");
@@ -3058,7 +3065,7 @@
// Object__next
glob.genTitleD("Object__next__S");
- glob.out.printf("xdc_Ptr %1Object__next__S( xdc_Ptr obj ) \n{\n%+", glob.cname);
+ glob.out.printf("xdc_Ptr %1Object__next__S( xdc_Ptr obj )\n{\n%+", glob.cname);
if (pol != STATIC_POLICY) {
glob.out.printf("%txdc_runtime_Types_InstHdr *iHdr = ((xdc_runtime_Types_InstHdr *)obj) - 1;\n\n");
if (fm.switchMod(mod) == FileManager.SEPARATE_FILE) {
@@ -3213,20 +3220,20 @@
* create__S functions completely.
*/
glob.genTitleD("create");
- glob.out.printf("%1Handle %1create( %1Module __mod", glob.cname);
+ glob.out.printf("%1Handle %1create( %1Module mod", glob.cname);
glob.genCreArgDecls(unit, Glob.Type$LCL, ", ");
- glob.out.printf("const %1Params *__prms, %2 )\n{\n%+", glob.cname,
+ glob.out.printf("const %1Params *prms, %2 )\n{\n%+", glob.cname,
Glob.ERRARG);
if (unit.hasCreateArgs()) {
- glob.out.printf("%t%1Args__create __args;\n", glob.cname);
+ glob.out.printf("%t%1Args__create args;\n", glob.cname);
for (Decl.Arg arg : unit.getCreator().getArgs()) {
- glob.out.printf("%t__args.%1 = %1;\n", arg.getName());
+ glob.out.printf("%targs.%1 = %1;\n", arg.getName());
}
}
- glob.out.printf("%treturn (%1Handle) __mod->__sysp->__create(",
+ glob.out.printf("%treturn (%1Handle) mod->__sysp->__create(",
glob.cname);
- glob.out.printf("%1, ", unit.hasCreateArgs() ? "&__args" : "0");
- glob.out.printf("(const xdc_UChar*)__prms, sizeof (%1Params), __eb);\n}\n%-", glob.cname);
+ glob.out.printf("%1, ", unit.hasCreateArgs() ? "&args" : "0");
+ glob.out.printf("(const xdc_UChar*)prms, sizeof (%1Params), eb);\n}\n%-", glob.cname);
glob.genTitleD("delete");
glob.out.printf("void %1delete( %1Handle *instp )\n{\n%+", glob.cname);