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

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


            }

            // Add a default case in the switch to throw an error if an invalid ordinal value is used.
            Block defaultBlock = new Block();
            LocalVariable bf = new LocalVariable("bf", JavaTypeName.STRING_BUILDER);
            defaultBlock.addStatement(new LocalVariableDeclaration (bf, new ClassInstanceCreationExpression(JavaTypeName.STRING_BUILDER)));
            LiteralWrapper badValueMessageWrapper1 = LiteralWrapper.make("Invalid ordinal value of ");
            JavaExpression message = new MethodInvocation.Instance(bf, "append", badValueMessageWrapper1, JavaTypeName.STRING, JavaTypeName.STRING_BUILDER, MethodInvocation.InvocationType.VIRTUAL);
            message = new  MethodInvocation.Instance(message, "append", METHODVAR_ORDINAL, JavaTypeName.INT, JavaTypeName.STRING_BUILDER, MethodInvocation.InvocationType.VIRTUAL);
            LiteralWrapper badValueMessageWrapper2 = LiteralWrapper.make(" in " + className.toString() + ".getTagDC().");
            message = new MethodInvocation.Instance(message, "append", badValueMessageWrapper2, JavaTypeName.STRING, JavaTypeName.STRING_BUILDER, MethodInvocation.InvocationType.VIRTUAL);
View Full Code Here


                        //        }
                        //        return field;
                        //}
                        String localName = fieldName+"$";
                        LocalVariable localVariable = new LocalVariable(localName, fieldType);
                        LocalVariableDeclaration localDeclaration = new LocalVariableDeclaration(localVariable);
                        javaMethod.addStatement(localDeclaration);
                        Assignment localAssignment = new Assignment(localVariable, field);
                        InstanceOf checkType = new InstanceOf(localAssignment, JavaTypeNames.RTRESULT_FUNCTION);
                        MethodInvocation getValue = new MethodInvocation.Instance(localVariable, "getValue", JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
                        Assignment fieldAssignment = new Assignment(field, getValue);
View Full Code Here

                } else if (i == arity - 2) {

                    if (arity > 2) {
                        //RTValue $currentRootNode;
                        argExtractorBlock.addStatement(new LocalVariableDeclaration(LOCALVAR_CURRENT_ROOT_NODE));
                        //($currentRootNode = $rootNode.prevArg()).getArgValue();
                        initializer =
                            SCJavaDefn.createInvocation(
                                new Assignment(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.PREVARG)),
                                SCJavaDefn.GETARGVALUE);
                    } else {
                        //$rootNode.prevArg().getArgValue();
                        initializer =
                            SCJavaDefn.createInvocation(
                                SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.PREVARG),
                                SCJavaDefn.GETARGVALUE);
                    }

                } else if (i == 0) {

                    //$currentRootNode.prevArg().getArgValue();
                    initializer =
                        SCJavaDefn.createInvocation(
                            SCJavaDefn.createInvocation(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.PREVARG),
                            SCJavaDefn.GETARGVALUE);

                } else {

                    //($currentRootNode = $currentRootNode.prevArg()).getArgValue();
                    initializer =
                        SCJavaDefn.createInvocation(
                            new Assignment(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.createInvocation(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.PREVARG)),
                            SCJavaDefn.GETARGVALUE);
                }

                LocalVariableDeclaration varDecl = new LocalVariableDeclaration(new LocalVariable(fixedUpVarName, JavaTypeNames.RTVALUE), initializer);

                argExtractorBlock.addStatement(varDecl);
            }

            // Make a call on the root node to free its member fields.
View Full Code Here

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

                    } else if (i == arity - 2) {

                        if (arity > 2) {
                            //RTValue $currentRootNode;
                            javaMethod.addStatement(new LocalVariableDeclaration(LOCALVAR_CURRENT_ROOT_NODE));
                            //($currentRootNode = $rootNode.prevArg()).getArgValue();
                            initializer =
                                SCJavaDefn.createInvocation(
                                    new Assignment(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.PREVARG)),
                                    SCJavaDefn.GETARGVALUE);
                        } else {
                            //$rootNode.prevArg().getArgValue();
                            initializer =
                                SCJavaDefn.createInvocation(
                                    SCJavaDefn.createInvocation(METHODVAR_ROOT_NODE, SCJavaDefn.PREVARG),
                                    SCJavaDefn.GETARGVALUE);
                        }

                    } else if (i == 0) {

                        //$currentRootNode.prevArg().getArgValue();
                        initializer =
                            SCJavaDefn.createInvocation(
                                SCJavaDefn.createInvocation(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.PREVARG),
                                SCJavaDefn.GETARGVALUE);

                    } else {

                        //($currentRootNode = $currentRootNode.prevArg()).getArgValue();
                        initializer =
                            SCJavaDefn.createInvocation(
                                new Assignment(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.createInvocation(LOCALVAR_CURRENT_ROOT_NODE, SCJavaDefn.PREVARG)),
                                SCJavaDefn.GETARGVALUE);
                    }

                    final LocalVariableDeclaration argDeclaration =
                        new LocalVariableDeclaration((LocalVariable)arguments[i], initializer, !fieldStrictness[i]);

                    javaMethod.addStatement(argDeclaration);
                }

                // Get arg types - all RTValues.
