Beispiel #1
0
        public override bool VisitTypedefDecl(TypedefDecl typedef)
        {
            TypeMap typeMap;
            if (TypeMapDatabase.FindTypeMap(typedef, out typeMap))
            {
                if (typeMap.IsIgnored)
                    Ignore();
                return false;
            }

            return base.VisitTypedefDecl(typedef);
        }
 public override bool VisitTypedefDecl(TypedefDecl typedef)
 {
     Type type = typedef.Type.Desugar();
     List<TypedefDecl> typedefDecls;
     if (TypeDefsPerType.ContainsKey(type))
         typedefDecls = TypeDefsPerType[type];
     else
         TypeDefsPerType.Add(type, typedefDecls = new List<TypedefDecl>());
     if (!typedefDecls.Contains(typedef))
         typedefDecls.Add(typedef);
     return base.VisitTypedefDecl(typedef);
 }
        public override bool VisitTypedefDecl(TypedefDecl typedef)
        {
            var @class = typedef.Namespace.FindClass(typedef.Name);

            // Clang will walk the typedef'd tag decl and the typedef decl,
            // so we ignore the class and process just the typedef.

            if (@class != null)
                typedef.ExplicityIgnored = true;

            if (typedef.Type == null)
                typedef.ExplicityIgnored = true;

            return base.VisitTypedefDecl(typedef);
        }
Beispiel #4
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
                return false;

            var @params = method.GatherInternalParams(Driver.Options.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var @delegate = new TypedefDecl
                {
                    Name = delegateName,
                    QualifiedType = new QualifiedType(
                        new PointerType(
                            new QualifiedType(
                                new FunctionType
                                {
                                    CallingConvention = method.CallingConvention,
                                    IsDependent = method.IsDependent,
                                    Parameters = @params,
                                    ReturnType = method.ReturnType
                                }))),
                    Namespace = namespaceDelegates
                };

            var delegateString = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(delegateString);
            if (existingDelegate != null)
            {
                Driver.Delegates.Add(method, existingDelegate);
                return true;
            }

            existingDelegate = new DelegateDefinition(Driver.Options.OutputNamespace, delegateString);
            Driver.Delegates.Add(method, existingDelegate);
            foreach (var library in Driver.Options.Libraries)
                libsDelegates[library].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);

            return true;
        }
Beispiel #5
0
        public bool GenerateTypedef(TypedefDecl typedef)
        {
            if (!typedef.IsGenerated)
                return false;

            FunctionType function;
            if (typedef.Type.IsPointerTo(out function))
            {
                PushBlock(CLIBlockKind.Typedef, typedef);
                GenerateDeclarationCommon(typedef);

                var insideClass = typedef.Namespace is Class;

                var attributedType = typedef.Type.GetPointee() as AttributedType;
                if (attributedType != null)
                {
                    var equivalentFunctionType = attributedType.Equivalent.Type as FunctionType;
                    var callingConvention = equivalentFunctionType.CallingConvention.ToInteropCallConv();
                    if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi)
                    {
                        WriteLine("[{0}({1}::{2})] ",
                            "System::Runtime::InteropServices::UnmanagedFunctionPointer",
                            "System::Runtime::InteropServices::CallingConvention",
                            callingConvention);
                    }
                }

                WriteLine("{0}{1};",
                    !insideClass ? "public " : "",
                    string.Format(TypePrinter.VisitDelegate(function),
                    typedef.Name));
                PopBlock(NewLineKind.BeforeNextBlock);

                return true;
            }

            return false;
        }
Beispiel #6
0
 public virtual bool VisitTypedefDecl(TypedefDecl typedef)
 {
     return(VisitTypedefNameDecl(typedef));
 }
Beispiel #7
0
 void SymbolDecl.IVisitor.Visit(TypedefDecl decl)
 {
     EntryDecl(decl);
 }
        public override bool VisitTypedefDecl(TypedefDecl typedef)
        {
            if (!base.VisitTypedefDecl(typedef))
                return false;

            if (typedef.TranslationUnit.IsSystemHeader)
                typedef.ExplicitlyIgnore();

            return true;
        }
Beispiel #9
0
 public static TypedefDecl __CreateInstance(TypedefDecl.Internal native)
 {
     return new TypedefDecl(native);
 }
Beispiel #10
0
 private static void* __CopyValue(TypedefDecl.__Internal native)
 {
     var ret = Marshal.AllocHGlobal(136);
     global::CppSharp.Parser.AST.TypedefDecl.__Internal.cctor_1(ret, new global::System.IntPtr(&native));
     return ret.ToPointer();
 }
