Package org.openquark.cal.internal.javamodel.JavaExpression

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


        JavaExpression.Nameable lhs = assignment.getLeftHandSide();
                                   
        if (lhs instanceof LocalName) {
            // Determine what type of creature this name represents.
            //   Note that because of the order of lookups, this takes scoping into account.
            LocalName localName = (LocalName)lhs;
            String varName = localName.getName();
            if (context.getLocalVarIndex(varName) != -1) {
                lhs = new LocalVariable(varName, localName.getTypeName());
            } else if (context.getMethodVarIndex(varName) != -1) {
                lhs = new MethodVariable(varName);
            } else {
                lhs = new JavaField.Instance(null, varName, localName.getTypeName());
            }
        }
       
        // assign the value
        if (lhs instanceof JavaField.Instance) {                      
View Full Code Here


    /* (non-Javadoc)
     * @see org.openquark.cal.internal.runtime.lecc.JavaModelVisitor#visitLocalNameExpression(org.openquark.cal.internal.runtime.lecc.JavaExpression.LocalName, java.lang.Object)
     */
    public JavaExpression visitLocalNameExpression(LocalName localName, T arg) {
        return new LocalName(localName.getName(), localName.getTypeName());
    }
View Full Code Here

                    if (javaDefn.isArgStrict(argIndex)) {
                        String fixedUpVarName = javaDefn.getJavaArgumentName(argIndex);
                        if (javaDefn.isArgUnboxable(argIndex)) {
                            // In this case the argument was named with an appended $L so that we can declare a
                            // local variable with the CAL argument name that is the unboxed primitive value.
                            JavaExpression evaluate = SCJavaDefn.createInvocation(new LocalName(fixedUpVarName + "$L", JavaTypeNames.RTVALUE), SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR);
                            evaluate = SCJavaDefn.unboxValue(javaDefn.getArgumentTypeName(argIndex), evaluate);
                            LocalVariableDeclaration lvd = new LocalVariableDeclaration(new LocalVariable(fixedUpVarName, javaDefn.getArgumentTypeName(argIndex)), evaluate);
                            block.addStatement(lvd);
                        } else {
                            JavaExpression.Nameable argVar = new LocalName(fixedUpVarName, JavaTypeNames.RTVALUE);
                            JavaExpression evaluate = SCJavaDefn.createInvocation(argVar, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR);
                            Assignment assign = new Assignment(argVar, evaluate);
                            block.addStatement(new ExpressionStatement (assign));
                        }
                    }
View Full Code Here

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

                String javaArgName = argNames[i];
                JavaTypeName javaArgType = argTypes[i];

                JavaExpression javaArgValue = new LocalName(javaArgName, javaArgType);
                if (!javaArgType.equals(JavaTypeNames.RTVALUE)) {
                    javaArgValue = SCJavaDefn.boxExpression(javaArgType, javaArgValue);
                }

                argValues[i] = javaArgValue;
View Full Code Here

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

                String javaArgName = argNames[i];
                JavaTypeName javaArgType = argTypes[i];

                JavaExpression javaArgValue = new LocalName(javaArgName, javaArgType);
                if (!javaArgType.equals(JavaTypeNames.RTVALUE)) {
                    javaArgValue = SCJavaDefn.boxExpression(javaArgType, javaArgValue);
                }

                argValues[i] = javaArgValue;
View Full Code Here

            !baseRecordPatternVarName.equals(Expression.RecordCase.WILDCARD_VAR)) {

            QualifiedName qn = QualifiedName.make(currentModuleName, baseRecordPatternVarName);
            VarInfo.RecordField varInfo = variableContext.addRecordField(qn, null);
            String javaBaseRecordPatternVarName = varInfo.getJavaName();
            LocalName lazyRef = new LocalName(varInfo.getJavaName(), JavaTypeNames.RTVALUE);
            varInfo.updateLazyReference(lazyRef);
            varInfo.updateStrictReference(SCJavaDefn.createInvocation(lazyRef, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR));

            //generate the Java code:
            //(in the case of both ordinal and textual field names
            //javaBaseRecordPatternVarName = conditionVar.makeMixedRecordRetraction(new int[] {ordinalFieldName1, ..., ordinalFieldNameN},
            //  new String[] {textualFieldName1, ..., textualFieldNameN}

            LocalVariable baseRecordPatternVar = new LocalVariable(javaBaseRecordPatternVarName, JavaTypeNames.RTRECORD_VALUE);

            JavaExpression javaExtractBaseRecordExpr;

            Expression.RecordCase.FieldData fieldData = recordCaseExpr.getBindingFieldsData();
            //todoBI there could be some more optimizations here to handle the cases
            //a. where the ordinal names are in tuple form, then only the tuple size needs to be passed.
            //b. where only a single ordinal or single textual field is being retracted, then we don't
            //   need to form the array.
            //Note however, that if the record pattern var is not used in the expression on the right hand side
            //of the ->, then it will not be created (earlier analysis replaces it by a _), so in fact this
            //code is not called that often anyways.
            int[] retractedOrdinalFields = fieldData.getOrdinalNames();
            String[] retractedTextualFields = fieldData.getTextualNames();

            if (retractedOrdinalFields.length > 0) {

                if (retractedTextualFields.length > 0) {

                    if (fieldData.hasTupleOrdinalPart()) {

                        javaExtractBaseRecordExpr = new MethodInvocation.Instance(
                                conditionVar,
                            "makeTupleMixedRecordRetraction",
                            new JavaExpression[] {
                                LiteralWrapper.make(Integer.valueOf(retractedOrdinalFields.length)),
                                createTextualNamesArray(retractedTextualFields)},
                            new JavaTypeName[] {JavaTypeName.INT, JavaTypeName.STRING_ARRAY},
                            JavaTypeNames.RTRECORD_VALUE,
                            InvocationType.VIRTUAL);
                    } else {

                        javaExtractBaseRecordExpr = new MethodInvocation.Instance(
                                conditionVar,
                            "makeMixedRecordRetraction",
                            new JavaExpression[] {
                                createOrdinalNamesArray(retractedOrdinalFields),
                                createTextualNamesArray(retractedTextualFields)},
                            new JavaTypeName[] {JavaTypeName.INT_ARRAY, JavaTypeName.STRING_ARRAY},
                            JavaTypeNames.RTRECORD_VALUE,
                            InvocationType.VIRTUAL);
                    }
                } else {

                    if (fieldData.hasTupleOrdinalPart()) {

                        javaExtractBaseRecordExpr = new MethodInvocation.Instance(
                                conditionVar,
                            "makeTupleRecordRetraction",
                            new JavaExpression[] {
                                LiteralWrapper.make(Integer.valueOf(retractedOrdinalFields.length))},
                            new JavaTypeName[] {JavaTypeName.INT},
                            JavaTypeNames.RTRECORD_VALUE,
                            InvocationType.VIRTUAL);
                    } else {

                        javaExtractBaseRecordExpr = new MethodInvocation.Instance(
                                conditionVar,
                            "makeOrdinalRecordRetraction",
                            new JavaExpression[] {
                                createOrdinalNamesArray(retractedOrdinalFields)},
                            new JavaTypeName[] {JavaTypeName.INT_ARRAY},
                            JavaTypeNames.RTRECORD_VALUE,
                            InvocationType.VIRTUAL);
                    }
                }

            } else if (retractedTextualFields.length > 0) {

                    javaExtractBaseRecordExpr = new MethodInvocation.Instance(
                            conditionVar,
                        "makeTextualRecordRetraction",
                        new JavaExpression[] {
                            createTextualNamesArray(retractedTextualFields)},
                        new JavaTypeName[] {JavaTypeName.STRING_ARRAY},
                        JavaTypeNames.RTRECORD_VALUE,
                        InvocationType.VIRTUAL);

            } else {
                javaExtractBaseRecordExpr = conditionVar;
            }

            LocalVariableDeclaration extractBaseRecordDeclaration =
                new LocalVariableDeclaration(baseRecordPatternVar, javaExtractBaseRecordExpr);
            recordCaseBlock.addStatement(extractBaseRecordDeclaration);
        }

        for (final Map.Entry<FieldName, String> entry : fieldBindingVarMap.entrySet()) {

            FieldName fieldName = entry.getKey();
            String bindingVarName = entry.getValue();

            //ignore anonymous pattern variables. These are guaranteed not to be used
            //by the result expression, and so don't need to be extracted from the condition record.
            if (!bindingVarName.equals(Expression.RecordCase.WILDCARD_VAR)) {

                QualifiedName qn = QualifiedName.make(currentModuleName, bindingVarName);
                VarInfo.RecordField varInfo = variableContext.addRecordField(qn, null);
                String javaBindingVarName = varInfo.getJavaName();
                LocalName lazyRef = new LocalName(varInfo.getJavaName(), JavaTypeNames.RTVALUE);
                varInfo.updateLazyReference(lazyRef);
                varInfo.updateStrictReference(SCJavaDefn.createInvocation(lazyRef, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR));

                LocalVariable bindingVar = new LocalVariable(javaBindingVarName, JavaTypeNames.RTVALUE);
View Full Code Here

            }

            Expression.Let.LetDefn def = defns [i];
            QualifiedName qn = QualifiedName.make(currentModuleName, def.getVar());
            letVars[i] = variableContext.addLetRecVar(qn, def.getVarType());
            LocalName lazyRef = new LocalName(letVars[i].getJavaName(), JavaTypeNames.RTVALUE);
            letVars[i].updateLazyReference(lazyRef);
            letVars[i].updateStrictReference(SCJavaDefn.createInvocation(lazyRef, SCJavaDefn.EVALUATE, SCJavaDefn.EXECUTION_CONTEXT_VAR));
        }

View Full Code Here

            // Mark evaluation state.
            varInfo.setEvaluated(isEvaluated);

            JavaExpression straightReference;
            if (isEvaluated && argType != null && !argType.equals(JavaTypeNames.RTVALUE) && !argType.equals(JavaTypeName.CAL_VALUE)) {
                straightReference= new LocalName(varInfo.getJavaName(), argType);
            } else {
                straightReference= new LocalName(varInfo.getJavaName(), JavaTypeNames.RTVALUE);
            }

            // Set up boxed/unboxed references
            if (isEvaluated) {
                if (argType != null && !argType.equals(JavaTypeNames.RTVALUE) && !argType.equals(JavaTypeName.CAL_VALUE)) {
View Full Code Here

TOP

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

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.