예제 #1
0
 public ImmutableNode <string> Visit(ByRefTypeReference byRefTypeReference)
 {
     return(new ImmutableNode <string>(null, "ref ", byRefTypeReference.ElementType.Accept(this)));
 }
예제 #2
0
    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);
        }
    }