Beispiel #1
0
        public virtual void GenerateClassProperties(Class @class)
        {
            foreach (var property in @class.Properties)
            {
                if (ASTUtils.CheckIgnoreProperty(property) || CppHeaders.TypeIgnored(property.Type))
                {
                    continue;
                }

                property.Visit(this);
            }
        }
Beispiel #2
0
        public override List <CodeGenerator> Generate(IEnumerable <TranslationUnit> units)
        {
            var outputs = new List <CodeGenerator>();

            var header = new CppHeaders(Context, units);

            outputs.Add(header);

            var source = new CppSources(Context, units);

            outputs.Add(source);

            return(outputs);
        }
Beispiel #3
0
        public virtual void GenerateClassMethods(Class @class)
        {
            foreach (var method in @class.Methods.Where(m => !m.IsOperator))
            {
                if (ASTUtils.CheckIgnoreMethod(method) || CppHeaders.FunctionIgnored(method))
                {
                    continue;
                }

                // Do not generate property getter/setter methods as they will be generated
                // as part of properties generation.
                var field = (method?.AssociatedDeclaration as Property)?.Field;
                if (field != null)
                {
                    continue;
                }

                method.Visit(this);
            }
        }
Beispiel #4
0
        public override bool VisitFunctionDecl(Function function)
        {
            if (!function.IsGenerated || CppHeaders.FunctionIgnored(function))
            {
                return(false);
            }

            PushBlock(BlockKind.Function, function);

            GenerateDeclarationCommon(function);

            var returnType = function.ReturnType.Visit(CTypePrinter);

            var name = function.Visit(CTypePrinter);

            Write($"{returnType} ({name})(");

            for (var i = 0; i < function.Parameters.Count; ++i)
            {
                var param = function.Parameters[i];
                Write($"{CTypePrinter.VisitParameter(param)}");
                if (i < function.Parameters.Count - 1)
                {
                    Write(", ");
                }
            }

            WriteLine(")");
            WriteOpenBraceAndIndent();

            GenerateFunctionCall(function);

            UnindentAndWriteCloseBrace();

            PopBlock(NewLineKind.BeforeNextBlock);

            return(true);
        }
Beispiel #5
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!method.IsGenerated || CppHeaders.FunctionIgnored(method))
            {
                return(false);
            }

            if (method.IsPure)
            {
                return(false);
            }

            PushBlock(BlockKind.Method, method);

            GenerateMethodSpecifier(method);
            NewLine();

            var @class = method.Namespace as Class;

            if (method.IsConstructor)
            {
                GenerateClassConstructorBase(@class, method);
            }

            WriteOpenBraceAndIndent();

            PushBlock(BlockKind.MethodBody, method);

            if (Context.DeclMaps.FindDeclMap(method, out DeclMap declMap))
            {
                declMap.Declaration        = method;
                declMap.DeclarationContext = @class;
                declMap.Generate(this);
                goto SkipImpl;
            }

            if (method.IsConstructor && @class.IsRefType)
            {
                WriteLine($"{Helpers.OwnsNativeInstanceIdentifier} = true;");
            }

            if (method.IsProxy)
            {
                goto SkipImpl;
            }

            if (@class.IsRefType)
            {
                if (method.IsConstructor)
                {
                    if ([email protected])
                    {
                        PushBlock(BlockKind.ConstructorBody, @class);

                        var @params = GenerateFunctionParamsMarshal(method.Parameters, method);
                        Write($"{Helpers.InstanceIdentifier} = new ::{method.Namespace.QualifiedOriginalName}(");
                        GenerateFunctionParams(@params);
                        WriteLine(");");

                        PopBlock();
                    }
                }
                else
                {
                    GenerateFunctionCall(method);
                }
            }

SkipImpl:

            PopBlock();

            UnindentAndWriteCloseBrace();

            PopBlock(NewLineKind.Always);

            return(true);
        }