Beispiel #11
0
        public override bool VisitTypedefDecl(TypedefDecl typedef)
        {
            if (!Targets.HasFlag(RenameTargets.Delegate))
                return false;

            return base.VisitTypedefDecl(typedef);
        }
Beispiel #12
0
 public string VisitTypedefDecl(TypedefDecl typedef)
 {
     return(VisitDeclaration(typedef));
 }
Beispiel #13
0
 public string VisitTypedefDecl(TypedefDecl typedef)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
 public virtual TypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
 {
     return(VisitDeclaration(typedef));
 }
Beispiel #15
0
 public virtual bool VisitTypedefDecl(TypedefDecl typedef)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
 private TypedefDecl(TypedefDecl.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
 }
Beispiel #17
0
        static SymbolDecl[] ParseSymbolInternal(string[] tokens, ref int index)
        {
            if (CppParser.Token(tokens, ref index, "public") || CppParser.Token(tokens, ref index, "protected") || CppParser.Token(tokens, ref index, "private"))
            {
                index--;
                return(null);
            }
            TemplateDecl templateDecl = null;

            if (CppParser.Token(tokens, ref index, "template"))
            {
                templateDecl = new TemplateDecl
                {
                    TypeParameters = new List <TypeParameterDecl>(),
                    Specialization = new List <TypeDecl>(),
                };
                CppParser.EnsureToken(tokens, ref index, "<");
                if (!CppParser.Token(tokens, ref index, ">"))
                {
                    while (true)
                    {
                        string token = null;
                        CppParser.SkipUntilInTemplate(tokens, ref index, out token, ",", ">", "=");

                        index -= 2;
                        templateDecl.TypeParameters.Add(new TypeParameterDecl
                        {
                            Name = CppParser.EnsureId(tokens, ref index),
                        });
                        index++;

                        if (token == "=")
                        {
                            CppParser.SkipUntilInTemplate(tokens, ref index, out token, ",", ">");
                        }

                        if (token == ">")
                        {
                            break;
                        }
                    }
                }
            }

            if (CppParser.Token(tokens, ref index, "friend"))
            {
                int    oldIndex = index - 1;
                string token    = null;
                CppParser.SkipUntil(tokens, ref index, out token, ";", "{");
                if (token == ";")
                {
                    return(null);
                }
                else
                {
                    index         = oldIndex;
                    tokens[index] = "static";
                }
            }

            if (CppParser.Token(tokens, ref index, "namespace"))
            {
                if (templateDecl != null)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                var decl = new NamespaceDecl();
                decl.Name = CppParser.EnsureId(tokens, ref index);

                CppParser.EnsureToken(tokens, ref index, "{");
                ParseSymbols(tokens, ref index, decl);
                CppParser.EnsureToken(tokens, ref index, "}");

                return(new SymbolDecl[] { decl });
            }
            else if (CppParser.Token(tokens, ref index, "using"))
            {
                if (CppParser.Token(tokens, ref index, "namespace"))
                {
                    if (templateDecl != null)
                    {
                        throw new ArgumentException("Failed to parse.");
                    }
                    var decl = new UsingNamespaceDecl();
                    decl.Path = new List <string>();
                    decl.Path.Add(CppParser.EnsureId(tokens, ref index));

                    while (!CppParser.Token(tokens, ref index, ";"))
                    {
                        CppParser.EnsureToken(tokens, ref index, ":");
                        CppParser.EnsureToken(tokens, ref index, ":");
                        decl.Path.Add(CppParser.EnsureId(tokens, ref index));
                    }

                    return(new SymbolDecl[] { decl });
                }
                else
                {
                    string name = null;
                    if (CppParser.Id(tokens, ref index, out name))
                    {
                        if (templateDecl != null)
                        {
                            if (CppParser.Token(tokens, ref index, "<"))
                            {
                                while (true)
                                {
                                    templateDecl.Specialization.Add(CppTypeParser.EnsureTypeWithoutNameInTemplate(tokens, ref index));
                                    if (CppParser.Token(tokens, ref index, ">"))
                                    {
                                        break;
                                    }
                                    CppParser.EnsureToken(tokens, ref index, ",");
                                }
                            }
                        }
                        if (CppParser.Token(tokens, ref index, "="))
                        {
                            SymbolDecl decl = new TypedefDecl
                            {
                                Name = name,
                                Type = CppTypeParser.EnsureTypeWithoutName(tokens, ref index),
                            };
                            CppParser.EnsureToken(tokens, ref index, ";");

                            if (templateDecl != null)
                            {
                                templateDecl.Element = decl;
                                decl = templateDecl;
                            }
                            return(new SymbolDecl[] { decl });
                        }
                    }
                    if (templateDecl != null)
                    {
                        throw new ArgumentException("Failed to parse.");
                    }
                    CppParser.SkipUntil(tokens, ref index, ";");
                }
            }
            else if (CppParser.Token(tokens, ref index, "typedef"))
            {
                if (templateDecl != null)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                string name = null;
                var    type = CppTypeParser.EnsureTypeWithName(tokens, ref index, out name);
                CppParser.EnsureToken(tokens, ref index, ";");

                var decl = new TypedefDecl();
                decl.Name = name;
                decl.Type = type;
                return(new SymbolDecl[] { decl });
            }
            else if (CppParser.Token(tokens, ref index, "enum"))
            {
                if (templateDecl != null)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                bool   enumClass = CppParser.Token(tokens, ref index, "class");
                string name      = CppParser.EnsureId(tokens, ref index);
                if (CppParser.Token(tokens, ref index, ":"))
                {
                    CppTypeParser.EnsureTypeWithoutName(tokens, ref index);
                }
                if (!CppParser.Token(tokens, ref index, ";"))
                {
                    CppParser.EnsureToken(tokens, ref index, "{");
                    var decl = new EnumDecl
                    {
                        Name      = name,
                        EnumClass = enumClass,
                        Children  = new List <SymbolDecl>(),
                    };

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

                        string document = null;
                        while (index < tokens.Length && tokens[index].Length >= 3 && tokens[index].StartsWith("///"))
                        {
                            var line = tokens[index];
                            if (document == null)
                            {
                                document = "";
                            }
                            document += line.StartsWith("/// ") || line.StartsWith("///\t")
                                ? line.Substring(4)
                                : line.Substring(3);
                            document += "\r\n";
                            index++;
                        }
                        decl.Children.Add(new EnumItemDecl
                        {
                            Name     = CppParser.EnsureId(tokens, ref index),
                            Document = document,
                        });

                        string token = null;
                        CppParser.SkipUntil(tokens, ref index, out token, ",", "}");
                        if (token == "}")
                        {
                            break;
                        }
                    }

                    if (CppParser.Id(tokens, ref index, out name))
                    {
                        var varDecl = new VarDecl
                        {
                            Static = false,
                            Name   = name,
                            Type   = new RefTypeDecl
                            {
                                Name = decl.Name,
                            },
                        };
                        CppParser.EnsureToken(tokens, ref index, ";");
                        return(new SymbolDecl[] { decl, varDecl });
                    }
                    else
                    {
                        CppParser.EnsureToken(tokens, ref index, ";");
                        return(new SymbolDecl[] { decl });
                    }
                }
            }
            else if (CppParser.Token(tokens, ref index, "struct") || CppParser.Token(tokens, ref index, "class") || CppParser.Token(tokens, ref index, "union"))
            {
                if (CppParser.Token(tokens, ref index, "{"))
                {
                    if (tokens[index - 2] == "class")
                    {
                        throw new ArgumentException("Failed to parse.");
                    }

                    var decl = new GroupedFieldDecl
                    {
                        Grouping = tokens[index - 2] == "struct" ? Grouping.Struct : Grouping.Union,
                    };
                    ParseSymbols(tokens, ref index, decl);
                    CppParser.EnsureToken(tokens, ref index, "}");
                    CppParser.EnsureToken(tokens, ref index, ";");
                    return(new SymbolDecl[] { decl });
                }
                else
                {
                    string name = CppParser.EnsureId(tokens, ref index);
                    if (!CppParser.Token(tokens, ref index, ";"))
                    {
                        var classDecl = new ClassDecl
                        {
                            ClassType =
                                tokens[index - 2] == "struct" ? ClassType.Struct :
                                tokens[index - 2] == "class" ? ClassType.Class :
                                ClassType.Union,
                            BaseTypes = new List <BaseTypeDecl>(),
                            Name      = name,
                        };

                        if (templateDecl != null)
                        {
                            if (CppParser.Token(tokens, ref index, "<"))
                            {
                                if (!CppParser.Token(tokens, ref index, ">"))
                                {
                                    while (true)
                                    {
                                        int oldIndex = index;
                                        templateDecl.Specialization.Add(CppTypeParser.EnsureTypeWithoutNameInTemplate(tokens, ref index));
                                        if (CppParser.Token(tokens, ref index, ">"))
                                        {
                                            break;
                                        }
                                        CppParser.EnsureToken(tokens, ref index, ",");
                                    }
                                }
                            }
                        }

                        CppParser.Token(tokens, ref index, "abstract");
                        if (CppParser.Token(tokens, ref index, ":"))
                        {
                            while (true)
                            {
                                Access access = classDecl.ClassType == ClassType.Class ? Access.Private : Access.Public;
                                CppParser.Token(tokens, ref index, "virtual");
                                if (CppParser.Token(tokens, ref index, "private"))
                                {
                                    access = Access.Private;
                                }
                                else if (CppParser.Token(tokens, ref index, "protected"))
                                {
                                    access = Access.Protected;
                                }
                                else if (CppParser.Token(tokens, ref index, "public"))
                                {
                                    access = Access.Public;
                                }
                                CppParser.Token(tokens, ref index, "virtual");
                                classDecl.BaseTypes.Add(new BaseTypeDecl
                                {
                                    Access = access,
                                    Type   = CppTypeParser.EnsureTypeWithoutName(tokens, ref index),
                                });
                                if (!CppParser.Token(tokens, ref index, ","))
                                {
                                    break;
                                }
                            }
                        }

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

                            Access access = classDecl.ClassType == ClassType.Class ? Access.Private : Access.Public;
                            if (CppParser.Token(tokens, ref index, "private"))
                            {
                                access = Access.Private;
                                CppParser.EnsureToken(tokens, ref index, ":");
                            }
                            else if (CppParser.Token(tokens, ref index, "protected"))
                            {
                                access = Access.Protected;
                                CppParser.EnsureToken(tokens, ref index, ":");
                            }
                            else if (CppParser.Token(tokens, ref index, "public"))
                            {
                                access = Access.Public;
                                CppParser.EnsureToken(tokens, ref index, ":");
                            }
                            ParseSymbols(tokens, ref index, classDecl, access);
                        }

                        SymbolDecl decl = classDecl;
                        if (templateDecl != null)
                        {
                            templateDecl.Element = decl;
                            decl = templateDecl;
                        }

                        if (CppParser.Id(tokens, ref index, out name))
                        {
                            var varDecl = new VarDecl
                            {
                                Static = false,
                                Name   = name,
                                Type   = new RefTypeDecl
                                {
                                    Name = classDecl.Name,
                                },
                            };
                            CppParser.EnsureToken(tokens, ref index, ";");
                            return(new SymbolDecl[] { decl, varDecl });
                        }
                        else
                        {
                            CppParser.EnsureToken(tokens, ref index, ";");
                            return(new SymbolDecl[] { decl });
                        }
                    }
                }
            }
            else if (!CppParser.Token(tokens, ref index, ";"))
            {
                Function function = Function.Function;
                {
                    int    oldIndex = index;
                    string name     = null;
                    if (CppParser.Id(tokens, ref index, out name))
                    {
                        if (CppParser.Token(tokens, ref index, "("))
                        {
                            CppParser.SkipUntil(tokens, ref index, ")");
                            if (CppParser.Token(tokens, ref index, ";") || CppParser.Token(tokens, ref index, "=") || CppParser.Token(tokens, ref index, ":") || CppParser.Token(tokens, ref index, "{"))
                            {
                                function = Function.Constructor;
                            }
                        }
                        index = oldIndex;
                    }
                    else if (CppParser.Token(tokens, ref index, "~"))
                    {
                        function = Function.Destructor;
                    }
                }

                if (function == Function.Function)
                {
                    Virtual virtualFunction = Virtual.Normal;
                    CppParser.Token(tokens, ref index, "extern");
                    CppParser.Token(tokens, ref index, "mutable");
                    if (CppParser.Token(tokens, ref index, "virtual"))
                    {
                        virtualFunction = Virtual.Virtual;
                    }
                    else if (CppParser.Token(tokens, ref index, "static"))
                    {
                        virtualFunction = Virtual.Static;
                    }
                    CppParser.Token(tokens, ref index, "inline");
                    CppParser.Token(tokens, ref index, "__forceinline");

                    if (CppParser.Token(tokens, ref index, "operator"))
                    {
                        TypeDecl returnType = null;
                        {
                            int oldIndex = index;
                            CppParser.SkipUntilInTemplate(tokens, ref index, "(");
                            int modify = --index;

                            tokens[modify] = "$";
                            index          = oldIndex;
                            returnType     = CppTypeParser.EnsureTypeWithoutName(tokens, ref index);
                            if (index != modify)
                            {
                                throw new ArgumentException("Failed to parse.");
                            }
                            tokens[modify] = "(";
                        }
                        var decl = new FuncDecl
                        {
                            Virtual  = Virtual.Normal,
                            Name     = "operator",
                            Function = function,
                        };

                        TypeDecl          functionType      = null;
                        Action <TypeDecl> continuation      = null;
                        CallingConvention callingConvention = CallingConvention.Default;
                        CppTypeParser.ParseTypeContinueAfterName(tokens, ref index, ref callingConvention, out functionType, out continuation);
                        continuation(returnType);
                        decl.Type = functionType;

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

                        if (templateDecl != null)
                        {
                            templateDecl.Element = decl;
                            return(new SymbolDecl[] { templateDecl });
                        }
                        else
                        {
                            return(new SymbolDecl[] { decl });
                        }
                    }
                    else
                    {
                        string   name = null;
                        TypeDecl type = null;
                        if (CppTypeParser.ParseType(tokens, ref index, out type, out name))
                        {
                            if (name == null)
                            {
                                throw new ArgumentException("Failed to parse.");
                            }

                            if (type is FunctionTypeDecl)
                            {
                                if (CppParser.Token(tokens, ref index, "="))
                                {
                                    if (CppParser.Token(tokens, ref index, "0"))
                                    {
                                        virtualFunction = Virtual.Abstract;
                                    }
                                    else
                                    {
                                        CppParser.EnsureToken(tokens, ref index, "default", "delete");
                                    }
                                }

                                var decl = new FuncDecl
                                {
                                    Virtual  = virtualFunction,
                                    Name     = name,
                                    Type     = type,
                                    Function = Function.Function,
                                };

                                {
                                    var funcType   = (FunctionTypeDecl)type;
                                    var returnType = funcType.ReturnType as RefTypeDecl;
                                    if (returnType != null && returnType.Name == "auto")
                                    {
                                        if (CppParser.Token(tokens, ref index, "-"))
                                        {
                                            CppParser.EnsureToken(tokens, ref index, ">");

                                            TypeDecl newReturnType = CppTypeParser.EnsureTypeWithoutName(tokens, ref index);
                                            funcType.ReturnType = newReturnType;
                                        }
                                    }

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

                                if (templateDecl != null)
                                {
                                    templateDecl.Element = decl;
                                    return(new SymbolDecl[] { templateDecl });
                                }
                                else
                                {
                                    return(new SymbolDecl[] { decl });
                                }
                            }
                            else
                            {
                                if (virtualFunction != Virtual.Normal && virtualFunction != Virtual.Static)
                                {
                                    throw new ArgumentException("Failed to parse.");
                                }
                                if (CppParser.Token(tokens, ref index, "="))
                                {
                                    CppParser.SkipUntil(tokens, ref index, ";");
                                }
                                else if (CppParser.Token(tokens, ref index, "{"))
                                {
                                    CppParser.SkipUntil(tokens, ref index, "}");
                                }
                                else
                                {
                                    CppParser.EnsureToken(tokens, ref index, ";");
                                }

                                if (!(type is ClassMemberTypeDecl))
                                {
                                    var decl = new VarDecl
                                    {
                                        Static = virtualFunction == Virtual.Static,
                                        Name   = name,
                                        Type   = type,
                                    };
                                    return(new SymbolDecl[] { decl });
                                }
                            }
                        }
                    }
                }
                else
                {
                    var decl = new FuncDecl
                    {
                        Virtual  = Virtual.Normal,
                        Name     = (function == Function.Constructor ? "" : "~") + CppParser.EnsureId(tokens, ref index),
                        Function = function,
                    };

                    TypeDecl          functionType      = null;
                    Action <TypeDecl> continuation      = null;
                    CallingConvention callingConvention = CallingConvention.Default;
                    CppTypeParser.ParseTypeContinueAfterName(tokens, ref index, ref callingConvention, out functionType, out continuation);
                    continuation(new RefTypeDecl
                    {
                        Name = "void"
                    });
                    decl.Type = functionType;

                    if (CppParser.Token(tokens, ref index, "="))
                    {
                        CppParser.EnsureToken(tokens, ref index, "default", "delete");
                    }

                    if (!CppParser.Token(tokens, ref index, ";"))
                    {
                        if (CppParser.Token(tokens, ref index, ":"))
                        {
                            do
                            {
                                CppTypeParser.EnsureMiniType(tokens, ref index);
                                if (CppParser.Token(tokens, ref index, "("))
                                {
                                    CppParser.SkipUntil(tokens, ref index, ")");
                                }
                                else if (CppParser.Token(tokens, ref index, "{"))
                                {
                                    CppParser.SkipUntil(tokens, ref index, "}");
                                }
                                else
                                {
                                    throw new ArgumentException("Failed to parse.");
                                }
                            }while (CppParser.Token(tokens, ref index, ","));
                        }
                        CppParser.EnsureToken(tokens, ref index, "{");
                        CppParser.SkipUntil(tokens, ref index, "}");
                    }

                    if (templateDecl != null)
                    {
                        templateDecl.Element = decl;
                        return(new SymbolDecl[] { templateDecl });
                    }
                    else
                    {
                        return(new SymbolDecl[] { decl });
                    }
                }
            }
            return(null);
        }