View Full Code Here

                   //        }
                   //        return field;
                   //}
                   String localName = javaFieldNames[i]+"$";
                   LocalVariable localVariable = new LocalVariable(localName, JavaTypeNames.RTVALUE);
                   LocalVariableDeclaration localDeclaration = new LocalVariableDeclaration(localVariable);
                   javaMethod.addStatement(localDeclaration);
                   Assignment localAssignment = new Assignment(localVariable, field);
                   InstanceOf checkType = new InstanceOf(localAssignment, JavaTypeNames.RTRESULT_FUNCTION);
                   MethodInvocation getValue = new MethodInvocation.Instance(localVariable, "getValue", JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
                   Assignment fieldAssignment = new Assignment(field, getValue);
View Full Code Here

                    LocalVariable letNameVariable = new LocalVariable(javaName, JavaTypeNames.RTINDIRECTION);

                    // RTValue javaName = new RTIndirection();
                    JavaExpression newIndirection = new ClassInstanceCreationExpression(JavaTypeNames.RTINDIRECTION);
                    LocalVariableDeclaration letDecl = new LocalVariableDeclaration(letNameVariable, newIndirection);
                    declarationBlock.addStatement(letDecl);

                    // Emit let variable definition.
                    // letName.setResult(letDef);
                    MethodInvocation letInvocation = createInvocation(letNameVariable, SETRESULT, boxedVarDef);
                    definitionBlock.addStatement(new ExpressionStatement(letInvocation));
                } else
                if (info instanceof VarInfo.LetNonRec) {
                    // This variable is referenced multiple times.
                    // We need to declare/initialize a local java variable.

                    // If the variable is already evaluated we behave differently.
                    if (info.isEvaluated()) {
                        if (info.getUnboxedType() != null) {
                            // The definition function will return an unboxed value.
                            // Declare an unboxed local variable.
                            LocalVariable unboxedLocal = new LocalVariable(info.getJavaName()+"$U", info.getUnboxedType());
                            LocalVariableDeclaration unboxedVarDecl = new LocalVariableDeclaration(unboxedLocal, ((VarInfo.LetNonRec)info).getUnboxedVarDef());
                            declarationBlock.addStatement(unboxedVarDecl);

                        } else {
                            // All references will be boxed.
                            // Declare a boxed local variable an update the strict/lazy refs.
                            // We use the strict variable def since we know this variable is already evaluated.
                            LocalVariable boxedLocal = new LocalVariable(info.getJavaName(), JavaTypeNames.RTVALUE);
                            LocalVariableDeclaration boxedVarDecl = new LocalVariableDeclaration(boxedLocal, ((VarInfo.LetNonRec)info).getStrictVarDef());
                            declarationBlock.addStatement(boxedVarDecl);
                        }
                    } else {
                        // The variable is not pre-evaluated.
                        // The variable is referenced more than once.
                        // We want to use the lazy initializer.
                        LocalVariable boxedLocal = new LocalVariable(info.getJavaName(), JavaTypeNames.RTVALUE);
                        LocalVariableDeclaration boxedVarDecl = new LocalVariableDeclaration(boxedLocal, ((VarInfo.LetNonRec)info).getLazyVarDef());
                        declarationBlock.addStatement(boxedVarDecl);
                    }

                } else
                if (info instanceof VarInfo.DCMember){
                    // The DCMember instance of VarInfo will only have one
                    // varDef defined.  i.e. unboxed or strict or lazy.
                    JavaExpression unboxedVarDef = ((VarInfo.DCMember)info).getUnboxedVarDef();
                    JavaExpression lazyVarDef = ((VarInfo.DCMember)info).getLazyVarDef();
                    JavaExpression strictVarDef = ((VarInfo.DCMember)info).getStrictVarDef();

                    if (unboxedVarDef != null) {
                        // Base declarations on unboxed definition.
                        // Declare a local unboxed variable and update the unboxed reference.
                        LocalVariable unboxedLocal = new LocalVariable(javaName+"$U", info.getUnboxedType());
                        LocalVariableDeclaration letDecl = new LocalVariableDeclaration(unboxedLocal, unboxedVarDef);
                        declarationBlock.addStatement(letDecl);
                    } else
                    if (strictVarDef != null) {
                        // If there is a strict variable definition we should never have unboxed use.
                        // Since a strict variable of an unboxable type would have an unboxed variable definition.
                        // Declare a boxed local and update the strict and lazy references.
                        LocalVariable boxedLocal = new LocalVariable (javaName, JavaTypeNames.RTVALUE);
                        LocalVariableDeclaration boxedDecl = new LocalVariableDeclaration (boxedLocal, strictVarDef);
                        declarationBlock.addStatement(boxedDecl);
                        info.updateStrictReference(boxedLocal);
                        info.updateLazyReference(boxedLocal);
                    } else {
                        // Lazy variable.
                        // Declare a lazy local variable.
                        LocalVariable lazyLocal = new LocalVariable(info.getJavaName(), JavaTypeNames.RTVALUE);
                        LocalVariableDeclaration lazyDecl = new LocalVariableDeclaration(lazyLocal, lazyVarDef);
                        declarationBlock.addStatement(lazyDecl);
                    }
                }
            }
View Full Code Here

TOP

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

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.