Esempio n. 1
0
        internal static String CreateElementKindString(ElementKind elementKind, GeneralArrayInfo arrayInfo)
        {
            var builder = new StringBuilder();

            CreateElementKindString(elementKind, arrayInfo, builder);
            return(builder.ToString());
        }
Esempio n. 2
0
        private static void CreateElementKindString(ElementKind elementKind, GeneralArrayInfo arrayInfo, StringBuilder builder)
        {
            switch (elementKind)
            {
            case ElementKind.Array:
                builder.Append('[');
                if (arrayInfo != null)
                {
                    if (arrayInfo.Rank == 1 && arrayInfo.Sizes.Count == 0 && arrayInfo.LowerBounds.Count == 0)
                    {
                        // Special case
                        builder.Append('*');
                    }
                    else
                    {
                        for (var i = 0; i < arrayInfo.Rank; ++i)
                        {
                            var appendLoBound = i < arrayInfo.LowerBounds.Count;
                            if (appendLoBound)
                            {
                                var loBound = arrayInfo.LowerBounds[i];
                                appendLoBound = loBound != 0;
                                if (appendLoBound)
                                {
                                    builder.Append(loBound).Append("..");
                                }
                            }
                            if (i < arrayInfo.Sizes.Count)
                            {
                                builder.Append(arrayInfo.Sizes[i]);
                            }
                            else if (appendLoBound)
                            {
                                builder.Append('.');
                            }

                            if (i < arrayInfo.Rank - 1)
                            {
                                builder.Append(',');
                            }
                        }
                    }
                }
                builder.Append(']');
                break;

            case ElementKind.Pointer:
                builder.Append('*');
                break;

            case ElementKind.Reference:
                builder.Append('&');
                break;
            }
        }
Esempio n. 3
0
        // Start idx = index of '[', End idx = index of ']'
        private static GeneralArrayInfo ReadArrayInfo(String typeStr, Int32 startIdx, Int32 endIdx, Int32 rank)
        {
            GeneralArrayInfo result;

            if (startIdx == endIdx - 1)
            {
                // Vector array
                result = null;
            }
            else
            {
                // General array
                ++startIdx;
                var sizes      = new Int32[rank];
                var sizeIdx    = 0;
                var loBounds   = new Int32[rank];
                var loBoundIdx = 0;
                // Check for special case - rank 1, no sizes, no lower bounds (is '[*]').
                if (startIdx != endIdx - 1 || typeStr[startIdx] != '*')
                {
                    var curIdx = startIdx;

                    while (curIdx <= endIdx)
                    {
                        switch (typeStr[curIdx])
                        {
                        case ',':
                        case ']':
                            // End of dimension
                            if (startIdx != curIdx)
                            {
                                // Size specified
                                // Implicitly add zero lower bound if needed
                                if (sizeIdx == loBoundIdx)
                                {
                                    loBounds[loBoundIdx++] = 0;
                                }
                                // Then save size
                                sizes[sizeIdx++] = Int32.Parse(typeStr.Substring(startIdx, curIdx - startIdx));
                            }
                            startIdx = curIdx + 1;
                            break;

                        case '.':
                            if (startIdx != curIdx)
                            {
                                // End of lower bound
                                loBounds[loBoundIdx++] = Int32.Parse(typeStr.Substring(startIdx, curIdx - startIdx));
                            }
                            startIdx = curIdx + 1;
                            break;
                        }
                        ++curIdx;
                    }
                }
                // Create actual size and lower bounds arrays
                var actualSizes = new Int32[sizeIdx];
                Array.Copy(sizes, actualSizes, sizeIdx);
                var actualLoBounds = new Int32[loBoundIdx];
                Array.Copy(loBounds, actualLoBounds, loBoundIdx);
                result = new GeneralArrayInfo(rank, actualSizes, actualLoBounds);
            }
            return(result);
        }