!arrays.avt

Переключить прокрутку окна
Загрузить этот исходный код

/*
    Компилятор языка программирования
    Объектно-ориентированный продвинутый векторный транслятор

    Copyright © 2021, 2024 Малик Разработчик

    Это свободная программа: вы можете перераспространять ее и/или изменять
    ее на условиях Стандартной общественной лицензии GNU в том виде,
    в каком она была опубликована Фондом свободного программного обеспечения;
    либо версии 3 лицензии, либо (по вашему выбору) любой более поздней версии.

    Эта программа распространяется в надежде, что она будет полезной,
    но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
    или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
    общественной лицензии GNU.

    Вы должны были получить копию Стандартной общественной лицензии GNU
    вместе с этой программой. Если это не так, см.
    <https://www.gnu.org/licenses/>.
*/

package ru.malik.elaborarer.avtoo.lang;

import avt.lang.array.*;
import avt.lang.math.*;

public class ArgumentArray(LocalArray, Cloneable, Measureable, ObjectArray)
{
    public static String toString(Type[] arguments) {
        StringBuilder result = new StringBuilder(0x0400) + '(';
        for(int limit = arguments == null ? -1 : arguments.length - 1, int index = 0; index <= limit; index++)
        {
            result + arguments[index].specialCanonicalName;
            if(index < limit) result + ", ";
        }
        return (result + ')').toString();
    }

    private final int fldStackElements;
    private final Local fldThisArgument;
    private final String fldUserString;
    private final String fldFullString;
    private final String fldFasmString;

    package (Local thisArgument, Local[] otherArguments): super(otherArguments) {
        int length = otherArguments.length;
        int stackElements = thisArgument != null ? 1 : 0;
        StringBuilder fullRepresentation = new StringBuilder(0x0400) + '(';
        StringBuilder userRepresentation = new StringBuilder(0x0400) + '(';
        for(int limit = length - 1, int index = 0; index < length; index++)
        {
            Local otherArgument = otherArguments[index];
            Type typeRef = otherArgument.type;
            String typeName = typeRef.specialCanonicalName;
            stackElements += typeRef.stackElements;
            fullRepresentation + typeName + ' ' + otherArgument.specialSimpleName;
            userRepresentation + typeName;
            if(index < limit)
            {
                fullRepresentation + ", ";
                userRepresentation + ", ";
            }
        }
        fldStackElements = stackElements;
        fldThisArgument = thisArgument;
        fldUserString = (userRepresentation + ')').toString();
        fldFullString = (fullRepresentation + ')').toString();
        for(userRepresentation.clear(), userRepresentation + '$', int index = 0; index < length; index++)
        {
            userRepresentation + otherArguments[index].type.fasmSimpleName + '$';
        }
        fldFasmString = userRepresentation.toString();
    }

    public boolean equals(Object anot) {
        if(anot == this) return true;
        if(!(anot instanceof ArgumentArray)) return false;
        Local[] anotArgs = ((ArgumentArray) anot).array;
        Local[] thisArgs = array;
        int index = anotArgs.length;
        label0: if(thisArgs.length == index)
        {
            while(index-- > 0) if(thisArgs[index].type != anotArgs[index].type) break label0;
            return true;
        }
        return false;
    }

    public int hashCode() {
        int result = 0;
        Local[] args = array;
        for(int index = args.length; index-- > 0; )
        {
            result ^= Int.rotateLeft(args[index].type.specialCanonicalName.hashCode(), index);
        }
        return result;
    }

    public long hashCodeAsLong() {
        long result = 0;
        Local[] args = array;
        for(int index = args.length; index-- > 0; )
        {
            result ^= Long.rotateLeft(args[index].type.specialCanonicalName.hashCodeAsLong(), index << 1);
        }
        return result;
    }

    public long2 hashCodeAsLong2() {
        long2 result = 0;
        Local[] args = array;
        for(int index = args.length; index-- > 0; )
        {
            result ^= Int128.rotateLeft(args[index].type.specialCanonicalName.hashCodeAsLong2(), index << 2);
        }
        return result;
    }

    public String toString() { return fldUserString; }

    public String toFullString() { return fldFullString; }

    public String toFasmString() { return fldFasmString; }

    public int stackElements { read = fldStackElements }

    public Local thisArgument { read = fldThisArgument }
}

public class ArrayTypeArray(Object, Cloneable, Measureable, ObjectArray)
{
    private ArrayType[] fldArray;

    package () { (fldArray = new ArrayType[0x1f]).length = 0; }

