Inheritance: System.Reflection.TypeInfo
Example #1
0
 public override Type MakePointerType()
 {
     return(SymbolType.FormCompoundType("*", this, 0) !);
 }
Example #2
0
 public override Type MakeByRefType()
 {
     return(SymbolType.FormCompoundType("&", this, 0) !);
 }
Example #3
0
 public override Type MakeArrayType()
 {
     return(SymbolType.FormCompoundType(m_format + "[]", m_baseType, 0) !);
 }
Example #4
0
        public override Type MakeArrayType(int rank)
        {
            string s = GetRankString(rank);

            return(SymbolType.FormCompoundType(s, this, 0) !);
        }
Example #5
0
        internal static Type?FormCompoundType(string?format, Type baseType, int curIndex)
        {
            // This function takes a string to describe the compound type, such as "[,][]", and a baseType.
            //
            // Example: [2..4]  - one dimension array with lower bound 2 and size of 3
            // Example: [3, 5, 6] - three dimension array with lower bound 3, 5, 6
            // Example: [-3, ] [] - one dimensional array of two dimensional array (with lower bound -3 for
            //          the first dimension)
            // Example: []* - pointer to a one dimensional array
            // Example: *[] - one dimensional array. The element type is a pointer to the baseType
            // Example: []& - ByRef of a single dimensional array. Only one & is allowed and it must appear the last!
            // Example: [?] - Array with unknown bound

            SymbolType symbolType;
            int        iLowerBound;
            int        iUpperBound;

            if (format == null || curIndex == format.Length)
            {
                // we have consumed all of the format string
                return(baseType);
            }



            if (format[curIndex] == '&')
            {
                // ByRef case

                symbolType = new SymbolType(TypeKind.IsByRef);
                symbolType.SetFormat(format, curIndex, 1);
                curIndex++;

                if (curIndex != format.Length)
                {
                    // ByRef has to be the last char!!
                    throw new ArgumentException(SR.Argument_BadSigFormat);
                }

                symbolType.SetElementType(baseType);
                return(symbolType);
            }

            if (format[curIndex] == '[')
            {
                // Array type.
                symbolType = new SymbolType(TypeKind.IsArray);
                int startIndex = curIndex;
                curIndex++;

                iLowerBound = 0;
                iUpperBound = -1;

                // Example: [2..4]  - one dimension array with lower bound 2 and size of 3
                // Example: [3, 5, 6] - three dimension array with lower bound 3, 5, 6
                // Example: [-3, ] [] - one dimensional array of two dimensional array (with lower bound -3 sepcified)

                while (format[curIndex] != ']')
                {
                    if (format[curIndex] == '*')
                    {
                        symbolType.m_isSzArray = false;
                        curIndex++;
                    }
                    // consume, one dimension at a time
                    if ((format[curIndex] >= '0' && format[curIndex] <= '9') || format[curIndex] == '-')
                    {
                        bool isNegative = false;
                        if (format[curIndex] == '-')
                        {
                            isNegative = true;
                            curIndex++;
                        }

                        // lower bound is specified. Consume the low bound
                        while (format[curIndex] >= '0' && format[curIndex] <= '9')
                        {
                            iLowerBound  = iLowerBound * 10;
                            iLowerBound += format[curIndex] - '0';
                            curIndex++;
                        }

                        if (isNegative)
                        {
                            iLowerBound = 0 - iLowerBound;
                        }

                        // set the upper bound to be less than LowerBound to indicate that upper bound it not specified yet!
                        iUpperBound = iLowerBound - 1;
                    }
                    if (format[curIndex] == '.')
                    {
                        // upper bound is specified

                        // skip over ".."
                        curIndex++;
                        if (format[curIndex] != '.')
                        {
                            // bad format!! Throw exception
                            throw new ArgumentException(SR.Argument_BadSigFormat);
                        }

                        curIndex++;
                        // consume the upper bound
                        if ((format[curIndex] >= '0' && format[curIndex] <= '9') || format[curIndex] == '-')
                        {
                            bool isNegative = false;
                            iUpperBound = 0;
                            if (format[curIndex] == '-')
                            {
                                isNegative = true;
                                curIndex++;
                            }

                            // lower bound is specified. Consume the low bound
                            while (format[curIndex] >= '0' && format[curIndex] <= '9')
                            {
                                iUpperBound  = iUpperBound * 10;
                                iUpperBound += format[curIndex] - '0';
                                curIndex++;
                            }
                            if (isNegative)
                            {
                                iUpperBound = 0 - iUpperBound;
                            }
                            if (iUpperBound < iLowerBound)
                            {
                                // User specified upper bound less than lower bound, this is an error.
                                // Throw error exception.
                                throw new ArgumentException(SR.Argument_BadSigFormat);
                            }
                        }
                    }

                    if (format[curIndex] == ',')
                    {
                        // We have more dimension to deal with.
                        // now set the lower bound, the size, and increase the dimension count!
                        curIndex++;
                        symbolType.SetBounds(iLowerBound, iUpperBound);

                        // clear the lower and upper bound information for next dimension
                        iLowerBound = 0;
                        iUpperBound = -1;
                    }
                    else if (format[curIndex] != ']')
                    {
                        throw new ArgumentException(SR.Argument_BadSigFormat);
                    }
                }

                // The last dimension information
                symbolType.SetBounds(iLowerBound, iUpperBound);

                // skip over ']'
                curIndex++;

                symbolType.SetFormat(format, startIndex, curIndex - startIndex);

                // set the base type of array
                symbolType.SetElementType(baseType);
                return(FormCompoundType(format, symbolType, curIndex));
            }
            else if (format[curIndex] == '*')
            {
                // pointer type.

                symbolType = new SymbolType(TypeKind.IsPointer);
                symbolType.SetFormat(format, curIndex, 1);
                curIndex++;
                symbolType.SetElementType(baseType);
                return(FormCompoundType(format, symbolType, curIndex));
            }

            return(null);
        }
