Package org.openquark.cal.internal.javamodel

Examples of org.openquark.cal.internal.javamodel.JavaExpression


                    // since we know the variable can't be primitive (because we called verifyUnboxType) and
                    // all non-primitives in Java are an instance of Object.
                    if ((unboxType == null && variableContext.getUnboxedType(var.getName()) != null) ||
                        (unboxType != null &&
                            (unboxType.equals(variableContext.getUnboxedType(var.getName())) || unboxType.equals(JavaTypeName.OBJECT)))) {
                        JavaExpression unboxedRef = variableContext.getUnboxedReference(var.getName());
                        if (unboxedRef != null) {
                            return new ExpressionContextPair(unboxedRef);
                        }
                    }
                }
View Full Code Here


                    // If the desired unbox type is Object we can simply use the variables unboxed reference
                    // since we know the variable can't be primitive (because we called verifyUnboxType) and
                    // all non-primitives in Java are an instance of Object.
                    if(unboxType.equals(unboxedTypeOfVar) ||
                       unboxType.equals(JavaTypeName.OBJECT)) {
                        JavaExpression unboxedRef = variableContext.getUnboxedReference(var.getName());
                        if (unboxedRef != null) {
                            return new ExpressionContextPair (unboxedRef);
                        }
                    } else {
                        if (unboxedTypeOfVar != null) {
View Full Code Here

        }

        if (directlyRetrieveUnboxed) {

            ExpressionContextPair ecp = genS_E(dcs.getDCValueExpr(), variableContext);
            JavaExpression target = new CastExpression (JavaTypeNames.RTCONS, ecp.getJavaExpression());

            // Call the unboxed version of getFieldByIndex.
            // In RTCons we declare versions of getFieldByIndex_As_...() for each of the Java primitive types,
            // Object, and java.lang.String.
            // At this point we need to decide which one to call.

            boolean retrieveAsObject = !(unboxedType instanceof JavaTypeName.Primitive) && !unboxedType.equals(JavaTypeName.STRING);

            JavaExpression mi;
            if (retrieveAsObject) {
                mi = new MethodInvocation.Instance(target,
                        "getFieldByIndex_As_Object",
                        new JavaExpression[] {
                                LiteralWrapper.make(Integer.valueOf(dcs.getDataConstructor().getOrdinal())),
View Full Code Here

            // 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));
                            }
                        }
View Full Code Here

        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.
View Full Code Here

        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.
View Full Code Here

        // 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);
                    }
View Full Code Here

        // 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();
View Full Code Here

        if (!switchExprEvaluated || alt.hasVars()) {
            caseVar = new LocalVariable("$case" + nestedCaseLevel, caseVarType);

            ExpressionContextPair pair = genS_E(eSwitch.getSwitchExpr(), variableContext);
            switchBlock.addStatement(pair.getContextBlock());
            JavaExpression caseExpression = pair.getJavaExpression();

            if (caseVarType.equals(JavaTypeNames.RTCONS)) {
                caseExpression = new CastExpression(JavaTypeNames.RTCONS, caseExpression);
            }

            LocalVariableDeclaration caseVarDeclaration =
                new LocalVariableDeclaration(caseVar, caseExpression);
            switchBlock.addStatement(caseVarDeclaration);
        }

        // Populate the switch statement with case statement groups.

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

        Block caseBlock = new Block();

        if (isSwitchingOnDC) {
            caseBlock.addStatement(new LineComment(((DataConstructor)altTag).getName().getQualifiedName()));
        }

        // Get this alternative's variables.  These have to be added to the active list of scope variables
        if (alt.hasVars()) {
            caseBlock.addStatement(new LineComment("Decompose data type to access members."));

            if (caseVar == null) {
                throw new CodeGenerationException ("Null case variable encountered in single alternate switch.");
            }

            // Must be a data constructor tag, since there are field names (see Expression.Switch.SwitchAlt).
            DataConstructor tagDC = (DataConstructor)altTag;

            TypeExpr fieldTypes[] = SCJavaDefn.getFieldTypesForDC(tagDC);

            // Cast the case var to the appropriate type to call getField0, getField1, etc.
            JavaTypeName dcTypeName = CALToJavaNames.createTypeNameFromDC(tagDC, module);
            JavaExpression castExpression = new CastExpression(dcTypeName, caseVar);

            // There is at least one field to be extracted.
            // Declare a local variable that is the casted case var so that we only do the cast once.
            JavaExpression castCaseVar = new LocalVariable("$dcCaseVar" + nestedCaseLevel, dcTypeName);
            LocalVariableDeclaration localVarStmnt = new LocalVariableDeclaration((LocalVariable)castCaseVar, castExpression);
            caseBlock.addStatement (localVarStmnt);

            for (final AltVarIndexPair altVarIndexPair : getAltVarIndexList(alt, tagDC)) {

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

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

                // Build in place representation of this variable mapped to its name
                QualifiedName qn = QualifiedName.make(currentModuleName, altVar);
                VarInfo.DCMember vi = variableContext.addDCField(qn, fieldTypes[fieldIndex]);

                boolean fieldIsStrict =
                    !LECCMachineConfiguration.IGNORE_STRICTNESS_ANNOTATIONS && tagDC.isArgStrict(fieldIndex);

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

                if (fieldIsStrict) {
                    if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[fieldIndex])) {
                        JavaTypeName strictType = SCJavaDefn.typeExprToTypeName(fieldTypes[fieldIndex]);
                        JavaExpression unboxedInitializer =
                            new JavaExpression.MethodInvocation.Instance(castCaseVar,
                                                                         fieldGetterName + "_As_" + SCJavaDefn.getNameForPrimitive(strictType),
                                                                         strictType,
                                                                         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 {
                        JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(castCaseVar, 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 {
                    JavaExpression initializer = new JavaExpression.MethodInvocation.Instance(castCaseVar, 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));
                    }
                }
View Full Code Here

        Block newContext = ecp[0].getContextBlock();
        for (int i = 1; i < chain.length; ++i) {
            newContext.addStatement(ecp[i].getContextBlock());
        }

        JavaExpression root = ecp[0].getJavaExpression();

        if (codeGenerationStats != null) {
            if (var.getForeignFunctionInfo() == null) {
                codeGenerationStats.incrementStrictSCNodeCount();
            } else {
                codeGenerationStats.incrementStrictForeignNodeCount();
            }
        }

        // Optimize Prelude.not to use the '!' java operator.
        if (var.getName().equals(CAL_Prelude.Functions.not)) {
            JavaExpression not = new JavaExpression.OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, ecp[1].getJavaExpression());
            return new ExpressionContextPair (not, newContext);
        }

        // This is a fully saturated supercombinator application that can be represented
        // using an special purpose graph node.
        JavaExpression args[] = new JavaExpression[calledArity + 1];
        args[0] = expressionVarToJavaDef(var, Scheme.E_SCHEME, variableContext);
        JavaTypeName argTypes[] = new JavaTypeName[calledArity + 1];
        if (useTypeSpecificAppNode) {
            argTypes[0] = CALToJavaNames.createTypeNameFromSC(var.getName(), module);
        } else {
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaExpression

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.