• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AST.Method类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CppSharp.AST.Method的典型用法代码示例。如果您正苦于以下问题:C# Method类的具体用法?C# Method怎么用?C# Method使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Method类属于CppSharp.AST命名空间,在下文中一共展示了Method类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: VisitMethodDecl

        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method))
            {
                return false;
            }

            if (!method.IsConstructor && (method.Name.EndsWith("Event", StringComparison.Ordinal) || method.Name == "event") &&
                method.Parameters.Count == 1)
            {
                var type = method.Parameters[0].Type;
                type = type.GetFinalPointee() ?? type;
                Class @class;
                if (type.TryGetClass(out @class) && @class.Name.EndsWith("Event", StringComparison.Ordinal))
                {
                    var name = char.ToUpperInvariant(method.Name[0]) + method.Name.Substring(1);
                    method.Name = "on" + name;
                    Method baseMethod;
                    if (!method.IsOverride ||
                        (baseMethod = ((Class) method.Namespace).GetBaseMethod(method, true, true)) == null ||
                        baseMethod.IsPure)
                    {
                        this.events.Add(method);
                        this.Context.Options.ExplicitlyPatchedVirtualFunctions.Add(method.QualifiedOriginalName);
                    }
                }
            }
            return true;
        }
开发者ID:grbd,项目名称:QtSharp,代码行数:29,代码来源:GenerateEventEventsPass.cs


示例2: CanOverride

 static bool CanOverride(Method method, Method @override)
 {
     return method.OriginalName == @override.OriginalName &&
            method.ReturnType == @override.ReturnType &&
            method.Parameters.SequenceEqual(@override.Parameters,
                new ParameterTypeComparer());
 }
开发者ID:farawayzheng,项目名称:CppSharp,代码行数:7,代码来源:VTables.cs


示例3: VisitMethodDecl

 public override bool VisitMethodDecl(Method method)
 {
     if (!method.IsConstructor && (method.Name.EndsWith("Event") || method.Name == "event") &&
         method.Parameters.Count == 1 && method.Parameters[0].Type.ToString().EndsWith("Event") &&
         method.OriginalName != "widgetEvent")
     {
         Event @event = new Event();
         if (method.Name.StartsWith("on"))
         {
             @event.Name = method.Name.Substring(2);
         }
         else
         {
             @event.Name = method.Name;
         }
         @event.OriginalDeclaration = method;
         @event.Namespace = method.Namespace;
         @event.Parameters.AddRange(method.Parameters);
         method.Namespace.Events.Add(@event);
         this.events.Add(@event);
         if (!method.Name.StartsWith("on"))
             method.Name = "on" + char.ToUpperInvariant(method.Name[0]) + method.Name.Substring(1);
     }
     return base.VisitMethodDecl(method);
 }
开发者ID:YekMX,项目名称:QtSharp,代码行数:25,代码来源:GenerateEventEventsPass.cs


示例4: CheckNonVirtualInheritedFunctions

        public void CheckNonVirtualInheritedFunctions(Class @class, Class originalClass = null)
        {
            if (originalClass == null)
                originalClass = @class;

            foreach (BaseClassSpecifier baseSpecifier in @class.Bases)
            {
                var @base = baseSpecifier.Class;
                if (@base.IsInterface) continue;

                var nonVirtualOffset = ComputeNonVirtualBaseClassOffset(originalClass, @base);
                if (nonVirtualOffset == 0)
                    continue;

                foreach (var method in @base.Methods.Where(method =>
                    !method.IsVirtual && (method.Kind == CXXMethodKind.Normal)))
                {
                    Console.WriteLine(method);

                    var adjustedMethod = new Method(method)
                    {
                        SynthKind = FunctionSynthKind.AdjustedMethod,
                        AdjustedOffset = nonVirtualOffset,
                    };

                    originalClass.Methods.Add(adjustedMethod);
                }

                CheckNonVirtualInheritedFunctions(@base, originalClass);
            }
        }
开发者ID:corefan,项目名称:CppSharp,代码行数:31,代码来源:MultipleInheritancePass.cs


示例5: GenerateToString

 void GenerateToString(Class @class, Block block, Method method)
 {
     needsStreamInclude = true;
     block.WriteLine("std::ostringstream os;");
     block.WriteLine("os << *NativePtr;");
     block.Write("return clix::marshalString<clix::E_UTF8>(os.str());");
 }
开发者ID:tritao,项目名称:CppSharp,代码行数:7,代码来源:ObjectOverridesPass.cs


