Package org.openquark.cal.internal.javamodel.JavaStatement

Examples of org.openquark.cal.internal.javamodel.JavaStatement.ReturnStatement


     */
    public JavaStatement visitReturnStatement(ReturnStatement returnStatement,
            T arg) {
       
        if (returnStatement.getReturnExpression() != null) {
            return new ReturnStatement (
                    (JavaExpression)returnStatement.getReturnExpression().accept(this, arg));
        } else {
            return new ReturnStatement();
        }
    }
View Full Code Here


            if (nd) {
                emitLine(sb, indent, " */");
            }

        } else if (statement instanceof ReturnStatement) {
            ReturnStatement returnStatement = (ReturnStatement)statement;
            if (returnStatement.getReturnExpression() == null) {
                emitLine(sb, indent, "return;");
            } else {
                emitLine(sb, indent, "return " + getSource(returnStatement.getReturnExpression(),indent, 7, context) ";");
            }
        } else if (statement instanceof IfThenElseStatement) {
            IfThenElseStatement iteStatement = (IfThenElseStatement)statement;

            emitLine(sb, indent, "if (" + getSource(iteStatement.getCondition(), indent, 4, context) + ") {");
View Full Code Here

                        new MethodInvocation.Instance(
                                null,
                                GET_DC_ORDINAL_METHOD_NAME,
                                JavaTypeName.INT,
                                MethodInvocation.InvocationType.VIRTUAL);
                    hashCode.addStatement(new ReturnStatement (call_getOrdinal));
                   
                    javaClassRep.addMethod(hashCode);
                }
            }
View Full Code Here

                                null,
                                GET_DC_NAME_METHOD_NAME,
                                JavaTypeName.STRING,
                                MethodInvocation.InvocationType.VIRTUAL);
                   
                    toString.addStatement(new ReturnStatement (getDCName));
                    return toString;
                } else {
                    toString = null;
                }
View Full Code Here

                    JavaField field = new JavaField.Static(dataType_TypeName, enumFieldName, dataType_TypeName);
                   
                    JavaStatement.SwitchStatement.IntCaseGroup intCase =
                        new SwitchStatement.IntCaseGroup(
                                dc.getOrdinal(),
                                new ReturnStatement(field));
                    switchStatement.addCase(intCase);
                }
               
                // Throw an error if ordinal is outside accepted range.
                JavaExpression message =
