Пример #1
0
        //public static void WriteInstanceConstructor(ScalaWriter writer, ConstructorDeclarationSyntax ctor)
        //{


        //	foreach (var field in TypeState.Instance.AllMembers
        //				.OfType<BaseFieldDeclarationSyntax>()
        //				.Where(o => !o.Modifiers.Any(SyntaxKind.StaticKeyword))
        //				.SelectMany(o => o.Declaration.Variables)
        //				.Where(o =>
        //					(o.Initializer != null && !WriteField.IsConst(o.Parent.Parent.As<BaseFieldDeclarationSyntax>().Modifiers, o.Initializer, o.Parent.As<VariableDeclarationSyntax>().Type))
        //					||
        //					(o.Initializer == null && TypeProcessor.ValueToReference(o.Parent.As<VariableDeclarationSyntax>().Type))
        //					||
        //					o.Parent.Parent is EventFieldDeclarationSyntax))
        //	{
        //		writer.WriteIndent();
        //		writer.Write(field.Identifier.ValueText);
        //		writer.Write(" = ");

        //		if (field.Initializer == null)
        //		{
        //			//The only way to get here with a null initializer is for a TypeProcess.ValueToReference field.
        //			writer.Write("new ");
        //			writer.Write(TypeProcessor.ConvertType(field.Parent.As<VariableDeclarationSyntax>().Type));
        //			writer.Write("()");
        //		}
        //		else
        //		{
        //			Core.Write(writer, field.Initializer.Value);
        //		}

        //		writer.Write(";\r\n");
        //	}

        //}



        public static void WriteStaticConstructor(ScalaWriter writer, ConstructorDeclarationSyntax staticConstructor)
        {
            //var staticFieldsNeedingInitialization = TypeState.Instance.AllMembers
            //	.OfType<BaseFieldDeclarationSyntax>()
            //	.Where(o => o.Modifiers.Any(SyntaxKind.StaticKeyword))
            //	.SelectMany(o => o.Declaration.Variables)
            //	.Where(o =>
            //		(o.Initializer != null && !WriteField.IsConst(o.Parent.Parent.As<BaseFieldDeclarationSyntax>().Modifiers, o.Initializer, o.Parent.As<VariableDeclarationSyntax>().Type))
            //		||
            //		(o.Initializer == null && TypeProcessor.ValueToReference(o.Parent.As<VariableDeclarationSyntax>().Type))
            //		||
            //		o.Parent.Parent is EventFieldDeclarationSyntax)
            //	.ToList();

            if (staticConstructor.Body == null)
            {
                return;
            }


            writer.WriteLine("def cctor()");
            writer.WriteOpenBrace();

            //foreach (var field in staticFieldsNeedingInitialization)
            //{
            //	writer.WriteIndent();
            //	writer.Write(field.Identifier.ValueText);
            //	writer.Write(" = ");

            //	if (field.Initializer == null)
            //	{
            //		//The only way to get here without an initializer is if it's a TypeProcessor.ValueToReference.
            //		writer.Write("new ");
            //		writer.Write(TypeProcessor.ConvertType(field.Parent.As<VariableDeclarationSyntax>().Type));
            //		writer.Write("()");
            //	}
            //	else
            //	{
            //		Core.Write(writer, field.Initializer.As<EqualsValueClauseSyntax>().Value);
            //	}
            //	writer.Write(";\r\n");
            //}



            foreach (var statement in staticConstructor.Body.As <BlockSyntax>().Statements)
            {
                Core.Write(writer, statement);
            }

            writer.WriteCloseBrace();

            StaticConstructors.Add(TypeState.Instance.Partials.First().Symbol.ContainingNamespace.FullNameWithDot() + TypeState.Instance.TypeName);
        }
Пример #2
0
        public static void WriteStaticConstructor(OutputWriter writer, ConstructorDeclarationSyntax staticConstructor,
                                                  List <string> otherStatics)
        {
            if (staticConstructor.Body == null && (otherStatics == null || otherStatics.Count == 0))
            {
                return;
            }

            writer.WriteLine();
            writer.WriteLine("static this()");
            writer.OpenBrace();

            if (otherStatics != null) //We need to write the static initializers before anything else
            {
                foreach (var statement in otherStatics)
                {
                    var nodeString = statement;

                    if (nodeString != null)
                    {
                        writer.WriteLine(nodeString);
                    }
                }
            }

            if (staticConstructor.Body != null)
            {
                foreach (var statement in staticConstructor.Body.As <BlockSyntax>().Statements)
                {
                    Core.Write(writer, statement);
                }
            }



            writer.CloseBrace();

            StaticConstructors.Add(Context.Instance.Partials.First().Symbol.ContainingNamespace.FullNameWithDot() +
                                   Context.Instance.TypeName);
        }
