Merge remote-tracking branch 'origin/xdccore-H-sasha' into master_ggentree
diff --git a/src/packages/xdc/runtime/Error.xdt b/src/packages/xdc/runtime/Error.xdt
index 6b271d3..fba7977 100644
--- a/src/packages/xdc/runtime/Error.xdt
+++ b/src/packages/xdc/runtime/Error.xdt
@@ -4,10 +4,10 @@
         {0, 0} /* data */
     },
     0,  /* id */
-    0,  /* msg */
+    NULL,  /* msg */
     {
         0,  /* mod */
-        0,  /* file */
+        NULL,  /* file */
         0   /* line */
     }
 };
diff --git a/src/packages/xdc/runtime/Error.xs b/src/packages/xdc/runtime/Error.xs
index cd36540..294187f 100644
--- a/src/packages/xdc/runtime/Error.xs
+++ b/src/packages/xdc/runtime/Error.xs
@@ -1,5 +1,5 @@
 /* --COPYRIGHT--,ESD
- *  Copyright (c) 2008-2018 Texas Instruments Incorporated
+ *  Copyright (c) 2008-2019 Texas Instruments Incorporated
  *  This program and the accompanying materials are made available under the
  *  terms of the Eclipse Public License v1.0 and Eclipse Distribution License
  *  v. 1.0 which accompanies this distribution. The Eclipse Public License is
@@ -49,9 +49,9 @@
 		 */
 		if (noBigS) {
 		    if (desc.msg.indexOf('%$S') != -1) {
-			this.$logWarning("the message for this error (= '"
-                            + desc.msg
-                            + "') requires %$S support but xdc.runtime.System.extendedFormats (= '"
+                        this.$logWarning("the message for this error (= '"
+                            + desc.msg + "') requires %$S support but "
+                            + "xdc.runtime.System.extendedFormats (= '"
                             + System.extendedFormats
                             + "') does not include '%$S'", mod, cn);
 		    }
@@ -141,7 +141,7 @@
     var encodedDesc = "0";
     if (desc) {
         encodedDesc = "(((xdc_runtime_Error_Id)" + desc.$private.id
-            + ") << 16 | " + (desc.code & 0xFFFF) + ")";
+            + ") << 16 | " + (desc.code & 0xFFFF) + "U)";
     }
     return (encodedDesc);
 }
diff --git a/src/packages/xdc/runtime/Text.c b/src/packages/xdc/runtime/Text.c
index 3b18b26..0e5d9cf 100644
--- a/src/packages/xdc/runtime/Text.c
+++ b/src/packages/xdc/runtime/Text.c
@@ -81,6 +81,10 @@
  *  FALSE if we need to move on to the next rope node, or TRUE if the
  *  comparison is complete. The actual result of the comparison is returned
  *  through the MatchVisState. 'res' is 1 if it's a match, -1 if not.
+ *
+ *  If *lenp == 0 and *src == '\0' at the same time, state->res will stay at 0
+ *  if the calling function doesn't call again with the new 'src'. If it does,
+ *  *src != '\0' and state->res changes to -1.
  */
 Bool Text_matchVisFxn(Ptr obj, CString src)
 {
@@ -102,7 +106,11 @@
         pat++;
     }
 
-    /* if src[0] != 0, we reached the end of pat */
+    /* if src[0] != 0, we reached the end of pat, there is no wildcard at there
+     * end, and we haven't finished the string, so there is no match. If the
+     * pattern is 'xdc.runtime.Timestamp' and the string is
+     * 'xdc.runtime.TimestampNull', that's not a match.
+     */
     if (*src != '\0') {
         state->res = -1;
         return (TRUE);
@@ -298,6 +306,7 @@
 
 /*
  *  ======== xprintf ========
+ *  After xprintf returns, *bufp points to '\0'
  */
 Int Text_xprintf(Char **bufp, SizeT len, CString fmt, ...)
 {
diff --git a/src/packages/xdc/runtime/Text.xdc b/src/packages/xdc/runtime/Text.xdc
index d8835f7..c48b252 100644
--- a/src/packages/xdc/runtime/Text.xdc
+++ b/src/packages/xdc/runtime/Text.xdc
@@ -22,7 +22,7 @@
  *
  *  This module efficiently manages a collection of strings that have common
  *  substrings.  Collections with a high degree of commonality are stored in
- *  much less space than as ordinary table of independent C strings.
+ *  much less space than as an ordinary table of independent C strings.
  *
  *  To further save space, the "compressed" representation need not even
  *  be loaded in the target's memory; see `{@link #isLoaded}`.
@@ -104,19 +104,19 @@
      *  set to `false`, the character strings managed by Text are removed from
      *  the application.
      *
-     * A consequence of setting this parameter to `false` is that all names 
-     * assigned to static instances are set to NULL, and cannot be displayed by
-     * the code loaded to the target. Also, the Log Events that automatically
-     * print instance names will print NULL for any static instance. The same
-     * code would print the pointers to the names if this parameter is set to
-     * `true` and 'isLoaded` is set to '`false`.
+     *  A consequence of setting this parameter to `false` is that all names
+     *  assigned to static instances are set to NULL, and cannot be displayed by
+     *  the code loaded to the target. Also, the Log Events that automatically
+     *  print instance names will print NULL for any static instance. The same
+     *  code would print the pointers to the names if this parameter is set to
+     *  `true` and 'isLoaded` is set to '`false`.
      *
-     * ROV is not affected by this parameter and it will also correctly display
-     * names of static instances in their modules' views. ROV detects these
-     * names from the saved configuration files.
+     *  ROV is not affected by this parameter and it will also correctly display
+     *  names of static instances in their modules' views. ROV detects these
+     *  names from the saved configuration files.
      *
-     * Module and event IDs are still unique and Log.Events within one module
-     * have consecutive IDs.
+     *  Module and event IDs are still unique and Log.Events within one module
+     *  have consecutive IDs.
      */
     config Bool isLoaded = true;
 
@@ -143,9 +143,14 @@
      *  Compare pattern string `pat` to String identified by `rope`.
      *  @_nodoc
      *
+     *  This function is invoked from `{@link Diags#setMask()}`, see the
+     *  documentation for that function to find out how the patterns are
+     *  created.
+     *
      *  @a(pre-conditions)
      *  @p(blist)
      *      - lenp must be less than or equal to the length of pat
+     *      - wildcard '%' is at src[(*lenp) - 1], if it's in the the pattern
      *  @p
 
      *  @a(post-conditions)
@@ -347,6 +352,22 @@
 
     config VisitRopeFxn2 visitRopeFxn2 = visitRope2;
 
+    /*!
+     *  ======== xprintf ========
+     *  @param(bufp)   address of the output buffer pointer or `NULL`
+     *
+     *                 If `bufp` is `NULL`, the site's name characters are
+     *                 output via `{@link System#putch()}`.
+     *
+     *  @param(len)    maximum number of characters to generate
+     *
+     *                 If `len` is negative, the number of characters to be
+     *                 generated is not limited.
+     *
+     *  @a(returns)
+     *  The return value always reflects the number of characters output,
+     *  but it may be less than `len`.
+     */
     Int xprintf(Char **bufp, SizeT len, CString fmt, ...);
 
     struct Module_State {
diff --git a/src/packages/xdc/runtime/Text.xdt b/src/packages/xdc/runtime/Text.xdt
index 7758973..7de7e26 100644
--- a/src/packages/xdc/runtime/Text.xdt
+++ b/src/packages/xdc/runtime/Text.xdt
@@ -1,11 +1,11 @@
 %%{
 /* --COPYRIGHT--,ESD
- *  Copyright (c) 2008 Texas Instruments. All rights reserved. 
- *  This program and the accompanying materials are made available under the 
+ *  Copyright (c) 2008-2019 Texas Instruments Incorporated
+ *  This program and the accompanying materials are made available under the
  *  terms of the Eclipse Public License v1.0 and Eclipse Distribution License
  *  v. 1.0 which accompanies this distribution. The Eclipse Public License is
  *  available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse
- *  Distribution License is available at 
+ *  Distribution License is available at
  *  http://www.eclipse.org/org/documents/edl-v10.php.
  *
  *  Contributors:
@@ -22,11 +22,14 @@
     xdc_Fxn visFxn, xdc_Ptr visState)
 {
 %if (this.isLoaded) {
+%   /* maxDepth is 1 or more */
     xdc_CString stack[`this.$capsule.maxDepth + 1`];
     xdc_runtime_Text_visitRope2__I(rope, visFxn, visState, stack);
 %}
 %else {
+%   /* We know it's MatchVisState and not PrintVisState because, printVisFxn
+%    * is passed to visitRope only when Text.isLoaded == TRUE.
+%    */
     ((xdc_runtime_Text_MatchVisState *)visState)->res = -1;
 %}
 }
-
diff --git a/src/packages/xdc/runtime/package.xs b/src/packages/xdc/runtime/package.xs
index bfd3717..2ce0229 100644
--- a/src/packages/xdc/runtime/package.xs
+++ b/src/packages/xdc/runtime/package.xs
@@ -272,17 +272,17 @@
         if (!mod.$used || mod.$hostonly || mod.PROXY$) {
             continue;
         }
-	if (!mod.$spec.attrBool('@Gated')) {
-	    if (mod.common$.gate != undefined
-	        && mod.$name != "xdc.runtime.Defaults") {
-		mod.$logWarning("this module is non-gated but it was assigned "
-		    + "a non-null gate", mod, "common$.gate");
-	    }
-	    continue;
-	}
+        if (!mod.$spec.attrBool('@Gated')) {
+            if (mod.common$.gate != undefined
+                && mod.$name != "xdc.runtime.Defaults") {
+                mod.$logWarning("this module is non-gated but it was assigned "
+                    + "a non-null gate", mod, "common$.gate");
+            }
+            continue;
+        }
 
-        /* TODO: validate gateObj/gatePrms come from same module if former
-         * is non-null
+        /* XDCTOOLS-301:
+         * validate gateObj/gatePrms come from same module if former is non-null
          */
         mod.Module__gateObj = (mod.common$.gate !== undefined) ?
             mod.common$.gate : Defaults.common$.gate;
@@ -314,12 +314,12 @@
             }
         }
 
-	/* prevent unintended logging of loggers (usually a mistake) */
-	if (mod instanceof xdc.om["xdc.runtime.ILogger"].Module) {
-	    if (mod.common$.logger === undefined) {
-		mod.common$.logger = null;
-	    }
-	}
+        /* prevent unintended logging of loggers (usually a mistake) */
+        if (mod instanceof xdc.om["xdc.runtime.ILogger"].Module) {
+            if (mod.common$.logger === undefined) {
+                mod.common$.logger = null;
+            }
+        }
 
         /* propagate Defaults to all used target modules */
         if (mod.$spec.needsRuntime()) {
diff --git a/src/packages/xdc/services/intern/gen/Config.java b/src/packages/xdc/services/intern/gen/Config.java
index c460196..5da3084 100644
--- a/src/packages/xdc/services/intern/gen/Config.java
+++ b/src/packages/xdc/services/intern/gen/Config.java
@@ -620,7 +620,7 @@
                 glob.out.printf("%t(xdc_CPtr)&%1Module__FXNS__C, /* fxnTab */\n", glob.cname);
             }
             else {
-                glob.out.printf("%t(xdc_CPtr)0, /* fxnTab */\n");
+                glob.out.printf("%t(xdc_CPtr)NULL, /* fxnTab */\n");
 
             }
         }