示例6: CanOverride

 public static bool CanOverride(this Method @override, Method method)
 {
     return (method.OriginalName == @override.OriginalName &&
         method.ReturnType == @override.ReturnType &&
         method.Parameters.SequenceEqual(@override.Parameters, ParameterTypeComparer.Instance)) ||
         (@override.IsDestructor && method.IsDestructor && method.IsVirtual);
 }
开发者ID:daxiazh,项目名称:CppSharp,代码行数:7,代码来源:FunctionExtensions.cs


示例7: VisitMethodDecl

 public override bool VisitMethodDecl(Method method)
 {
     if (!method.IsConstructor && !method.IsDestructor && !method.IsOperator &&
         !method.Ignore)
         DistributeMethod(method);
     return base.VisitMethodDecl(method);
 }
开发者ID:jijamw,项目名称:CppSharp,代码行数:7,代码来源:GetterSetterToPropertyAdvancedPass.cs


示例8: VisitMethodDecl

 public override bool VisitMethodDecl(Method method)
 {
     if (!method.IsConstructor && !method.IsDestructor && !method.IsOperator &&
         method.IsGenerated && !method.IsSynthetized)
         DistributeMethod(method);
     return base.VisitMethodDecl(method);
 }
开发者ID:kitsilanosoftware,项目名称:CppSharp,代码行数:7,代码来源:GetterSetterToPropertyAdvancedPass.cs


示例9: VisitFunctionDecl

        public override bool VisitFunctionDecl(Function function)
        {
            if (function.Ignore || !function.IsOperator)
                return false;

            var param = function.Parameters[0];

            Class @class;
            if (!FunctionToInstanceMethodPass.GetClassParameter(param, out @class))
                return false;

            // Create a new fake method so it acts as a static method.

            var method = new Method(function)
            {
                Namespace = @class,
                Kind = CXXMethodKind.Operator,
                OperatorKind = function.OperatorKind,
                SynthKind = FunctionSynthKind.NonMemberOperator,
                OriginalFunction = null,
                IsStatic = true
            };

            function.ExplicityIgnored = true;

            @class.Methods.Add(method);

            Driver.Diagnostics.Debug("Function converted to operator: {0}::{1}",
                @class.Name, function.Name);

            return true;
        }
开发者ID:jijamw,项目名称:CppSharp,代码行数:32,代码来源:MoveOperatorToClassPass.cs


示例10: VisitMethodDecl

        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method))
                return false;

            if (method.IsPure && method.IsOperator)
                method.ExplicitlyIgnore();

            return true;
        }
开发者ID:tritao,项目名称:CppSharp,代码行数:10,代码来源:IgnoreAbstractOperatorsPass.cs


示例11: VisitMethodDecl

        public override bool VisitMethodDecl(Method decl)
        {
            if (ASTUtils.CheckIgnoreMethod(decl))
                return false;

            if (!AlreadyVisited(decl) && decl.ExplicitInterfaceImpl == null)
                CheckDuplicate(decl);

            return false;
        }
开发者ID:jijamw,项目名称:CppSharp,代码行数:10,代码来源:CheckDuplicatedNamesPass.cs


示例12: VisitFunctionDecl

        public override bool VisitFunctionDecl(Function function)
        {
            if (!function.IsGenerated)
                return false;

            // Check if this function can be converted.
            if (function.Parameters.Count == 0)
                return false;

            var classParam = function.Parameters[0];

            Class @class;
            if (!GetClassParameter(classParam, out @class))
                return false;

            // If we reach here, it means the first parameter is of class type.
            // This means we can change the function to be an instance method.

            // Clean up the name of the function now that it will be an instance method.
            if (!function.Name.StartsWith(@class.Name))
                return false;

            function.Name = function.Name.Substring(@class.Name.Length);
            function.ExplicitlyIgnore();

            // Create a new fake method so it acts as an instance method.
            var method = new Method
                {
                    Namespace = @class,
                    OriginalNamespace = function.Namespace,
                    Name = function.Name,
                    OriginalName = function.OriginalName,
                    Mangled = function.Mangled,
                    Access = AccessSpecifier.Public,
                    Kind = CXXMethodKind.Normal,
                    ReturnType = function.ReturnType,
                    Parameters = function.Parameters,
                    CallingConvention = function.CallingConvention,
                    IsVariadic = function.IsVariadic,
                    IsInline = function.IsInline,
                    Conversion = MethodConversionKind.FunctionToInstanceMethod
                };

            if (Options.GeneratorKind == GeneratorKind.CSharp)
                method.Parameters = method.Parameters.Skip(1).ToList();

            @class.Methods.Add(method);

            Diagnostics.Debug("Function converted to instance method: {0}::{1}", @class.Name,
                function.Name);

            return true;
        }
