Exemple #1
0
 /// <summary>
 /// Convert a string to an initializer. "12" will be turned to {'1','2'}. Zeros will 
 /// be patched if the length of the string is smaller than size. If the length of the 
 /// string is greater than size, then only the first size of chars will be converted, 
 /// unless if size is zero or less, in which case, the count number of chars will be
 /// converted.
 /// </summary>
 /// <param name="initialValue">The initial string</param>
 /// <param name="size">The target size</param>
 /// <param name="parent">The parent expression</param>
 /// <returns></returns>
 public static VccInitializer fromStringWithPatchedZeros(string initialValue, int size, Expression parent)
 {
     if (initialValue == null) return null;
       int count = initialValue.Length;
       if (size <= 0) size = count;
       char[] charArr = initialValue.ToCharArray();
       List<Expression> exprs = new List<Expression>();
       VccInitializer result = new VccInitializer(exprs, false, SourceDummy.SourceLocation);
       for (uint i = 0; i < size; i++) {
     if (i < count) {
       sbyte val = (sbyte)charArr[i];
       Expression ch = new CompileTimeConstant(val, parent.SourceLocation);
       ch.SetContainingExpression(parent);
       exprs.Add(ch);
     }
       // If we dont have enough element, we patch zero. It is intentional that no '\0' is added
       // if size == count.
     else {
       Expression zeroPatch = new CompileTimeConstant(0, parent.SourceLocation);
       zeroPatch.SetContainingExpression(parent);
       exprs.Add(zeroPatch);
     }
       }
       result.SetContainingExpression(parent);
       return result;
 }