ZCsl::Variable* ZCsl::Block::addVar(
   const ZString& aVarName,
   const ZString& aInitValue,
   ZBoolean aIsConst,
   ZBoolean aIsRef,
   ZBoolean aIsKnown,
   ZBoolean aIsExtern)
{
   ZFUNCTRACE_DEVELOP("ZCsl::Block::addVar(...)");
   Variable* v = findVar(aVarName, zFalse);
   if (v) {
      if (!v->iIsExtern)
         iParent->throwExcept(msgVarAlrdyDef, aVarName);
      if (v->iIsConst != aIsConst ||
          (v->iRef && !aIsRef)    ||
          (!v->iRef && aIsRef)    ||
          aVarName.occurrencesOf('[') != v->dims() )
         iParent->throwExcept(msgVarDiffers, aVarName);
      Variable var(iParent, aVarName, aInitValue,
                   aIsConst, aIsRef, aIsKnown, aIsExtern, 0);
      if (v->iVals) delete [] v->iVals;
      v->iVals = var.iVals;
      var.iVals = 0;
      v->iIsKnown = var.iIsKnown;
      v->iIsExtern = var.iIsExtern;
      for (int i = 0; i < MAXDIMS; i++)
         v->iDims[i] = var.iDims[i];
      return v;
   } // if
   iVars = new Variable(iParent, aVarName, aInitValue,
                        aIsConst, aIsRef, aIsKnown, aIsExtern, iVars);
   return iVars;
} // addVar
Example #2
0
void ZCsl::showIdents (Block * b, char *lead, long &depth)
{
  ZFUNCTRACE_DEVELOP ("ZCsl::showIdents(Block* b, char* lead, long& depth)");
  Variable *v = b->iVars;
  while (v && depth > 0)
      {
        ZString msg (lead);
        msg += v->iIsConst ? "const " : "var ";
        if (v->iRef)
          msg += "&";
        msg += v->iName;
        if (v->iIsExtern)
            {
              if (v->dims ())
                for (int d = 0; d < v->dims (); d++)
                  msg += "[]";
              msg += ", unallocated external";
            }
        else
            {
              if (v->dims ())
                  {
                    for (int d = 0; d < v->dims (); d++)
                      msg += "[" + ZString (v->iDims[d]) + "]";
                  }
              else
                  {
                    v->match (v->iName);
                    msg += " = " + v->value ();
                  }             // if
            }                   // if
        log (msg.constBuffer ());
        v = v->iPrev;
        depth--;
      }                         // while
}                               // showIdents