Exemple #1
0
 public void Visit(FunctionTypeDecl decl)
 {
     Deserialize(decl);
     decl.CallingConvention = LoadEnum <CallingConvention>(this.Element.Attribute("CallingConvention").Value);
     decl.Const             = bool.Parse(this.Element.Attribute("Const").Value);
     decl.ReturnType        = TypeDecl.Deserialize(this.Element.Element("ReturnType").Elements().First());
     decl.Parameters        = this.Element.Element("Parameters").Elements().Select(x => (VarDecl)SymbolDecl.Deserialize(x)).ToList();
 }
Exemple #2
0
 public void Visit(FunctionTypeDecl decl)
 {
     Serialize(decl);
     this.Element.Add(new XAttribute("CallingConvention", decl.CallingConvention.ToString()));
     this.Element.Add(new XAttribute("Const", decl.Const.ToString()));
     this.Element.Add(new XElement("ReturnType", decl.ReturnType.Serialize()));
     this.Element.Add(new XElement("Parameters", decl.Parameters.Select(x => x.Serialize())));
 }
        public void Visit(FunctionTypeDecl decl)
        {
            string result = "function ";

            switch (decl.CallingConvention)
            {
            case global::DocSymbol.CallingConvention.CDecl:
                result += "__cdecl ";
                break;

            case global::DocSymbol.CallingConvention.ClrCall:
                result += "__clrcall ";
                break;

            case global::DocSymbol.CallingConvention.StdCall:
                result += "__stdcall ";
                break;

            case global::DocSymbol.CallingConvention.FastCall:
                result += "__fastcall ";
                break;

            case global::DocSymbol.CallingConvention.ThisCall:
                result += "__thiscall ";
                break;

            case global::DocSymbol.CallingConvention.VectorCall:
                result += "__vectorcall ";
                break;
            }
            if (decl.Const)
            {
                result += "const ";
            }

            result += "(";
            for (int i = 0; i < decl.Parameters.Count; i++)
            {
                if (i > 0)
                {
                    result += ", ";
                }
                if (decl.Parameters[i].Name != null)
                {
                    result += decl.Parameters[i].Name + " : ";
                }
                result += decl.Parameters[i].Type.ToString();
            }

            result     += ") : " + decl.ReturnType.ToString();
            this.Result = result;
        }
 public void Visit(FunctionTypeDecl decl)
 {
     decl.ReturnType.Resolve(this.Symbol, this.Environment);
     foreach (var type in decl.Parameters)
     {
         if (type.Parent == null)
         {
             type.Type.Resolve(this.Symbol, this.Environment);
         }
         else
         {
             type.Resolve(this.Environment);
         }
     }
 }
        public void Visit(FunctionTypeDecl decl)
        {
            string result = "function ";
            switch (decl.CallingConvention)
            {
                case global::DocSymbol.CallingConvention.CDecl:
                    result += "__cdecl ";
                    break;
                case global::DocSymbol.CallingConvention.ClrCall:
                    result += "__clrcall ";
                    break;
                case global::DocSymbol.CallingConvention.StdCall:
                    result += "__stdcall ";
                    break;
                case global::DocSymbol.CallingConvention.FastCall:
                    result += "__fastcall ";
                    break;
                case global::DocSymbol.CallingConvention.ThisCall:
                    result += "__thiscall ";
                    break;
                case global::DocSymbol.CallingConvention.VectorCall:
                    result += "__vectorcall ";
                    break;
            }
            if (decl.Const)
            {
                result += "const ";
            }

            result += "(";
            for (int i = 0; i < decl.Parameters.Count; i++)
            {
                if (i > 0)
                {
                    result += ", ";
                }
                if (decl.Parameters[i].Name != null)
                {
                    result += decl.Parameters[i].Name + " : ";
                }
                result += decl.Parameters[i].Type.ToString();
            }

            result += ") : " + decl.ReturnType.ToString();
            this.Result = result;
        }
 public void Visit(FunctionTypeDecl decl)
 {
     Serialize(decl);
     this.Element.Add(new XAttribute("CallingConvention", decl.CallingConvention.ToString()));
     this.Element.Add(new XAttribute("Const", decl.Const.ToString()));
     this.Element.Add(new XElement("ReturnType", decl.ReturnType.Serialize()));
     this.Element.Add(new XElement("Parameters", decl.Parameters.Select(x => x.Serialize())));
 }
Exemple #7
0
        internal static void ParseTypeContinueAfterName(string[] tokens, ref int index, ref CallingConvention callingConvention, out TypeDecl decl, out Action<TypeDecl> continuation)
        {
            decl = null;
            continuation = null;

            while (true)
            {
                if (CppParser.Token(tokens, ref index, "["))
                {
                    var oldIndex = index;
                    CppParser.SkipUntil(tokens, ref index, "]");
                    var arrayDecl = new ArrayTypeDecl
                    {
                        Expression = tokens
                            .Skip(oldIndex)
                            .Take(index - 1 - oldIndex)
                            .Aggregate("", (a, b) => a == "" ? b : a + " " + b),
                    };
                    if (decl == null)
                    {
                        continuation = x => arrayDecl.Element = x;
                    }
                    else
                    {
                        arrayDecl.Element = decl;
                    }
                    decl = arrayDecl;
                }
                else if (CppParser.Token(tokens, ref index, "("))
                {
                    var funcDecl = new FunctionTypeDecl
                    {
                        Const = false,
                        CallingConvention = callingConvention,
                        Parameters = new List<VarDecl>(),
                    };
                    callingConvention = CallingConvention.Default;

                    if (decl == null)
                    {
                        continuation = x => funcDecl.ReturnType = x;
                    }
                    else
                    {
                        funcDecl.ReturnType = decl;
                    }
                    decl = funcDecl;

                    bool skipParameters = false;
                    if (CppParser.Token(tokens, ref index, "void"))
                    {
                        if (CppParser.Token(tokens, ref index, ")"))
                        {
                            skipParameters = true;
                        }
                        else
                        {
                            index--;
                        }
                    }

                    if (!skipParameters && !CppParser.Token(tokens, ref index, ")"))
                    {
                        while (true)
                        {
                            string name = null;
                            var parameterType = EnsureType(tokens, ref index, out name);

                            funcDecl.Parameters.Add(new VarDecl
                            {
                                Static = false,
                                Name = name,
                                Type = parameterType,
                            });

                            if (CppParser.Token(tokens, ref index, "="))
                            {
                                CppParser.SkipUntilInTemplate(tokens, ref index, ",", ")", ";");
                                index--;
                            }

                            if (CppParser.Token(tokens, ref index, ")"))
                            {
                                break;
                            }
                            CppParser.EnsureToken(tokens, ref index, ",");
                        }
                    }

                    while (true)
                    {
                        if (CppParser.Token(tokens, ref index, "const"))
                        {
                            funcDecl.Const = true;
                        }
                        else if (CppParser.Token(tokens, ref index, "override"))
                        {

                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
 public void Visit(FunctionTypeDecl decl)
 {
     decl.ReturnType.Resolve(this.Symbol, this.Environment);
     foreach (var type in decl.Parameters)
     {
         if (type.Parent == null)
         {
             type.Type.Resolve(this.Symbol, this.Environment);
         }
         else
         {
             type.Resolve(this.Environment);
         }
     }
 }