    public ArrayType[] clone() {
        ArrayType[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new ArrayType[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public ArrayType operator [](int index) { return fldArray[index]; }

    package void append(ArrayType item) {
        ArrayType[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new ArrayType[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package ArrayType[] array { read = fldArray }
}

public class ChunkArray(Object, Cloneable, Measureable, ObjectArray)
{
    private Chunk[] fldArray;

    package (Chunk[] array) { fldArray = array; }

    public Chunk[] clone() {
        Chunk[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Chunk[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Chunk operator [](int index) { return fldArray[index]; }
}

public class ClassTypeArray(Object, Cloneable, Measureable, ObjectArray)
{
    private ClassType[] fldArray;

    package () { (fldArray = new ClassType[0x0f]).length = 0; }

    public ClassType[] clone() {
        ClassType[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new ClassType[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public ClassType operator [](int index) { return fldArray[index]; }

    package void append(ClassType item) {
        ClassType[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new ClassType[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package ClassType[] array { read = fldArray }
}

public class LibraryArray(Object, Cloneable, Measureable, ObjectArray)
{
    private Library[] fldArray;

    package () { (fldArray = new Library[0x0f]).length = 0; }

    public Library[] clone() {
        Library[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Library[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Library operator [](int index) { return fldArray[index]; }

    package void append(Library item) {
        Library[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new Library[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package int indexOf(Library item) { return Array.indexOf(item, fldArray, 0, 0); }
}

public class LocalArray(Object, Cloneable, Measureable, ObjectArray)
{
    private Local[] fldArray;

    package () { (fldArray = new Local[0x0f]).length = 0; }

    package (Local[] array) { fldArray = array; }

    public Local[] clone() {
        Local[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Local[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Local operator [](int index) { return fldArray[index]; }

    package void append(Local item) {
        Local[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new Local[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package Local[] array { read = fldArray }

    private int getLength() { return fldArray.length; }
}

public class NodeArray(Object, Cloneable, Measureable, ObjectArray)
{
    package static void removeItemFrom(Node[] array, Node item) {
        int length = array.length;
        int index = Array.indexOf(item, array, 0, 0);
        if(index >= 0)
        {
            Array.copy(array, index + 1, array, index, --length - index);
            array[length] = null;
            array.length = length;
        }
    }

    package static void removeNodeFrom(Node[] array, Node node) {
        int length = array.length;
        for(int index = length; index-- > 0; )
        {
            Node current = array[index];
            if(current == node || current.isParent(node))
            {
                Array.copy(array, index + 1, array, index, --length - index);
                array[length] = null;
            }
        }
        array.length = length;
    }

    package static void removeChildsFrom(Node[] array, Node node) {
        int length = array.length;
        for(int index = length; index-- > 0; )
        {
            Node current = array[index];
            if(current.isParent(node))
            {
                Array.copy(array, index + 1, array, index, --length - index);
                array[length] = null;
            }
        }
        array.length = length;
    }

    private Node[] fldArray;

    package () { (fldArray = new Node[0x0f]).length = 0; }

    public Node[] clone() {
        Node[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Node[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Node operator [](int index) { return fldArray[index]; }

    package void append(Node item) {
        Node[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new Node[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package void remove(Node item) { removeItemFrom(fldArray, item); }

    package void removeNode(Node node) { removeNodeFrom(fldArray, node); }

    package void removeChilds(Node node) { removeChildsFrom(fldArray, node); }

    package int indexOf(Node item) { return Array.indexOf(item, fldArray, 0, 0); }
}

public class PackageArray(Object, Cloneable, Measureable, ObjectArray)
{
    private Package[] fldArray;

    package () { (fldArray = new Package[0x0f]).length = 0; }

    public Package[] clone() {
        Package[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Package[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Package operator [](int index) { return fldArray[index]; }

    package void append(Package item) {
        Package[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new Package[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package int indexOf(Package item) { return Array.indexOf(item, fldArray, 0, 0); }

    package Package[] array { read = fldArray }
}

public class RequiredReflectItemArray(Object, Cloneable, Measureable, ObjectArray)
{
    private RequiredReflectItem[] fldArray;

    package () { (fldArray = new RequiredReflectItem[0x0f]).length = 0; }

    public RequiredReflectItem[] clone() {
        RequiredReflectItem[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new RequiredReflectItem[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public RequiredReflectItem operator [](int index) { return fldArray[index]; }

    package void append(RequiredReflectItem item) {
        RequiredReflectItem[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new RequiredReflectItem[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package int indexOf(RequiredReflectItem item) { return Array.indexOf(item, fldArray, 0, 0); }

    package RequiredReflectItem[] array { read = fldArray }
}

public class SourceArray(Object, Cloneable, Measureable, ObjectArray)
{
    private Source[] fldArray;

    package () { (fldArray = new Source[0x0f]).length = 0; }

    public Source[] clone() {
        Source[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Source[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Source operator [](int index) { return fldArray[index]; }

    package void append(Source item) {
        Source[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new Source[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package int indexOf(Source item) { return Array.indexOf(item, fldArray, 0, 0); }
}

public class StringArray(Object, Cloneable, Measureable, ObjectArray)
{
    protected String[] fldArray;

    public (String[] array) { fldArray = array != null ? array : new String[0]; }

    public String[] clone() {
        String[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new String[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public String operator [](int index) { return fldArray[index]; }
}

public class TypeArray(Object, Cloneable, Measureable, ObjectArray)
{
    private Type[] fldArray;

    package () { (fldArray = new Type[0xff]).length = 0; }

    public Type[] clone() {
        Type[] result = fldArray;
        int length = result.length;
        Array.copy(result, 0, result = new Type[length], 0, length);
        return result;
    }

    public int length { read = fldArray.length }

    public Type operator [](int index) { return fldArray[index]; }

    package void append(Type item) {
        Type[] array = fldArray;
        int length = array.length;
        if(length == array.capacity)
        {
            if(length == Int.MAX_VALUE)
            {
                throw new BufferTooLargeError(avt.lang.package.getResourceString("!error.buffer-too-large"));
            }
            Array.copy(array, 0, fldArray = array = new Type[length << 1 | 1], 0, length);
        }
        array.length = length + 1;
        array[length] = item;
    }

    package int indexOf(Type item) { return Array.indexOf(item, fldArray, 0, 0); }

    package Type[] array { read = fldArray }
}