Search in sources :

Example 6 with Def_Timer

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer in project titan.EclipsePlug-ins by eclipse.

the class Def_Function_Writer method writeDefinitionStatement.

// updated
public void writeDefinitionStatement(Definition_Statement tc_defStatement) {
    defCounter++;
    if (tc_defStatement.getDefinition() instanceof Def_Timer) {
        Def_Timer def_Timer = (Def_Timer) tc_defStatement.getDefinition();
        functionString.append("rownum=" + def_Timer.getLocation().getLine() + ";\r\n");
        functionString.append("Timer " + def_Timer.getIdentifier().toString() + " = new Timer(" + functionVarValues.get(defCounter) + ");\r\n");
        functionString.append("TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timer " + def_Timer.getIdentifier().toString() + " set to " + functionVarValues.get(defCounter) + ".\", false);" + "\r\n");
    } else if (functionVarTypes.get(defCounter).equals("BITSTRING")) {
        functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (functionVarIsConstant.get(defCounter)) {
            functionString.append("final ");
        }
        if (functionVarValues.get(defCounter) == null) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BITSTRING();\r\n");
        } else if (functionValueIsAValueReference.get(defCounter)) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
        } else {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BITSTRING(\"" + functionVarValues.get(defCounter) + "\");\r\n");
        }
    // TODO: add logging here
    } else if (functionVarTypes.get(defCounter).equals("INTEGER")) {
        functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (functionVarIsConstant.get(defCounter)) {
            functionString.append("final ");
        }
        if (functionVarValues.get(defCounter) == null) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new INTEGER();\r\n");
        } else if (functionValueIsAValueReference.get(defCounter)) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
        } else {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new INTEGER(\"" + functionVarValues.get(defCounter) + "\");\r\n");
        }
    // TODO: add logging here
    } else if (functionVarTypes.get(defCounter).equals("CHARSTRING")) {
        functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (functionVarIsConstant.get(defCounter)) {
            functionString.append("final ");
        }
        if (functionVarValues.get(defCounter) == null) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new CHARSTRING();\r\n");
        } else if (functionValueIsAValueReference.get(defCounter)) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
        } else {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new CHARSTRING(\"" + functionVarValues.get(defCounter) + "\");\r\n");
        }
    // TODO: add logging here
    } else if (functionVarTypes.get(defCounter).equals("BOOLEAN")) {
        functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (functionVarIsConstant.get(defCounter)) {
            functionString.append("final ");
        }
        if (functionVarValues.get(defCounter) == null) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=new BOOLEAN();\r\n");
        } else if (functionValueIsAValueReference.get(defCounter)) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "=" + functionVarValues.get(defCounter) + ";\r\n");
        } else {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + " = BOOLEAN.valueOf(" + functionVarValues.get(defCounter) + ");\r\n");
        }
    // TODO: add logging here
    } else if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(functionVarTypes.get(defCounter))) {
        functionString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (functionVarValues.get(defCounter) != null) {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + "= new " + functionVarTypes.get(defCounter) + "(" + functionVarValues.get(defCounter) + ")" + ";\r\n");
        } else {
            functionString.append(functionVarTypes.get(defCounter) + " " + functionVars.get(defCounter) + ";\r\n");
        }
    }
}
Also used : Def_Timer(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer)

Example 7 with Def_Timer

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer in project titan.EclipsePlug-ins by eclipse.

the class Def_Testcase_Writer method writeDefinitionStatement.

