Exemple #1
0
 private static bool ParsePrimitiveType(string[] input, ref int index, ref CppType result)
 {
     if (ParseSignedUnsigned(input, ref index))
     {
         if (ParseInt(input, ref index))
         {
             result = new CppType()
             {
                 Name = input[index - 2] + " " + input[index - 1],
             };
             return(true);
         }
         else
         {
             throw new ArgumentException(string.Format("{0} is not a valid type.", input[index - 2] + " " + input[index - 1]));
         }
     }
     else if (ParseName(input, ref index))
     {
         result = new CppType()
         {
             Name = input[index - 1],
         };
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #2
0
        public static CppType Parse(string input)
        {
            List <string> pieces = new List <string>();
            int           index  = 0;

            while (true)
            {
                int find = input.IndexOfAny("<> ,*&()".ToCharArray(), index);
                if (find == -1)
                {
                    pieces.Add(input.Substring(index, input.Length - index));
                    break;
                }
                else
                {
                    pieces.Add(input.Substring(index, find - index));
                    pieces.Add(input.Substring(find, 1));
                    index = find + 1;
                }
            }

            index = 0;
            string[] tokens = pieces.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
            CppType  type   = null;

            if (!ParseType(input, tokens, ref index, ref type))
            {
                throw new ArgumentException(string.Format("Completely not understand what type is {0}.", input));
            }
            else if (index != tokens.Length)
            {
                throw new ArgumentException(string.Format("Only a prefix of {0} is parsed.", input));
            }
            return(type);
        }
Exemple #3
0
 private static bool ParseType(string raw, string[] input, ref int index, ref CppType result)
 {
     if (ParsePrimitiveType(input, ref index, ref result))
     {
         while (true)
         {
             if (ParseString(input, ref index, "__cdecl", "__clrcall", "__stdcall", "__fastcall", "__thiscall"))
             {
                 result.CallingConversion = input[index - 1];
             }
             if (ParseString(input, ref index, "<") || ParseString(input, ref index, "("))
             {
                 if (result.CallingConversion != "" && input[index - 1] == "<")
                 {
                     throw new ArgumentException(string.Format("Token \"(\" is missing in {0}.", raw));
                 }
                 string         endToken   = input[index - 1] == "<" ? ">" : ")";
                 CppDecoration  decoration = input[index - 1] == "<" ? CppDecoration.Template : CppDecoration.Function;
                 List <CppType> arguments  = new List <CppType>();
                 while (true)
                 {
                     CppType argument = null;
                     if (ParseType(raw, input, ref index, ref argument))
                     {
                         arguments.Add(argument);
                         if (ParseString(input, ref index, endToken))
                         {
                             break;
                         }
                         else if (!ParseString(input, ref index, ","))
                         {
                             throw new ArgumentException(string.Format("Token \",\" is missing in {0}.", raw));
                         }
                     }
                     else
                     {
                         throw new ArgumentException(string.Format("Type is missing in {0}.", raw));
                     }
                 }
                 result.Decoration = decoration;
                 result.Arguments  = arguments.ToArray();
             }
             else if (ParseVCRP(input, ref index))
             {
                 result = new CppType()
                 {
                     Name       = input[index - 1],
                     Decoration = CppDecoration.Decoration,
                     Arguments  = new CppType[] { result },
                 };
             }
             else
             {
                 break;
             }
         }
         return(true);
     }
     return(false);
 }
Exemple #4
0
        protected void WriteHyperlinkType(CppType type, TextWriter writer, DocItemWriterContext context)
        {
            switch (type.Decoration)
            {
            case CppDecoration.None:
            {
                WriteHyperlinkPrimitiveType(type.Name, writer, context);
            }
            break;

            case CppDecoration.Decoration:
            {
                WriteHyperlinkType(type.Arguments[0], writer, context);
                writer.Write(" " + type.Name);
            }
            break;

            case CppDecoration.Template:
            {
                WriteHyperlinkPrimitiveType(type.Name, writer, context);
                writer.Write("<");
                for (int i = 0; i < type.Arguments.Length; i++)
                {
                    WriteHyperlinkType(type.Arguments[i], writer, context);
                    if (i == type.Arguments.Length - 1)
                    {
                        writer.Write(">");
                    }
                    else
                    {
                        writer.Write(", ");
                    }
                }
            }
            break;

            case CppDecoration.Function:
            {
                WriteHyperlinkPrimitiveType(type.Name, writer, context);
                writer.Write(" " + type.CallingConversion + "(");
                for (int i = 0; i < type.Arguments.Length; i++)
                {
                    WriteHyperlinkType(type.Arguments[i], writer, context);
                    if (i == type.Arguments.Length - 1)
                    {
                        writer.Write(")");
                    }
                    else
                    {
                        writer.Write(", ");
                    }
                }
            }
            break;
            }
        }
Exemple #5
0
 protected void WriteHyperlinkType(CppType type, TextWriter writer, DocItemWriterContext context)
 {
     switch (type.Decoration)
     {
         case CppDecoration.None:
             {
                 WriteHyperlinkPrimitiveType(type.Name, writer, context);
             }
             break;
         case CppDecoration.Decoration:
             {
                 WriteHyperlinkType(type.Arguments[0], writer, context);
                 writer.Write(" " + type.Name);
             }
             break;
         case CppDecoration.Template:
             {
                 WriteHyperlinkPrimitiveType(type.Name, writer, context);
                 writer.Write("<");
                 for (int i = 0; i < type.Arguments.Length; i++)
                 {
                     WriteHyperlinkType(type.Arguments[i], writer, context);
                     if (i == type.Arguments.Length - 1)
                     {
                         writer.Write(">");
                     }
                     else
                     {
                         writer.Write(", ");
                     }
                 }
             }
             break;
         case CppDecoration.Function:
             {
                 WriteHyperlinkPrimitiveType(type.Name, writer, context);
                 writer.Write(" " + type.CallingConversion + "(");
                 for (int i = 0; i < type.Arguments.Length; i++)
                 {
                     WriteHyperlinkType(type.Arguments[i], writer, context);
                     if (i == type.Arguments.Length - 1)
                     {
                         writer.Write(")");
                     }
                     else
                     {
                         writer.Write(", ");
                     }
                 }
             }
             break;
     }
 }
Exemple #6
0
        protected void WriteHyperlinkType(string type, TextWriter writer, DocItemWriterContext context)
        {
            CppType cppType = CppType.Parse(type);

            WriteHyperlinkType(cppType, writer, context);
        }
Exemple #7
0
 private static bool ParseType(string raw, string[] input, ref int index, ref CppType result)
 {
     if (ParsePrimitiveType(input, ref index, ref result))
     {
         while (true)
         {
             if (ParseString(input, ref index, "__cdecl", "__clrcall", "__stdcall", "__fastcall", "__thiscall"))
             {
                 result.CallingConversion = input[index - 1];
             }
             if (ParseString(input, ref index, "<") || ParseString(input, ref index, "("))
             {
                 if (result.CallingConversion != "" && input[index - 1] == "<")
                 {
                     throw new ArgumentException(string.Format("Token \"(\" is missing in {0}.", raw));
                 }
                 string endToken = input[index - 1] == "<" ? ">" : ")";
                 CppDecoration decoration = input[index - 1] == "<" ? CppDecoration.Template : CppDecoration.Function;
                 List<CppType> arguments = new List<CppType>();
                 while (true)
                 {
                     CppType argument = null;
                     if (ParseType(raw, input, ref index, ref argument))
                     {
                         arguments.Add(argument);
                         if (ParseString(input, ref index, endToken))
                         {
                             break;
                         }
                         else if (!ParseString(input, ref index, ","))
                         {
                             throw new ArgumentException(string.Format("Token \",\" is missing in {0}.", raw));
                         }
                     }
                     else
                     {
                         throw new ArgumentException(string.Format("Type is missing in {0}.", raw));
                     }
                 }
                 result.Decoration = decoration;
                 result.Arguments = arguments.ToArray();
             }
             else if (ParseVCRP(input, ref index))
             {
                 result = new CppType()
                 {
                     Name = input[index - 1],
                     Decoration = CppDecoration.Decoration,
                     Arguments = new CppType[] { result },
                 };
             }
             else
             {
                 break;
             }
         }
         return true;
     }
     return false;
 }
Exemple #8
0
 private static bool ParsePrimitiveType(string[] input, ref int index, ref CppType result)
 {
     if (ParseSignedUnsigned(input, ref index))
     {
         if (ParseInt(input, ref index))
         {
             result = new CppType()
             {
                 Name = input[index - 2] + " " + input[index - 1],
             };
             return true;
         }
         else
         {
             throw new ArgumentException(string.Format("{0} is not a valid type.", input[index - 2] + " " + input[index - 1]));
         }
     }
     else if (ParseName(input, ref index))
     {
         result = new CppType()
         {
             Name = input[index - 1],
         };
         return true;
     }
     else
     {
         return false;
     }
 }