Exemplo n.º 1
0
        private static FuncTemplParam ParseFuncParam(string strname, ref int pos)
        {
            FuncTemplParam func = new FuncTemplParam();

            for (; pos < strname.Length; pos++)
            {
                char ch = strname[pos];
                if (ch == '$')
                {
                    pos++;
                    func.ReturnType = ParseParam(strname, ref pos);
                    return(func);
                }
                else
                {
                    if (ch == 't')
                    {
                        pos++;
                        int paramIndex = (int)char.GetNumericValue(strname[pos]) - 1;
                        func.ArgsTypes.Add(func.ArgsTypes[paramIndex]);
                    }
                    else
                    {
                        func.ArgsTypes.Add(ParseParam(strname, ref pos));
                    }
                }
            }
            throw new ApplicationException("Cannot parse function type, unexpected end of string");
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 private static FuncTemplParam ParseFuncParam(string strname, ref int pos)
 {
     FuncTemplParam func = new FuncTemplParam();
     for (; pos < strname.Length; pos++)
     {
         char ch = strname[pos];
         if (ch == '$')
         {
             pos++;
             func.ReturnType = ParseParam(strname, ref pos);
             return func;
         }
         else
         {
             if (ch == 't')
             {
                 pos++;
                 int paramIndex = (int)char.GetNumericValue(strname[pos]) - 1;
                 func.ArgsTypes.Add(func.ArgsTypes[paramIndex]);
             }
             else
             {
                 func.ArgsTypes.Add(ParseParam(strname, ref pos));
             }
         }
     }
     throw new ApplicationException("Cannot parse function type, unexpected end of string");
 }