Пример #1
0
        public bool VisitPrimitiveType(PrimitiveType primitive)
        {
            var typePrinter = new CppTypePrinter(Context.Context);
            var type        = typePrinter.VisitPrimitiveType(primitive);

            Context.Before.WriteLine($"{type} {Context.ArgName};");

            switch (primitive)
            {
            case PrimitiveType.Void:
                return(true);

            case PrimitiveType.Bool:
            //JS_ToBool
            case PrimitiveType.Char:
            case PrimitiveType.UChar:
            case PrimitiveType.Short:
            case PrimitiveType.UShort:
            case PrimitiveType.Int:
                Context.Before.WriteLine($"if (JS_ToInt32(ctx, &{Context.ArgName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                return(true);

            case PrimitiveType.UInt:
            case PrimitiveType.Long:
            case PrimitiveType.ULong:
            case PrimitiveType.LongLong:
            case PrimitiveType.ULongLong:
            case PrimitiveType.Float:
            case PrimitiveType.Double:
            case PrimitiveType.WideChar:
            default:
                throw new NotImplementedException();
            }
        }
Пример #2
0
        public void HandleRefOutNonDefaultIntegerEnum(Enumeration @enum)
        {
            // This deals with marshaling of managed enums with non-C default
            // backing types (ie. enum : short).

            // Unlike C++ or Objective-C, C enums always have the default integer
            // type size, so we need to create a local variable of the right type
            // for marshaling with the managed runtime and cast it back to the
            // correct type.

            var backingType = @enum.BuiltinType.Type;
            var typePrinter = new CppTypePrinter();
            var integerType = typePrinter.VisitPrimitiveType(backingType);
            var newArgName = CGenerator.GenId(Context.ArgName);
            Context.SupportBefore.WriteLine("{0} {1} = *(({0}*) {2});",
                integerType, newArgName, Context.ArgName);
            Context.Return.Write("&{0}", newArgName);
            Context.SupportAfter.WriteLine("*{0} = ({1}) {2};", Context.ArgName,
                @enum.QualifiedName, newArgName);
        }
Пример #3
0
        public bool VisitPrimitiveType(PrimitiveType primitive)
        {
            var typePrinter = new CppTypePrinter(Context.Context);
            var type        = typePrinter.VisitPrimitiveType(primitive);

            var argName = Context.Parameter.Name;

            Context.Before.WriteLine($"{type} {argName};");

            switch (primitive)
            {
            case PrimitiveType.Void:
                return(true);

            case PrimitiveType.Bool:
                Context.Before.WriteLine($"{argName} = JS_ToBool(ctx, argv[{Context.ParameterIndex}]);");
                Context.Before.WriteLine($"if ({argName} == -1)");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.Char:
            case PrimitiveType.SChar:
            case PrimitiveType.UChar:
                Context.Before.WriteLine($"int32_t _{argName};");
                Context.Before.WriteLine($"if (JS_ToInt32(ctx, &_{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Before.WriteLine($"{argName} = ({type})_{argName};");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.Short:
            case PrimitiveType.UShort:
                Context.Before.WriteLine($"int32_t _{argName};");
                Context.Before.WriteLine($"if (JS_ToInt32(ctx, &_{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Before.WriteLine($"{argName} = ({type})_{argName};");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.Int:
            case PrimitiveType.Long:
                Context.Before.WriteLine($"if (JS_ToInt32(ctx, &{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.UInt:
            case PrimitiveType.ULong:
                Context.Before.WriteLine($"if (JS_ToUint32(ctx, &{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.LongLong:
                Context.Before.WriteLine($"int64_t _{argName};");
                Context.Before.WriteLine($"if (JS_ToInt64Ext(ctx, &_{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Before.WriteLine($"{argName} = ({type})_{argName};");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.ULongLong:
                Context.Before.WriteLine($"int64_t _{argName};");
                Context.Before.WriteLine($"if (JS_ToInt64Ext(ctx, &_{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Before.WriteLine($"{argName} = ({type})_{argName};");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.Float:
                Context.Before.WriteLine($"double _{argName};");
                Context.Before.WriteLine($"if (JS_ToFloat64(ctx, &_{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Before.WriteLine($"{argName} = ({type})_{argName};");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.Double:
                Context.Before.WriteLine($"if (JS_ToFloat64(ctx, &{argName}, argv[{Context.ParameterIndex}]))");
                Context.Before.WriteLineIndent("return JS_EXCEPTION;");
                Context.Return.Write($"{argName}");
                return(true);

            case PrimitiveType.WideChar:
            default:
                throw new NotImplementedException();
            }
        }