@@ -635,7 +635,7 @@
             glob.out.printf("%t&%1Module__root__V.link, /* modLink */\n", glob.cname);
         }
         else {
-            glob.out.printf("%t(xdc_Ptr)0, /* modLink */\n");
+            glob.out.printf("%t(xdc_Ptr)NULL, /* modLink */\n");
         }
         glob.out.printf("%tsizeof(%1__S1) - sizeof(%1Object2__), /* objAlign */\n", glob.cname);
         glob.out.printf("%t%1, /* objHeap */\n", instHeap != null ? instHeap : "0");
@@ -643,7 +643,7 @@
             glob.out.printf("%toffsetof(%1Object__, __name), /* objName */\n", glob.cname);
         }
         else {
-            glob.out.printf("%t0, /* objName */\n");
+            glob.out.printf("%tNULL, /* objName */\n");
         }
 
         glob.out.printf("%tsizeof(%1Object2__), /* objSize */\n", glob.cname);
@@ -1491,11 +1491,11 @@
             }
             else if (fld.getName().equals("Object__table")) {
                 glob.out.printf("%1", inscnt > 0
-                    ? (glob.cname + "Object__table__V") : "0");
+                    ? (glob.cname + "Object__table__V") : "NULL");
             }
             else if (fld.getName().equals("Object__heap")) {
                 Value.Obj vref = (Value.Obj)commonGetv(mod, "instanceHeap");
-                glob.out.printf("%1", vref != null ? valToStr(vref) : "0");
+                glob.out.printf("%1", vref != null ? valToStr(vref) : "NULL");
             }
             else {
                 genVal(fld.getProto(), fldval, "CT__" + fn);
@@ -1770,8 +1770,8 @@
             clink(cname + ps, cname + "Params");
             glob.out.printf("__FAR__ const %1Params %1%2 = {\n%+", cname, ps);
             glob.out.printf("%tsizeof (%1Params), /* __size */\n", cname);
-            glob.out.printf("%t0, /* __self */\n", cname, ps);
-            glob.out.printf("%t0, /* __fxns */\n");
+            glob.out.printf("%tNULL, /* __self */\n", cname, ps);
+            glob.out.printf("%tNULL, /* __fxns */\n");
             glob.out.printf("%t(xdc_runtime_IInstance_Params*)&%1%2.__iprms, /* instance */\n",
                 cname, ps);
             /* Here is where the declared parameters are generated. */
@@ -3722,7 +3722,7 @@
     private String ptrToStr(Object pobj, String qual)     // Proto.Adr
     {
         if (pobj == null) {
-            return "0";
+            return "NULL";
         }
         else if (pobj instanceof Extern) {
             Extern ext = (Extern)pobj;
@@ -3920,8 +3920,10 @@
                 otname = vobj.getOrig().getProto().tname();
                 cn = otname.substring(0, otname.lastIndexOf('.')).replace('.', '_');
             }
-            an = tname.substring(0, tname.lastIndexOf('.')).replace('.', '_') + "_Handle";
-            return "(" + an + ")&" + instArr(cn + '_') + "[" + vobj.geti("$index") + "]";
+            an = tname.substring
+                (0, tname.lastIndexOf('.')).replace('.', '_') + "_Handle";
+            return "(" + an + ")&" + instArr(cn + '_') + "["
+                + vobj.geti("$index") + "]";
         }
 
         int nxt;
@@ -3976,7 +3978,8 @@
                 }
                 continue;
             }
-            res += (under ? '_' : '.') + (sel.equals("$delegate") ? "__deleg" : sel);
+            res += (under ? '_' : '.')
+                + (sel.equals("$delegate") ? "__deleg" : sel);
             if (under && !(sel.equals("$delegate"))) {
                 res += "__C";
             }
@@ -3984,7 +3987,8 @@
         }
 
         if (tname.endsWith(".Instance")) {
-            an = tname.substring(0, tname.lastIndexOf('.')).replace('.', '_') + "_Handle";
+            an = tname.substring
+                (0, tname.lastIndexOf('.')).replace('.', '_') + "_Handle";
             return "(" + an + ")&" + res;
         }
         else {