Example #1
0
        public void GenerateClassFields(Class @class)
        {
            // Handle the case of struct (value-type) inheritance by adding the base
            // properties to the managed value subtypes.
            if (@class.IsValueType)
            {
                foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared))
                {
                    GenerateClassFields(@base.Class);
                }
            }

            Indent();
            // check for value types because some of the ignored fields may back properties;
            // not the case for ref types because the NativePtr pattern is used there
            foreach (var field in @class.Fields.Where(f => !ASTUtils.CheckIgnoreField(f)))
            {
                var property = @class.Properties.FirstOrDefault(p => p.Field == field);
                if (property != null && !property.IsInRefTypeAndBackedByValueClassField())
                {
                    field.Visit(this);
                }
            }
            Unindent();
        }
Example #2
0
        public override bool VisitFieldDecl(Field field)
        {
            var @class = field.Namespace as Class;

            if (@class == null)
            {
                return(false);
            }

            if (@class.IsValueType)
            {
                return(false);
            }

            if (ASTUtils.CheckIgnoreField(field))
            {
                return(false);
            }

            var prop = new Property()
            {
                Name          = field.Name,
                Namespace     = field.Namespace,
                QualifiedType = field.QualifiedType,
                Field         = field
            };

            @class.Properties.Add(prop);

            field.ExplicityIgnored = true;

            return(false);
        }
Example #3
0
        public override bool VisitFieldDecl(Field field)
        {
            if (!VisitDeclaration(field))
            {
                return(false);
            }

            if (ASTUtils.CheckIgnoreField(field))
            {
                return(false);
            }

            var @class = field.Namespace as Class;

            if (@class == null)
            {
                return(false);
            }

            // Check if we already have a synthetized property.
            var existingProp = @class.Properties.FirstOrDefault(property => property.Field == field);

            if (existingProp != null)
            {
                return(false);
            }

            field.GenerationKind = GenerationKind.Internal;

            var prop = new Property
            {
                Name                  = field.Name,
                Namespace             = field.Namespace,
                QualifiedType         = field.QualifiedType,
                Access                = field.Access,
                Field                 = field,
                AssociatedDeclaration = field
            };

            if (Options.GeneratorKind == GeneratorKind.CPlusPlus)
            {
                GenerateAcessorMethods(field, prop);
            }

            // do not rename value-class fields because they would be
            // generated as fields later on even though they are wrapped by properties;
            // that is, in turn, because it's cleaner to write
            // the struct marshalling logic just for properties
            if (!prop.IsInRefTypeAndBackedByValueClassField())
            {
                field.Name = Generator.GeneratedIdentifier(field.Name);
            }

            @class.Properties.Add(prop);

            Diagnostics.Debug($"Property created from field: {field.QualifiedName}");

            return(false);
        }
Example #4
0
        public override bool VisitFieldDecl(Field field)
        {
            if (!VisitDeclaration(field))
            {
                return(false);
            }

            var @class = field.Namespace as Class;

            if (@class == null)
            {
                return(false);
            }

            if (ASTUtils.CheckIgnoreField(field))
            {
                return(false);
            }

            // Check if we already have a synthetized property.
            var existingProp = @class.Properties.FirstOrDefault(property =>
                                                                property.Name == field.Name &&
                                                                property.QualifiedType == field.QualifiedType);

            if (existingProp != null)
            {
                field.ExplicityIgnored = true;
                return(false);
            }

            field.ExplicityIgnored = true;

            var prop = new Property
            {
                Name          = field.Name,
                Namespace     = field.Namespace,
                QualifiedType = field.QualifiedType,
                Access        = field.Access,
                Field         = field
            };

            // do not rename value-class fields because they would be
            // generated as fields later on even though they are wrapped by properties;
            // that is, in turn, because it's cleaner to write
            // the struct marshalling logic just for properties
            if (!prop.IsInRefTypeAndBackedByValueClassField())
            {
                field.Name = Generator.GeneratedIdentifier(field.Name);
            }

            @class.Properties.Add(prop);

            Log.Debug("Property created from field: {0}::{1}", @class.Name,
                      field.Name);

            return(false);
        }
        public override bool VisitFieldDecl(Field decl)
        {
            if (ASTUtils.CheckIgnoreField(decl))
            {
                return(false);
            }

            if (!AlreadyVisited(decl))
            {
                CheckDuplicate(decl);
            }

            return(false);
        }
