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

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


        final ForeignFunctionInfo foreignFunctionInfo = basicOpExpressions.getForeignFunctionInfo();
        final ForeignFunctionInfo.JavaKind kind = foreignFunctionInfo.getJavaKind();

        JavaExpression returnExpression = null;
        Block returnContext = new Block();

        if (kind.isMethod()) {

            final ForeignFunctionInfo.Invocation invocationInfo = (ForeignFunctionInfo.Invocation)foreignFunctionInfo;

            final Method method = (Method)SCJavaDefn.getJavaProxy(invocationInfo);
            if (method.getReturnType() == void.class && (scheme != Scheme.R_SCHEME)) {
                ExpressionContextPair ecp = genS_C (e, variableContext);
                JavaExpression expr = ecp.getJavaExpression();
                JavaStatement block = ecp.getContextBlock();
                JavaExpression.MethodInvocation eval = createInvocation(expr, EVALUATE, EXECUTION_CONTEXT_VAR);
                return new ExpressionContextPair(eval, block);
            }

            int nJavaArgs = SCJavaDefn.getNArguments(foreignFunctionInfo);
            final Class<?> invocationClass = SCJavaDefn.getInvocationClass(invocationInfo);
            final JavaTypeName invocationClassName = JavaTypeName.make(invocationClass);
            String methodName = method.getName();
            int startArg = 0;

            Class<?>[] exceptions = method.getExceptionTypes();
            for (int i = 0; i < exceptions.length; ++i) {
                if (!exceptionHandled(exceptions [i])) {
                    addExceptionHandler(exceptions[i]);
                }
            }

            if (!LECCMachineConfiguration.generateDirectPrimOpCalls()) {
                if (!exceptionHandled(Throwable.class)) {
                    addExceptionHandler(Throwable.class);
                }
            }

            JavaExpression target;
            InvocationType invocationType;      // static, virtual, or interface.  Can't be special (ie. private method).
            if (kind.isStatic()){
                target = null;
                invocationType = InvocationType.STATIC;
            } else {
                ExpressionContextPair pair = generateUnboxedForeignFunctionArgument(invocationClassName, basicOpExpressions.getArgument(0), variableContext);
                target = pair.getJavaExpression();
                invocationType = invocationClass.isInterface() ? InvocationType.INTERFACE : InvocationType.VIRTUAL;
                returnContext.addStatement(pair.getContextBlock());
                startArg = 1;
            }

            Class<?>[] argTypes = method.getParameterTypes();
            JavaExpression[] args = new JavaExpression[argTypes.length];
            JavaTypeName[] argTypeNames = new JavaTypeName[argTypes.length];

            for (int i = startArg, j = 0; i < nJavaArgs; ++i, ++j) {
                int index = i - startArg;
                final JavaTypeName argTypeName = JavaTypeName.make(argTypes[index]);
                ExpressionContextPair pair = generateUnboxedForeignFunctionArgument(argTypeName, basicOpExpressions.getArgument(i), variableContext);
                args[index] = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());

                argTypeNames[index] = argTypeName;
            }

            JavaTypeName returnType = JavaTypeName.make(method.getReturnType());

            if (kind.isStatic()) {
                returnExpression = new MethodInvocation.Static(invocationClassName, methodName, args, argTypeNames, returnType);
            } else {
                returnExpression = new MethodInvocation.Instance(target, methodName, invocationClassName, args, argTypeNames, returnType, invocationType);
            }

            if (boxResult) {
                ExpressionContextPair pair = returnTypeToCal(method.getReturnType(), returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isField()) {

            final ForeignFunctionInfo.Invocation invocationInfo = (ForeignFunctionInfo.Invocation)foreignFunctionInfo;

            final Field field = (Field)SCJavaDefn.getJavaProxy(invocationInfo);

            JavaTypeName fieldType = JavaTypeName.make(field.getType());
            String fieldName = field.getName();

            final JavaTypeName invocationClassName = JavaTypeName.make(SCJavaDefn.getInvocationClass(invocationInfo));
            if (kind.isStatic()) {
                returnExpression = new JavaField.Static(invocationClassName, fieldName, fieldType);
            } else {
                ExpressionContextPair pair = generateUnboxedForeignFunctionArgument(invocationClassName, basicOpExpressions.getArgument(0), variableContext);
                JavaExpression instance = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
                returnExpression = new JavaField.Instance(instance, fieldName, fieldType);
            }

            if (boxResult) {
                ExpressionContextPair pair = returnTypeToCal (field.getType(), returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isConstructor()) {

            final ForeignFunctionInfo.Invocation invocationInfo = (ForeignFunctionInfo.Invocation)foreignFunctionInfo;

            Constructor<?> constructor = (Constructor<?>)SCJavaDefn.getJavaProxy(invocationInfo);
            int nJavaArgs = SCJavaDefn.getNArguments(foreignFunctionInfo);
            Class<?> clazz = constructor.getDeclaringClass();
            Class<?>[] argTypes = constructor.getParameterTypes();

            Class<?>[] exceptions = constructor.getExceptionTypes();
            for (int i = 0; i < exceptions.length; ++i) {
                if (!exceptionHandled(exceptions [i])) {
                    addExceptionHandler(exceptions[i]);
                }
            }

            JavaExpression[] args = new JavaExpression[argTypes.length];
            JavaTypeName[] argTypeNames = new JavaTypeName[argTypes.length];
            for (int i = 0; i < nJavaArgs; i++) {
                final JavaTypeName argTypeName = JavaTypeName.make(argTypes[i]);
                ExpressionContextPair pair = generateUnboxedForeignFunctionArgument(argTypeName, basicOpExpressions.getArgument(i), variableContext);
                args[i] = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
                argTypeNames[i] = argTypeName;
            }

            returnExpression = new ClassInstanceCreationExpression(JavaTypeName.make(clazz), args, argTypeNames);

            if (boxResult) {
                ExpressionContextPair pair = returnTypeToCal(constructor.getDeclaringClass(), returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isCast()) {

            final Class<?> argType = SCJavaDefn.getJavaArgumentType(foreignFunctionInfo, 0);
            final Class<?> resultType = SCJavaDefn.getJavaReturnType(foreignFunctionInfo);

            final ExpressionContextPair argExprPair = generateUnboxedForeignFunctionArgument(JavaTypeName.make(argType), basicOpExpressions.getArgument(0), variableContext);
            final JavaExpression argExpr = argExprPair.getJavaExpression();
            returnContext.addStatement(argExprPair.getContextBlock());

            if (kind == ForeignFunctionInfo.JavaKind.IDENTITY_CAST ||
                kind == ForeignFunctionInfo.JavaKind.WIDENING_REFERENCE_CAST) {

                //it is important to do nothing for a widening reference cast (except for evaluating)
                //this is because at the JavaTypeName level, where the inheritance hierarchy is not available, it is not possible for
                //the bytecode generator to determine if this is truly a widening reference cast i.e. a no-op. Hence we must make
                //this optimization at this point.
                returnExpression = argExpr;

            } else if (kind == ForeignFunctionInfo.JavaKind.NARROWING_PRIMITIVE_CAST ||
                       kind == ForeignFunctionInfo.JavaKind.WIDENING_PRIMITIVE_CAST ||
                       kind == ForeignFunctionInfo.JavaKind.NARROWING_REFERENCE_CAST) {

                returnExpression = new JavaExpression.CastExpression(JavaTypeName.make(resultType), argExpr);

            } else {
                throw new CodeGenerationException("Unrecognized foreign function cast kind: " + kind);
            }

            if (boxResult) {
                ExpressionContextPair pair = returnTypeToCal(resultType, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isInstanceOf()) {

            final Class<?> argType = SCJavaDefn.getJavaArgumentType(foreignFunctionInfo, 0);
            final ForeignFunctionInfo.InstanceOf instanceOfInfo = (ForeignFunctionInfo.InstanceOf)foreignFunctionInfo;
            final Class<?> instanceOfType = SCJavaDefn.getInstanceOfType(instanceOfInfo);

            final ExpressionContextPair argExprPair = generateUnboxedForeignFunctionArgument(JavaTypeName.make(argType), basicOpExpressions.getArgument(0), variableContext);
            final JavaExpression argExpr = argExprPair.getJavaExpression();
            returnContext.addStatement(argExprPair.getContextBlock());

            returnExpression = new JavaExpression.InstanceOf(argExpr, JavaTypeName.make(instanceOfType));

            if (boxResult) {
                ExpressionContextPair pair = returnTypeToCal(boolean.class, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isClassLiteral()) {

            final ForeignFunctionInfo.ClassLiteral classLiteralInfo = (ForeignFunctionInfo.ClassLiteral)foreignFunctionInfo;
            final Class<?> referentType = SCJavaDefn.getReferentType(classLiteralInfo);

            returnExpression = new JavaExpression.ClassLiteral(JavaTypeName.make(referentType));

            if (boxResult) {
                ExpressionContextPair pair = returnTypeToCal(Class.class, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isNullLiteral()) {

            returnExpression = JavaExpression.LiteralWrapper.NULL;
            if (boxResult) {
                final ExpressionContextPair pair = returnTypeToCal(SCJavaDefn.getJavaReturnType(foreignFunctionInfo), returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind.isNullCheck()) {

            final ForeignFunctionInfo.NullCheck nullCheckInfo = (ForeignFunctionInfo.NullCheck)foreignFunctionInfo;

            final Class<?> argType = SCJavaDefn.getJavaArgumentType(foreignFunctionInfo, 0);

            final ExpressionContextPair argExprPair = generateUnboxedForeignFunctionArgument(JavaTypeName.make(argType), basicOpExpressions.getArgument(0), variableContext);
            final JavaExpression argExpr = argExprPair.getJavaExpression();
            returnContext.addStatement(argExprPair.getContextBlock());

            final JavaOperator javaOp = nullCheckInfo.checkIsNull() ? JavaOperator.EQUALS_OBJECT : JavaOperator.NOT_EQUALS_OBJECT;

            returnExpression = new JavaExpression.OperatorExpression.Binary(javaOp, argExpr, LiteralWrapper.NULL);

            if (boxResult) {
                final ExpressionContextPair pair = returnTypeToCal(boolean.class, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind == ForeignFunctionInfo.JavaKind.NEW_ARRAY) {

            //e.g. newString3Array :: Int -> Int -> JString3Array; (for new String[d1][d2][])

            //note, this may be less than the dimension of the array e.g. for new String[10][7][] this is 2.
            final int nJavaArgs = SCJavaDefn.getNArguments(foreignFunctionInfo);
            final Class<?> newArrayType = SCJavaDefn.getJavaReturnType(foreignFunctionInfo);

            final JavaExpression[] args = new JavaExpression[nJavaArgs];
            final JavaTypeName[] argTypeNames = new JavaTypeName[nJavaArgs];
            for (int i = 0; i < nJavaArgs; i++) {
                final ExpressionContextPair pair = generateUnboxedForeignFunctionArgument(JavaTypeName.INT, basicOpExpressions.getArgument(i), variableContext);
                args[i] = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
                argTypeNames[i] = JavaTypeName.INT;
            }

            returnExpression = new ClassInstanceCreationExpression(JavaTypeName.make(newArrayType), args, argTypeNames);

            if (boxResult) {
                final ExpressionContextPair pair = returnTypeToCal(newArrayType, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind == ForeignFunctionInfo.JavaKind.LENGTH_ARRAY) {

            final Class<?> argType = SCJavaDefn.getJavaArgumentType(foreignFunctionInfo, 0);

            final ExpressionContextPair argExprPair = generateUnboxedForeignFunctionArgument(JavaTypeName.make(argType), basicOpExpressions.getArgument(0), variableContext);
            final JavaExpression argExpr = argExprPair.getJavaExpression();
            returnContext.addStatement(argExprPair.getContextBlock());

            returnExpression = new JavaExpression.ArrayLength(argExpr);

            if (boxResult) {
                final ExpressionContextPair pair = returnTypeToCal(int.class, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);


        } else if (kind == ForeignFunctionInfo.JavaKind.SUBSCRIPT_ARRAY) {

            //e.g. subscriptString3Array :: String3Array -> Int -> Int -> StringArray;
            //for subscripting using 2 indices a 3-dimensional String array to get a 1-dimensional String array

            //note, this may be less than the dimension of the array e.g. for new String[10][7][] this is 2.
            final int nJavaArgs = SCJavaDefn.getNArguments(foreignFunctionInfo);
            final Class<?> subscriptedArrayType = SCJavaDefn.getJavaReturnType(foreignFunctionInfo);

            for (int i = 0; i < nJavaArgs; i++) {

                final JavaTypeName argTypeName = JavaTypeName.make(SCJavaDefn.getJavaArgumentType(foreignFunctionInfo, i));
                final ExpressionContextPair pair =
                    generateUnboxedForeignFunctionArgument(argTypeName, basicOpExpressions.getArgument(i), variableContext);
                returnContext.addStatement(pair.getContextBlock());

                if (i == 0) {
                    //the initial array expression
                    returnExpression = pair.getJavaExpression();
                } else {
                    //subscript by the next index
                    returnExpression = new JavaExpression.ArrayAccess(returnExpression, pair.getJavaExpression());
                }
            }

            if (boxResult) {
                final ExpressionContextPair pair = returnTypeToCal(subscriptedArrayType, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);

        } else if (kind == ForeignFunctionInfo.JavaKind.UPDATE_ARRAY) {

            //e.g. updateString3Array :: String3Array -> Int -> Int -> StringArray -> StringArray;
            //for updating using 2 indices a 3-dimensional String array with a 1-dimensional String array

            //note, this may be less than the dimension of the array to update
            final int nJavaArgs = SCJavaDefn.getNArguments(foreignFunctionInfo);
            final Class<?> updatedElementType = SCJavaDefn.getJavaReturnType(foreignFunctionInfo);

            for (int i = 0; i < nJavaArgs; i++) {

                final JavaTypeName argTypeName = JavaTypeName.make(SCJavaDefn.getJavaArgumentType(foreignFunctionInfo, i));
                final ExpressionContextPair pair =
                    generateUnboxedForeignFunctionArgument(argTypeName, basicOpExpressions.getArgument(i), variableContext);
                returnContext.addStatement(pair.getContextBlock());

                if (i == 0) {

                    //the initial array expression
                    returnExpression = pair.getJavaExpression();

                } else if (i < nJavaArgs - 1) {

                    //subscript by the next index
                    returnExpression = new JavaExpression.ArrayAccess(returnExpression, pair.getJavaExpression());

                } else if (i == nJavaArgs - 1) {

                    returnExpression = new JavaExpression.Assignment((JavaExpression.Nameable)returnExpression, pair.getJavaExpression());

                }
            }


            if (boxResult) {
                final ExpressionContextPair pair = returnTypeToCal(updatedElementType, returnExpression);
                returnExpression = pair.getJavaExpression();
                returnContext.addStatement(pair.getContextBlock());
            }

            return new ExpressionContextPair(returnExpression, returnContext);
        }
View Full Code Here


            throw new CodeGenerationException("Invalid basic operator arity: " + nArgs);
        }

        // The arguments for primitive ops are handled as a special case.
        // We want to avoid boxing/unboxing of primitive values wherever possible.
        Block generatedContext = new Block();
        JavaExpression args[] = new JavaExpression[nArgs];
        for (int i = 0; i < nArgs; ++i) {
            int argIndex = nArgs - i - 1;
            ExpressionContextPair pair = generateUnboxedPrimOpArgument(basicOpExpressions, basicOpExpressions.getArgument(argIndex), argIndex, variableContext);
            args[argIndex] = pair.getJavaExpression();
            generatedContext.addStatement(pair.getContextBlock());
        }

        JavaExpression javaExpression = PrimOp.getPrimOpDefinition(op, args);

        if (boxResult) {
View Full Code Here

            return genS_E(basicOpExpressions.getArgument(0), variableContext);
        }

        // The arguments for primitive ops are handled as a special case.
        // We want to avoid boxing/unboxing of primitive values wherever possible.
        Block generatedContext = new Block();
        JavaExpression args[] = new JavaExpression[nArgs];
        for (int i = 0; i < nArgs; ++i) {
            int argIndex = nArgs - i - 1;
            ExpressionContextPair pair;
            if (op == PrimOps.PRIMOP_CAL_VALUE_TO_OBJECT) {
                //Prelude.calValueToObject is an unusual primitive op in that it is non-strict in its argument
                pair = genS_C(basicOpExpressions.getArgument(argIndex), variableContext);
            } else
            {
                pair = generateUnboxedPrimOpArgument(basicOpExpressions, basicOpExpressions.getArgument(argIndex), argIndex, variableContext);
            }

            args[argIndex] = pair.getJavaExpression();
            generatedContext.addStatement(pair.getContextBlock());
        }

        JavaExpression javaExpression = PrimOp.getPrimOpDefinition(op, args);

        if (boxResult) {
View Full Code Here

     * @param variableContext
     * @return the java switch statement.
     * @throws CodeGenerationException
     */
    private JavaStatement generateSwitchOnDataConstructor (Expression.Switch eswitch, VariableContext variableContext) throws CodeGenerationException {
        Block switchBlock = new Block();

        // Extract the alternatives
        Expression.Switch.SwitchAlt[] alts = eswitch.getAlts();

        TypeConstructor typeCons = null;
        boolean isEnumDataType = false;
        for (int i = 0; i < alts.length; ++i) {
            if (!alts[i].isDefaultAlt()) {
                DataConstructor dc = (DataConstructor)alts[i].getFirstAltTag();
                typeCons = dc.getTypeConstructor();
                isEnumDataType = SCJavaDefn.isEnumDataType(dc);
                break;
            }
        }

        if (typeCons == null) {
            throw new CodeGenerationException ("Unable to retrieve TypeConstructor for switch in " + getFunctionName() + ".");
        }



        int nDataConstructorsForType = typeCons.getNDataConstructors();
        if (nDataConstructorsForType == 0) {
            throw new CodeGenerationException ("Encountered a data type with zero data constructors in a switch in " + getFunctionName() + ".");
        }

        DataConstructor[] allDCs = new DataConstructor [nDataConstructorsForType];
        for (int i = 0; i < nDataConstructorsForType; ++i ) {
            DataConstructor dc = typeCons.getNthDataConstructor(i);
            allDCs[dc.getOrdinal()] = dc;
        }

        // 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;
                }
            } else if (altExpr.asVar() != null) {
                DataConstructor dcv = altExpr.asVar().getDataConstructor();
                if (dcv == null || !isTrueOrFalseDataCons(dcv)) {
                    isa = false;
                    break;
                }
            } else {
                isa = false;
                break;
            }
        }

        // We either need to have a default alt or an alt for every data
        // constructor for the type.
        if (isa && (eswitch.hasDefaultAlt() || nDataConstructorsForType == alts.length)) {
            return generateIsAFunctionFromSwitch (eswitch, variableContext);
        }

        // Determining if any of the alternates have alt vars that need to be extracted from the
        // switch value.
        boolean noAltVars = true;
        for (int i = 0; i < alts.length; ++i) {
            if (alts[i].hasVars()) {
                noAltVars = false;
                break;
            }
        }

        if (LECCMachineConfiguration.OPTIMIZE_SINGLE_DC_CASES && nDataConstructorsForType == 1) {
            // If there is only one DataConstructor we can eliminate the switch.
            if (codeGenerationStats != null) {
                codeGenerationStats.incrementSingleDCCases();
            }
            if (codeGenerationStats != null) {
                codeGenerationStats.incrementSingleDCCases();
            }

            return generateSingleAltSwitch(eswitch, variableContext);
        }

        // Create a boolean array to determine which cases we have.
        boolean[] caseExistsArray = new boolean[nDataConstructorsForType]// false by default.
        for (int i = 0; i < alts.length; ++i) {
            if (!alts[i].isDefaultAlt()) {
                List<Object> tags = alts[i].getAltTags();
                for (final Object tag : tags) {
                    DataConstructor dc = (DataConstructor)tag;
                    caseExistsArray[dc.getOrdinal()] = true;
                }
            }
        }

        // Generate the switch conditional.
        LocalVariable caseVar = null;
        SwitchStatement switchStatement;
        if (noAltVars /*&& (defaultAltProvided || !missingCases)*/) {
            // If there are no alt vars and we don't have to fill in any missing cases we don't need a local
            // variable holding the switchexpression.  This means we can generate something like:
            // switch (expression.evaluate().getOrdinal())
            ExpressionContextPair ecp = generateUnboxedArgument(JavaTypeName.INT, eswitch.getSwitchExpr(), variableContext);
            switchBlock.addStatement(ecp.getContextBlock());
            JavaExpression conditionExpression = ecp.getJavaExpression();

            switchStatement = new SwitchStatement(conditionExpression);
            switchBlock.addStatement(switchStatement);

        } else {
            // If there are alternates that have alt vars we generate something like:
            // RTValue caseVar;
            // switch ((caseVar = expression.evaluate()).getIntValue())
            // We do the assignment of the local in the actual switch statement
            // because analysis of the generated bytecode has shown this to be
            // slightly more efficient than initializing the local as part of the
            // declaration.
            JavaStatement caseVarDeclaration = null;
            Expression switchExpression = eswitch.getSwitchExpr();

            // Generate a local variable and assign the evaluated value of the expression
            // we are switching on.
            JavaTypeName typeClassName = isEnumDataType ? JavaTypeNames.RTVALUE : CALToJavaNames.createTypeNameFromType(typeCons, module);
            caseVar = new LocalVariable("$case" + nestedCaseLevel, typeClassName);

            // Add the local variable declaration.
            caseVarDeclaration = new LocalVariableDeclaration(caseVar);
            switchBlock.addStatement(caseVarDeclaration);

            // Compile the expression we are switching on strictly.
            ExpressionContextPair pair = genS_E(switchExpression, variableContext);
            switchBlock.addStatement(pair.getContextBlock());

            JavaExpression caseExpression = pair.getJavaExpression();
            //caseExpression = releaseVarsInSwitchCondition(eswitch, caseExpression, variableContext);

            // We may need to cast the result of the case expression to the type of the local variable.
            caseExpression = (isEnumDataType || caseExpression instanceof ClassInstanceCreationExpression) ? caseExpression : new CastExpression(typeClassName, caseExpression);

            // Assign the result of the switch expression to the local an then get the ordinal value.
            JavaExpression assignLocal = new JavaExpression.Assignment(caseVar, caseExpression);
            JavaExpression getOrdinal = SCJavaDefn.createInvocation(assignLocal, SCJavaDefn.GETORDINALVALUE);

            switchStatement = new SwitchStatement(getOrdinal);
            switchBlock.addStatement(switchStatement);
        }

        // Populate the switch statement with case statement groups.
        for (final SwitchAlt alt : alts) {
            List<Object> altTags = alt.getAltTags();

            // If no variables are used, we can share the code among all data constructors for this alt.
            if (!alt.hasVars()) {

                Block caseBlock = new Block();

                // Add a comment for the data constructors in the group if any (ie. if not the default alt).
                if (alt.getFirstAltTag() instanceof DataConstructor) {
                    StringBuilder commentSB = new StringBuilder();

                    boolean firstDC = true;
                    for (final Object tag : altTags) {
                        DataConstructor tagDC = (DataConstructor)tag;
                        if (firstDC) {
                            firstDC = false;
                        } else {
                            commentSB.append(", ");
                        }
                        commentSB.append(tagDC.getName().getQualifiedName());

                    }
                    caseBlock.addStatement(new LineComment(commentSB.toString()));
                }

                // Create a new child variable scope to handle the alternate and any let variables it contains.
                variableContext.pushJavaScope();

                // Compile the body of the alternate.
                JavaStatement altStatement = genS_R(alt.getAltExpr(), variableContext);
                caseBlock.addStatement(variableContext.popJavaScope());
                caseBlock.addStatement(altStatement);

                if (alt.isDefaultAlt()) {
                    switchStatement.addCase(new SwitchStatement.DefaultCase(caseBlock));

                } else {
                    int[] caseLabels = new int[altTags.size()];
                    int index = 0;
                    for (final Object tag : altTags) {
                        if (!(tag instanceof DataConstructor)) {
                            throw new CodeGenerationException ("Unknown tag type in DC case statement in " + getFunctionName() + ": " + tag.getClass().getName());
                        }

                        caseLabels[index] = ((DataConstructor)tag).getOrdinal();
                        index++;
                    }

                    switchStatement.addCase(new SwitchStatement.IntCaseGroup(caseLabels, caseBlock));
                }

            } else {
                // The alts use variables.

                if (alt instanceof SwitchAlt.Positional) {
                    // Positional notation for extracted variables.
                    // For now, a separate code block must be generated for each data constructor in the case.

                    Collection<List<DataConstructor>> tagGroups = consolidatePositionalSwitchAlt((SwitchAlt.Positional)alt);

                    for (final List<DataConstructor> group : tagGroups) {
                        // Must be a data constructor tag, since there are field names (see Expression.Switch.SwitchAlt).

                        Block caseBlock = new Block();

                        int[] caseLabels = new int[group.size()];
                        int index = 0;
                        DataConstructor firstDC = null;
                        // Must be a data constructor tag, since there are field names (see Expression.Switch.SwitchAlt).
                        for (final DataConstructor tagDC : group) {
                            if (firstDC == null) {
                                firstDC = tagDC;
                            } else
                            if (tagDC.getOrdinal() < firstDC.getOrdinal()) {
                                firstDC = tagDC;
                            }
                            caseBlock.addStatement(new LineComment(tagDC.getName().getQualifiedName()));
                            caseLabels[index] = tagDC.getOrdinal();
                            index++;
                        }

                        caseBlock.addStatement(new LineComment("Decompose data type to access members."));

                        // Create a new child variable scope to handle the alternate and any let variables it contains.
                        variableContext.pushJavaScope();

                        // Get this alternative's variables.  These have to be added to the active list of scope variables
                        TypeExpr fieldTypes[] = SCJavaDefn.getFieldTypesForDC(firstDC);
                        for (final AltVarIndexPair altVarIndexPair : getAltVarIndexList(alt, firstDC)) {

                            String altVar = altVarIndexPair.getAltVar();
                            int fieldIndex = altVarIndexPair.getIndex();

                            QualifiedName qn = QualifiedName.make(currentModuleName, altVar);
                            VarInfo.DCMember vi = variableContext.addDCField(qn, fieldTypes[fieldIndex]);

                            boolean fieldIsStrict =
                                !LECCMachineConfiguration.IGNORE_STRICTNESS_ANNOTATIONS;

                            for (final DataConstructor tagDC : group) {
                                fieldIsStrict = fieldIsStrict && tagDC.isArgStrict(fieldIndex);
                            }

                            if (fieldIsStrict) {
                                vi.setEvaluated(true);
                            }

                            String fieldName = SCJavaDefn.getJavaFieldNameFromDC(firstDC, fieldIndex);
                            String fieldGetterName = "get" + fieldName;

                            // Generate the code defining the variable.
                            if (fieldIsStrict) {
                                if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[fieldIndex])) {
                                    // This is a strict field of a primitive type so has both a boxed and unboxed form.
                                    JavaExpression unboxedInitializer =
                                        new JavaExpression.MethodInvocation.Instance(caseVar,
                                                                                     fieldGetterName + "_As_" + SCJavaDefn.getNameForPrimitive(fieldTypes[fieldIndex]),
                                                                                     SCJavaDefn.typeExprToTypeName(fieldTypes[fieldIndex]),
                                                                                     JavaExpression.MethodInvocation.InvocationType.VIRTUAL);

                                    vi.updateUnboxedVarDef(unboxedInitializer);
                                    JavaExpression localVar = new LocalVariable(vi.getJavaName()+"$U", vi.getUnboxedType());
                                    vi.updateUnboxedReference(localVar);
                                    JavaExpression boxedDef = SCJavaDefn.boxExpression(vi.getUnboxedType(), localVar);
                                    vi.updateStrictReference(boxedDef);
                                    vi.updateLazyReference(boxedDef);
                                } else {
                                    // RTValue altVarName = ((DCClass)caseVar).getFieldn();
                                    JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(caseVar, fieldGetterName, JavaTypeNames.RTVALUE, JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
                                    vi.updateStrictVarDef (initializer);
                                    JavaExpression localVar = new LocalVariable(vi.getJavaName(), JavaTypeNames.RTVALUE);
                                    vi.updateStrictReference(localVar);
                                    vi.updateLazyReference(localVar);
                                }
                            } else {
                                // RTValue altVarName = ((DCClass)caseVar).getFieldn();
                                JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(caseVar, fieldGetterName, JavaTypeNames.RTVALUE, JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
                                vi.updateLazyVarDef (initializer);
                                JavaExpression localVar = new LocalVariable(vi.getJavaName(), JavaTypeNames.RTVALUE);
                                vi.updateLazyReference(localVar);

                                JavaExpression evaluatedVar = SCJavaDefn.createInvocation(localVar, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR);
                                vi.updateStrictReference(evaluatedVar);
                                if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[fieldIndex])) {
                                    vi.updateUnboxedReference(SCJavaDefn.unboxValue(vi.getUnboxedType(), evaluatedVar));
                                }
                            }
                        }

                        // Compile the actual body of the alternate.
                        JavaStatement altStatement = genS_R(alt.getAltExpr(), variableContext);
                        caseBlock.addStatement(variableContext.popJavaScope());
                        caseBlock.addStatement(altStatement);

                        switchStatement.addCase(new SwitchStatement.IntCaseGroup(caseLabels, caseBlock));
                    }
                } else {
                    // Matching notation for switch alternate.
                    Map<FieldName, String> fieldNameToVarNameMap = ((SwitchAlt.Matching)alt).getFieldNameToVarNameMap();

                    Block caseBlock = new Block();

                    int[] caseLabels = new int[altTags.size()];
                    int index = 0;
                    DataConstructor firstDC = null;
                    // Must be a data constructor tag, since there are field names (see Expression.Switch.SwitchAlt).
                    for (final Object altTag : altTags) {
                        DataConstructor tagDC = (DataConstructor)altTag;
                        if (firstDC == null) {
                            firstDC = tagDC;
                        } else if (tagDC.getOrdinal() < firstDC.getOrdinal()) {
                            firstDC = tagDC;
                        }
                        caseBlock.addStatement(new LineComment(tagDC.getName().getQualifiedName()));
                        caseLabels[index] = tagDC.getOrdinal();
                        index++;
                    }

                    caseBlock.addStatement(new LineComment("Decompose data type to access members."));

                    // Create a new child variable scope to handle the alternate and any let variables it contains.
                    variableContext.pushJavaScope();

                    for (int iField = 0; iField < firstDC.getArity(); ++iField) {
                        FieldName fn = firstDC.getNthFieldName(iField);
                        String altVar = fieldNameToVarNameMap.get(fn);
                        if (altVar == null) {
                            continue;
                        }

                        QualifiedName qn = QualifiedName.make(currentModuleName, altVar);
                        TypeExpr fieldType = SCJavaDefn.getFieldTypeForDC(firstDC, fn);

                        VarInfo.DCMember vi = variableContext.addDCField(qn, fieldType);

                        boolean fieldIsStrict = !LECCMachineConfiguration.IGNORE_STRICTNESS_ANNOTATIONS;
                        for (final Object altTag : altTags) {
                            DataConstructor tagDC = (DataConstructor)altTag;
                            fieldIsStrict = fieldIsStrict & tagDC.isArgStrict(tagDC.getFieldIndex(fn));
                        }

                        if (fieldIsStrict) {
                            vi.setEvaluated(true);
                        }

                        String fieldName = SCJavaDefn.getJavaFieldNameFromFieldName(fn);
                        String fieldGetterName = "get" + fieldName;

                        // Generate the code defining the variable.
                        if (fieldIsStrict) {
                            if (SCJavaDefn.canTypeBeUnboxed(fieldType)) {
                                // This is a strict field of a primitive type so has both a boxed and unboxed form.
                                JavaExpression unboxedInitializer =
                                    new JavaExpression.MethodInvocation.Instance(caseVar,
                                                                                 fieldGetterName + "_As_" + SCJavaDefn.getNameForPrimitive(fieldType),
                                                                                 SCJavaDefn.typeExprToTypeName(fieldType),
                                                                                 JavaExpression.MethodInvocation.InvocationType.VIRTUAL);

                                vi.updateUnboxedVarDef(unboxedInitializer);
                                JavaExpression localVar = new LocalVariable(vi.getJavaName()+"$U", vi.getUnboxedType());
                                vi.updateUnboxedReference(localVar);
                                JavaExpression boxedDef = SCJavaDefn.boxExpression(vi.getUnboxedType(), localVar);
                                vi.updateStrictReference(boxedDef);
                                vi.updateLazyReference(boxedDef);
                            } else {
                                // RTValue altVarName = ((DCClass)caseVar).getFieldn();
                                JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(caseVar, fieldGetterName, JavaTypeNames.RTVALUE, JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
                                vi.updateStrictVarDef (initializer);
                                JavaExpression localVar = new LocalVariable(vi.getJavaName(), JavaTypeNames.RTVALUE);
                                vi.updateStrictReference(localVar);
                                vi.updateLazyReference(localVar);
                            }
                        } else {
                            // RTValue altVarName = ((DCClass)caseVar).getFieldn();
                            JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(caseVar, fieldGetterName, JavaTypeNames.RTVALUE, JavaExpression.MethodInvocation.InvocationType.VIRTUAL);
                            vi.updateLazyVarDef (initializer);
                            JavaExpression localVar = new LocalVariable(vi.getJavaName(), JavaTypeNames.RTVALUE);
                            vi.updateLazyReference(localVar);

                            JavaExpression evaluatedVar = SCJavaDefn.createInvocation(localVar, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR);
                            vi.updateStrictReference(evaluatedVar);
                            if (SCJavaDefn.canTypeBeUnboxed(fieldType)) {
                                vi.updateUnboxedReference(SCJavaDefn.unboxValue(vi.getUnboxedType(), evaluatedVar));
                            }
                        }
                    }

                    // Compile the actual body of the alternate.
                    JavaStatement altStatement = genS_R(alt.getAltExpr(), variableContext);
                    caseBlock.addStatement(variableContext.popJavaScope());
                    caseBlock.addStatement(altStatement);

                    switchStatement.addCase(new SwitchStatement.IntCaseGroup(caseLabels, caseBlock));
                }
            }
        }
View Full Code Here

        for (int i = 0; i < nTags; i++) {
            // Generate a case for each tag -
            // Since there is no default case provided we want to treat this as an error..

            final int tag = intTagList.get(i).intValue();
            final Block altBody = new Block();
            final String dataConsName = typeCons.getNthDataConstructor(tag).getName().getQualifiedName();

            altBody.addStatement (new JavaStatement.LineComment(dataConsName));

            // We generate a call to unhandledSwitchIndex with the data cons name appearing as a string literal.
            final MethodInvocation errorCall =
                new MethodInvocation.Instance(null,
                                              "unhandledSwitchIndex",
                                              new JavaExpression[]{getErrorInfo(eSwitch.getErrorInfo()), LiteralWrapper.make(dataConsName)},
                                              new JavaTypeName[]{JavaTypeName.ERRORINFO, JavaTypeName.STRING},
                                              JavaTypeNames.RTVALUE,
                                              MethodInvocation.InvocationType.VIRTUAL);

            altBody.addStatement(generateReturn (errorCall, null));
            switchStatement.addCase(new SwitchStatement.IntCaseGroup (new int[] {tag}, altBody));
        }
    }
View Full Code Here

     * @return the java switch statement.
     * @throws CodeGenerationException
     */
    private JavaStatement generateSwitchOnInteger (Expression.Switch eswitch, VariableContext variableContext) throws CodeGenerationException {

        Block switchBlock = new Block();

        // Extract the alternatives
        Expression.Switch.SwitchAlt[] alts = eswitch.getAlts();

        // Generate the switch conditional.
        SwitchStatement switchStatement;

        // Generate code to get the int value that we are switching on.
        ExpressionContextPair ecp = generateUnboxedArgument(JavaTypeName.INT, eswitch.getSwitchExpr(), variableContext);
        switchBlock.addStatement(ecp.getContextBlock());
        JavaExpression conditionExpression = ecp.getJavaExpression();

        switchStatement = new SwitchStatement(conditionExpression);
        switchBlock.addStatement(switchStatement);

        // Populate the switch statement with case statement groups.
        for (final SwitchAlt alt : alts) {
            // Create a new child variable scope to handle the alternate and any let variables it contains.
            variableContext.pushJavaScope();

            Block caseBlock = new Block();

            // If we are switching on an integer we should never have alt variables.
            if (alt.hasVars()) {
                throw new CodeGenerationException ("Alt vars encountered in integer switch in " + getFunctionName() + ".");
            }

            JavaStatement altStatement = genS_R(alt.getAltExpr(), variableContext);
            caseBlock.addStatement(variableContext.popJavaScope());
            caseBlock.addStatement(altStatement);

            if (alt.isDefaultAlt()) {
                switchStatement.addCase(new SwitchStatement.DefaultCase(caseBlock));

            } else {
View Full Code Here

     * @return the java switch statement.
     * @throws CodeGenerationException
     */
    private JavaStatement generateSwitchOnCharacter (Expression.Switch eswitch, VariableContext variableContext) throws CodeGenerationException {

        Block switchBlock = new Block();

        // Extract the alternatives
        Expression.Switch.SwitchAlt[] alts = eswitch.getAlts();

        // Generate the switch conditional.
        SwitchStatement switchStatement;

        // Generate code to get the char value that we are switching on.
        ExpressionContextPair ecp = generateUnboxedArgument(JavaTypeName.CHAR, eswitch.getSwitchExpr(), variableContext);
        switchBlock.addStatement(ecp.getContextBlock());
        JavaExpression conditionExpression = ecp.getJavaExpression();

        switchStatement = new SwitchStatement(conditionExpression);
        switchBlock.addStatement(switchStatement);

        // Populate the switch statement with case statement groups.
        for (final SwitchAlt alt : alts) {
            // Create a new child variable scope to handle the alternate and any let variables it contains.
            variableContext.pushJavaScope();

            Block caseBlock = new Block();

            // If we are switching on an character we should never have alt variables.
            if (alt.hasVars()) {
                throw new CodeGenerationException ("Alt vars encountered in character switch in " + getFunctionName() + ".");
            }

            JavaStatement altStatement = genS_R(alt.getAltExpr(), variableContext);
            caseBlock.addStatement(variableContext.popJavaScope());
            caseBlock.addStatement(altStatement);

            if (alt.isDefaultAlt()) {
                switchStatement.addCase(new SwitchStatement.DefaultCase(caseBlock));

            } else {
View Full Code Here

        // int $intVal = switchExpression;
        // !($intVal == c || $intVal == d)
        // Where c and d are the cases that return false.


        Block isABlock = new Block();

        // Extract the alternatives
        Expression.Switch.SwitchAlt[] alts = eswitch.getAlts();

        boolean lookingForTrue = true;
        int defaultIndex = -1;
        int trueCount = 0;
        // Need to determine if there is a default case and how many true and false cases.
        for (int i = 0; i < alts.length; ++i) {
            Expression altExpr = alts[i].getAltExpr();
            Expression.Literal lit = altExpr.asLiteral();
            Expression.Var var = altExpr.asVar();
            boolean isTrue = false;
            if (lit != null && lit.getLiteral() instanceof Boolean && ((Boolean)lit.getLiteral()).booleanValue()) {
                isTrue = true;
                trueCount++;
            } else
            if (var != null && var.getDataConstructor() != null && isTrueDataCons(var.getDataConstructor())) {
                isTrue = true;
                trueCount++;
            }

            if(alts[i].isDefaultAlt()) {
                defaultIndex = i;
                // If the default case returns true we want to build up our expression based
                // on the cases that return false.
                if (isTrue) {
                    lookingForTrue = false;
                }
            }
        }

        if (trueCount == alts.length) {
            isABlock.addStatement(
                    generateReturn(
                            boxPrimitiveOpResult(
                                    PrimOps.PRIMOP_OR,
                                    JavaExpression.LiteralWrapper.make(Boolean.TRUE)), variableContext));
            return isABlock;
        }

        if (trueCount == 0) {
            isABlock.addStatement(generateReturn(boxPrimitiveOpResult(PrimOps.PRIMOP_OR, JavaExpression.LiteralWrapper.make(Boolean.FALSE)), variableContext));
            return isABlock;
        }

        int falseCount = alts.length - trueCount;

        // Generate the switch conditional.
        ExpressionContextPair pair = genS_E (eswitch.getSwitchExpr(), variableContext);

        isABlock.addStatement(pair.getContextBlock());

        JavaExpression isAExpr = null;
        JavaExpression tagValue = SCJavaDefn.createInvocation (pair.getJavaExpression(), SCJavaDefn.GETORDINALVALUE);
        if ((lookingForTrue && trueCount > 1) || (!lookingForTrue && falseCount > 1)) {
            LocalVariable intVal = new LocalVariable ("$intVal", JavaTypeName.INT);
            LocalVariableDeclaration intValDeclaration = new LocalVariableDeclaration(intVal, tagValue);
            isABlock.addStatement (intValDeclaration);
            tagValue = intVal;
        }

        for (int i = 0; i < alts.length; ++i) {
            // We arrange things so that we don't have to explicitly handle the default case.
            if (i == defaultIndex) {
                continue;
            }

            Expression altExpr = alts[i].getAltExpr();
            Expression.Literal lit = altExpr.asLiteral();
            Expression.Var var = altExpr.asVar();

            boolean isTrue = false;
            if (lit != null && lit.getLiteral() instanceof Boolean && ((Boolean)lit.getLiteral()).booleanValue()) {
                isTrue = true;
            } else
            if (var != null && var.getDataConstructor() != null && isTrueDataCons(var.getDataConstructor())) {
                isTrue = true;
            }

            if (isTrue == lookingForTrue) {
                for (final Object altTag : alts[i].getAltTags()) {
                    int ord = ((DataConstructor)altTag).getOrdinal();
                    JavaExpression litOrd = JavaExpression.LiteralWrapper.make(Integer.valueOf(ord));
                    JavaExpression eqExpression = new JavaExpression.OperatorExpression.Binary(JavaOperator.EQUALS_INT, tagValue, litOrd);
                    if (isAExpr == null) {
                        isAExpr = eqExpression;
                    } else {
                        isAExpr = new JavaExpression.OperatorExpression.Binary(JavaOperator.CONDITIONAL_OR, isAExpr, eqExpression);
                    }
                }
            }
        }


        if (isAExpr == null) {
            isAExpr = JavaExpression.LiteralWrapper.make(Boolean.valueOf(!lookingForTrue));
        } else {
            if (!lookingForTrue) {
                isAExpr = new JavaExpression.OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, isAExpr);
            }
        }

        isABlock.addStatement(generateReturn(boxPrimitiveOpResult(PrimOps.PRIMOP_OR, isAExpr), variableContext));

        return isABlock;
    }
View Full Code Here

        Expression condExpression = eSwitch.getSwitchExpr();
        ExpressionContextPair pair = generateUnboxedArgument(JavaTypeName.BOOLEAN, condExpression, variableContext);

        // Then
        Block thenBlock;
        if (trueAlt == null) {
            LiteralWrapper badValueMessageWrapper = LiteralWrapper.make("Illegal fallthrough to default case.");
            JavaExpression returnValueExpression = getBadValueCall(eSwitch.getErrorInfo(), badValueMessageWrapper);
            JavaStatement badValueReturnStatement = generateReturn(returnValueExpression, variableContext);
            thenBlock = new Block();
            thenBlock.addStatement (badValueReturnStatement);
        } else {
            variableContext.pushJavaScope();
            JavaStatement thenPart = genS_R (trueAlt, variableContext);

            thenBlock = variableContext.popJavaScope();
            thenBlock.addStatement(thenPart);
        }

        // Else
        Block elseBlock;
        if (falseAlt == null) {
            LiteralWrapper badValueMessageWrapper = LiteralWrapper.make("Illegal fallthrough to default case in function.");
            JavaStatement badValueReturnStatement = generateReturn(getBadValueCall(eSwitch.getErrorInfo(), badValueMessageWrapper), variableContext);
            elseBlock = new Block();
            elseBlock.addStatement (badValueReturnStatement);
        } else {
            variableContext.pushJavaScope();
            JavaStatement elsePart = genS_R (falseAlt, variableContext);

            elseBlock = variableContext.popJavaScope();
            elseBlock.addStatement(elsePart);
        }

        JavaStatement ite = new IfThenElseStatement(pair.getJavaExpression(), thenBlock, elseBlock);

        Block contextBlock = pair.getContextBlock();
        contextBlock.addStatement(ite);
        return contextBlock;
    }
View Full Code Here

                remainingVars.add(variablesOfInterestForHandler);
                VarReleaser vr = new VarReleaser(variablesOfInterestForHandler);
                newExceptionHandlers.add((JavaExceptionHandler)(oldExceptionHandlers.get(i)).accept(vr, arg));
            }

            Block newBlock = new Block(newExceptionHandlers);

            // Update variables of interest.
            if (remainingVars.size() > 0) {
                variablesOfInterest.clear();
                for (String varName : remainingVars.get(0).keySet()) {
                    boolean missing = false;
                    for (int i = 1, n = remainingVars.size(); i < n; ++i) {
                        if (!remainingVars.get(i).containsKey(varName)) {
                            missing = true;
                            break;
                        }
                    }
                    if (!missing) {
                        variablesOfInterest.put(varName, remainingVars.get(0).get(varName));
                    }
                }
            }

            // Traverse the contained statements in reverse order, since we want to release the
            // last reference to each variable.
            List<JavaStatement> newStatements = new ArrayList<JavaStatement>(block.getNBlockStatements());
            for (int i = block.getNBlockStatements() - 1; i >= 0; --i) {
                newStatements.add(0, (JavaStatement)block.getNthBlockStatement(i).accept(this, arg));
            }

            for (int i = 0, n = newStatements.size(); i < n; ++i) {
                newBlock.addStatement(newStatements.get(i));
            }

            return newBlock;
        }
View Full Code Here

TOP

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

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.