Package org.teavm.common

Examples of org.teavm.common.IntegerArray


    }

    void rebuildMethodTree() {
        long[] exactMethods = this.exactMethods.clone();
        Arrays.sort(exactMethods);
        IntegerArray methods = new IntegerArray(1);
        int lastClass = -1;
        for (int i = 0; i < exactMethods.length; ++i) {
            long exactMethod = exactMethods[i];
            int classIndex = (int)(exactMethod >>> 32);
            if (classIndex != lastClass) {
                if (lastClass >= 0) {
                    ClassMetadata clsData = classesMetadata.get(lastClass);
                    clsData.methods = methods.getAll();
                    methods.clear();
                }
                lastClass = classIndex;
            }
            int methodIndex = (int)exactMethod;
            methods.add(methodIndex);
        }
        if (lastClass >= 0) {
            ClassMetadata clsData = classesMetadata.get(lastClass);
            clsData.methods = methods.getAll();
            Arrays.sort(clsData.methods);
        }

        int[] start = new int[exactMethods.length];
        Arrays.fill(start, -1);
        IntegerArray data = new IntegerArray(1);
        IntegerArray next = new IntegerArray(1);
        for (int i = 0; i < classesMetadata.size(); ++i) {
            ClassMetadata clsData = classesMetadata.get(i);
            if (clsData.parentId == null || clsData.methods == null) {
                continue;
            }
            for (int methodIndex : clsData.methods) {
                ClassMetadata superclsData = classesMetadata.get(clsData.parentId);
                Integer parentId = clsData.parentId;
                while (superclsData != null) {
                    if (superclsData.methods != null && Arrays.binarySearch(superclsData.methods, methodIndex) >= 0) {
                        int childMethod = getExactMethodIndex(i, methodIndex);
                        int parentMethod = getExactMethodIndex(parentId, methodIndex);
                        int ptr = start[parentMethod];
                        start[parentMethod] = data.size();
                        data.add(childMethod);
                        next.add(ptr);
                        break;
                    }
                    parentId = superclsData.parentId;
                    superclsData = parentId != null ? classesMetadata.get(parentId) : null;
                }
            }
        }

        MethodTree methodTree = new MethodTree();
        methodTree.offsets = new int[start.length + 1];
        methodTree.data = new int[data.size()];
        int index = 0;
        for (int i = 0; i < start.length; ++i) {
            int ptr = start[i];
            while (ptr != -1) {
                methodTree.data[index++] = data.get(ptr);
                ptr = next.get(ptr);
            }
            methodTree.offsets[i + 1] = index;
        }
        this.methodTree = methodTree;
    }
View Full Code Here


    }

    private void writeCFG(RecordArray mapping) throws IOException {
        writeUnsignedNumber(mapping.size());
        writeRle(mapping.cut(0));
        IntegerArray sizes = new IntegerArray(1);
        IntegerArray files = new IntegerArray(1);
        IntegerArray lines = new IntegerArray(1);
        int lastFile = 0;
        int lastLine = 0;
        for (int i = 0; i < mapping.size(); ++i) {
            int type = mapping.get(i).get(0);
            if (type == 0) {
                continue;
            }
            int[] data = mapping.get(i).getArray(0);
            sizes.add(data.length / 2);
            for (int j = 0; j < data.length; j += 2) {
                int file = data[j];
                int line = data[j + 1];
                files.add(convertToSigned(file - lastFile));
                lines.add(convertToSigned(line - lastLine));
                lastFile = file;
                lastLine = line;
            }
        }
        writeRle(sizes.getAll());
        writeRle(files.getAll());
        writeRle(lines.getAll());
    }
View Full Code Here

        classMap.put("Pi", Character.INITIAL_QUOTE_PUNCTUATION);
        classMap.put("Pf", Character.FINAL_QUOTE_PUNCTUATION);
    }

    private static void parseUnicodeData() {
        IntegerArray digitValues = new IntegerArray(4096);
        IntegerArray classes = new IntegerArray(65536);
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(UnicodeHelper.class
                .getResourceAsStream("UnicodeData.txt")))) {
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                if (line.isEmpty()) {
                    continue;
                }
                String[] fields = splitLine(line);
                int charCode = parseHex(fields[0]);
                while (classes.size() < charCode) {
                    classes.add(0);
                }
                if (!fields[6].isEmpty()) {
                    int digit = Integer.parseInt(fields[6]);
                    digitValues.add(charCode);
                    digitValues.add(digit);
                }
                Byte charClass = classMap.get(fields[2]);
                classes.add(charClass != null ? charClass.intValue() : 0);
            }
        } catch (IOException e) {
            throw new RuntimeException("Error reading unicode data", e);
        }
        IntegerArray letterDigitValues = new IntegerArray(256);
        for (int i = 'A'; i <= 'Z'; ++i) {
            letterDigitValues.add(i);
            letterDigitValues.add(i - 'A' + 10);
        }
        for (int i = 'a'; i <= 'z'; ++i) {
            letterDigitValues.add(i);
            letterDigitValues.add(i - 'a' + 10);
        }
        for (int i = '\uFF21'; i <= '\uFF3A'; ++i) {
            letterDigitValues.add(i);
            letterDigitValues.add(i - '\uFF21' + 10);
        }
        for (int i = '\uFF41'; i <= '\uFF5A'; ++i) {
            letterDigitValues.add(i);
            letterDigitValues.add(i - '\uFF41' + 10);
        }
        UnicodeSupport.digitValues = mergePairs(digitValues.getAll(), letterDigitValues.getAll());
        UnicodeSupport.classes = new byte[classes.size()];
        for (int i = 0; i < classes.size(); ++i) {
            UnicodeSupport.classes[i] = (byte)classes.get(i);
        }
    }
View Full Code Here

TOP

Related Classes of org.teavm.common.IntegerArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.