Пример #3
0
        public static void WriteStaticConstructor(HaxeWriter writer, ConstructorDeclarationSyntax staticConstructorOpt)
        {
            if (staticConstructorOpt == null)
            {
                return; //No static constructor needed
            }
            writer.WriteLine("public static function cctor():Void");
            writer.WriteOpenBrace();


            if (staticConstructorOpt != null && staticConstructorOpt.Body != null)
            {
                foreach (var statement in staticConstructorOpt.Body.As <BlockSyntax>().Statements)
                {
                    Core.Write(writer, statement);
                }
            }

            writer.WriteCloseBrace();

            StaticConstructors.Add(TypeState.Instance.TypeName);
        }
Пример #4
0
        public static void WriteStaticConstructor(OutputWriter writer, ConstructorDeclarationSyntax staticConstructor,
                                                  List <string> otherStatics)
        {
            if (staticConstructor.Body == null && (otherStatics == null || otherStatics.Count == 0))
            {
                return;
            }

            writer.WriteLine();
            writer.WriteLine("static this()");
            writer.OpenBrace();

            if (staticConstructor.Body != null)
            {
                foreach (var statement in staticConstructor.Body.As <BlockSyntax>().Statements)
                {
                    Core.Write(writer, statement);
                }
            }

            if (otherStatics != null)
            {
                foreach (var statement in otherStatics)
                {
                    var nodeString = statement;
//				if (nodeString.EndsWith (" SharpNative;\n")) {
//					nodeString = nodeString.RemoveFromEndOfString(" SharpNative;\n")+";\n";
//				}
                    writer.WriteLine(nodeString);
                }
            }

            writer.CloseBrace();

            StaticConstructors.Add(Context.Instance.Partials.First().Symbol.ContainingNamespace.FullNameWithDot() +
                                   Context.Instance.TypeName);
        }
Пример #5
0
        public static void WriteStaticConstructor(HaxeWriter writer, ConstructorDeclarationSyntax staticConstructorOpt)
        {
            var staticFieldsNeedingInitialization = TypeState.Instance.AllMembers
                                                    .OfType <BaseFieldDeclarationSyntax>()
                                                    .Where(o => o.Modifiers.Any(SyntaxKind.StaticKeyword))
                                                    .SelectMany(o => o.Declaration.Variables)
                                                    .Where(o =>
                                                           (o.Initializer != null && !WriteField.IsConst(o.Parent.Parent.As <BaseFieldDeclarationSyntax>().Modifiers, o.Initializer, o.Parent.As <VariableDeclarationSyntax>().Type))
                                                           ||
                                                           (o.Initializer == null && GenerateInitializerForFieldWithoutInitializer(o.Parent.As <VariableDeclarationSyntax>().Type))
                                                           ||
                                                           o.Parent.Parent is EventFieldDeclarationSyntax)
                                                    .ToList();

            if (staticConstructorOpt == null && staticFieldsNeedingInitialization.Count == 0)
            {
                return; //No static constructor needed
            }
            writer.WriteLine("public static function cctor():Void");
            writer.WriteOpenBrace();

            foreach (var field in staticFieldsNeedingInitialization)
            {
                var parentType = field.Parent.As <VariableDeclarationSyntax>().Type;

                writer.WriteIndent();
                writer.Write(field.Identifier.ValueText);
                writer.Write(" = ");

                if (field.Parent.Parent is EventFieldDeclarationSyntax)
                {
                    writer.Write("new CsEvent<");
                    writer.Write(TypeProcessor.ConvertType(parentType));
                    writer.Write(">()");
                }
                else if (field.Initializer == null)
                {
                    if (TypeProcessor.ValueToReference(parentType))
                    {
                        writer.Write("new ");
                        writer.Write(TypeProcessor.ConvertType(parentType));
                        writer.Write("()");
                    }
                    else
                    {
                        writer.Write(TypeProcessor.DefaultValue(TypeProcessor.ConvertType(parentType)));
                    }
                }
                else
                {
                    Core.Write(writer, field.Initializer.As <EqualsValueClauseSyntax>().Value);
                }
                writer.Write(";\r\n");
            }

            if (staticConstructorOpt != null && staticConstructorOpt.Body != null)
            {
                foreach (var statement in staticConstructorOpt.Body.As <BlockSyntax>().Statements)
                {
                    Core.Write(writer, statement);
                }
            }

            writer.WriteCloseBrace();

            StaticConstructors.Add(TypeState.Instance.TypeName);
        }