Beispiel #18
0
 internal TypedefDecl(TypedefDecl.Internal native)
     : this(&native)
 {
 }
Beispiel #19
0
 public bool VisitTypedefDecl(TypedefDecl typedef)
 {
     return(false);
 }
Beispiel #20
0
 private TypedefDecl(TypedefDecl.Internal native, bool skipVTables = false)
     : this(__CopyValue(native), skipVTables)
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Beispiel #21
0
 private static bool Match(TypedefDecl t, string delegateName, Module module)
 {
     return(t.Name == delegateName &&
            (module == t.TranslationUnit.Module ||
             module.Dependencies.Contains(t.TranslationUnit.Module)));
 }
Beispiel #22
0
 private TypedefDecl(TypedefDecl.Internal native)
     : this(__CopyValue(native))
 {
     __ownsNativeInstance = true;
     NativeToManagedMap[__Instance] = this;
 }
Beispiel #23
0
 public override bool VisitTypedefDecl(TypedefDecl typedef)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public override TypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
 {
     return(VisitDeclaration(typedef));
 }
Beispiel #25
0
 void SymbolDecl.IVisitor.Visit(TypedefDecl decl)
 {
     Fix(decl);
     Execute(decl.Type);
 }
Beispiel #26
0
 public bool VisitTypedefDecl(TypedefDecl typedef)
 {
     throw new System.NotImplementedException();
 }