开发者ID:ddobrev,项目名称:CppSharp,代码行数:53,代码来源:FunctionToInstanceMethodPass.cs


示例13: VisitMethodDecl

        public override bool VisitMethodDecl(Method method)
        {
            if (!VisitDeclaration(method))
                return false;

            if (ASTUtils.CheckIgnoreMethod(method, Driver.Options))
                return false;

            var @class = method.Namespace as Class;

            if (@class == null || @class.IsIncomplete)
                return false;

            if (method.IsConstructor)
                return false;

            if (method.IsSynthetized)
                return false;

            if (IsGetter(method))
            {
                var name = method.Name.Substring("get".Length);
                var prop = GetOrCreateProperty(@class, name, method.ReturnType);
                prop.GetMethod = method;
                prop.Access = method.Access;

                // Do not generate the original method now that we know it is a getter.
                method.GenerationKind = GenerationKind.Internal;

                Driver.Diagnostics.Debug("Getter created: {0}::{1}", @class.Name, name);

                return false;
            }

            if (IsSetter(method) && IsValidSetter(method))
            {
                var name = method.Name.Substring("set".Length);

                var type = method.Parameters[0].QualifiedType;
                var prop = GetOrCreateProperty(@class, name, type);
                prop.SetMethod = method;
                prop.Access = method.Access;

                // Ignore the original method now that we know it is a setter.
                method.GenerationKind = GenerationKind.Internal;

                Driver.Diagnostics.Debug("Setter created: {0}::{1}", @class.Name, name);

                return false;
            }

            return false;
        }
开发者ID:daxiazh,项目名称:CppSharp,代码行数:53,代码来源:GetterSetterToPropertyPass.cs


示例14: VisitMethodDecl

 public override bool VisitMethodDecl(Method method)
 {
     if (method.IsOverride && !method.IsSynthetized)
     {
         Method rootBaseMethod = ((Class) method.Namespace).GetBaseMethod(method);
         for (int i = 0; i < method.Parameters.Count; i++)
         {
             method.Parameters[i].DefaultArgument = rootBaseMethod.Parameters[i].DefaultArgument;
         }
     }
     return base.VisitMethodDecl(method);
 }
开发者ID:daxiazh,项目名称:CppSharp,代码行数:12,代码来源:FixDefaultParamValuesOfOverridesPass.cs


示例15: VisitMethodDecl

        public override bool VisitMethodDecl(Method decl)
        {
            if (!VisitDeclaration(decl))
                return false;

            if (ASTUtils.CheckIgnoreMethod(decl, Driver.Options))
                return false;

            if (decl.ExplicitInterfaceImpl == null)
                CheckDuplicate(decl);

            return false;
        }
开发者ID:fangsunjian,项目名称:CppSharp,代码行数:13,代码来源:CheckDuplicatedNamesPass.cs


示例16: GenerateEquals

        void GenerateEquals(Class @class, Block block, Method method)
        {
            var cliTypePrinter = new CLITypePrinter(Driver);
            var classCliType = @class.Visit(cliTypePrinter);

            block.WriteLine("if (!object) return false;");
            block.WriteLine("auto obj = dynamic_cast<{0}>({1});",
                classCliType, method.Parameters[0].Name);
            block.NewLine();

            block.WriteLine("if (!obj) return false;");
            block.Write("return __Instance == obj->__Instance;");
        }
开发者ID:kidleon,项目名称:CppSharp,代码行数:13,代码来源:ObjectOverridesPass.cs


示例17: GetVTableIndex

 public static int GetVTableIndex(Method method, Class @class)
 {
     switch (@class.Layout.ABI)
     {
         case CppAbi.Microsoft:
             return (from table in @class.Layout.VFTables
                     let j = table.Layout.Components.FindIndex(m => CanOverride(m.Method, method))
                     where j >= 0
                     select j).First();
         default:
             // ignore offset to top and RTTI
             return @class.Layout.Layout.Components.FindIndex(m => m.Method == method) - 2;
     }
 }
开发者ID:farawayzheng,项目名称:CppSharp,代码行数:14,代码来源:VTables.cs


