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

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


               
                for (int i = 0, n = typeConstructorInfo.typeConstructor.getNDataConstructors(); i < n; ++i) {
                    DataConstructor dc = typeConstructorInfo.typeConstructor.getNthDataConstructor(i);
                   
                    String enumFieldName = createEnumFieldName(dc.getName().getUnqualifiedName());
                    JavaField field = new JavaField.Static(dataType_TypeName, enumFieldName, dataType_TypeName);
                   
                    JavaStatement.SwitchStatement.IntCaseGroup intCase =
                        new SwitchStatement.IntCaseGroup(
                                dc.getOrdinal(),
                                new ReturnStatement(field));
View Full Code Here


   
            // Create the method.
            JavaMethod javaMethod = new JavaMethod(modifiers, fieldType, methodName);
   
            if (implementAtThisLevel) {
                JavaField field = new JavaField.Instance (null, fieldName, fieldType);
                javaMethod.addStatement(new ReturnStatement(field));
            } else {
                // This class should throw an error for any access.  The methods will
                // be overridden by derived classes for each data constructor.
                JavaExpression getDCName =
View Full Code Here

                new JavaMethod (
                        Modifier.PUBLIC | Modifier.FINAL,
                        JavaTypeName.INT,
                        "hashCode");
           
            JavaField hashCodeField =
                new JavaField.Instance (
                        null,
                        HASH_CODE_FIELD_NAME,
                        JavaTypeName.INT);
           
            JavaExpression condition =
                new OperatorExpression.Binary (
                        JavaOperator.EQUALS_INT,
                        hashCodeField,
                        LiteralWrapper.make(new Integer(0)));
           
            JavaStatement.Block thenBlock = new JavaStatement.Block();
           
            IfThenElseStatement ifThen =
                new IfThenElseStatement (condition, thenBlock);
           
            hashCode.addStatement (ifThen);
           
            // build up the hashcode value.
            JavaExpression.LocalVariable result =
                new LocalVariable ("result", JavaTypeName.INT);
            LocalVariableDeclaration localVarDecl =
                new LocalVariableDeclaration(result, LiteralWrapper.make(new Integer(17)));
            thenBlock.addStatement(localVarDecl);
           
            LiteralWrapper thirtySeven = LiteralWrapper.make (new Integer(37));
            JavaExpression thirtySevenTimesResult =
                new OperatorExpression.Binary(JavaOperator.MULTIPLY_INT, thirtySeven, result);

            LiteralWrapper zero = LiteralWrapper.make (new Integer (0));
            LiteralWrapper one  = LiteralWrapper.make (new Integer (1));

            // Start by including dc name in the hashcode.
            // get objects hashcode
            JavaExpression nameExpression =
                new MethodInvocation.Instance (
                        new MethodInvocation.Instance(
                                null,
                                GET_DC_NAME_METHOD_NAME,
                                JavaTypeName.STRING,
                                MethodInvocation.InvocationType.VIRTUAL),
                        "hashCode",
                        JavaTypeName.INT,
                        MethodInvocation.InvocationType.VIRTUAL);

            JavaExpression newResult =
                new OperatorExpression.Binary (JavaOperator.ADD_INT, thirtySevenTimesResult, nameExpression);
            JavaExpression assignResult = new Assignment (result, newResult);
            thenBlock.addStatement(new ExpressionStatement (assignResult));
           
            // Now get the contribution from each dc field.
            for (FieldName fn : fieldNames) {
                String javaFieldName = typeConstructorInfo.fieldJavaNames.get (fn);
                JavaTypeName fieldType = fieldNameToType.get (fn);
                JavaField field = new JavaField.Instance(null, javaFieldName, fieldType);
               
                JavaExpression fieldExpression;
                if (fieldType instanceof JavaTypeName.Primitive) {
                    if (fieldType instanceof JavaTypeName.Primitive.Boolean) {
                        fieldExpression =
View Full Code Here

                        JavaTypeName.OBJECT,
                        false,
                        "equals");

            MethodVariable objectArg = new MethodVariable (argName);
            JavaField thisField = new JavaField.This(typeName);
           
            // if (object == this) {
            //     return true;
            // }
            JavaExpression condition =
View Full Code Here

            bindingMethod.setJavaDocComment(funcComment);
           
            // Build up the body of the method.
           
            // We want to us the QualifiedName field.
            JavaField nameField = new JavaField.Static(functionsClassTypeName, javaFuncName, QUALIFIED_NAME_TYPE_NAME);
           
            // Create an instance of SourceModel.Expr.Var for the CAL function.
            JavaExpression sourceModelVarCreation =
                new MethodInvocation.Static(
                        SOURCE_MODEL_EXPR_VAR_TYPE_NAME,
View Full Code Here

                bindingFunction.setJavaDocComment(funcComment);
               
                // Now we need to fill in the body.
               
                // Create an instance of SourceModel.Expr.DataCons for the data constructor.
                JavaField nameField = new JavaField.Static(dataConstructorsClassTypeName, javaFuncName, QUALIFIED_NAME_TYPE_NAME);
                JavaExpression sourceModelDataConsCreation =
                    new MethodInvocation.Static(
                            SOURCE_MODEL_EXPR_DATA_CONS_TYPE_NAME,
                            "make",
                            nameField,
View Full Code Here

            SwitchStatement ordSwitch = new SwitchStatement(METHODVAR_ORDINAL);
            for (final DataConstructor dc : dataConsList) {
                if (dc.getArity() == 0) {
                    // Return the static TagDC instance for this ordinal.
                    String fieldName = CALToJavaNames.fixupVarName(dc.getName().getUnqualifiedName());
                    JavaField field = new JavaField.Static(className, fieldName, tagDCTypeName);
                    SwitchStatement.SwitchCase sc = new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement(field));
                    ordSwitch.addCase(sc);
                } else {
                    // This is a valid ordinal for the data type but does not correspond to a zero arity DC.
                    LiteralWrapper badValueMessageWrapper = LiteralWrapper.make ("Attempt to treat " + dc.getName() + " as a zero arity data constructor.");
View Full Code Here

            String methodName = "get" + fieldName;
            JavaMethod javaMethod = new JavaMethod(modifiers, JavaTypeNames.RTVALUE, methodName);
            javaClassRep.addMethod(javaMethod);

            if (implementAtThisLevel) {
                JavaField field = new JavaField.Instance (null, fieldName, fieldType);
                if (primitiveType) {
                    javaMethod.addStatement(new ReturnStatement(SCJavaDefn.boxExpression(fieldTypeExpr, field)));
                } else {
                    if (!fieldIsStrict) {
                        // We have a non-strict field of type RTValue.  In order to reduce space usage
View Full Code Here

            javaMethod.addThrows(JavaTypeName.CAL_EXECUTOR_EXCEPTION);

            javaClassRep.addMethod(javaMethod);

            if (implementAtThisLevel && isStrict) {
                JavaField field = new JavaField.Instance (null, fieldName, fieldType);
                javaMethod.addStatement(new ReturnStatement (field));
            } else {
                // This class should throw an error for any access.  The methods will
                // be overridden by derived classes for each data constructor.
                // We want to call the RTCons method badFieldAccessor_...
View Full Code Here

            //    }
            //}

            JavaMethod method = new JavaMethod (Modifier.PUBLIC | Modifier.FINAL, JavaTypeName.STRING, "debug_getNodeStartText");

            JavaField resultField = new JavaField.Instance(null, "result", JavaTypeNames.RTVALUE);
            JavaExpression conditionExpr =
                new JavaExpression.OperatorExpression.Binary(
                    JavaOperator.NOT_EQUALS_OBJECT,
                    resultField,
                    LiteralWrapper.NULL)
View Full Code Here

TOP

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

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.