示例#1
0
        private static TemplateParam ParseParam(string strname, ref int pos)
        {
            ComplexTemplParam topComplex     = null;
            ComplexTemplParam currentComplex = null;
            int  state                = 0;
            bool signed               = false;
            bool unsigned             = false;
            int  templParamUdtNameLen = 0;

            for (; pos < strname.Length; pos++)
            {
                char ch = strname[pos];
                switch (state)
                {
                case 0:
                    if (char.IsDigit(ch))
                    {
                        templParamUdtNameLen = (int)char.GetNumericValue(ch);
                        state = 1;
                    }
                    else
                    {
                        PrimitiveTemplParam prim = TryParsePrimitive(ch);
                        if (prim != null)
                        {
                            prim.Signed   = signed;
                            prim.Unsigned = unsigned;
                            signed        = false;
                            unsigned      = false;
                            if (currentComplex != null)
                            {
                                currentComplex.Combine(prim);
                                return(topComplex);
                            }
                            else
                            {
                                return(prim);
                            }
                        }
                        else
                        {
                            switch (ch)
                            {
                            case 'u':
                                unsigned = true;
                                break;

                            case 'z':
                                signed = true;
                                break;

                            case 'x':
                            case 'w':
                                ModifierTemplParam newModifier = new ModifierTemplParam();
                                if (ch == 'x')
                                {
                                    newModifier.Attributes |= ModifierAttributes.Const;
                                }
                                else if (ch == 'w')
                                {
                                    newModifier.Attributes |= ModifierAttributes.Volatile;
                                }
                                if (topComplex == null)
                                {
                                    topComplex     = newModifier;
                                    currentComplex = newModifier;
                                }
                                else
                                {
                                    currentComplex.Combine(newModifier, out currentComplex);
                                }
                                break;

                            case 'p':
                            case 'r':
                                PointerTemplParam newPointer = new PointerTemplParam();
                                newPointer.IsReference = ch == 'r';
                                if (topComplex == null)
                                {
                                    topComplex     = newPointer;
                                    currentComplex = newPointer;
                                }
                                else
                                {
                                    currentComplex.Combine(newPointer, out currentComplex);
                                }
                                break;

                            case 'q':
                                pos++;
                                FuncTemplParam funcParam = ParseFuncParam(strname, ref pos);
                                if (currentComplex != null)
                                {
                                    currentComplex.Combine(funcParam);
                                    return(topComplex);
                                }
                                else
                                {
                                    return(funcParam);
                                }

                            default:
                                pos--;
                                return(null);
                            }
                        }
                    }
                    break;

                case 1:
                    if (char.IsDigit(ch))
                    {
                        templParamUdtNameLen *= 10;
                        templParamUdtNameLen += (int)char.GetNumericValue(ch);
                    }
                    else
                    {
                        if (strname.Length < pos + templParamUdtNameLen)
                        {
                            throw new ApplicationException("Invalid type name length: " + templParamUdtNameLen.ToString() + ", exceed name length: " + strname.Length.ToString());
                        }
                        TagTemplParam tagTemplParam = new TagTemplParam();
                        tagTemplParam.Tag = TranslateUdtNameV2(strname.Substring(pos, templParamUdtNameLen));
                        pos += templParamUdtNameLen - 1;
                        if (currentComplex != null)
                        {
                            currentComplex.Combine(tagTemplParam);
                            return(topComplex);
                        }
                        else
                        {
                            return(tagTemplParam);
                        }
                    }
                    break;
                }
            }
            return(null);
        }
示例#2
0
 private static TemplateParam ParseParam(string strname, ref int pos)
 {
     ComplexTemplParam topComplex = null;
     ComplexTemplParam currentComplex = null;
     int state = 0;
     bool signed = false;
     bool unsigned = false;
     int templParamUdtNameLen = 0;
     for (; pos < strname.Length; pos++)
     {
         char ch = strname[pos];
         switch (state)
         {
             case 0:
                 if (char.IsDigit(ch))
                 {
                     templParamUdtNameLen = (int)char.GetNumericValue(ch);
                     state = 1;
                 }
                 else
                 {
                     PrimitiveTemplParam prim = TryParsePrimitive(ch);
                     if (prim != null)
                     {
                         prim.Signed = signed;
                         prim.Unsigned = unsigned;
                         signed = false;
                         unsigned = false;
                         if (currentComplex != null)
                         {
                             currentComplex.Combine(prim);
                             return topComplex;
                         }
                         else
                         {
                             return prim;
                         }
                     }
                     else
                     {
                         switch (ch)
                         {
                             case 'u':
                                 unsigned = true;
                                 break;
                             case 'z':
                                 signed = true;
                                 break;
                             case 'x':
                             case 'w':
                                 ModifierTemplParam newModifier = new ModifierTemplParam();
                                 if (ch == 'x')
                                     newModifier.Attributes |= ModifierAttributes.Const;
                                 else if (ch == 'w')
                                     newModifier.Attributes |= ModifierAttributes.Volatile;
                                 if (topComplex == null)
                                 {
                                     topComplex = newModifier;
                                     currentComplex = newModifier;
                                 }
                                 else
                                 {
                                     currentComplex.Combine(newModifier, out currentComplex);
                                 }
                                 break;
                             case 'p':
                             case 'r':
                                 PointerTemplParam newPointer = new PointerTemplParam();
                                 newPointer.IsReference = ch == 'r';
                                 if (topComplex == null)
                                 {
                                     topComplex = newPointer;
                                     currentComplex = newPointer;
                                 }
                                 else
                                 {
                                     currentComplex.Combine(newPointer, out currentComplex);
                                 }
                                 break;
                             case 'q':
                                 pos++;
                                 FuncTemplParam funcParam = ParseFuncParam(strname, ref pos);
                                 if (currentComplex != null)
                                 {
                                     currentComplex.Combine(funcParam);
                                     return topComplex;
                                 }
                                 else
                                 {
                                     return funcParam;
                                 }
                             default:
                                 pos--;
                                 return null;
                         }
                     }
                 }
                 break;
             case 1:
                 if (char.IsDigit(ch))
                 {
                     templParamUdtNameLen *= 10;
                     templParamUdtNameLen += (int)char.GetNumericValue(ch);
                 }
                 else
                 {
                     if (strname.Length < pos + templParamUdtNameLen)
                         throw new ApplicationException("Invalid type name length: " + templParamUdtNameLen.ToString() + ", exceed name length: " + strname.Length.ToString());
                     TagTemplParam tagTemplParam = new TagTemplParam();
                     tagTemplParam.Tag = TranslateUdtNameV2(strname.Substring(pos, templParamUdtNameLen));
                     pos += templParamUdtNameLen - 1;
                     if (currentComplex != null)
                     {
                         currentComplex.Combine(tagTemplParam);
                         return topComplex;
                     }
                     else
                     {
                         return tagTemplParam;
                     }
                 }
                 break;
         }
     }
     return null;
 }