Example #6
0
 public override Type MakeByRefType()
 {
     return(SymbolType.FormCompoundType(m_format + "&", m_baseType, 0) !);
 }
 public override Type MakePointerType()
 {
     return(SymbolType.FormCompoundType("*".ToCharArray(), this, 0));
 }
 internal static Type FormCompoundType(char[] bFormat, Type baseType, int curIndex)
 {
     SymbolType type;
     if ((bFormat == null) || (curIndex == bFormat.Length))
     {
         return baseType;
     }
     if (bFormat[curIndex] == '&')
     {
         type = new SymbolType(TypeKind.IsByRef);
         type.SetFormat(bFormat, curIndex, 1);
         curIndex++;
         if (curIndex != bFormat.Length)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
         }
         type.SetElementType(baseType);
         return type;
     }
     if (bFormat[curIndex] == '[')
     {
         type = new SymbolType(TypeKind.IsArray);
         int num3 = curIndex;
         curIndex++;
         int lower = 0;
         int upper = -1;
         while (bFormat[curIndex] != ']')
         {
             if (bFormat[curIndex] == '*')
             {
                 type.m_isSzArray = false;
                 curIndex++;
             }
             if (((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9')) || (bFormat[curIndex] == '-'))
             {
                 bool flag = false;
                 if (bFormat[curIndex] == '-')
                 {
                     flag = true;
                     curIndex++;
                 }
                 while ((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9'))
                 {
                     lower *= 10;
                     lower += bFormat[curIndex] - '0';
                     curIndex++;
                 }
                 if (flag)
                 {
                     lower = -lower;
                 }
                 upper = lower - 1;
             }
             if (bFormat[curIndex] == '.')
             {
                 curIndex++;
                 if (bFormat[curIndex] != '.')
                 {
                     throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                 }
                 curIndex++;
                 if (((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9')) || (bFormat[curIndex] == '-'))
                 {
                     bool flag2 = false;
                     upper = 0;
                     if (bFormat[curIndex] == '-')
                     {
                         flag2 = true;
                         curIndex++;
                     }
                     while ((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9'))
                     {
                         upper *= 10;
                         upper += bFormat[curIndex] - '0';
                         curIndex++;
                     }
                     if (flag2)
                     {
                         upper = -upper;
                     }
                     if (upper < lower)
                     {
                         throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                     }
                 }
             }
             if (bFormat[curIndex] == ',')
             {
                 curIndex++;
                 type.SetBounds(lower, upper);
                 lower = 0;
                 upper = -1;
             }
             else if (bFormat[curIndex] != ']')
             {
                 throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
             }
         }
         type.SetBounds(lower, upper);
         curIndex++;
         type.SetFormat(bFormat, num3, curIndex - num3);
         type.SetElementType(baseType);
         return FormCompoundType(bFormat, type, curIndex);
     }
     if (bFormat[curIndex] == '*')
     {
         type = new SymbolType(TypeKind.IsPointer);
         type.SetFormat(bFormat, curIndex, 1);
         curIndex++;
         type.SetElementType(baseType);
         return FormCompoundType(bFormat, type, curIndex);
     }
     return null;
 }
Example #9
0
 public override Type MakeArrayType()
 {
     return(SymbolType.FormCompoundType((new String(m_bFormat) + "[]").ToCharArray(), m_baseType, 0));
 }
 public override Type MakeByRefType()
 {
     return(SymbolType.FormCompoundType("&".ToCharArray(), this, 0));
 }
        internal static Type FormCompoundType(char[] bFormat, Type baseType, int curIndex)
        {
            SymbolType type;

            if ((bFormat == null) || (curIndex == bFormat.Length))
            {
                return(baseType);
            }
            if (bFormat[curIndex] == '&')
            {
                type = new SymbolType(TypeKind.IsByRef);
                type.SetFormat(bFormat, curIndex, 1);
                curIndex++;
                if (curIndex != bFormat.Length)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                }
                type.SetElementType(baseType);
                return(type);
            }
            if (bFormat[curIndex] == '[')
            {
                type = new SymbolType(TypeKind.IsArray);
                int num3 = curIndex;
                curIndex++;
                int lower = 0;
                int upper = -1;
                while (bFormat[curIndex] != ']')
                {
                    if (bFormat[curIndex] == '*')
                    {
                        type.m_isSzArray = false;
                        curIndex++;
                    }
                    if (((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9')) || (bFormat[curIndex] == '-'))
                    {
                        bool flag = false;
                        if (bFormat[curIndex] == '-')
                        {
                            flag = true;
                            curIndex++;
                        }
                        while ((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9'))
                        {
                            lower *= 10;
                            lower += bFormat[curIndex] - '0';
                            curIndex++;
                        }
                        if (flag)
                        {
                            lower = -lower;
                        }
                        upper = lower - 1;
                    }
                    if (bFormat[curIndex] == '.')
                    {
                        curIndex++;
                        if (bFormat[curIndex] != '.')
                        {
                            throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                        }
                        curIndex++;
                        if (((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9')) || (bFormat[curIndex] == '-'))
                        {
                            bool flag2 = false;
                            upper = 0;
                            if (bFormat[curIndex] == '-')
                            {
                                flag2 = true;
                                curIndex++;
                            }
                            while ((bFormat[curIndex] >= '0') && (bFormat[curIndex] <= '9'))
                            {
                                upper *= 10;
                                upper += bFormat[curIndex] - '0';
                                curIndex++;
                            }
                            if (flag2)
                            {
                                upper = -upper;
                            }
                            if (upper < lower)
                            {
                                throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                            }
                        }
                    }
                    if (bFormat[curIndex] == ',')
                    {
                        curIndex++;
                        type.SetBounds(lower, upper);
                        lower = 0;
                        upper = -1;
                    }
                    else if (bFormat[curIndex] != ']')
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                    }
                }
                type.SetBounds(lower, upper);
                curIndex++;
                type.SetFormat(bFormat, num3, curIndex - num3);
                type.SetElementType(baseType);
                return(FormCompoundType(bFormat, type, curIndex));
            }
            if (bFormat[curIndex] == '*')
            {
                type = new SymbolType(TypeKind.IsPointer);
                type.SetFormat(bFormat, curIndex, 1);
                curIndex++;
                type.SetElementType(baseType);
                return(FormCompoundType(bFormat, type, curIndex));
            }
            return(null);
        }
Example #12
0
        //************************************************
        //
        // This function will not increase the argument count. It only fills in bytes
        // in the signature based on clsArgument. This helper is called for return type.
        //
        //************************************************
        private void AddOneArgTypeHelper(Type clsArgument)
        {
            if (clsArgument == null)
            {
                throw new ArgumentNullException("clsArgument");
            }
            if (clsArgument is TypeBuilder)
            {
                TypeBuilder clsBuilder = (TypeBuilder)clsArgument;
                TypeToken   tkType;
                if (clsBuilder.Module == m_module)
                {
                    tkType = clsBuilder.TypeToken;
                }
                else
                {
                    tkType = m_module.GetTypeToken(clsArgument);
                }
                if (clsArgument.IsValueType)
                {
                    InternalAddTypeToken(tkType, ELEMENT_TYPE_VALUETYPE);
                }
                else
                {
                    InternalAddTypeToken(tkType, ELEMENT_TYPE_CLASS);
                }
            }
            else if (clsArgument is EnumBuilder)
            {
                TypeBuilder clsBuilder = ((EnumBuilder)clsArgument).m_typeBuilder;
                TypeToken   tkType;
                if (clsBuilder.Module == m_module)
                {
                    tkType = clsBuilder.TypeToken;
                }
                else
                {
                    tkType = m_module.GetTypeToken(clsArgument);
                }

                if (clsArgument.IsValueType)
                {
                    InternalAddTypeToken(tkType, ELEMENT_TYPE_VALUETYPE);
                }
                else
                {
                    InternalAddTypeToken(tkType, ELEMENT_TYPE_CLASS);
                }
            }
            else if (clsArgument is SymbolType)
            {
                SignatureBuffer sigBuf  = new SignatureBuffer();
                SymbolType      symType = (SymbolType)clsArgument;
                int             i;

                // convert SymbolType to blob form
                symType.ToSigBytes(m_module, sigBuf);

                // add to our signature buffer
                // ensure the size of the signature buffer
                if ((m_currSig + sigBuf.m_curPos) > m_signature.Length)
                {
                    m_signature = ExpandArray(m_signature, m_currSig + sigBuf.m_curPos);
                }

                // copy over the signature segment
                for (i = 0; i < sigBuf.m_curPos; i++)
                {
                    m_signature[m_currSig++] = sigBuf.m_buf[i];
                }
            }
            else
            {
                if (clsArgument.IsByRef)
                {
                    AddElementType(ELEMENT_TYPE_BYREF);
                    clsArgument = clsArgument.GetElementType();
                }

                if (clsArgument.IsArray || clsArgument.IsPointer)
                {
                    AddArrayOrPointer(clsArgument);
                    return;
                }

                RuntimeType rType = clsArgument as RuntimeType;
                int         type  = rType != null?GetCorElementTypeFromClass(rType) : ELEMENT_TYPE_MAX;

                if (IsSimpleType(type))
                {
                    // base element type
                    AddElementType(type);
                }
                else
                {
                    if (clsArgument.IsValueType)
                    {
                        InternalAddTypeToken(m_module.GetTypeToken(clsArgument), ELEMENT_TYPE_VALUETYPE);
                    }
                    else
                    {
                        if (clsArgument == SystemObject)
                        {
                            // use the short cut for System.Object
                            AddElementType(ELEMENT_TYPE_OBJECT);
                        }
                        else if (clsArgument == SystemString)
                        {
                            // use the short cut for System.String
                            AddElementType(ELEMENT_TYPE_STRING);
                        }
                        else
                        {
                            InternalAddTypeToken(m_module.GetTypeToken(clsArgument), ELEMENT_TYPE_CLASS);
                        }
                    }
                }
            }
        }
Example #13
0
        private char[] m_bFormat;               // format string to form the full name.



        //***********************************************
        //
        // This function takes a string to describe the compound type, such as "[,][]", and a baseType.
        //
        // Example: [2..4]  - one dimension array with lower bound 2 and size of 3
        // Example: [3, 5, 6] - three dimension array with lower bound 3, 5, 6
        // Example: [-3, ] [] - one dimensional array of two dimensional array (with lower bound -3 for
        //          the first dimension)
        // Example: []* - pointer to a one dimensional array
        // Example: *[] - one dimensional array. The element type is a pointer to the baseType
        // Example: []& - ByRef of a single dimensional array. Only one & is allowed and it must appear the last!
        // Example: [?] - Array with unknown bound
        //
        //***********************************************
        internal static Type FormCompoundType(char[] bFormat, Type baseType, int curIndex)
        {
            SymbolType symbolType;
            int        iLowerBound;
            int        iUpperBound;

            if (bFormat == null || curIndex == bFormat.Length)
            {
                // we have consumed all of the format string
                return(baseType);
            }

            // @todo: baseType cannot be already a array type or a pointer type.
            // We need to do checking here...

            if (bFormat[curIndex] == '&')
            {
                // ByRef case

                symbolType = new SymbolType(TypeKind.IsByRef);
                symbolType.SetFormat(bFormat, curIndex);
                curIndex++;
                if (curIndex != bFormat.Length)
                {
                    // ByRef has to be the last char!!
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                }
                symbolType.SetElementType(baseType);
                return(symbolType);
            }
            if (bFormat[curIndex] == '[')
            {
                // Array type.
                symbolType = new SymbolType(TypeKind.IsArray);
                symbolType.SetFormat(bFormat, curIndex);
                curIndex++;

                iLowerBound = 0;
                iUpperBound = -1;

                // Example: [2..4]  - one dimension array with lower bound 2 and size of 3
                // Example: [3, 5, 6] - three dimension array with lower bound 3, 5, 6
                // Example: [-3, ] [] - one dimensional array of two dimensional array (with lower bound -3 sepcified)
                while (bFormat[curIndex] != ']')
                {
                    // consume, one dimension at a time
                    if ((bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9') || bFormat[curIndex] == '-')
                    {
                        bool isNegative = false;
                        if (bFormat[curIndex] == '-')
                        {
                            isNegative = true;
                            curIndex++;
                        }

                        // lower bound is specified. Consume the low bound
                        while (bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9')
                        {
                            iLowerBound  = iLowerBound * 10;
                            iLowerBound += bFormat[curIndex] - '0';
                            curIndex++;
                        }
                        if (isNegative)
                        {
                            iLowerBound = 0 - iLowerBound;
                        }

                        // set the upper bound to be less than LowerBound to indicate that upper bound it not specified
                        // yet!
                        iUpperBound = iLowerBound - 1;
                    }
                    if (bFormat[curIndex] == '.')
                    {
                        // upper bound is specified

                        // skip over ".."
                        curIndex++;
                        if (bFormat[curIndex] != '.')
                        {
                            // bad format!! Throw exception
                            throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                        }

                        curIndex++;
                        // consume the upper bound
                        if ((bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9') || bFormat[curIndex] == '-')
                        {
                            bool isNegative = false;
                            iUpperBound = 0;
                            if (bFormat[curIndex] == '-')
                            {
                                isNegative = true;
                                curIndex++;
                            }

                            // lower bound is specified. Consume the low bound
                            while (bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9')
                            {
                                iUpperBound  = iUpperBound * 10;
                                iUpperBound += bFormat[curIndex] - '0';
                                curIndex++;
                            }
                            if (isNegative)
                            {
                                iUpperBound = 0 - iUpperBound;
                            }
                            if (iUpperBound < iLowerBound)
                            {
                                // User specified upper bound less than lower bound, this is an error.
                                // Throw error exception.
                                throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                            }
                        }
                    }

                    if (bFormat[curIndex] == ',')
                    {
                        // We have more dimension to deal with.
                        // now set the lower bound, the size, and increase the dimension count!
                        curIndex++;
                        symbolType.SetBounds(iLowerBound, iUpperBound);

                        // clear the lower and upper bound information for next dimension
                        iLowerBound = 0;
                        iUpperBound = -1;
                    }
                    else if (bFormat[curIndex] != ']')
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                    }
                }

                // The last dimension information
                symbolType.SetBounds(iLowerBound, iUpperBound);

                // skip over ']'
                curIndex++;

                // set the base type of array
                symbolType.SetElementType(baseType);
                return(FormCompoundType(bFormat, symbolType, curIndex));
            }
            else if (bFormat[curIndex] == '*')
            {
                // pointer type.

                symbolType = new SymbolType(TypeKind.IsPointer);
                symbolType.SetFormat(bFormat, curIndex);
                curIndex++;
                symbolType.SetElementType(baseType);
                return(FormCompoundType(bFormat, symbolType, curIndex));
            }
            return(null);
        }
Example #14
0
 public override Type MakeArrayType()
 {
     return(SymbolType.FormCompoundType("[]", this, 0) !);
 }
Example #15
0
 public override Type MakePointerType()
 {
     return(SymbolType.FormCompoundType(m_format + "*", m_baseType, 0) !);
 }
        internal static Type FormCompoundType(char[] bFormat, Type baseType, int curIndex)
        {
            // This function takes a string to describe the compound type, such as "[,][]", and a baseType.
            // 
            // Example: [2..4]  - one dimension array with lower bound 2 and size of 3
            // Example: [3, 5, 6] - three dimension array with lower bound 3, 5, 6
            // Example: [-3, ] [] - one dimensional array of two dimensional array (with lower bound -3 for 
            //          the first dimension)
            // Example: []* - pointer to a one dimensional array
            // Example: *[] - one dimensional array. The element type is a pointer to the baseType
            // Example: []& - ByRef of a single dimensional array. Only one & is allowed and it must appear the last!
            // Example: [?] - Array with unknown bound

            SymbolType symbolType;
            int iLowerBound;
            int iUpperBound;

            if (bFormat == null || curIndex == bFormat.Length)
            {
                // we have consumed all of the format string
                return baseType;
            }

              
             

            if (bFormat[curIndex] == '&')
            {
                // ByRef case

                symbolType = new SymbolType(TypeKind.IsByRef);
                symbolType.SetFormat(bFormat, curIndex, 1);
                curIndex++;
                
                if (curIndex != bFormat.Length)
                    // ByRef has to be the last char!!
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));

                symbolType.SetElementType(baseType);
                return symbolType;
            }

            if (bFormat[curIndex] == '[')
            {
                // Array type.
                symbolType = new SymbolType(TypeKind.IsArray);
                int startIndex = curIndex;
                curIndex++;

                iLowerBound = 0;
                iUpperBound = -1;

                // Example: [2..4]  - one dimension array with lower bound 2 and size of 3
                // Example: [3, 5, 6] - three dimension array with lower bound 3, 5, 6
                // Example: [-3, ] [] - one dimensional array of two dimensional array (with lower bound -3 sepcified)
                
                while (bFormat[curIndex] != ']')
                {
                    if (bFormat[curIndex] == '*')
                    {
                        symbolType.m_isSzArray = false;
                        curIndex++;                        
                    }
                    // consume, one dimension at a time
                    if ((bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9') || bFormat[curIndex] == '-')
                    {
                        bool isNegative = false;
                        if (bFormat[curIndex] == '-')
                        {
                            isNegative = true;
                            curIndex++;
                        }

                        // lower bound is specified. Consume the low bound
                        while (bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9')
                        {
                            iLowerBound = iLowerBound * 10;
                            iLowerBound += bFormat[curIndex] - '0';
                            curIndex++;
                        }

                        if (isNegative)
                        {
                            iLowerBound = 0 - iLowerBound;
                        }

                        // set the upper bound to be less than LowerBound to indicate that upper bound it not specified yet!
                        iUpperBound = iLowerBound - 1;

                    }
                    if (bFormat[curIndex] == '.')
                    {                       
                        // upper bound is specified

                        // skip over ".."
                        curIndex++;
                        if (bFormat[curIndex] != '.')
                        {
                            // bad format!! Throw exception
                            throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                        }

                        curIndex++;
                        // consume the upper bound
                        if ((bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9') || bFormat[curIndex] == '-')
                        {
                            bool isNegative = false;
                            iUpperBound = 0;
                            if (bFormat[curIndex] == '-')
                            {
                                isNegative = true;
                                curIndex++;
                            }

                            // lower bound is specified. Consume the low bound
                            while (bFormat[curIndex] >= '0' && bFormat[curIndex] <= '9')
                            {
                                iUpperBound = iUpperBound * 10;
                                iUpperBound += bFormat[curIndex] - '0';
                                curIndex++;
                            }
                            if (isNegative)
                            {
                                iUpperBound = 0 - iUpperBound;
                            }
                            if (iUpperBound < iLowerBound)
                            {
                                // User specified upper bound less than lower bound, this is an error.
                                // Throw error exception.
                                throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                            }
                        }
                    }

                    if (bFormat[curIndex] == ',')
                    {
                        // We have more dimension to deal with.
                        // now set the lower bound, the size, and increase the dimension count!
                        curIndex++;
                        symbolType.SetBounds(iLowerBound, iUpperBound);

                        // clear the lower and upper bound information for next dimension
                        iLowerBound = 0;
                        iUpperBound = -1;
                    }
                    else if (bFormat[curIndex] != ']')
                    {
                        throw new ArgumentException(Environment.GetResourceString("Argument_BadSigFormat"));
                    }
                }
                
                // The last dimension information
                symbolType.SetBounds(iLowerBound, iUpperBound);

                // skip over ']'
                curIndex++;

                symbolType.SetFormat(bFormat, startIndex, curIndex - startIndex);

                // set the base type of array
                symbolType.SetElementType(baseType);
                return FormCompoundType(bFormat, symbolType, curIndex);
            }
            else if (bFormat[curIndex] == '*')
            {
                // pointer type.

                symbolType = new SymbolType(TypeKind.IsPointer);
                symbolType.SetFormat(bFormat, curIndex, 1);
                curIndex++;
                symbolType.SetElementType(baseType);
                return FormCompoundType(bFormat, symbolType, curIndex);
            }

            return null;
        }
Example #17
0
 public override Type MakeArrayType()
 {
     return(SymbolType.FormCompoundType("[]".ToCharArray(), (Type)this, 0));
 }