Search in sources :

Example 1 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Def_AltStatement_Writer method writeTestCaseAltStatement.

public void writeTestCaseAltStatement(Alt_Statement altStatement) {
    AltGuards currentAltGuards = altStatement.getAltGuards();
    String[] negativeConditions = new String[currentAltGuards.getNofAltguards()];
    String[] positiveConditions = new String[currentAltGuards.getNofAltguards()];
    // initialize values
    for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) {
        AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i);
        if (currentAltGuard instanceof Operation_Altguard) {
            Statement currentStatement = ((Operation_Altguard) currentAltGuard).getGuardStatement();
            if (currentStatement instanceof Receive_Port_Statement) {
                altReceiveCounter++;
                if (altGuardConditions.get(i) != null) {
                    // alt guard present && any port receive
                    if (altGuardPortReference.get(altReceiveCounter).equals("any port")) {
                        positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + "anyPortReceive(true))";
                        negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + "anyPortReceive(false))";
                    } else {
                        // alt guard present && normal port receive
                        positiveConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",true)!=null)";
                        negativeConditions[i] = altGuardConditions.get(altReceiveCounter) + ".getValue()" + "&&(" + altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",false)!=null)";
                        if (altGuardReceiveValue.get(altReceiveCounter).startsWith("Templates")) {
                            altGuardReceiveType.set(altReceiveCounter, "Templates");
                        }
                    }
                } else {
                    // no alt guard && any port recieve
                    if (altGuardPortReference.get(altReceiveCounter).equals("any port")) {
                        positiveConditions[i] = "anyPortReceive(true)";
                        negativeConditions[i] = "anyPortReceive(false)";
                    } else {
                        // no alt guard && no receive parameter
                        if (altGuardReceiveType.get(altReceiveCounter).equals("noparam")) {
                            positiveConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(true)!=null";
                            negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(false)!=null";
                        } else if (// no alt guard && typed port recieve
                        altGuardReceiveType.get(altReceiveCounter).equals("_TYPED_PARAM_")) {
                            negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive_" + altGuardReceiveValue.get(altReceiveCounter) + "(false)!=null";
                            if (altGuardReceiveAnyValValue.get(altReceiveCounter) != null) {
                                positiveConditions[i] = "(" + altGuardReceiveAnyValValue.get(altReceiveCounter) + "=" + altGuardPortReference.get(altReceiveCounter) + ".receive_" + altGuardReceiveValue.get(altReceiveCounter) + "(true))!=null";
                            } else {
                            }
                        } else {
                            // no alt guard && normal port recieve
                            positiveConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",true)!=null";
                            negativeConditions[i] = altGuardPortReference.get(altReceiveCounter) + ".receive(" + altGuardReceiveValue.get(altReceiveCounter) + ",false)!=null";
                        }
                        if (altGuardReceiveValue.get(altReceiveCounter) != null && altGuardReceiveValue.get(altReceiveCounter).startsWith("Templates")) {
                            altGuardReceiveType.set(altReceiveCounter, "Templates");
                        }
                    }
                }
            }
            if (currentStatement instanceof Timeout_Statement) {
                timeOutCounter++;
                if (altGuardConditions.get(i) != null) {
                    positiveConditions[i] = altGuardConditions.get(i) + "&&(" + altGuardTimeout.get(timeOutCounter) + ".timeout()";
                    negativeConditions[i] = altGuardConditions.get(i) + "&&(!" + altGuardTimeout.get(i) + ".timeout()";
                } else {
                    positiveConditions[i] = altGuardTimeout.get(timeOutCounter) + ".timeout()";
                    negativeConditions[i] = "!" + altGuardTimeout.get(timeOutCounter) + ".timeout()";
                }
            }
        }
    }
    // write
    altString.append("rownum=" + altStatement.getLocation().getLine() + ";\r\n");
    altString.append("for(;;){" + "\r\n");
    altString.append("if(!(");
    for (int j = 0; j < negativeConditions.length; j++) {
        altString.append(negativeConditions[j]);
        if (j + 1 < negativeConditions.length) {
            altString.append("||");
        }
    }
    altString.append(")){" + "\r\n");
    // timer
    if (isThereAStartedTimer) {
        altString.append("long timeout = -1;" + "\r\n");
        altString.append("long newtimeout;" + "\r\n");
        altString.append("if(" + currentTimerName + ".running)if((newtimeout=(long)(" + currentTimerName + ".read().value*1000.0))<timeout || timeout == -1) timeout=newtimeout;" + "\r\n");
        altString.append("if(timeout>0) try{queue.poll(timeout,TimeUnit.MILLISECONDS);}catch(InterruptedException e){} " + "\r\n");
    } else {
        altString.append("try{queue.take();}catch(InterruptedException e){}" + "\r\n");
    }
    // endoftimer
    altString.append("}" + "\r\n");
    altString.append("this.lock();" + "\r\n");
    // ifwriter
    altReceiveCounter = -1;
    boolean isFirstIf = true;
    for (int i = 0; i < currentAltGuards.getNofAltguards(); i++) {
        AltGuard currentAltGuard = currentAltGuards.getAltguardByIndex(i);
        if (currentAltGuard instanceof Operation_Altguard) {
            Statement currentStatement = ((Operation_Altguard) currentAltGuard).getGuardStatement();
            StatementBlock currentStatementBlock = ((Operation_Altguard) currentAltGuard).getStatementBlock();
            if (isFirstIf) {
                altString.append("if(" + positiveConditions[i] + "){\r\n");
                isFirstIf = false;
            } else {
                altString.append("else if(" + positiveConditions[i] + "){\r\n");
            }
            if (currentStatement instanceof Receive_Port_Statement) {
                altReceiveCounter++;
                altString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n");
                if (altGuardReceiveType.get(altReceiveCounter).equals("noparam")) {
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + "\", true);" + "\r\n");
                } else if (altGuardReceiveType.get(altReceiveCounter).equals("Templates")) {
                    String methodName = altGuardReceiveValue.get(altReceiveCounter);
                    if (methodName.endsWith("()") && methodName.startsWith("Templates.")) {
                        methodName = (String) methodName.subSequence(10, methodName.length() - 2);
                    }
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ":\\n " + methodName + ":=\" + " + altGuardReceiveValue.get(altReceiveCounter) + ".toString(), true);" + "\r\n");
                } else if (altGuardReceiveType.get(altReceiveCounter).equals("any port")) {
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port any port\", true);" + "\r\n");
                } else if (altGuardReceiveType.get(altReceiveCounter).equals("_TYPED_PARAM_")) {
                    altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ": type " + altGuardReceiveValue.get(altReceiveCounter) + "\", true);" + "\r\n");
                } else {
                    if (altGuardReceiveValue.get(altReceiveCounter) != null) {
                        altString.append("	TTCN3Logger.writeLog(compid, \"PORTEVENT\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"RECEIVE event on port " + altGuardPortReference.get(altReceiveCounter) + ":\" + " + altGuardReceiveValue.get(altReceiveCounter) + ".toString(), true);" + "\r\n");
                    }
                }
            } else if (currentStatement instanceof Timeout_Statement) {
                altString.append("rownum=" + currentStatement.getLocation().getLine() + ";\r\n" + "TTCN3Logger.writeLog(compid, \"TIMEROP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"Timeout on timer " + currentTimerName + ".\", false);" + "\r\n");
            }
            boolean isThereARepeatStatement = false;
            for (int j = 0; j < currentStatementBlock.getSize(); j++) {
                Statement currentStatementBlockStatement = currentStatementBlock.getStatementByIndex(j);
                if (currentStatementBlockStatement instanceof Setverdict_Statement) {
                    Setverdict_Statement setVerdictStatement = (Setverdict_Statement) currentStatementBlockStatement;
                    String verdict = "";
                    if (setVerdictStatement.getVerdictValue() instanceof Verdict_Value) {
                        Verdict_Value verdictValue = (Verdict_Value) setVerdictStatement.getVerdictValue();
                        if (verdictValue.getValue().toString().equals("PASS")) {
                            verdict = "pass";
                        } else if (verdictValue.getValue().toString().equals("INCONC")) {
                            verdict = "inconc";
                        } else {
                            verdict = "fail";
                        }
                    }
                    altString.append("rownum=" + setVerdictStatement.getLocation().getLine() + ";\r\n");
                    altString.append("TTCN3Logger.writeLog(compid, \"VERDICTOP\", sourcefilename, rownum, \"function\", \"" + nodeName + "\", \"setverdict(" + verdict + "): \" + getVerdict() + \" -> " + verdict + "\", true);" + "\r\n");
                    altString.append("setVerdict(\"" + verdict + "\");" + "\r\n");
                }
                if (currentStatementBlockStatement instanceof Assignment_Statement) {
                    if (isFunction) {
                        functionParent.assignCounter++;
                        altString.append(functionParent.writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement));
                        String test = "";
                        test.toString();
                    } else if (isTestCase) {
                        testcaseParent.assignCounter++;
                        altString.append(testcaseParent.writeAssignmentStatement((Assignment_Statement) currentStatementBlockStatement));
                    }
                }
                if (currentStatementBlockStatement instanceof Send_Statement) {
                    if (isFunction) {
                        functionParent.sendCounter++;
                        altString.append(functionParent.writeSendStatement((Send_Statement) currentStatementBlockStatement));
                    } else if (isTestCase) {
                        testcaseParent.sendCounter++;
                        altString.append(testcaseParent.writeSendStatement((Send_Statement) currentStatementBlockStatement));
                    }
                }
                if (currentStatementBlockStatement instanceof Repeat_Statement) {
                    isThereARepeatStatement = true;
                }
            }
            if (isThereARepeatStatement) {
                isThereARepeatStatement = false;
            } else {
                altString.append("break;\r\n");
            }
            altString.append("}\r\n");
        }
    }
    altString.append("this.unlock();" + "\r\n");
    altString.append("}" + "\r\n");
}
Also used : AltGuard(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Repeat_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Repeat_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) AltGuards(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Repeat_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Repeat_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Timeout_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Timeout_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 2 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class TestCase_Function_Visit_Handler method leave.

public void leave(IVisitableNode node) {
    if (waitForTC || waitForFunction) {
        if (node instanceof Definition_Statement) {
            if (!waitForRecord) {
                nodeVarIsRecord.add(false);
            }
            waitForRecord = false;
            waitForValue = false;
            evaluateExpression();
        }
        if (node instanceof Undefined_LowerIdentifier_Value) {
            blockReferenceListing = false;
        }
        if ((node instanceof Assignment_Statement) || ((node instanceof If_Clause))) {
            waitForValue = false;
            // if assignment is a createExpression
            if (node instanceof Assignment_Statement) {
                if (((Assignment_Statement) node).getTemplate() instanceof SpecificValue_Template) {
                    SpecificValue_Template specValTemplate = (SpecificValue_Template) ((Assignment_Statement) node).getTemplate();
                    if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
                        isCreate = true;
                    }
                }
            }
            evaluateExpression();
        }
        if (node instanceof SequenceOf_Value) {
            evaluateExpression();
        }
        if ((waitForFunction && (node instanceof Return_Statement)) || (waitForTC && (node instanceof ComponentCreateExpression)) || (node instanceof Send_Statement) || (node instanceof Receive_Port_Statement)) {
            evaluateExpression();
        }
        if (waitForTcStartValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
            myASTVisitor.blockIdListing = false;
        }
        if (waitForTcStopValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
            myASTVisitor.blockIdListing = false;
        }
        if (node instanceof Connect_Statement) {
            waitForTcConnectValues = false;
        }
        if (node instanceof Disconnect_Statement) {
            waitForTcDisconnectValues = false;
        }
        if (node instanceof Unknown_Start_Statement) {
            waitForTcStartValues = false;
        }
        if (node instanceof Unknown_Stop_Statement) {
            waitForTcStopValues = false;
        }
        if (node instanceof Definition_Statement) {
            waitForDefStatement = false;
            if (waitForValue) {
                nodeVarValues.add(null);
                nodeVarIsAValueReference.add(false);
                waitForValue = false;
            }
        }
        if (node instanceof Map_Statement) {
            waitForMapIdentifiers = false;
        }
        if (node instanceof ComponentCreateExpression) {
            // switch first two values
            testCaseCreateValues.add(testCaseCreateCharValues.get(0));
            testCaseCreateValues.add(testCaseCreateRefValues.get(0));
            for (int i = 1; i < testCaseCreateCharValues.size(); i++) {
                testCaseCreateValues.add(testCaseCreateCharValues.get(i));
            }
            testCaseCreateCharValues.clear();
            testCaseCreateRefValues.clear();
            waitForTcCreateValues = false;
        }
        if (node instanceof Assignment_Statement) {
            waitForAssignmentIdentifiers = false;
            waitForValue = true;
        }
        if (waitForTcIfCondition && (node instanceof If_Clause)) {
            waitForTcIfCondition = false;
        }
        if (waitForTcStartParameter && (node instanceof Unknown_Start_Statement)) {
            testCaseStartValueParameters.add(null);
        }
        if (waitForTcStopParameter && (node instanceof Unknown_Stop_Statement)) {
            testCaseStopValueParameters.add(null);
        }
        if (isAltGuards && (node instanceof Operation_Altguard)) {
            altGuardConditions.add(null);
        }
        if (node instanceof Operation_Altguard) {
            waitForAltStatements = false;
            isAltGuards = false;
            isReceiveValue = false;
        }
        handleAltCases(node);
        if (node instanceof Unknown_Start_Statement) {
            waitForUnknownStartStatement = false;
        }
        if (node instanceof Unknown_Stop_Statement) {
            waitForUnknownStopStatement = false;
        }
        if (node instanceof Receive_Port_Statement) {
            if (waitForReceiveParameter) {
                altGuardReceiveType.add("noparam");
            }
        // TODO checkAnyport = true;
        }
    }
    if (node instanceof Def_Testcase) {
        handleTestcase(node);
        waitForTC = false;
    }
    if (node instanceof Def_Function) {
        handleFunction(node);
        waitForTC = false;
    }
    if (waitForAssignmentIdentifiers && (node instanceof ArraySubReference)) {
        waitForAssignmentIdentifiers = false;
    }
}
Also used : Connect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement) Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ComponentCreateExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Identifier(org.eclipse.titan.designer.AST.Identifier) Unknown_Stop_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement) Return_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Disconnect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement) Unknown_Start_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement) Map_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 3 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Type method checkThisReferencedValue.

