public static void SetClassAsOpaque(this ASTContext context, string name) { foreach (var @class in context.FindClass(name)) { @class.IsOpaque = true; } }
public static void SetClassAsValueType(this ASTContext context, string className) { foreach (var @class in context.FindClass(className)) { @class.Type = ClassType.ValueType; } }
private Class FindClassToMoveFunctionTo(Function function) { Class @class = null; if (function.IsOperator) { foreach (var param in function.Parameters) { if (FunctionToInstanceMethodPass.GetClassParameter(param, out @class)) { break; } } if (@class == null) { function.ExplicitlyIgnore(); } } else { var unit = function.Namespace as TranslationUnit; @class = unit == null ? ASTContext.FindClass( function.Namespace.Name, ignoreCase : true).FirstOrDefault() : ASTContext.FindCompleteClass( unit.FileNameWithoutExtension.ToLowerInvariant(), true); } return(@class); }
public static void IgnoreClassWithName(this ASTContext context, string name) { foreach (var @class in context.FindClass(name)) { @class.ExplicitlyIgnore(); } }
public static void SetClassBindName(this ASTContext context, string className, string name) { foreach (var @class in context.FindClass(className)) { @class.Name = name; } }
public static void IgnoreClassField(this ASTContext context, string name, string field) { foreach (var @class in context.FindClass(name)) { foreach (var classField in @class.Fields.FindAll(f => f.Name == field)) classField.ExplicitlyIgnore(); } }
public static void SetNameOfClassMethod(this ASTContext context, string name, string methodName, string newMethodName) { foreach (var @class in context.FindClass(name)) { var method = @class.Methods.Find(m => m.Name == methodName); if (method != null) method.Name = newMethodName; } }
public static void IgnoreClassMethodWithName(this ASTContext context, string className, string name) { foreach (var method in from @class in context.FindClass(className) from method in @class.Methods where method.Name == name select method) { method.ExplicitlyIgnore(); } }
private Class FindClassToMoveFunctionTo(INamedDecl @namespace) { var unit = @namespace as TranslationUnit; if (unit == null) { return(ASTContext.FindClass( @namespace.Name, ignoreCase: true).FirstOrDefault()); } return(ASTContext.FindCompleteClass( unit.FileNameWithoutExtension.ToLowerInvariant(), true)); }
public override bool VisitASTContext(ASTContext context) { // we need this one for marshalling std::string foreach (var name in new[] { "allocator", "char_traits" }) foreach (var usedStdType in context.FindClass(name, false, true).Where( a => a.TranslationUnit.IsSystemHeader)) usedStdTypes.Add(usedStdType); var result = base.VisitASTContext(context); foreach (var unit in Options.SystemModule.Units) RemoveUnusedStdTypes(unit); return result; }
/// Do transformations that should happen after passes are processed. public override void Postprocess(Driver driver, ASTContext ctx) { foreach (string s in ClassDecls) { IEnumerable <Class> classes = ctx.FindClass(s); foreach (Class c in classes) { if (WithoutCommon && !c.Name.Contains(Class)) { ctx.IgnoreClassWithName(c.Name); } else { ctx.SetClassAsValueType(c.Name); } } } }
public override bool VisitASTContext(ASTContext context) { // we need this one for marshalling std::string foreach (var allocator in context.FindClass("allocator", false, true).Where( a => a.TranslationUnit.IsSystemHeader)) { usedStdTypes.Add(allocator); } var result = base.VisitASTContext(context); foreach (var unit in Options.SystemModule.Units) { RemoveUnusedStdTypes(unit); } return(result); }
public static void SetPropertyAsReadOnly(this ASTContext context, string className, string propertyName) { var properties = context.FindClass(className) .SelectMany(c => c.Properties.Where(p => p.Name == propertyName && p.HasSetter)); foreach (var property in properties) if (property.SetMethod != null) property.SetMethod.GenerationKind = GenerationKind.None; else { var field = property.Field; var quals = field.QualifiedType.Qualifiers; quals.IsConst = true; var qualType = field.QualifiedType; qualType.Qualifiers = quals; field.QualifiedType = qualType; } }
/// <summary> /// Sets the parameter usage for a method parameter. /// </summary> /// <param name="parameterIndex">first parameter has index 1</param> public static void SetMethodParameterUsage(this ASTContext context, string className, string methodName, int parameterIndex, ParameterUsage usage) { if (parameterIndex <= 0) { throw new ArgumentException("parameterIndex"); } foreach (var @class in context.FindClass(className)) { var method = @class.Methods.Find(m => m.Name == methodName); if (method == null) { throw new ArgumentException("methodName"); } if (method.Parameters.Count < parameterIndex) { throw new ArgumentException("parameterIndex"); } method.Parameters[parameterIndex - 1].Usage = usage; } }
public static Class Class(this ASTContext context, string name) { return(context.FindClass(name).First()); }
/// Do transformations that should happen after passes are processed. public override void Postprocess(Driver driver, ASTContext ctx) { //ctx.SetClassBindName("@base", "VaiBase"); //ctx.SetClassAsValueType("@base"); IEnumerable <Class> classes = ctx.FindClass("VaiCtx") .Concat(ctx.FindClass("PlaidmlDevconf")) .Concat(ctx.FindClass("PlaidmlDevconf")) .Concat(ctx.FindClass("PlaidmlDevice")) .Concat(ctx.FindClass("PlaidmlDeviceEnumerator")) .Concat(ctx.FindClass("PlaidmlBuffer")) .Concat(ctx.FindClass("PlaidmlMapping")) .Concat(ctx.FindClass("PlaidmlShape")) .Concat(ctx.FindClass("PlaidmlFunction")) .Concat(ctx.FindClass("PlaidmlVar")) .Concat(ctx.FindClass("PlaidmlApplier")) .Concat(ctx.FindClass("PlaidmlComposer")) .Concat(ctx.FindClass("PlaidmlInvoker")) .Concat(ctx.FindClass("PlaidmlInvocatio")) .Concat(ctx.FindClass("PlaidmlGradient"));; foreach (Class c in classes) { ctx.SetClassAsValueType(c.Name); } }
public void Postprocess(Driver driver, ASTContext ctx) { var libNamespace = ctx.FindClass("Size").Single().Namespace; ctx.SetClassAsValueType("HostCallbacks"); ctx.SetClassAsValueType("Size"); ctx.SetClassAsValueType("Margins"); ctx.SetClassAsValueType("Position"); ctx.SetClassAsValueType("ViewLayout"); var initWithEgl = ctx.FindFunction("InitWithEgl").Single(); initWithEgl.GenerationKind = GenerationKind.None; var performUpdates = ctx.FindFunction("PerformUpdates").Single(); performUpdates.GenerationKind = GenerationKind.None; var loadUrl = ctx.FindFunction("LoadUrl").Single(); loadUrl.GenerationKind = GenerationKind.None; var scroll = ctx.FindFunction("Scroll").Single(); scroll.GenerationKind = GenerationKind.None; var version = ctx.FindFunction("ServoVersion").Single(); version.GenerationKind = GenerationKind.None; var servoSharp = new Class { Name = "ServoSharp", Access = AccessSpecifier.Public, Type = ClassType.RefType, Namespace = libNamespace, }; servoSharp.Methods.AddRange(new[] { new Method { Namespace = servoSharp, IsDefaultConstructor = true, Kind = CXXMethodKind.Constructor }, new Method(initWithEgl) { Namespace = servoSharp, GenerationKind = GenerationKind.Generate }, new Method(performUpdates) { Namespace = servoSharp, GenerationKind = GenerationKind.Generate }, new Method(loadUrl) { Namespace = servoSharp, GenerationKind = GenerationKind.Generate }, new Method(scroll) { Namespace = servoSharp, GenerationKind = GenerationKind.Generate }, new Method(version) { Namespace = servoSharp, GenerationKind = GenerationKind.Generate } }); ctx.TranslationUnits[0].Classes.Add(servoSharp); ctx.FindEnum("ServoResult").Single().Items.ForEach(item => item.Name = item.Name.Replace("ServoResult", string.Empty)); ctx.FindEnum("ScrollState").Single().Items.ForEach(item => item.Name = item.Name.Replace("ScrollState", string.Empty)); ctx.FindEnum("TouchState").Single().Items.ForEach(item => item.Name = item.Name.Replace("TouchState", string.Empty)); }
public void Preprocess(Driver driver, ASTContext ctx) { ctx.IgnoreHeadersWithName("API.h"); ctx.IgnoreHeadersWithName("Concurrency.h"); ctx.IgnoreHeadersWithName("ConcurrentQueue.h"); ctx.IgnoreHeadersWithName("Delegate.h"); ctx.IgnoreHeadersWithName("Event.h"); ctx.IgnoreHeadersWithName("Handle.h"); ctx.IgnoreHeadersWithName("Object.h"); ctx.IgnoreHeadersWithName("Pointers.h"); ctx.IgnoreHeadersWithName("References.h"); ctx.IgnoreHeadersWithName("Reflection.h"); ctx.IgnoreHeadersWithName("ReflectionHelpers.h"); ctx.IgnoreHeadersWithName("Task.h"); ctx.IgnoreHeadersWithName("Timer.h"); ctx.IgnoreHeadersWithName("Swap.h"); //Core ctx.IgnoreClassWithName("Object"); ctx.IgnoreClassWithName("Class"); ctx.IgnoreClassWithName("ReferenceCounted"); ctx.IgnoreClassWithName("HandleManager"); ctx.IgnoreClassWithName("Delegate0"); ctx.IgnoreClassWithName("Delegate1"); ctx.IgnoreClassWithName("Delegate2"); ctx.IgnoreClassWithName("TaskPool"); ctx.IgnoreClassWithName("ConcurrentQueue"); ctx.SetClassAsValueType("StringHash"); ctx.IgnoreClassWithName("RawStringCompare"); ctx.SetClassAsValueType("LogEntry"); ctx.IgnoreFunctionWithName("LogCreate"); ctx.IgnoreFunctionWithName("AllocatorAllocate"); ctx.IgnoreFunctionWithName("AllocatorDeallocate"); ctx.SetNameOfFunction("AllocatorReset", "AllocatorResetMemory"); ctx.IgnoreClassWithName("StreamFuncs"); ctx.IgnoreClassWithName("FileStream"); ctx.SetClassAsValueType("FileWatchEvent"); ctx.IgnoreFunctionWithPattern(".+GetType"); ctx.IgnoreFunctionWithName("ClassGetIdMap"); ctx.IgnoreFunctionWithName("ReflectionSetHandleContext"); ctx.IgnoreFunctionWithName("SerializerCreateJSON"); ctx.IgnoreFunctionWithName("SerializerCreateBinary"); ctx.IgnoreClassWithName("ReflectionContext"); ctx.IgnoreClassWithName("ValueContext"); ctx.SetClassAsValueType("ExtensionMetadata"); ctx.IgnoreClassWithName("MemoryStream"); ctx.IgnoreClassWithName("Serializer"); ctx.IgnoreClassWithName("Thread"); // Math ctx.SetClassAsValueType("ColorP"); ctx.SetClassAsValueType("Color"); ctx.SetClassAsValueType("Vector2P"); ctx.SetClassAsValueType("Vector2"); ctx.SetClassAsValueType("Vector2i"); ctx.SetClassAsValueType("Vector3P"); ctx.SetClassAsValueType("Vector3"); ctx.SetClassAsValueType("Vector4"); ctx.SetClassAsValueType("EulerAngles"); ctx.SetClassAsValueType("QuaternionP"); ctx.SetClassAsValueType("Quaternion"); ctx.SetClassAsValueType("Matrix4x3"); ctx.SetClassAsValueType("Matrix4x4"); ctx.CopyClassFields("ColorP", "Color"); ctx.CopyClassFields("Vector2P", "Vector2"); ctx.CopyClassFields("Vector3P", "Vector3"); ctx.CopyClassFields("QuaternionP", "Quaternion"); ctx.IgnoreClassWithName("ColorP"); ctx.IgnoreClassWithName("Vector2P"); ctx.IgnoreClassWithName("Vector3P"); ctx.IgnoreClassWithName("QuaternionP"); ctx.SetNameOfClassMethod("Matrix4x3", "identity", "setIdentity"); ctx.SetNameOfClassMethod("Matrix4x4", "identity", "setIdentity"); ctx.SetNameOfClassMethod("Quaternion", "identity", "setIdentity"); ctx.SetNameOfClassMethod("Vector2", "zero", "setZero"); ctx.SetNameOfClassMethod("Vector3", "zero", "setZero"); ctx.SetNameOfClassMethod("Vector4", "zero", "setZero"); // Resources ctx.IgnoreFunctionWithName("ResourcesInitialize"); ctx.IgnoreFunctionWithName("ResourcesDeinitialize"); //lib.SetClassAsValueType("ResourceEvent"); ctx.SetClassAsValueType("ResourceLoadOption"); ctx.SetClassAsValueType("ResourceLoadOptions"); ctx.SetNameOfClassMethod("Texture", "allocate", "alloc"); ctx.ExcludeFromPass("ResourceHandleCreate", typeof (FunctionToInstanceMethodPass)); // Set generic type constraints on template methods var resourceManager = ctx.FindClass("ResourceManager").FirstOrDefault(); if (resourceManager != null) foreach (var template in resourceManager.Templates) { for (var i = 0; i < template.Parameters.Count; ++i) { var param = template.Parameters[i]; param.Constraint = "Flood::Resource"; template.Parameters[i] = param; } } // Graphics ctx.SetClassAsValueType("RenderContextSettings"); ctx.SetClassAsValueType("RenderBatchRange"); ctx.SetClassAsValueType("VertexElementP"); ctx.SetClassAsValueType("VertexElement"); ctx.SetClassAsValueType("UniformBufferElement"); ctx.SetClassAsValueType("RenderState"); ctx.SetClassAsValueType("LightState"); ctx.IgnoreHeadersWithName("MaxRectsBinPack.h"); ctx.IgnoreClassWithName("MaxRectsBinPack"); ctx.IgnoreClassWithName("CompareHandle"); ctx.SetClassAsValueType("Glyph"); ctx.SetClassAsValueType("Rectangle"); ctx.SetClassAsValueType("RectangleF"); ctx.SetClassAsValueType("SubTexture"); ctx.SetMethodParameterUsage("TextureAtlas", "getImageSubTexture", 2, ParameterUsage.Out); ctx.SetMethodParameterUsage("Font", "getGlyphInfo", 3, ParameterUsage.Out); // Engine ctx.IgnoreClassMethodWithName("Engine", "addSubsystem"); }
public static void IgnoreClassWithName(this ASTContext context, string name) { foreach (var @class in context.FindClass(name)) @class.GenerationKind = GenerationKind.Internal; }