Package org.openquark.cal.compiler.Expression.Switch

Examples of org.openquark.cal.compiler.Expression.Switch.SwitchAlt


        // If all the case alternatives return a boolean literal we may
        // be able to optimize this.
        boolean isa = true;
        for (int i = 0; i < alts.length; ++i) {
            SwitchAlt switchAlt = alts[i];
            if (!switchAlt.isDefaultAlt() &&
                !(switchAlt.getFirstAltTag() instanceof DataConstructor)) {
                isa = false;
                break;
            }
            Expression altExpr = switchAlt.getAltExpr();
            if (altExpr.asLiteral() != null) {
                if (!(altExpr.asLiteral().getLiteral() instanceof Boolean)) {
                    isa = false;
                    break;
                }
View Full Code Here


        Expression trueAlt = null;
        Expression falseAlt = null;
        Expression defaultAlt = null;

        for (int i = 0; i < alts.length; ++i) {
            SwitchAlt switchAlt = alts[i];
            if (switchAlt.isDefaultAlt()) {
                defaultAlt = switchAlt.getAltExpr();

            } else {
                if (switchAlt.getAltTags().size() > 1) {
                    // (True | False) - ie. always.
                    return genS_R(switchAlt.getAltExpr(), variableContext);
                }

                Object altTag = switchAlt.getFirstAltTag();

                if (altTag instanceof DataConstructor) {
                    // This is either Prelude.True or Prelude.False
                    DataConstructor dc = (DataConstructor)altTag;
                    if (dc.getName().equals(CAL_Prelude.DataConstructors.True)) {
                        altTag = Boolean.TRUE;
                    } else
                    if (dc.getName().equals(CAL_Prelude.DataConstructors.False)) {
                        altTag = Boolean.FALSE;
                    } else {
                        // We should never get here.
                        throw new CodeGenerationException ("Trying to generate if-then-else from data constructor: " + dc.getName().getQualifiedName());
                    }
                }

                // Tag is a boolean.
                if (((Boolean)altTag).booleanValue()) {
                    trueAlt = switchAlt.getAltExpr();
                } else {
                    falseAlt = switchAlt.getAltExpr();
                }
            }
        }

        if (trueAlt == null) {
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.Expression.Switch.SwitchAlt

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.