示例18: VisitMethodDecl

        public override bool VisitMethodDecl(Method method)
        {
            if (!method.IsConstructor)
                return false;
            if (method.IsCopyConstructor)
                return false;
            if (method.Parameters.Count != 1)
                return false;
            var parameter = method.Parameters[0];
            // TODO: disable implicit operators for C++/CLI because they seem not to be support parameters
            if (!Driver.Options.IsCSharpGenerator)
            {
                var pointerType = parameter.Type as PointerType;
                if (pointerType != null && !pointerType.IsReference)
                    return false;
            }
            var qualifiedPointee = parameter.Type.SkipPointerRefs();
            Class castFromClass;
            if (qualifiedPointee.TryGetClass(out castFromClass))
            {
                var castToClass = method.OriginalNamespace as Class;
                if (castToClass == null)
                    return false;
                if (castFromClass == castToClass)
                    return false;
            }

            var operatorKind = method.IsExplicit
                ? CXXOperatorKind.ExplicitConversion
                : CXXOperatorKind.Conversion;
            var qualifiedCastToType = new QualifiedType(new TagType(method.Namespace));
            var conversionOperator = new Method
            {
                Name = Operators.GetOperatorIdentifier(operatorKind),
                Namespace = method.Namespace,
                Kind = CXXMethodKind.Conversion,
                SynthKind = FunctionSynthKind.ComplementOperator,
                ConversionType = qualifiedCastToType,
                ReturnType = qualifiedCastToType,
                OperatorKind = operatorKind
            };
            var p = new Parameter(parameter);
            Class @class;
            if (p.Type.SkipPointerRefs().TryGetClass(out @class))
                p.QualifiedType = new QualifiedType(new TagType(@class), parameter.QualifiedType.Qualifiers);
            p.DefaultArgument = null;
            conversionOperator.Parameters.Add(p);
            ((Class) method.Namespace).Methods.Add(conversionOperator);
            return true;
        }
开发者ID:nalkaro,项目名称:CppSharp,代码行数:50,代码来源:ConstructorToConversionOperatorPass.cs


示例19: VisitClassDecl

        public override bool VisitClassDecl(Class @class)
        {
            // FIXME: Add a better way to hook the event
            if (!isHooked)
            {
                Driver.Generator.OnUnitGenerated += OnUnitGenerated;
                isHooked = true;
            }

            if (!VisitDeclaration(@class))
                return false;

            if (AlreadyVisited(@class))
                return true;

            if (@class.IsValueType)
                return false;

            var methodEqualsParam = new Parameter
            {
                Name = "object",
                QualifiedType = new QualifiedType(new CILType(typeof(Object))),
            };

            var methodEquals = new Method
            {
                Name = "Equals",
                Namespace = @class,
                ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Bool)),
                Parameters = new List<Parameter> { methodEqualsParam },
                IsSynthetized = true,
                IsOverride = true,
                IsProxy = true
            };
             @class.Methods.Add(methodEquals);

            var methodHashCode = new Method
            {
                Name = "GetHashCode",
                Namespace = @class,
                ReturnType = new QualifiedType(new BuiltinType(PrimitiveType.Int32)),
                IsSynthetized = true,
                IsOverride = true,
                IsProxy = true
            };

            @class.Methods.Add(methodHashCode);
            return true;
        }
开发者ID:jijamw,项目名称:CppSharp,代码行数:49,代码来源:ObjectOverridesPass.cs


示例20: VisitFunctionDecl

        public override bool VisitFunctionDecl(Function function)
        {
            if (!function.IsGenerated)
                return false;

            var types = StringHelpers.SplitCamelCase(function.Name);
            if (types.Length == 0)
                return false;

            var @class = ASTContext.FindCompleteClass(types[0]);
            if (@class == null)
                return false;

            // TODO: If the translation units of the declarations are different,
            // and we apply the pass, we might need additional includes in the
            // generated translation unit of the class.
            if (@class.TranslationUnit != function.TranslationUnit)
                return false;

            // Clean up the name of the function now that it will be a static method.
            var name = function.Name.Substring(@class.Name.Length);
            function.ExplicitlyIgnore();

            // Create a new fake method so it acts as a static method.
            var method = new Method
            {
                Namespace = @class,
                OriginalNamespace = function.Namespace,
                Name = name,
                OriginalName = function.OriginalName,
                Mangled = function.Mangled,
                Access = AccessSpecifier.Public,
                Kind = CXXMethodKind.Normal,
                ReturnType = function.ReturnType,
                Parameters = function.Parameters,
                CallingConvention = function.CallingConvention,
                IsVariadic = function.IsVariadic,
                IsInline = function.IsInline,
                IsStatic = true,
                Conversion = MethodConversionKind.FunctionToStaticMethod
            };

            @class.Methods.Add(method);

            Diagnostics.Debug("Function converted to static method: {0}::{1}",
                @class.Name, function.Name);

            return true;
        }
开发者ID:ddobrev,项目名称:CppSharp,代码行数:49,代码来源:FunctionToStaticMethodPass.cs



注:本文中的CppSharp.AST.Method类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Generators.MarshalContext类代码示例发布时间:2022-05-24
下一篇:
C# CppSharp.Driver类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap