Search in sources :

Example 1 with Export

use of org.elixir_lang.beam.chunk.exports.Export in project intellij-elixir by KronicDeth.

the class Exports method from.

/*
     * Static Methods
     */
@Nullable
public static Exports from(@NotNull Chunk chunk) {
    Exports exports = null;
    if (chunk.typeID.equals(EXPT.toString()) && chunk.data.length >= 4) {
        Collection<Export> exportCollection = new THashSet<Export>();
        int offset = 0;
        Pair<Long, Integer> exportCountByteCount = unsignedInt(chunk.data, 0);
        long exportCount = exportCountByteCount.first;
        offset += exportCountByteCount.second;
        for (long i = 0; i < exportCount; i++) {
            Pair<Long, Integer> atomIndexByteCount = unsignedInt(chunk.data, offset);
            long atomIndex = atomIndexByteCount.first;
            offset += atomIndexByteCount.second;
            Pair<Long, Integer> arityByteCount = unsignedInt(chunk.data, offset);
            long arity = arityByteCount.first;
            offset += arityByteCount.second;
            // label is currently unused, but it must be consumed to read the next export at the correct offset
            Pair<Long, Integer> labelByteCount = unsignedInt(chunk.data, offset);
            offset += labelByteCount.second;
            exportCollection.add(new Export(atomIndex, arity));
        }
        exports = new Exports(exportCollection);
    }
    return exports;
}
Also used : Export(org.elixir_lang.beam.chunk.exports.Export) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Export

use of org.elixir_lang.beam.chunk.exports.Export in project intellij-elixir by KronicDeth.

the class Exports method macroNameAritySortedSet.

/**
     * Set of {@link MacroNameArity} sorted as
     * 1. {@link MacroNameArity#macro}, so that {@code defmacro} is before {@code def}
     * 2. {@link MacroNameArity#name} is sorted alphabetically
     * 3. {@link MacroNameArity#arity} is sorted ascending
     *
     * @param atoms used to look up the names of the {@link Export}s in {@link #exportCollection}.
     * @return The sorted set will be the same size as {@link #exportCollection} unless {@link Export#name(Atoms)}
     *   returns {@code null} for some {@link Export}s.
     */
@NotNull
public SortedSet<MacroNameArity> macroNameAritySortedSet(@NotNull Atoms atoms) {
    SortedSet<MacroNameArity> macroNameAritySortedSet = new TreeSet<MacroNameArity>();
    for (Export export : exportCollection) {
        String exportName = export.name(atoms);
        if (exportName != null) {
            MacroNameArity macroNameArity = new MacroNameArity(exportName, (int) export.arity());
            macroNameAritySortedSet.add(macroNameArity);
        }
    }
    return macroNameAritySortedSet;
}
Also used : MacroNameArity(org.elixir_lang.beam.MacroNameArity) Export(org.elixir_lang.beam.chunk.exports.Export) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Export (org.elixir_lang.beam.chunk.exports.Export)2 THashSet (gnu.trove.THashSet)1 MacroNameArity (org.elixir_lang.beam.MacroNameArity)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1