Example #6
0
        public override bool VisitFieldDecl(Field decl)
        {
            if (!VisitDeclaration(decl))
            {
                return(false);
            }

            if (ASTUtils.CheckIgnoreField(decl))
            {
                return(false);
            }

            CheckDuplicate(decl);
            return(false);
        }
Example #7
0
        public virtual bool VisitClassDeclContext(Class @class)
        {
            if (!VisitDeclContext(@class))
            {
                return(false);
            }

            foreach (var field in @class.Fields.Where(f => !ASTUtils.CheckIgnoreField(f)))
            {
                field.Visit(this);
            }

            foreach (var property in @class.Properties.Where(p => !ASTUtils.CheckIgnoreProperty(p)))
            {
                property.Visit(this);
            }

            VisitClassConstructors(@class);
            VisitClassMethods(@class);

            foreach (var @event in @class.Events)
            {
                if ([email protected])
                {
                    continue;
                }

                @event.Visit(this);
            }

            foreach (var variable in @class.Variables)
            {
                if (!variable.IsGenerated)
                {
                    continue;
                }

                if (variable.Access != AccessSpecifier.Public)
                {
                    continue;
                }

                variable.Visit(this);
            }

            return(true);
        }
Example #8
0
        public void GenerateClassFields(Class @class)
        {
            if ([email protected])
            {
                return;
            }

            // Handle the case of struct (value-type) inheritance by adding the base
            // fields to the managed value subtypes.
            foreach (var @base in @class.Bases)
            {
                Class baseClass;
                if ([email protected](out baseClass))
                {
                    continue;
                }

                if (!baseClass.IsValueType || baseClass.Ignore)
                {
                    Console.WriteLine("Ignored base class of value type '{0}'",
                                      baseClass.Name);
                    continue;
                }

                GenerateClassFields(baseClass);
            }

            PushIndent();
            foreach (var field in @class.Fields)
            {
                if (ASTUtils.CheckIgnoreField(field))
                {
                    continue;
                }

                GenerateDeclarationCommon(field);
                if (@class.IsUnion)
                {
                    WriteLine("[FieldOffset({0})]", field.Offset);
                }
                WriteLine("{0} {1};", field.Type, SafeIdentifier(field.Name));
            }
            PopIndent();
        }
Example #9
0
        private void GenerateStructMarshaling(Class @class, string nativeVar)
        {
            foreach (var @base in @class.Bases)
            {
                if ([email protected] || @base.Class.Ignore)
                {
                    continue;
                }

                var baseClass = @base.Class;
                GenerateStructMarshaling(baseClass, nativeVar);
            }

            foreach (var field in @class.Fields)
            {
                if (ASTUtils.CheckIgnoreField(field))
                {
                    continue;
                }

                var nativeField = string.Format("{0}{1}",
                                                nativeVar, field.OriginalName);

                var ctx = new MarshalContext(Driver)
                {
                    ArgName       = field.Name,
                    ReturnVarName = nativeField,
                    ReturnType    = field.QualifiedType
                };

                var marshal = new CLIMarshalNativeToManagedPrinter(ctx);
                field.Visit(marshal);

                if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
                {
                    Write(marshal.Context.SupportBefore);
                }

                WriteLine("{0} = {1};", field.Name, marshal.Context.Return);
            }
        }
Example #10
0
        public virtual bool VisitClassDeclContext(Class @class)
        {
            if (!VisitDeclContext(@class))
            {
                return(false);
            }

            foreach (var field in @class.Fields.Where(f => !ASTUtils.CheckIgnoreField(f)))
            {
                field.Visit(this);
            }

            foreach (var property in @class.Properties.Where(p => !ASTUtils.CheckIgnoreProperty(p)))
            {
                property.Visit(this);
            }

            VisitClassConstructors(@class);
            VisitClassMethods(@class);

            return(true);
        }