package carray;

import java.util.Set;

import polyglot.frontend.ExtensionInfo;
import polyglot.main.OptFlag;
import polyglot.main.OptFlag.Arg;
import polyglot.main.OptFlag.Switch;
import polyglot.main.Options;
import polyglot.main.UsageError;

/**
 * Extend default options to add an option to translate CArray program to plain
 * Java program, preserving type tests.
 */
public class CArrayOptions extends Options {
    public boolean translateCArray;

    public CArrayOptions(ExtensionInfo extension) {
        super(extension);
    }

    @Override
    protected void populateFlags(Set<OptFlag<?>> flags) {
        super.populateFlags(flags);

        // Add new flag option.
        flags.add(new Switch(new String[] { "-translateCArray",
                                     "--translateCArray" },
                             "Translate CArray features to Java features"));
    }

    @Override
    protected void handleArg(Arg<?> arg) throws UsageError {
        // Define how to deal with new flags.
        if (arg.flag().ids().contains("-translateCArray")) {
            this.translateCArray = (Boolean) arg.value();
        }
        else super.handleArg(arg);
    }
}
