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

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


            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "getOrdinalValue");
            javaClassRep.addMethod(javaMethod);

            // Add the body..
            // return (ordinal);
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(Integer.valueOf(dc.getOrdinal()))));
        }
View Full Code Here


            // Add the body..
            // The no argument version of make should only be called for an instance to
            // be used as a supercombinator so we can return the singleton instance.
            JavaField selfField = new JavaField.Static(className, instanceName, className);
            javaMethod.addStatement(new ReturnStatement(selfField));

        }
View Full Code Here

                }

                // return new ThisClass($arg0, $arg1, ...);
                final JavaExpression cice = new ClassInstanceCreationExpression(className, arguments, argTypes);

                javaMethod.addStatement(new ReturnStatement(cice));
            } else {
                // return new ThisClass();
                final JavaExpression cice = new ClassInstanceCreationExpression(className, JavaExpression.LiteralWrapper.NULL, JavaTypeNames.RTEXECUTION_CONTEXT);
                javaMethod.addStatement(new ReturnStatement(cice));
            }
        }
View Full Code Here

                }
            }

            JavaExpression cc = new ClassInstanceCreationExpression (className, constructorArgs, constructorArgTypes);

            javaMethod.addStatement(new ReturnStatement(cc));
        }
View Full Code Here

            JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "isLogicalTrue");
            javaClassRep.addMethod(javaMethod);

            // Add the body..
            // return false;
            javaMethod.addStatement(new ReturnStatement(LiteralWrapper.FALSE));
        }
View Full Code Here

            // return a boxed version of the field.
            JavaExpression jf;
            if (fieldStrictness[i] && SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
                jf = new JavaField.Instance (null, javaFieldNames[i], SCJavaDefn.typeExprToTypeName(fieldTypes[i]));
                jf = SCJavaDefn.boxExpression(fieldTypes[i], jf);
                javaMethod.addStatement(new ReturnStatement(jf));
            } else {
                JavaField field = new JavaField.Instance (null, javaFieldNames[i], JavaTypeNames.RTVALUE);
                jf = field;
               if (!fieldStrictness[i]) {
                   // We have a non-strict field of type RTValue.  In order to reduce space usage
                   // we want to update the field value to be the result of the original suspension.
                   // If the field value is an RTResultFunction we want to re-assign the field with
                   // a call to 'getValue()'.
                   // For example:
                   //public final RTValue get_head() {
                   //    RTValue field;
                   //        if ((field = _head) instanceof RTResultFunction) {
                   //            return (_head = field.getValue());
                   //        }
                   //        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);
                   ReturnStatement returnNewVal = new ReturnStatement(fieldAssignment);
                   IfThenElseStatement ifThen = new IfThenElseStatement(checkType, returnNewVal);
                   javaMethod.addStatement(ifThen);
                   javaMethod.addStatement(new ReturnStatement (localVariable));

               } else {
                   // The field is strict and therefore already in WHNF.
                   javaMethod.addStatement(new ReturnStatement(jf));
               }

            }

            // If the field type is primitive and strict we want to generate
            // a method that retrieves the field as an unboxed value.
            if (SCJavaDefn.canTypeBeUnboxed(fieldTypes[i]) && dc.isArgStrict((i))) {

                returnType = SCJavaDefn.typeExprToTypeName(fieldTypes[i]);
                methodName = methodName + "_As_" + SCJavaDefn.getNameForPrimitive(returnType);

                // If all the fields with this name/type combination across all DCs are strict we
                // don't need an RTExecutionContext passed to the getter.
                javaMethod = new JavaMethod (modifiers, returnType, methodName);
                javaClassRep.addMethod(javaMethod);

                // Add the throws declaration
                javaMethod.addThrows(JavaTypeName.CAL_EXECUTOR_EXCEPTION);

                if (fieldStrictness[i]) {
                    jf = new JavaField.Instance (null, javaFieldNames[i], returnType);
                } else {
                    // This is an error.  We should only get to this point if all
                    // instances of this field/type are strict across all DCs.
                    throw new CodeGenerationException ("Attempt to generate unboxed accessor on lazy field " + javaFieldNames[i] + " for DC " + dc.getName());
                }
                javaMethod.addStatement(new ReturnStatement(jf));

            }
        }
View Full Code Here

                    if (forType != null) {
                        jf = SCJavaDefn.unboxValue(forType, jf);
                    }
                }

                SwitchStatement.IntCaseGroup iCase = new SwitchStatement.IntCaseGroup(i, new ReturnStatement (jf));
                sw.addCase(iCase);
                nReturnedFields++;

            }
View Full Code Here

            }

        }

        private final ReturnStatement makeDefaultValReturnStatement (JavaTypeName forType) {
            return new ReturnStatement(JavaDefinitionBuilder.getDefaultValueForType(forType));
        }
View Full Code Here

         */
        private void createMethod_getModuleName () {
            JavaMethod javaMethod = new JavaMethod (Modifier.PUBLIC | Modifier.FINAL, JavaTypeName.STRING, "getModuleName");
            javaClassRep.addMethod (javaMethod);

            javaMethod.addStatement (new ReturnStatement (LiteralWrapper.make (dc.getName().getModuleName().toSourceText())));
        }
View Full Code Here

         */
        private void createMethod_getUnqualifiedName () {
            JavaMethod javaMethod = new JavaMethod (Modifier.PUBLIC | Modifier.FINAL, JavaTypeName.STRING, "getUnqualifiedName");
            javaClassRep.addMethod (javaMethod);

            javaMethod.addStatement (new ReturnStatement (LiteralWrapper.make (dc.getName().getUnqualifiedName())));
        }
View Full Code Here

TOP

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

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.