Beispiel #27
0
 public string VisitTypedefDecl(TypedefDecl typedef)
 {
     return(typedef.Name);
 }
Beispiel #28
0
 public override bool VisitTypedefDecl(TypedefDecl typedef)
 {
     throw new NotImplementedException();
 }
Beispiel #29
0
 public virtual TypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Generates a new typedef for the given type if necessary and returns the new type.
        /// </summary>
        /// <param name="namespace">The namespace the typedef will be added to.</param>
        /// <param name="type">The type to check.</param>
        /// <returns>The new type.</returns>
        private QualifiedType CheckType(DeclarationContext @namespace, QualifiedType type)
        {
            if (type.Type.IsDependent)
                return type;

            var pointerType = type.Type as PointerType;
            if (pointerType == null)
                return type;

            var functionType = pointerType.Pointee as FunctionType;
            if (functionType == null)
                return type;

            List<Typedef> typedefs;
            if (!allTypedefs.TryGetValue(@namespace.QualifiedName, out typedefs))
            {
                typedefs = new List<Typedef>();
                allTypedefs.Add(@namespace.QualifiedName, typedefs);
            }

            var typedef = FindMatchingTypedef(typedefs, functionType);
            if (typedef == null)
            {
                for (int i = 0; i < functionType.Parameters.Count; i++)
                {
                    functionType.Parameters[i].Name = string.Format("_{0}", i);
                }

                typedef = new TypedefDecl
                {
                    Access = AccessSpecifier.Public,
                    Name = string.Format("__AnonymousDelegate{0}", typedefs.Count),
                    Namespace = @namespace,
                    QualifiedType = type,
                    IsSynthetized = true
                };
                typedefs.Add(new Typedef
                {
                    Context = @namespace,
                    Declaration = typedef
                });
            }

            var typedefType = new TypedefType
            {
                Declaration = typedef
            };
            return new QualifiedType(typedefType);
        }