public void writeDefinitionStatement(Definition_Statement tc_defStatement) {
    if (tc_defStatement.getDefinition() instanceof Def_Timer) {
        Def_Timer def_Timer = (Def_Timer) tc_defStatement.getDefinition();
        testCaseString.append("rownum=" + def_Timer.getLocation().getLine() + ";\r\n");
        testCaseString.append("Timer " + def_Timer.getIdentifier().toString() + " = new Timer(" + tcVarValues.get(defCounter) + ");\r\n");
        testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timer " + def_Timer.getIdentifier().toString() + " set to " + tcVarValues.get(defCounter) + ".\", false);" + "\r\n");
    } else if (tcVarTypes.get(defCounter).equals("BITSTRING")) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BITSTRING();\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BITSTRING(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
        // TODO: add logging here
        }
    } else if (tcVarTypes.get(defCounter).equals("INTEGER")) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new INTEGER();\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new INTEGER(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
        // TODO: add logging here
        }
    } else if (tcVarTypes.get(defCounter).equals("CHARSTRING")) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new CHARSTRING();\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new CHARSTRING(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
        // TODO: add logging here
        }
    } else if (tcVarTypes.get(defCounter).equals("OCTETSTRING")) {
        testCaseString.append("rownum = ").append(tc_defStatement.getLocation().getLine()).append(";").append("\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new OCTETSTRING();\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new OCTETSTRING(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
        // TODO: add logging here
        }
    } else if (tcVarTypes.get(defCounter).equals("BOOLEAN")) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BOOLEAN();\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new BOOLEAN(" + tcVarValues.get(defValueCounter) + ");\r\n");
        // TODO: add logging here
        }
    } else if (tcVarTypes.get(defCounter).equals("FLOAT")) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new FLOAT();\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=new FLOAT(" + tcVarValues.get(defValueCounter) + ");\r\n");
        // TODO: add logging here
        }
    } else if (nodeVarIsRecord.get(defCounter)) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "= new " + tcVarTypes.get(defCounter) + "();\r\n");
        int childSize = myASTVisitor.nodeNameChildrenNamesHashMap.get(tcVarTypes.get(defCounter)).length;
        for (int i = 0; i < childSize; i++) {
            String childType = myASTVisitor.nodeNameChildrenTypesHashMap.get(tcVarTypes.get(defCounter))[i];
            String childName = myASTVisitor.nodeNameChildrenNamesHashMap.get(tcVarTypes.get(defCounter))[i];
            testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
            writeRecordChildren(childType, childName);
            if (i + 1 < childSize) {
                defValueCounter++;
            }
        }
    } else if (tcValueTypeIsAReference.get(defCounter)) {
        testCaseString.append("rownum=" + tc_defStatement.getLocation().getLine() + ";\r\n");
        if (tcVarIsConstant.get(defCounter)) {
            testCaseString.append("final ");
        }
        if (tcVarIsTemplate.get(defCounter)) {
            testCaseString.append("template ");
        }
        if (tcVarValues.get(defValueCounter) == null) {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + ";\r\n");
        // TODO: add logging here
        } else if (tcValueIsAValueReference.get(defCounter)) {
            if (myASTVisitor.nodeNameNodeTypeHashMap.containsKey(tcVarTypes.get(defCounter))) {
                if (myASTVisitor.nodeNameNodeTypeHashMap.get(tcVarTypes.get(defCounter)).equals("enum")) {
                    testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "= new " + tcVarTypes.get(defCounter) + "(\"" + tcVarValues.get(defValueCounter) + "\");\r\n");
                }
            } else {
                testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
            }
        // TODO: add logging here
        } else {
            testCaseString.append(tcVarTypes.get(defCounter) + " " + tcVars.get(defCounter) + "=" + tcVarValues.get(defValueCounter) + ";\r\n");
        // TODO: add logging here
        }
    }
}
Also used : Def_Timer(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer)

Example 8 with Def_Timer

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer in project titan.EclipsePlug-ins by eclipse.

the class Def_Timer method generateCodeInitComp.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInitComp(final JavaGenData aData, final StringBuilder initComp, final Definition definition) {
    if (defaultDuration == null) {
        return;
    }
    if (!(definition instanceof Def_Timer)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    final Def_Timer baseTimerDefinition = (Def_Timer) definition;
    if (baseTimerDefinition.defaultDuration == null) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    // constants in both timers
    if (defaultDuration.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || baseTimerDefinition.defaultDuration.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || defaultDuration.checkEquality(CompilationTimeStamp.getBaseTimestamp(), baseTimerDefinition.defaultDuration)) {
        if (dimensions == null) {
            final ExpressionStruct expression = new ExpressionStruct();
            expression.expression.append(baseTimerDefinition.getGenNameFromScope(aData, initComp, myScope, ""));
            expression.expression.append(".setDefaultDuration(");
            defaultDuration.generateCodeExpression(aData, expression, true);
            expression.expression.append(')');
            expression.mergeExpression(initComp);
        } else {
            generateCodeArrayDuration(aData, initComp, baseTimerDefinition.getGenNameFromScope(aData, initComp, myScope, ""), new ArrayList<String>(), baseTimerDefinition.defaultDuration, 0);
        }
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 9 with Def_Timer

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer in project titan.EclipsePlug-ins by eclipse.

the class TimerReadExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
            {
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
                }
                break;
            }
        case A_PAR_TIMER:
            if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
            }
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR2, assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, true, false);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)6 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)5 Def_Timer (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer)4 IType (org.eclipse.titan.designer.AST.IType)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IValue (org.eclipse.titan.designer.AST.IValue)2 Reference (org.eclipse.titan.designer.AST.Reference)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)2 Value_Assignment (org.eclipse.titan.designer.AST.ASN1.Value_Assignment)1 Assignment_type (org.eclipse.titan.designer.AST.Assignment.Assignment_type)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)1 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)1 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)1 Array_Value (org.eclipse.titan.designer.AST.TTCN3.values.Array_Value)1 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)1 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)1 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)1