View Full Code Here

               
                JavaMethod javaMethod = new JavaMethod(modifiers, JavaTypeName.INT, GET_DC_ORDINAL_METHOD_NAME);
               
                if (typeConstructorInfo.isEnumerationType) {
                    // return instance field.
                    javaMethod.addStatement (new ReturnStatement (new JavaField.Instance (null, ORDINAL_FIELD_NAME, JavaTypeName.INT)));
                } else {
                    javaMethod.addStatement (new ReturnStatement(LiteralWrapper.make (new Integer(-1))));
                }
               
                JavaDocComment jdc =
                    new JavaDocComment ("@return the ordinal of this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);
View Full Code Here

               
                JavaMethod javaMethod = new JavaMethod(modifiers, JavaTypeName.STRING, GET_DC_NAME_METHOD_NAME);
               
                if (typeConstructorInfo.isEnumerationType) {
                    // return the name$ field
                    javaMethod.addStatement (new ReturnStatement (new JavaField.Instance (null, DC_NAME_FIELD_NAME, JavaTypeName.STRING)));
                } else {
                    javaMethod.addStatement (new ReturnStatement(LiteralWrapper.NULL));
                }
               
                JavaDocComment jdc =
                    new JavaDocComment ("@return the name of the data constructor corresponding to this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);
View Full Code Here

            }
            atSee = atSee + ")";
           
            if (paramNames.length == 0) {
                // Simply return the Expr.Var
                bindingMethod.addStatement(new ReturnStatement(sourceModelVarCreation));
            } else {
                // Need to create an application.
               
                // Create an array of SourceModel.Expr.  The first element is the SourceModel.Expr.Var
                // for the CAL function the remaining elements are the function arguments.
                JavaExpression arrayElements[] = new JavaExpression[paramNames.length + 1];
                arrayElements[0] = sourceModelVarCreation;
               
                for (int i = 1; i <= paramNames.length; ++i) {
                    arrayElements[i] = new JavaExpression.MethodVariable(paramNames[i-1]);
                }
               
                // Build the array creation expression.
                JavaExpression arrayCreation =
                    new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
               
                // Invoke SourceModel.Expr.Application.make()
                MethodInvocation makeApply =
                    new MethodInvocation.Static(
                            SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                            "make",
                            arrayCreation,
                            JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                            SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
               
                bindingMethod.addStatement(new ReturnStatement (makeApply));
           
                // If any of the argument types correspond to a Java type.
                // (eg. Prelude.Int, Prelude.Long, etc. we can generate a version
                // of the binding function that takes these argument types.
                boolean primArgs = false;

                TypeExpr[] pieces = te.getTypePieces();
                for (int i = 0; i < paramNames.length; ++i) {
                    if (canTypeBeUnboxed(pieces[i])) {
                        primArgs = true;
                        // Change the param type.
                        paramTypes[i] = typeExprToTypeName(pieces[i]);
                       
                        // Since the parameter will now be an int, boolean, long, etc. we
                        // need to create the appropriate SourceModel wrapper around the
                        // value.
                        arrayElements[i+1] = wrapArgument(paramNames[i], pieces[i]);
                    }
                }
               
                if (primArgs) {
                    // Create the alternate helper method.
                    bindingMethod =
                        new JavaMethod(PUBLIC_STATIC_FINAL,
                                       SOURCE_MODEL_EXPR_TYPE_NAME,
                                       paramNames,
                                       paramTypes,
                                       null, javaFuncName);
                    functionsClass.addMethod(bindingMethod);
                   
                    JavaStatement.JavaDocComment comment = new JavaStatement.JavaDocComment(atSee);
                    for (int iArg = 0; iArg < paramNames.length; ++iArg) {
                        comment.addLine("@param " + paramNames[iArg]);
                    }                       
                    comment.addLine("@return the SourceModel.Expr representing an application of " + calFuncName);
                    bindingMethod.setJavaDocComment(comment);
                   
                    arrayCreation =
                        new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
                   
                    makeApply =
                        new MethodInvocation.Static(
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                                "make",
                                arrayCreation,
                                JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
                   
                    bindingMethod.addStatement(new ReturnStatement (makeApply));
   
                }
            }
           
            // Add a field for the function name.
View Full Code Here

                }
                atSee = atSee + ")";
               
                if (dc.getArity() == 0) {
                    // Simply return the Expr.DataCons.
                    bindingFunction.addStatement(new ReturnStatement(sourceModelDataConsCreation));
                } else {
                    // Need to build up an application.
                   
                    // Create an array of SourceModel.Expr where the first element is the
                    // SourceModel.Expr.DataCons instance and the following elements are
                    // the function arguments.
                    JavaExpression arrayElements[] = new JavaExpression[dc.getArity() + 1];
                    arrayElements[0] = sourceModelDataConsCreation;
                   
                    for (int j = 1; j <= argNames.length; ++j) {
                        arrayElements[j] = new JavaExpression.MethodVariable(argNames[j-1]);
                    }
                   
                    JavaExpression arrayCreation =
                        new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
                   
                    // Invoke SourceModle.Expr.Application.make()
                    MethodInvocation makeApply =
                        new MethodInvocation.Static(
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                                "make",
                                arrayCreation,
                                JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
                   
                    bindingFunction.addStatement(new ReturnStatement (makeApply));
               
                    // If any of the argument types correspond to a Java type.
                    // (eg. Prelude.Int, Prelude.Long, etc. we can generate a version
                    // of the binding function that takes these argument types.
                    boolean primArgs = false;
                    for (int j = 0, k = fieldTypes.length; j < k; ++j) {
                        if (canTypeBeUnboxed(fieldTypes[j])) {
                            primArgs = true;
                            // Update the type of the argument.
                            argTypes[j] = typeExprToTypeName(fieldTypes[j]);
                           
                            // The argument to Application.make needs to be updated.
                            // We need to wrap the raw value (i.e. int, boolean, etc.)
                            // in the appropriate SourceModel construct.
                            arrayElements[j+1] = wrapArgument(argNames[j], fieldTypes[j]);
                        }
                    }

                   
                    if (primArgs) {
                        bindingFunction =
                            new JavaMethod(PUBLIC_STATIC_FINAL,
                                           SOURCE_MODEL_EXPR_TYPE_NAME,
                                           argNames,
                                           argTypes,
                                           null, javaFuncName);
                        dataConstructorsClass.addMethod(bindingFunction);
                       
                        // For the comment for this method we want an @see referring to the previous method.
                       
                        JavaStatement.JavaDocComment comment = new JavaStatement.JavaDocComment(atSee);
                        for (int iArg = 0; iArg < argNames.length; ++iArg) {
                            comment.addLine("@param " + argNames[iArg]);
                        }                       
                        comment.addLine("@return " + SOURCE_MODEL_EXPR_TYPE_NAME.getFullJavaSourceName());
                        bindingFunction.setJavaDocComment(comment);
                       
                        arrayCreation =
                            new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
                       
                        makeApply =
                            new MethodInvocation.Static(
                                    SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                                    "make",
                                    arrayCreation,
                                    JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                                    SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
                       
                        bindingFunction.addStatement(new ReturnStatement (makeApply));
       
                    }
                   
                }
               
View Full Code Here

            // Create the method.
            JavaMethod javaMethod = new JavaMethod(modifiers, fieldType, methodName);
   
            if (implementAtThisLevel) {
                JavaField field = new JavaField.Instance (null, fieldName, fieldType);
                javaMethod.addStatement(new ReturnStatement(field));
            } else {
                // This class should throw an error for any access.  The methods will
                // be overridden by derived classes for each data constructor.
                JavaExpression getDCName =
                    new MethodInvocation.Instance(null, GET_DC_NAME_METHOD_NAME, JavaTypeName.STRING, MethodInvocation.InvocationType.VIRTUAL);
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaStatement.ReturnStatement

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.