Search in sources :

Example 26 with SpecificValue_Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.

the class Def_Function_Writer method writeAssignmentStatement.

// updated
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
    StringBuilder functionString = new StringBuilder("");
    if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
        SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
        if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
            // TODO assignments for indexed bitstrings
            functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
            functionString.append(functionAssignIdentifiers.get(assignCounter) + functionAssignValues.get(assignCounter) + ";\r\n");
        // TODO: add logging here
        }
    }
    /*StringBuilder functionString = new StringBuilder("");

		if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
			SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();

			if (specValTemplate.getSpecificValue() instanceof Bitstring_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BITSTRING(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Integer_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Charstring_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new CHARSTRING(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Boolean_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BOOLEAN("
						+ functionAssignValues.get(assignCounter) + ");\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
						+ functionAssignValues.get(assignCounter) + ";\r\n");

				// TODO: add logging here
			}

			if (specValTemplate.getSpecificValue() instanceof Referenced_Value) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
						+ functionAssignValues.get(assignCounter) + ";\r\n");

				// TODO: add logging here
			}

			if ((specValTemplate.getSpecificValue() instanceof AddExpression)
					|| (specValTemplate.getSpecificValue() instanceof SubstractExpression)
					|| (specValTemplate.getSpecificValue() instanceof MultiplyExpression)
					|| (specValTemplate.getSpecificValue() instanceof DivideExpression)
					|| (specValTemplate.getSpecificValue() instanceof ModuloExpression)
					|| (specValTemplate.getSpecificValue() instanceof RemainderExpression)) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter)
						+ functionAssignValues.get(assignCounter) + ";\r\n");

				// TODO: add logging here

			}

			if (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression) {

				functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");

				functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
						+ functionAssignValues.get(assignCounter) + "\");\r\n");

				// TODO: add logging here

			}

		}
*/
    return functionString.toString();
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) StringConcatenationExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.StringConcatenationExpression) Not4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Not4bExpression) RotateLeftExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RotateLeftExpression) ShiftRightExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ShiftRightExpression) Or4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Or4bExpression) RemainderExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) UnaryMinusExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.UnaryMinusExpression) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) RotateRightExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RotateRightExpression) MultiplyExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) DivideExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression) AddExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression) ShiftLeftExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ShiftLeftExpression) SubstractExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression) And4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.And4bExpression) Xor4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Xor4bExpression) ModuloExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 27 with SpecificValue_Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.

the class Def_Testcase_Writer method writeAssignmentStatement.

public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
    StringBuilder testCaseString = new StringBuilder("");
    if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
        SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
        if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
            ComponentCreateExpression componenetCreateExp = (ComponentCreateExpression) specValTemplate.getSpecificValue();
            createCounter++;
            logCreateCounter++;
            int logSizeValue = 1;
            while (tcCreateCounter.get(logCreateCounter).equals(String.valueOf(createCounter))) {
                logCreateCounter++;
                logSizeValue++;
                if (tcCreateCounter.size() == (logCreateCounter)) {
                    break;
                }
            }
            String[] logValues = new String[logSizeValue];
            int logWriteCounter = 0;
            testCaseString.append("rownum=" + componenetCreateExp.getLocation().getLine() + ";\r\n");
            if (tcAssignIdentifiers.get(assignCounter).endsWith("=")) {
                tcAssignIdentifiers.set(assignCounter, tcAssignIdentifiers.get(assignCounter).substring(0, tcAssignIdentifiers.get(assignCounter).length() - 1));
            }
            testCaseString.append("hc.create(" + "\"" + tcAssignIdentifiers.get(assignCounter) + "\"");
            logValues[logWriteCounter] = tcAssignIdentifiers.get(assignCounter);
            currentCounterValue++;
            // assignCounter++;
            logWriteCounter++;
            while (tcCreateCounter.get(currentCounterValue).equals(String.valueOf(createCounter))) {
                testCaseString.append(",\"" + tcCreateValues.get(currentCounterValue) + "\"");
                logValues[logWriteCounter] = tcCreateValues.get(currentCounterValue);
                logWriteCounter++;
                currentCounterValue++;
                if (tcCreateCounter.size() == (currentCounterValue)) {
                    break;
                }
            }
            testCaseString.append("); " + "\r\n");
            testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + nodeName + "\", \"Starting PTC " + logValues[0] + " type " + logValues[1] + " on " + logValues[2] + "\", false);" + "\r\n");
        } else if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
            // TODO assignments for indexed bitstrings
            testCaseString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
            testCaseString.append(tcAssignIdentifiers.get(assignCounter) + tcAssignValues.get(assignCounter) + ";\r\n");
        // TODO: add logging here
        }
    }
    return testCaseString.toString();
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) StringConcatenationExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.StringConcatenationExpression) Not4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Not4bExpression) ComponentCreateExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression) RotateLeftExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RotateLeftExpression) ShiftRightExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ShiftRightExpression) Or4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Or4bExpression) RemainderExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RemainderExpression) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) UnaryMinusExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.UnaryMinusExpression) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) RotateRightExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.RotateRightExpression) MultiplyExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.MultiplyExpression) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) DivideExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.DivideExpression) AddExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.AddExpression) ShiftLeftExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ShiftLeftExpression) SubstractExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.SubstractExpression) And4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.And4bExpression) Xor4bExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.Xor4bExpression) ModuloExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ModuloExpression) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 28 with SpecificValue_Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.

