예제 #1
0
        public void GenerateEnum(Enumeration @enum)
        {
            if ([email protected] || @enum.IsIncomplete)
            {
                return;
            }

            PushBlock(CLIBlockKind.Enum, @enum);

            GenerateDeclarationCommon(@enum);

            if (@enum.Modifiers.HasFlag(Enumeration.EnumModifiers.Flags))
            {
                WriteLine("[System::Flags]");
            }

            // A nested class cannot have an assembly access specifier as part
            // of its declaration.
            if (@enum.Namespace is Namespace)
            {
                Write("public ");
            }

            Write("enum struct {0}", @enum.Name);

            var typeName = TypePrinter.VisitPrimitiveType(@enum.BuiltinType.Type,
                                                          new TypeQualifiers());

            if (@enum.BuiltinType.Type != PrimitiveType.Int)
            {
                Write(" : {0}", typeName);
            }

            NewLine();
            WriteStartBraceIndent();

            foreach (var item in @enum.Items)
            {
                PushBlock(CLIBlockKind.EnumItem);

                GenerateInlineSummary(item.Comment);

                Write(item.Name);

                if (item.ExplicitValue)
                {
                    Write(" = {0}", @enum.GetItemValueAsString(item));
                }

                if (item != @enum.Items.Last())
                {
                    WriteLine(",");
                }

                PopBlock(NewLineKind.Never);
            }

            PopIndent();
            WriteLine("};");

            PopBlock(NewLineKind.BeforeNextBlock);
        }
 public CSharpExpressionPrinter(TypePrinter typePrinter)
 {
     this.typePrinter = typePrinter;
 }
예제 #3
0
 public string GetManagedName(Type t)
 {
     return(TypePrinter.GetName(t, TypeNameKind.Managed));
 }
예제 #4
0
        public void HandleRefOutPrimitiveType(PrimitiveType type, Enumeration @enum = null)
        {
            TypePrinter.PushContext(TypePrinterContextKind.Native);
            var typeName = Context.Parameter.Visit(TypePrinter);

            TypePrinter.PopContext();

            CheckRefOutParameter(type != PrimitiveType.String && Context.Parameter.IsInOut);

            string marshal = $"{Context.ArgName}.get()";

            var isEnum = @enum != null;

            if (isEnum)
            {
                marshal = $"{marshal}.getValue()";
            }

            if (type == PrimitiveType.Bool)
            {
                marshal = $"((byte) ({marshal} ? 1 : 0))";
            }

            if (IsReferenceIntegerType(type))
            {
                var integerTypeName = TypePrinter.VisitPrimitiveType(GetSignedIntegerType(type));
                marshal = $"({integerTypeName}){marshal}.intValue()";
            }

            var varName = JavaGenerator.GeneratedIdentifier(Context.ArgName);

            Context.SupportBefore.Write($"{typeName} {varName} = ");

            if (isEnum || type == PrimitiveType.Bool || IsReferenceIntegerType(type))
            {
                Context.SupportBefore.WriteLine($"new {typeName}({marshal});");
            }
            else
            {
                Context.SupportBefore.WriteLine($"({marshal}) != null ? new {typeName}({marshal}) : new {typeName}();");
            }

            Context.Return.Write(varName);

            var value = $"{varName}.getValue()";

            marshal = value;

            if (isEnum)
            {
                marshal = $"{@enum.Visit(TypePrinter)}.fromOrdinal({value})";
            }

            if (type == PrimitiveType.Bool)
            {
                marshal = $"{value} != 0";
            }

            if (IsReferenceIntegerType(type))
            {
                var integerTypeName = Context.Parameter.Type.Visit(TypePrinter);
                marshal = $"new {integerTypeName}({value})";
            }

            Context.SupportAfter.WriteLine($"{Context.ArgName}.set({marshal});");
        }
예제 #5
0
    public static void Main(string[] args)
    {
        var tp = new TypePrinter();

        tp.printtypes_of_file(args[0]);
    }