/**
 * Checks the provided referenced value.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the referenced value to be checked.
 * @param lhs
 *                the assignment to check against
 * @param expectedValue
 *                the expectations we have for the value.
 * @param referenceChain
 *                the reference chain to detect circular references.
 * @param strElem
 *                true if the value to be checked is an element of a
 *                string
 * @return true if the value contains a reference to lhs
 */
private boolean checkThisReferencedValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final Expected_Value_type expectedValue, final IReferenceChain referenceChain, final boolean subCheck, final boolean strElem) {
    final Reference reference = ((Referenced_Value) value).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true, referenceChain);
    if (assignment == null) {
        value.setIsErroneous(true);
        return false;
    }
    final Assignment myAssignment = getDefiningAssignment();
    if (myAssignment != null && myAssignment instanceof Definition) {
        final String referingModuleName = value.getMyScope().getModuleScope().getName();
        if (!((Definition) myAssignment).referingHere.contains(referingModuleName)) {
            ((Definition) myAssignment).referingHere.add(referingModuleName);
        }
    }
    assignment.check(timestamp);
    final boolean selfReference = assignment == lhs;
    boolean isConst = false;
    boolean errorFlag = false;
    boolean checkRunsOn = false;
    IType governor = null;
    if (assignment.getIsErroneous()) {
        value.setIsErroneous(true);
    } else {
        switch(assignment.getAssignmentType()) {
            case A_CONST:
                isConst = true;
                break;
            case A_OBJECT:
            case A_OS:
                final ISetting setting = reference.getRefdSetting(timestamp);
                if (setting == null || setting.getIsErroneous(timestamp)) {
                    value.setIsErroneous(true);
                    return selfReference;
                }
                if (!Setting_type.S_V.equals(setting.getSettingtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format("This InformationFromObjects construct does not refer to a value: {0}", value.getFullName()));
                    value.setIsErroneous(true);
                    return selfReference;
                }
                governor = ((Value) setting).getMyGovernor();
                if (governor != null) {
                    isConst = true;
                }
                break;
            case A_EXT_CONST:
            case A_MODULEPAR:
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluatable) constant value was expected instead of {0}", assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_VAR:
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        value.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
                        errorFlag = true;
                        break;
                    case EXPECTED_STATIC_VALUE:
                        value.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
                        errorFlag = true;
                        break;
                    default:
                        break;
                }
                break;
            case A_TEMPLATE:
            case A_MODULEPAR_TEMPLATE:
            case A_VAR_TEMPLATE:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_FUNCTION_RVAL:
                checkRunsOn = true;
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        {
                            final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    case EXPECTED_STATIC_VALUE:
                        {
                            final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case A_EXT_FUNCTION_RVAL:
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        {
                            final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    case EXPECTED_STATIC_VALUE:
                        {
                            final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case A_FUNCTION_RTEMP:
                checkRunsOn = true;
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_EXT_FUNCTION_RTEMP:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_FUNCTION:
            case A_EXT_FUNCTION:
                value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of a call of {1}, which does not have a return type", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
                value.setIsErroneous(true);
                return selfReference;
            default:
                value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
                value.setIsErroneous(true);
                return selfReference;
        }
    }
    if (checkRunsOn) {
        reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
    }
    if (governor == null) {
        final IType type = assignment.getType(timestamp);
        if (type != null) {
            governor = type.getFieldType(timestamp, reference, 1, expectedValue, referenceChain, false);
        }
    }
    if (governor == null) {
        value.setIsErroneous(true);
        return selfReference;
    }
    final TypeCompatibilityInfo info = new TypeCompatibilityInfo(this, governor, true);
    info.setStr1Elem(strElem);
    info.setStr2Elem(reference.refersToStringElement());
    final CompatibilityLevel compatibilityLevel = getCompatibility(timestamp, governor, info, null, null);
    if (compatibilityLevel != CompatibilityLevel.COMPATIBLE) {
        // Port or signature values do not exist at all. These
        // errors are already
        // reported at those definitions. Extra errors should
        // not be reported
        // here.
        final IType type = getTypeRefdLast(timestamp, null);
        switch(type.getTypetype()) {
            case TYPE_PORT:
                // neither port values nor templates exist
                break;
            case TYPE_SIGNATURE:
                if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    final String message = MessageFormat.format("Type mismatch: a signature template of type `{0}'' was expected instead of `{1}''", getTypename(), governor.getTypename());
                    value.getLocation().reportSemanticError(message);
                }
                break;
            case TYPE_SEQUENCE_OF:
            case TYPE_ASN1_SEQUENCE:
            case TYPE_TTCN3_SEQUENCE:
            case TYPE_ARRAY:
            case TYPE_ASN1_SET:
            case TYPE_TTCN3_SET:
            case TYPE_SET_OF:
            case TYPE_ASN1_CHOICE:
            case TYPE_TTCN3_CHOICE:
            case TYPE_ANYTYPE:
                if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
                    value.getLocation().reportSemanticError(info.getSubtypeError());
                } else {
                    value.getLocation().reportSemanticError(info.toString());
                }
                break;
            default:
                if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
                    value.getLocation().reportSemanticError(info.getSubtypeError());
                } else {
                    final String message = MessageFormat.format("Type mismatch: a {0} of type `{1}'' was expected instead of `{2}''", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", getTypename(), governor.getTypename());
                    value.getLocation().reportSemanticError(message);
                }
                break;
        }
        errorFlag = true;
    } else {
        if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
            if (info.getNeedsConversion()) {
                value.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, this.getTypename(), governor.getTypename()));
            }
        }
    }
    if (errorFlag) {
        value.setIsErroneous(true);
        return selfReference;
    }
    // checking for circular references
    final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
    if (isConst && !last.getIsErroneous(timestamp)) {
        if (subCheck && (subType != null)) {
            subType.checkThisValue(timestamp, value);
        }
    }
    return selfReference;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 4 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Value method generateCodeInitMandatory.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateCodeInitMandatory(final JavaGenData aData, final StringBuilder source, final String name) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last == this) {
        final ExpressionStruct expression = new ExpressionStruct();
        expression.expression.append(name);
        expression.expression.append(".assign(");
        reference.generateConstRef(aData, expression);
        generateCodeExpressionOptionalFieldReference(aData, expression, reference);
        expression.expression.append(")");
        expression.mergeExpression(source);
        return source;
    }
    // the code generation is based on the referred value
    if (last.canGenerateSingleExpression() && myScope.getModuleScope() == last.getMyScope().getModuleScope()) {
        // simple substitution for in-line values within the same module
        source.append(MessageFormat.format("{0}.assign({1});\n", name, last.generateSingleExpression(aData)));
    } else {
        // TODO might need initialization see needs_init_precede
        // TODO Value.cc:generate_code_init_refd
        source.append(MessageFormat.format("{0}.assign({1});\n", name, last.getGenNameOwn(myScope)));
    }
    return source;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 5 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Def_Timer method checkArrayDuration.