the class FormalParameter method checkActualParameterPort.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a port parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param actualParameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param expectedValue
 *                the value kind expected from the actual parameter.
 *
 * @return the actual parameter created from the value, or null if there
 *         was an error.
 */
private ActualParameter checkActualParameterPort(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
    final Type parameterType = actualParameter.getType();
    if (parameterType != null) {
        parameterType.getLocation().reportSemanticWarning("Explicit type specification is useless for a port parameter");
        actualParameter.checkType(timestamp, type);
    }
    final Reference derivedReference = actualParameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError("An in-line modified temlate cannot be used as port parameter");
        actualParameter.checkDerivedReference(timestamp, type);
    }
    final ITTCN3Template parameterTemplate = actualParameter.getTemplateBody();
    if (!(parameterTemplate instanceof SpecificValue_Template) || !((SpecificValue_Template) parameterTemplate).isReference()) {
        actualParameter.getLocation().reportSemanticError("Reference to a port or port parameter was expected for a port parameter");
        final ActualParameter temp = new Value_ActualParameter(null);
        temp.setIsErroneous();
        return temp;
    }
    final Reference reference = ((SpecificValue_Template) parameterTemplate).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        final ActualParameter temp = new Value_ActualParameter(null);
        temp.setIsErroneous();
        return temp;
    }
    Type referredType;
    switch(assignment.getAssignmentType()) {
        case A_PORT:
            final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
            if (dimensions != null) {
                dimensions.checkIndices(timestamp, reference, "port", false, expectedValue);
            } else if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
            }
            referredType = ((Def_Port) assignment).getType(timestamp);
            break;
        case A_PAR_PORT:
            if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR3, assignment.getDescription()));
            }
            referredType = ((FormalParameter) assignment).getType(timestamp);
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(PORTEXPECTED, assignment.getDescription()));
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
    }
    if (referredType != null && type != null && !type.isIdentical(timestamp, referredType)) {
        reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH, type.getTypename(), referredType.getTypename()));
    }
    return new Referenced_ActualParameter(reference);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) CodeSectionType(org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)

Example 29 with SpecificValue_Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.

the class FormalParameter method checkActualParameterByReference.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a reference parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param isTemplate
 *                true if the formal parameter is template, false
 *                otherwise
 * @param expectedValue
 *                the value kind expected from the actual parameter.
 *
 * @return the actual parameter created from the value, or null if there
 *         was an error.
 */
