private static bool RequiresMathNamespace(ClassDefinition @class) { if (@class.NestedClasses.Any(RequiresMathNamespace)) { return(true); } if (@class.IsExcluded) { return(false); } foreach (var method in @class.Methods.Where(m => !m.IsExcluded)) { if (@class.HidePublicConstructors && method.IsConstructor) { continue; } if (DefaultParser.TypeRequiresMarshal(method.ReturnType)) { return(true); } if (method.Parameters.Any(param => DefaultParser.TypeRequiresMarshal(param.Type))) { return(true); } } return(false); }
public CWriter(DefaultParser parser) : base(parser) { _wrapperHeaderGuards = new Dictionary<string, string> { {"btActionInterface", "_BT_ACTION_INTERFACE_H"}, {"btBroadphaseAabbCallback", "BT_BROADPHASE_INTERFACE_H"}, {"btBroadphaseRayCallback", "BT_BROADPHASE_INTERFACE_H"}, {"ContactResultCallback", "BT_COLLISION_WORLD_H"}, {"ConvexResultCallback", "BT_COLLISION_WORLD_H"}, {"RayResultCallback", "BT_COLLISION_WORLD_H"}, {"btIDebugDraw", "BT_IDEBUG_DRAW__H"}, {"btMotionState", "BT_MOTIONSTATE_H"}, {"btSerializer", "BT_SERIALIZER_H"}, {"btInternalTriangleIndexCallback", "BT_TRIANGLE_CALLBACK_H"}, {"btTriangleCallback", "BT_TRIANGLE_CALLBACK_H"}, {"IControl", "_BT_SOFT_BODY_H"}, {"ImplicitFn", "_BT_SOFT_BODY_H"} }; }
public CWriter(DefaultParser parser) : base(parser) { _wrapperHeaderGuards = new Dictionary <string, string> { { "btActionInterface", "_BT_ACTION_INTERFACE_H" }, { "btBroadphaseAabbCallback", "BT_BROADPHASE_INTERFACE_H" }, { "btBroadphaseRayCallback", "BT_BROADPHASE_INTERFACE_H" }, { "ContactResultCallback", "BT_COLLISION_WORLD_H" }, { "ConvexResultCallback", "BT_COLLISION_WORLD_H" }, { "RayResultCallback", "BT_COLLISION_WORLD_H" }, { "btIDebugDraw", "BT_IDEBUG_DRAW__H" }, { "btMotionState", "BT_MOTIONSTATE_H" }, { "btSerializer", "BT_SERIALIZER_H" }, { "btInternalTriangleIndexCallback", "BT_TRIANGLE_CALLBACK_H" }, { "btTriangleCallback", "BT_TRIANGLE_CALLBACK_H" }, { "IControl", "_BT_SOFT_BODY_H" }, { "ImplicitFn", "_BT_SOFT_BODY_H" } }; }
private static bool RequiresConversionHeader(ClassDefinition @class) { if (@class.NestedClasses.Any(RequiresConversionHeader)) { return(true); } foreach (var method in @class.Methods.Where(m => !m.IsExcluded)) { if (DefaultParser.TypeRequiresMarshal(method.ReturnType)) { return(true); } if (method.Parameters.Any(p => DefaultParser.TypeRequiresMarshal(p.Type))) { return(true); } } return(false); }
public CMakeWriter(DefaultParser parser) : base(parser) { }
protected WrapperWriter(DefaultParser parser) { Parser = parser; Project = parser.Project; }
private void WriteMethod(ManagedMethod method, int level, int numOptionalParams = 0) { var nativeMethod = method.Native; var parentClass = method.Parent; // No whitespace between get/set methods if (!(method.Property != null && method.Equals(method.Property.Setter))) { EnsureSourceWhiteSpace(); hasHeaderWhiteSpace = false; } // #ifndef DISABLE_FEATURE bool hasConditional = false; if (method.Property == null) { foreach (var param in method.Parameters) { string typeConditional = GetTypeConditional(param.Native.Type, parentClass.Header); if (typeConditional != null) { WriteLine($"#ifndef {typeConditional}", WriteTo.Header | WriteTo.Source); hasSourceWhiteSpace = true; hasConditional = true; } } } WriteMethodDeclaration(method, level, numOptionalParams); var prevTo = To; To = WriteTo.Source; // Constructor chaining int numParameters = method.Parameters.Length - numOptionalParams; // Getters with parameter for return value if (numParameters == 1 && method.Property != null && method.Equals(method.Property.Getter)) { numParameters = 0; } var currentParams = method.Parameters.Take(numParameters).ToList(); bool doConstructorChaining = false; if (nativeMethod.IsConstructor && parentClass.BaseClass != null) { // If there is no need for marshalling code, we can chain constructors doConstructorChaining = currentParams.All(p => !DefaultParser.TypeRequiresMarshal(p.Native.Type)); Write(1, $": {parentClass.BaseClass.Name}("); if (doConstructorChaining) { Write("new "); WriteMethodMarshal(method, numParameters); if (parentClass.BaseClass.Native.HasPreventDelete) { Write(", false"); } } else { Write('0'); } WriteLine(')'); } // Method body WriteLine('{'); if (!doConstructorChaining) { WriteMethodDefinition(method, numParameters); } // Cache property values if (nativeMethod.IsConstructor) { var assignments = new List <string>(); var methodParent = method.Parent; while (methodParent != null) { foreach (var cachedProperty in methodParent.CachedProperties.OrderBy(p => p.Key)) { foreach (var param in currentParams) { if (!param.Name.ToLower().Equals(cachedProperty.Key.ToLower())) { continue; } var paramType = GetName(param.Native.Type); var propType = GetName(cachedProperty.Value.Property.Type); if (!paramType.Equals(propType)) { return; } string assignment = $"\t{cachedProperty.Value.CacheFieldName} = {param.Name};"; assignments.Add(assignment); } } methodParent = methodParent.BaseClass; } if (assignments.Count != 0) { EnsureSourceWhiteSpace(); foreach (string assignment in assignments) { WriteLine(assignment); } hasSourceWhiteSpace = false; } } WriteLine('}'); hasSourceWhiteSpace = false; // #endif // DISABLE_FEATURE if (hasConditional) { foreach (var param in currentParams) { string typeConditional = GetTypeConditional(param.Native.Type, method.Parent.Header); if (typeConditional != null) { WriteLine("#endif", WriteTo.Header | WriteTo.Source); hasHeaderWhiteSpace = true; } } } // If there are optional parameters, then output all possible combinations of calls if (currentParams.Any() && currentParams.Last().Native.IsOptional) { WriteMethod(method, level, numOptionalParams + 1); } To = prevTo; }