Beispiel #31
0
 public override TypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
 {
     return(GetName(typedef));
 }
Beispiel #32
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
                return false;

            var @params = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var module = method.TranslationUnit.Module;

            Namespace namespaceDelegates;
            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                namespaceDelegates = new Namespace
                {
                    Name = DelegatesNamespace,
                    Namespace = module.Units.Last()
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
                {
                    Name = delegateName,
                    QualifiedType = new QualifiedType(
                        new PointerType(
                            new QualifiedType(
                                new FunctionType
                                {
                                    CallingConvention = method.CallingConvention,
                                    IsDependent = method.IsDependent,
                                    Parameters = @params,
                                    ReturnType = method.ReturnType
                                }))),
                    Namespace = namespaceDelegates,
                    IsSynthetized = true
                };

            Generator.CurrentOutputNamespace = module.OutputNamespace;
            var delegateString = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                method.TranslationUnit.Module.Libraries, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(method, existingDelegate);
                return true;
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(method, existingDelegate);

            foreach (var library in module.Libraries)
                libsDelegates[library].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);

            return true;
        }
Beispiel #33
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
            {
                return(false);
            }

            var @params      = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var module = method.TranslationUnit.Module;

            Namespace namespaceDelegates;

            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                Namespace parent = null;
                if (string.IsNullOrEmpty(module.OutputNamespace))
                {
                    var group = module.Units.SelectMany(u => u.Declarations).OfType <Namespace>(
                        ).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList();
                    if (group.Count == 1)
                    {
                        parent = group.Last().Last();
                    }
                }
                if (parent == null)
                {
                    parent = module.Units.Last();
                }
                namespaceDelegates = new Namespace
                {
                    Name      = DelegatesNamespace,
                    Namespace = parent
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
            {
                Name          = delegateName,
                QualifiedType = new QualifiedType(
                    new PointerType(
                        new QualifiedType(
                            new FunctionType
                {
                    CallingConvention = method.CallingConvention,
                    IsDependent       = method.IsDependent,
                    Parameters        = @params,
                    ReturnType        = method.ReturnType
                }))),
                Namespace     = namespaceDelegates,
                IsSynthetized = true,
                Access        = AccessSpecifier.Private
            };

            var delegateString   = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                method.TranslationUnit.Module, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(method, existingDelegate);
                return(true);
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(method, existingDelegate);

            libsDelegates[module].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);

            return(true);
        }