private void checkArrayDuration(final CompilationTimeStamp timestamp, final IValue duration, final int startDimension) {
    final ArrayDimension dim = dimensions.get(startDimension);
    final boolean arraySizeKnown = !dim.getIsErroneous(timestamp);
    int arraySize = 0;
    if (arraySizeKnown) {
        arraySize = (int) dim.getSize();
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) duration.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (v.getIsErroneous(timestamp)) {
        // error
        return;
    }
    if (v.getValuetype() == Value_type.SEQUENCEOF_VALUE) {
        final SequenceOf_Value value = (SequenceOf_Value) v;
        final int nofComp = value.getNofComponents();
        // Value-list notation.
        if (!value.isIndexed()) {
            if (arraySizeKnown) {
                if (arraySize > nofComp) {
                    duration.getLocation().reportSemanticError("Too few elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
                } else if (arraySize < nofComp) {
                    duration.getLocation().reportSemanticError("Too many elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
                }
            }
            final boolean last_dim = startDimension + 1 >= dimensions.size();
            for (int i = 0; i < nofComp; ++i) {
                final IValue array_v = value.getValueByIndex(i);
                if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                if (last_dim) {
                    checkSingleDuration(timestamp, array_v);
                } else {
                    checkArrayDuration(timestamp, array_v, startDimension + 1);
                }
            }
        } else {
            // Indexed-notation.
            final boolean last_dim = startDimension + 1 >= dimensions.size();
            final Map<Integer, Integer> indexMap = new HashMap<Integer, Integer>();
            for (int i = 0; i < nofComp; ++i) {
                final IValue array_v = value.getValueByIndex(i);
                if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                if (last_dim) {
                    checkSingleDuration(timestamp, array_v);
                } else {
                    checkArrayDuration(timestamp, array_v, startDimension + 1);
                }
                final IValue array_index = value.getIndexByIndex(i);
                dim.checkIndex(timestamp, array_index, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                final IValue tmp = array_index.getValueRefdLast(timestamp, referenceChain);
                if (tmp.getValuetype() == Value_type.INTEGER_VALUE) {
                    final BigInteger index = ((Integer_Value) tmp).getValueValue();
                    if (index.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
                        array_index.getLocation().reportSemanticError(MessageFormat.format("An integer value less than {0} was expected for indexing timer array instead of {1}", Integer.MAX_VALUE, index));
                        array_index.setIsErroneous(true);
                    } else {
                        final int IndexValue = index.intValue();
                        if (indexMap.containsKey(IndexValue)) {
                            array_index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value {0} for timer array elements {1} and {2}", index, i + 1, indexMap.get(IndexValue)));
                            array_index.setIsErroneous(true);
                        } else {
                            indexMap.put(IndexValue, i + 1);
                        }
                    }
                }
            }
            // It's not possible to have "indexMap.size() > arraySize", since we
            // add only correct constant-index values into the map.  It's possible
            // to create partially initialized timer arrays.
            indexMap.clear();
        }
    } else {
        if (arraySizeKnown) {
            duration.getLocation().reportSemanticError("An array value (with " + arraySize + " elements) was expected as default duration of timer array");
        } else {
            duration.getLocation().reportSemanticError("An array value was expected as default duration of timer array");
        }
        duration.setIsErroneous(true);
    }
}
Also used : BigInteger(java.math.BigInteger) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) BigInteger(java.math.BigInteger) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Identifier (org.eclipse.titan.designer.AST.Identifier)9 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)9 HashMap (java.util.HashMap)8 IType (org.eclipse.titan.designer.AST.IType)6 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Value (org.eclipse.titan.designer.AST.Value)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Module (org.eclipse.titan.designer.AST.Module)3 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)3 List (java.util.List)2 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2