private ActualParameter checkActualParameterByReference(final CompilationTimeStamp timestamp, final TemplateInstance parameter, final boolean isTemplate, final Expected_Value_type expectedValue) {
    final Type parameterType = parameter.getType();
    if (parameterType != null) {
        parameterType.getLocation().reportSemanticWarning(MessageFormat.format(EXPLICITESPECIFICATIONFORREFERENCE, getAssignmentName()));
        parameter.checkType(timestamp, type);
    }
    final Reference derivedReference = parameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError(MessageFormat.format(INLINETEMPLATEFORREFERENCE, getAssignmentName()));
        parameter.checkDerivedReference(timestamp, type);
    }
    String expectedString;
    if (isTemplate) {
        expectedString = "template variable or template parameter";
    } else {
        expectedString = "variable or value parameter";
    }
    final ITTCN3Template template = parameter.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
        final Reference reference = ((SpecificValue_Template) template).getReference();
        reference.setUsedOnLeftHandSide();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true);
        if (assignment == null) {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
        }
        boolean assignmentTypeIsCorrect;
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL_IN:
                ((FormalParameter) assignment).useAsLValue(reference);
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                assignmentTypeIsCorrect = !isTemplate;
                break;
            case A_PAR_TEMP_IN:
                assignmentTypeIsCorrect = isTemplate;
                ((FormalParameter) assignment).useAsLValue(reference);
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                assignmentTypeIsCorrect = isTemplate;
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                assignmentTypeIsCorrect = isTemplate;
                break;
            default:
                assignmentTypeIsCorrect = false;
                break;
        }
        if (assignmentTypeIsCorrect) {
            final IType fieldType = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
            if (fieldType != null) {
                if (type != null && !type.isCompatible(timestamp, fieldType, null, null, null)) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, expectedString, type.getTypename(), fieldType.getTypename()));
                } else if (type != null && type.getSubtype() != null && fieldType.getSubtype() != null && !type.getSubtype().isCompatible(timestamp, fieldType.getSubtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBTYPEMISMATCH, type.getSubtype().toString(), fieldType.getSubtype().toString()));
                }
                if (!reference.getSubreferences().isEmpty() && reference.refersToStringElement()) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED3, fieldType.getTypename()));
                }
            }
        } else {
            reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED1, expectedString, getAssignmentName(), assignment.getDescription()));
        }
        final ActualParameter returnActualParameter = new Referenced_ActualParameter(reference);
        if (isTemplate && assignmentTypeIsCorrect) {
            TemplateRestriction.Restriction_type refdRestriction;
            switch(assignment.getAssignmentType()) {
                case A_VAR_TEMPLATE:
                    {
                        final Def_Var_Template temp = (Def_Var_Template) assignment;
                        refdRestriction = temp.getTemplateRestriction();
                        break;
                    }
                case A_PAR_TEMP_IN:
                case A_PAR_TEMP_OUT:
                case A_PAR_TEMP_INOUT:
                    {
                        final FormalParameter par = (FormalParameter) assignment;
                        refdRestriction = par.getTemplateRestriction();
                        break;
                    }
                default:
                    return returnActualParameter;
            }
            TemplateRestriction.getSubRestriction(refdRestriction, timestamp, reference);
            if (templateRestriction != refdRestriction) {
                final boolean preCallCheck = TemplateRestriction.isLessRestrictive(templateRestriction, refdRestriction);
                final boolean postCallCheck = TemplateRestriction.isLessRestrictive(refdRestriction, templateRestriction);
                if (preCallCheck || postCallCheck) {
                    final String message = MessageFormat.format("Inadequate restriction on the referenced {0} `{1}'' this may cause a dynamic test case error at runtime", assignment.getAssignmentName(), reference.getDisplayName());
                    reference.getLocation().reportSemanticWarning(message);
                }
            }
            // written C++ code
            if (!Restriction_type.TR_NONE.equals(refdRestriction)) {
                switch(myParameterList.getMyDefinition().getAssignmentType()) {
                    case A_EXT_FUNCTION:
                    case A_EXT_FUNCTION_RVAL:
                    case A_EXT_FUNCTION_RTEMP:
                        // here
                        break;
                    default:
                        break;
                }
            }
        }
        return returnActualParameter;
    }
    parameter.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED2, expectedString, getAssignmentName()));
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IType(org.eclipse.titan.designer.AST.IType) Assignment(org.eclipse.titan.designer.AST.Assignment) CodeSectionType(org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)

Example 30 with SpecificValue_Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.

the class Type method checkThisTemplateRef.

@Override
public /**
 * {@inheritDoc}
 */
