All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.jet.codegen.inline.Parameters Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
/*
 * Copyright 2010-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.jet.codegen.inline;

import com.google.common.collect.Iterables;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

//All parameters with gaps
public class Parameters implements Iterable {

    private final List real;

    private final List captured;

    public Parameters(List real, List captured) {
        this.real = real;
        this.captured = captured;
    }

    public List getReal() {
        return real;
    }

    public List getCaptured() {
        return captured;
    }

    public int totalSize() {
        return real.size() + captured.size();
    }

    public ParameterInfo get(int index) {
        if (index < real.size()) {
            return real.get(index);
        }
        return captured.get(index - real.size());
    }

    @NotNull
    @Override
    public Iterator iterator() {
        return Iterables.concat(real, captured).iterator();
    }

    public static List shiftAndAddStubs(List capturedParams, int realSize) {
        List result = new ArrayList();
        for (CapturedParamInfo capturedParamInfo : capturedParams) {
            CapturedParamInfo newInfo = capturedParamInfo.newIndex(result.size() + realSize);
            result.add(newInfo);
            if (capturedParamInfo.getType().getSize() == 2) {
                result.add(CapturedParamInfo.STUB);
            }
        }
        return result;
    }

    public static List addStubs(List params) {
        List result = new ArrayList();
        for (ParameterInfo newInfo : params) {
            result.add(newInfo);
            if (newInfo.getType().getSize() == 2) {
                result.add(ParameterInfo.STUB);
            }
        }
        return result;
    }

    public ArrayList getCapturedTypes() {
        ArrayList result = new ArrayList();
        for (CapturedParamInfo info : captured) {
            if(info != CapturedParamInfo.STUB) {
                result.add(info.getType());
            }
        }
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy