Package org.openquark.cal.compiler.SourceModel.Expr

Examples of org.openquark.cal.compiler.SourceModel.Expr.Application


            boolean isRedundant = false;

            Expr lambdaExp = getExprWithoutParen(lambda.getDefiningExpr());
           
            if(lambdaExp instanceof Application) {
                Application definingExpr = (Application)lambdaExp;
                isRedundant = (definingExpr.getNExpressions() >= lambda.getNParameters() + 1);
               
                // Walk backwards along the parameters so that we catch cases like
                // (\x -> map add x)
                int i = lambda.getNParameters() - 1;
                int j = definingExpr.getNExpressions() - 1;
                for(;isRedundant && i >= 0 && j >= 1;i--, j--) {
                   
                    if(!isParameterVar(lambda.getNthParameter(i), definingExpr.getNthExpression(j))) {
                        isRedundant = false;
                    }
                }
               
            } else if(lambdaExp instanceof BinaryOp) {
                BinaryOp definingExpr = (BinaryOp)lambdaExp;
               
                if(lambda.getNParameters() == 2 &&
                   isParameterVar(lambda.getNthParameter(0), definingExpr.getLeftExpr()) &&
                   isParameterVar(lambda.getNthParameter(1), definingExpr.getRightExpr())) {
                   
                    isRedundant = true;
                   
                } else if(lambda.getNParameters() == 1 &&
                   isParameterVar(lambda.getNthParameter(0), definingExpr.getRightExpr()) &&
                   !containsParameterReference(lambda.getNthParameter(0), definingExpr.getLeftExpr())) {
                   
                    isRedundant = true;
                }
           
            } else if(lambdaExp instanceof UnaryOp) {
                UnaryOp definingExpr = (UnaryOp)lambdaExp;
                if(lambda.getNParameters() == 1 &&
                   isParameterVar(lambda.getNthParameter(0), definingExpr.getExpr())) {
                   
                    isRedundant = true;
                }
            }
           
View Full Code Here


            Expr definingExpr = algebraic.getDefiningExpr();
            Expr aliasedEntityExpr = null;
           
            boolean isPotentialAlias = false;
            if(definingExpr instanceof Application) {
                Application application = (Application)definingExpr;
                aliasedEntityExpr = application.getNthExpression(0);
               
                // An alias is an application of a function or data constructor to exactly the same
                // arguments in exactly the same order.
                if((aliasedEntityExpr instanceof DataCons || aliasedEntityExpr instanceof Var)
                   && application.getNExpressions() == algebraic.getNParameters() + 1) {
                   
                    isPotentialAlias = true;
                    for(int i = 1; isPotentialAlias && i < application.getNExpressions(); i++) {
                        if(!isParameterVar(algebraic.getNthParameter(i - 1), application.getNthExpression(i))) {
                            isPotentialAlias = false;
                        }
                    }
                }
            }
View Full Code Here

            } else if(potentialConsumer instanceof DataCons) {
                return ((DataCons)potentialConsumer).getDataConsName();
           
            // Special case for expressions of the form `(compose foo bar) baz`
            } else if(potentialConsumer instanceof Application) {
                Application app = (Application)potentialConsumer;
                Name.Qualifiable consumerName = getTopLevelConsumerName(app.getNthExpression(0));
               
                if(consumerName != null) {
                    FunctionalAgent consumer = super.getFunctionalAgent(consumerName);
                   
                    if(consumer.getName().equals(COMPOSE) && app.getNExpressions() == 3) {
                        return getTopLevelConsumerName(app.getNthExpression(2));
                    }
                }
           
            // Special case for expressions of the form `(foo # bar) baz`
            } else if(potentialConsumer instanceof BinaryOp.Compose) {
View Full Code Here

                DataCons cons = (DataCons)argumentExpression;
                producer = super.getFunctionalAgent(cons.getDataConsName());
            }
           
            else if (argumentExpression instanceof Application) {
                Application app = (Application)argumentExpression;
                processArgumentExpression(consumerName, argumentNumber, app.getNthExpression(0));
                return;
            }
           
            else if (argumentExpression instanceof BinaryOp.Apply) {
                BinaryOp.Apply app = (BinaryOp.Apply)argumentExpression;
                processArgumentExpression(consumerName, argumentNumber, app.getLeftExpr());
                return;
            }
           
            else if (argumentExpression instanceof BinaryOp.Compose) {
                BinaryOp.Compose composeOp = (BinaryOp.Compose)argumentExpression;
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.SourceModel.Expr.Application

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.