Beispiel #34
0
 internal TypedefDecl(TypedefDecl.Internal native)
     : this(__CopyValue(native))
 {
 }
Beispiel #35
0
 public CSharpTypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
 {
     return(GetNestedQualifiedName(typedef));
 }
Beispiel #36
0
 internal TypedefDecl(TypedefDecl.Internal* native)
     : this(new global::System.IntPtr(native))
 {
 }
Beispiel #37
0
 public override bool VisitTypedefDecl(TypedefDecl typedef)
 {
     return(true);
 }
Beispiel #38
0
        public override bool VisitTypedefDecl(TypedefDecl typedef)
        {
            if (!VisitDeclaration(typedef))
                return false;

            string msg;
            if (HasInvalidType(typedef.Type, out msg))
            {
                typedef.ExplicitlyIgnore();
                Log.Debug("Typedef '{0}' was ignored due to {1} type",
                    typedef.Name, msg);
                return false;
            }

            return true;
        }
Beispiel #39
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
            {
                return(false);
            }

            var @params      = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var module = method.TranslationUnit.Module;

            Namespace namespaceDelegates;

            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                namespaceDelegates = new Namespace
                {
                    Name      = DelegatesNamespace,
                    Namespace = module.Units.Last()
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
            {
                Name          = delegateName,
                QualifiedType = new QualifiedType(
                    new PointerType(
                        new QualifiedType(
                            new FunctionType
                {
                    CallingConvention = method.CallingConvention,
                    IsDependent       = method.IsDependent,
                    Parameters        = @params,
                    ReturnType        = method.ReturnType
                }))),
                Namespace     = namespaceDelegates,
                IsSynthetized = true
            };

            Generator.CurrentOutputNamespace = module.OutputNamespace;
            var delegateString   = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                method.TranslationUnit.Module.Libraries, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(method, existingDelegate);
                return(true);
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(method, existingDelegate);

            foreach (var library in module.Libraries)
            {
                libsDelegates[library].Add(delegateString, existingDelegate);
            }

            namespaceDelegates.Declarations.Add(@delegate);

            return(true);
        }