ITTCN3Template checkThisTemplateRef(final CompilationTimeStamp timestamp, final ITTCN3Template t, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    switch(t.getTemplatetype()) {
        case SUPERSET_MATCH:
        case SUBSET_MATCH:
            final IType it1 = getTypeRefdLast(timestamp);
            final Type_type tt = it1.getTypetype();
            if (Type_type.TYPE_SEQUENCE_OF.equals(tt) || Type_type.TYPE_SET_OF.equals(tt)) {
                return t;
            } else {
                t.getLocation().reportSemanticError(MessageFormat.format("{0} cannot be used for type {1}", t.getTemplateTypeName(), getTypename()));
                t.setIsErroneous(true);
                return t;
            }
        case SPECIFIC_VALUE:
            // cont below
            break;
        default:
            return t;
    }
    // Case of specific value:
    final ITTCN3Template template = t;
    IValue value = ((SpecificValue_Template) template).getSpecificValue();
    if (value == null) {
        return template;
    }
    value = checkThisValueRef(timestamp, value);
    switch(value.getValuetype()) {
        case REFERENCED_VALUE:
            // FIXME: referenceChain or null?
            final Assignment assignment = ((Referenced_Value) value).getReference().getRefdAssignment(timestamp, false, referenceChain);
            if (assignment == null) {
                template.setIsErroneous(true);
            } else {
                switch(assignment.getAssignmentType()) {
                    case A_VAR_TEMPLATE:
                        if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                            template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                            template.setIsErroneous(true);
                        }
                        final IType type = ((Def_Var_Template) assignment).getType(timestamp);
                        switch(type.getTypetype()) {
                            case TYPE_BITSTRING:
                            case TYPE_BITSTRING_A:
                            case TYPE_HEXSTRING:
                            case TYPE_OCTETSTRING:
                            case TYPE_CHARSTRING:
                            case TYPE_UCHARSTRING:
                            case TYPE_UTF8STRING:
                            case TYPE_NUMERICSTRING:
                            case TYPE_PRINTABLESTRING:
                            case TYPE_TELETEXSTRING:
                            case TYPE_VIDEOTEXSTRING:
                            case TYPE_IA5STRING:
                            case TYPE_GRAPHICSTRING:
                            case TYPE_VISIBLESTRING:
                            case TYPE_GENERALSTRING:
                            case TYPE_UNIVERSALSTRING:
                            case TYPE_BMPSTRING:
                            case TYPE_UTCTIME:
                            case TYPE_GENERALIZEDTIME:
                            case TYPE_OBJECTDESCRIPTOR:
                                {
                                    final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
                                    final int nofSubreferences = subReferences.size();
                                    if (nofSubreferences > 1) {
                                        final ISubReference subreference = subReferences.get(nofSubreferences - 1);
                                        if (subreference instanceof ArraySubReference) {
                                            template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
                                            template.setIsErroneous(true);
                                            return template;
                                        }
                                    }
                                    break;
                                }
                            default:
                                break;
                        }
                        return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
                    case A_CONST:
                        IType type1;
                        if (assignment instanceof Value_Assignment) {
                            type1 = ((Value_Assignment) assignment).getType(timestamp);
                        } else {
                            type1 = ((Def_Const) assignment).getType(timestamp);
                        }
                        switch(type1.getTypetype()) {
                            case TYPE_BITSTRING:
                            case TYPE_BITSTRING_A:
                            case TYPE_HEXSTRING:
                            case TYPE_OCTETSTRING:
                            case TYPE_CHARSTRING:
                            case TYPE_UCHARSTRING:
                            case TYPE_UTF8STRING:
                            case TYPE_NUMERICSTRING:
                            case TYPE_PRINTABLESTRING:
                            case TYPE_TELETEXSTRING:
                            case TYPE_VIDEOTEXSTRING:
                            case TYPE_IA5STRING:
                            case TYPE_GRAPHICSTRING:
                            case TYPE_VISIBLESTRING:
                            case TYPE_GENERALSTRING:
                            case TYPE_UNIVERSALSTRING:
                            case TYPE_BMPSTRING:
                            case TYPE_UTCTIME:
                            case TYPE_GENERALIZEDTIME:
                            case TYPE_OBJECTDESCRIPTOR:
                                {
                                    final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
                                    final int nofSubreferences = subReferences.size();
                                    if (nofSubreferences > 1) {
                                        final ISubReference subreference = subReferences.get(nofSubreferences - 1);
                                        if (subreference instanceof ArraySubReference) {
                                            template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
                                            template.setIsErroneous(true);
                                            return template;
                                        }
                                    }
                                    break;
                                }
                            default:
                                break;
                        }
                        break;
                    case A_TEMPLATE:
                    case A_MODULEPAR_TEMPLATE:
                    case A_PAR_TEMP_IN:
                    case A_PAR_TEMP_OUT:
                    case A_PAR_TEMP_INOUT:
                    case A_FUNCTION_RTEMP:
                    case A_EXT_FUNCTION_RTEMP:
                        if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                            template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                            template.setIsErroneous(true);
                        }
                        return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
                    default:
                        break;
                }
            }
            break;
        case EXPRESSION_VALUE:
            {
                final Expression_Value expression = (Expression_Value) value;
                if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
                    IType type = expression.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
                    if (type == null) {
                        break;
                    }
                    type = type.getTypeRefdLast(timestamp);
                    if (type != null && Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
                        return template.setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
                    }
                }
                break;
            }
        default:
            break;
    }
    return template;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) List(java.util.List) ArrayList(java.util.ArrayList) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Aggregations

SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)30 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)27 IValue (org.eclipse.titan.designer.AST.IValue)26 Assignment (org.eclipse.titan.designer.AST.Assignment)15 Reference (org.eclipse.titan.designer.AST.Reference)15 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)12 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)9 IType (org.eclipse.titan.designer.AST.IType)7 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)6 ArrayList (java.util.ArrayList)5 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)5 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)5 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)3 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)3 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)3 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)3