public ImVersionConstantsTransformation(TranslatedLibrary library, TranslatedLibraryConstantEvaluator constantEvaluator) { //TODO: Handle the macros missing TranslatedMacro[] macros = new[] { library.Macros.First(m => m.Name == nameof(IMGUI_VERSION)), library.Macros.First(m => m.Name == nameof(IMGUI_VERSION_NUM)) }; ImmutableArray <ConstantEvaluationResult> result = constantEvaluator.EvaluateBatch(macros); Debug.Assert(result.Length == 2); IMGUI_VERSION = new TranslatedConstant(nameof(IMGUI_VERSION), result[0]); IMGUI_VERSION_NUM = new TranslatedConstant(nameof(IMGUI_VERSION_NUM), result[1]); }
private TranslatedRecord?TryGetSimpleBaseType(TranslatedLibrary library, TranslatedRecord declaration) { if (declaration.NonVirtualBaseField is null || declaration.NonVirtualBaseField.Offset != 0) { return(null); } if (declaration.NonVirtualBaseField.Type is not TranslatedTypeReference baseType) { return(null); } if (baseType.TryResolve(library) is not TranslatedRecord baseRecord) { return(null); } return(baseRecord); }
protected override TranslatedLibrary PreTransformLibrary(TranslatedLibrary library) { Debug.Assert(PxBatchQueryDescFile is null); PxBatchQueryDescFile = library.Files.FirstOrDefault(f => f.WasInScope && !f.WasNotUsed && Path.GetFileName(f.FilePath) == "PxBatchQueryDesc.h"); return(library); }
public InheritanceViaGenericAdapter(TranslatedLibrary library, Adapter targetAdapter, Adapter replacedAdapter) : base(targetAdapter) { // Save and validate our output type // (We mostly only validate the replaced adapter since we assume it's well-formed to adapt to this output.) OutputType = targetAdapter.InputType; if (OutputType is not PointerTypeReference) { throw new ArgumentException("The target adapter must take a pointer.", nameof(targetAdapter)); } // Determine the actual record type TypeReference recordTypeReference = replacedAdapter.InputType; if (recordTypeReference is ByRefTypeReference byRefType) { ByRefKind = byRefType.Kind; recordTypeReference = byRefType.Inner; } int pointerArity = 0; while (recordTypeReference is PointerTypeReference pointerType) { pointerArity++; recordTypeReference = pointerType.Inner; } if (ByRefKind is null && pointerArity == 0) { throw new ArgumentException("The replaced adapter must be passed by reference.", nameof(replacedAdapter)); } if (recordTypeReference is not TranslatedTypeReference translatedType) { throw new ArgumentException("The replaced adapter does not adapt a translated type reference or uses an unrecognized method to do so.", nameof(replacedAdapter)); } if (translatedType.TryResolve(library) is not TranslatedRecord targetRecord) { throw new ArgumentException("The replaced adapter does not adapt a record type reference.", nameof(replacedAdapter)); } // Determine the constraint info ConstraintInterfaceNamespace = $"{targetRecord.Namespace}.{PhysXMarkerInterfacesDeclaration.InfrastructureNamespaceName}"; ConstraintInterfaceTypeName = $"I{targetRecord.Name}"; // Name the generic parameter based on the parameter name GenericParameterName = $"T{Char.ToUpperInvariant(replacedAdapter.Name[0])}{replacedAdapter.Name.AsSpan().Slice(1)}"; // Name our temporary (only used when we're byref) TemporaryName = $"__{Name}P"; // Create the input type InputType = new ExternallyDefinedTypeReference(GenericParameterName); for (int i = 0; i < pointerArity; i++) { InputType = new PointerTypeReference(InputType); } TemporaryType = InputType; if (ByRefKind is ByRefKind byRefKind) { InputType = new ByRefTypeReference(byRefKind, InputType); TemporaryType = new PointerTypeReference(TemporaryType); } }