Beispiel #40
0
 public static TypedefDecl __CreateInstance(TypedefDecl.Internal native, bool skipVTables = false)
 {
     return new TypedefDecl(native, skipVTables);
 }
Beispiel #41
0
 public abstract TRet VisitTypedef(TypedefDecl decl);
Beispiel #42
0
 protected TypedefDecl(TypedefDecl.Internal* native, bool skipVTables = false)
     : base((CppSharp.Parser.AST.Declaration.Internal*) null)
 {
     __PointerAdjustment = 0;
     if (native == null)
         return;
     __Instance = new global::System.IntPtr(native);
 }
Beispiel #43
0
        public virtual TRet Visit(Parser.AST.Declaration decl)
        {
            switch (decl.Kind)
            {
            case DeclarationKind.TranslationUnit:
            {
                var _decl = new TranslationUnit(decl.__Instance);
                return(VisitTranslationUnit(_decl));
            }

            case DeclarationKind.Namespace:
            {
                var _decl = new Namespace(decl.__Instance);
                return(VisitNamespace(_decl));
            }

            case DeclarationKind.Typedef:
            {
                var _decl = new TypedefDecl(decl.__Instance);
                return(VisitTypedef(_decl));
            }

            case DeclarationKind.Parameter:
            {
                var _decl = new Parameter(decl.__Instance);
                return(VisitParameter(_decl));
            }

            case DeclarationKind.Function:
            {
                var _decl = new Function(decl.__Instance);
                return(VisitFunction(_decl));
            }

            case DeclarationKind.Method:
            {
                var _decl = new Method(decl.__Instance);
                return(VisitMethod(_decl));
            }

            case DeclarationKind.Enumeration:
            {
                var _decl = new Enumeration(decl.__Instance);
                return(VisitEnumeration(_decl));
            }

            case DeclarationKind.EnumerationItem:
            {
                var _decl = new Enumeration.Item(decl.__Instance);
                return(VisitEnumerationItem(_decl));
            }

            case DeclarationKind.Variable:
            {
                var _decl = new Variable(decl.__Instance);
                return(VisitVariable(_decl));
            }

            case DeclarationKind.Field:
            {
                var _decl = new Field(decl.__Instance);
                return(VisitField(_decl));
            }

            case DeclarationKind.AccessSpecifier:
            {
                var _decl = new AccessSpecifierDecl(decl.__Instance);
                return(VisitAccessSpecifier(_decl));
            }

            case DeclarationKind.Class:
            {
                var _decl = new Class(decl.__Instance);
                return(VisitClass(_decl));
            }

            case DeclarationKind.ClassTemplate:
            {
                var _decl = new ClassTemplate(decl.__Instance);
                return(VisitClassTemplate(_decl));
            }

            case DeclarationKind.ClassTemplateSpecialization:
            {
                var _decl = new ClassTemplateSpecialization(decl.__Instance);
                return(VisitClassTemplateSpecialization(_decl));
            }

            case DeclarationKind.ClassTemplatePartialSpecialization:
            {
                var _decl = new ClassTemplatePartialSpecialization(decl.__Instance);
                return(VisitClassTemplatePartialSpecialization(_decl));
            }

            case DeclarationKind.FunctionTemplate:
            {
                var _decl = new FunctionTemplate(decl.__Instance);
                return(VisitFunctionTemplate(_decl));
            }

            case DeclarationKind.MacroDefinition:
            {
                var _decl = new MacroDefinition(decl.__Instance);
                return(VisitMacroDefinition(_decl));
            }

            case DeclarationKind.MacroExpansion:
            {
                var _decl = new MacroExpansion(decl.__Instance);
                return(VisitMacroExpansion(_decl));
            }
            }

            throw new ArgumentOutOfRangeException();
        }
Beispiel #44
0
 private static TypedefDecl.Internal* __CopyValue(TypedefDecl.Internal native)
 {
     var ret = Marshal.AllocHGlobal(184);
     CppSharp.Parser.AST.TypedefDecl.Internal.cctor_2(ret, new global::System.IntPtr(&native));
     return (TypedefDecl.Internal*) ret;
 }
        private Class AddInternalImplementation(Class @class)
        {
            var internalImpl = GetInternalImpl(@class);

            var abstractMethods = GetRelevantAbstractMethods(@class);

            foreach (var abstractMethod in abstractMethods)
            {
                var method = new Method(abstractMethod) { Namespace = internalImpl };
                internalImpl.Methods.Add(method);
                var @delegate = new TypedefDecl
                                {
                                    Name = ASTHelpers.GetDelegateName(abstractMethod),
                                    QualifiedType = abstractMethod.GetFunctionType(),
                                    IgnoreFlags = abstractMethod.IgnoreFlags,
                                    Namespace = internalImpl,
                                    Access = AccessSpecifier.Private
                                };
                internalImpl.Typedefs.Add(@delegate);
            }

            internalImpl.Layout = new ClassLayout(@class.Layout);
            FillVTable(@class, abstractMethods, internalImpl);

            foreach (var method in internalImpl.Methods)
            {
                method.IsPure = false;
                method.IsOverride = true;
                method.IsSynthetized = true;
            }
            return internalImpl;
        }
Beispiel #46
0
 protected TypedefDecl(TypedefDecl.Internal* native, bool isInternalImpl = false)
     : base((CppSharp.Parser.AST.Declaration.Internal*) native)
 {
 }
Beispiel #47
0
        public bool GenerateTypedef(TypedefDecl typedef)
        {
            if (typedef.Ignore)
                return false;

            FunctionType function;
            if (typedef.Type.IsPointerTo(out function))
            {
                PushBlock(CLIBlockKind.Typedef, typedef);
                GenerateDeclarationCommon(typedef);

                var insideClass = typedef.Namespace is Class;

                WriteLine("{0}{1};",
                    !insideClass ? "public " : "",
                    string.Format(TypePrinter.VisitDelegate(function),
                    typedef.Name));
                PopBlock(NewLineKind.BeforeNextBlock);

                return true;
            }

            return false;
        }