Search in sources :

Example 11 with Referenced_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value 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 12 with Referenced_Value

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

the class IsValueExpression method checkExpressionTemplateInstance.

/**
 * Checks if the templateinstance parameter (which is a parameter of the
 * expression parameter) is actually a constant or static value or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expression
 *                the expression to report the possible errors to.
 * @param instance
 *                the template instance parameter of the expression to
 *                be checked.
 * @param type
 *                the type against which the template instance shall be
 *                checked.
 * @param referenceChain
 *                the referencechain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
public static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
    Expected_Value_type internalExpectation;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
    } else {
        internalExpectation = expectedValue;
    }
    instance.check(timestamp, type);
    if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
        if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
            instance.getLocation().reportSemanticError(CONSTEXPECTED1);
        } else {
            instance.getLocation().reportSemanticError(STATICEXPECTED1);
        }
        expression.setIsErroneous(true);
    }
    ITTCN3Template template = instance.getTemplateBody();
    if (template.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    switch(template.getTemplatetype()) {
        case TEMPLATE_REFD:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
                template = template.getTemplateReferencedLast(timestamp, referenceChain);
                if (template.getIsErroneous(timestamp)) {
                    expression.setIsErroneous(true);
                }
            } else {
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
                    instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                } else {
                    instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                }
                expression.setIsErroneous(true);
            }
            break;
        case SPECIFIC_VALUE:
            final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
            switch(tempValue.getValuetype()) {
                case REFERENCED_VALUE:
                    type.checkThisValueRef(timestamp, tempValue);
                    break;
                case EXPRESSION_VALUE:
                    tempValue.getValueRefdLast(timestamp, referenceChain);
                    break;
                default:
                    break;
            }
            if (tempValue.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 13 with Referenced_Value

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

the class UndefRunningExpression 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) {
    setIsErroneous(false);
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
        case A_PAR_TIMER:
            {
                realExpression = new TimerRunningExpression(reference);
                realExpression.setMyScope(getMyScope());
                realExpression.setFullNameParent(this);
                realExpression.setLocation(getLocation());
                realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
                break;
            }
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            {
                final Referenced_Value value = new Referenced_Value(reference);
                value.setMyScope(getMyScope());
                value.setFullNameParent(this);
                value.getValueRefdLast(timestamp, referenceChain);
                realExpression = new ComponentRunnningExpression(value);
                realExpression.setMyScope(getMyScope());
                realExpression.setFullNameParent(this);
                realExpression.setLocation(getLocation());
                realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
                break;
            }
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format("First operand of operation `<timer or component> running'' should be timer or component reference instead of {0}", assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 14 with Referenced_Value

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

the class Assignment_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    if (reference == null || template == null) {
        return;
    }
    final boolean rhsCopied = selfReference;
    // TODO this is actually much more complicated
    final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), true);
    if (assignment == null) {
        // TODO: handle null
        return;
    }
    boolean isValue;
    switch(assignment.getAssignmentType()) {
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_PAR_VAL:
        case A_VAR:
            isValue = true;
            break;
        default:
            isValue = false;
            break;
    }
    boolean isOptional = false;
    if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
        isOptional = true;
    }
    if (isValue) {
        final String rhsCopy = aData.getTemporaryVariableName();
        String rhsRef = rhsCopy;
        if (rhsCopied) {
            source.append("{\n");
            if (isOptional) {
                source.append(MessageFormat.format("Optional<{0}> {1} = new Optional<{0}>({0}.class);\n", template.getMyGovernor().getGenNameValue(aData, source, myScope), rhsCopy));
                rhsRef += ".get()";
            } else {
                source.append(MessageFormat.format("{0} {1} = new {0}();\n", template.getMyGovernor().getGenNameValue(aData, source, myScope), rhsCopy));
            }
        }
        final IValue value = template.getValue();
        // TODO handle needs_conv
        if (reference.getSubreferences().size() > 1) {
            if (value.canGenerateSingleExpression()) {
                final ExpressionStruct expression = new ExpressionStruct();
                reference.generateCode(aData, expression);
                source.append(expression.preamble);
                String temp;
                IType type = getType(CompilationTimeStamp.getBaseTimestamp(), assignment);
                type = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference, 1, Expected_Value_type.EXPECTED_TEMPLATE, false);
                // if (value.getValuetype() != Value_type.OMIT_VALUE && (isOptional || type.getTypetypeTtcn3() != value.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE))) {
                if (value.getValuetype() != Value_type.OMIT_VALUE && value.getValuetype() != Value_type.REFERENCED_VALUE && (isOptional || type.getTypetypeTtcn3() != value.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE))) {
                    temp = MessageFormat.format("new {0}({1})", value.getMyGovernor().getGenNameValue(aData, source, myScope), value.generateSingleExpression(aData));
                } else {
                    temp = value.generateSingleExpression(aData).toString();
                }
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", rhsCopy, temp));
                    expression.expression.append(MessageFormat.format(".assign({0});\n", rhsCopy));
                } else {
                    expression.expression.append(MessageFormat.format(".assign({0});\n", temp));
                }
                source.append(expression.expression);
                source.append(expression.postamble);
            } else {
                final String tempID = aData.getTemporaryVariableName();
                final String typeGenname = value.getMyGovernor().getGenNameValue(aData, source, myScope);
                final ExpressionStruct leftExpression = new ExpressionStruct();
                reference.generateCode(aData, leftExpression);
                if (rhsCopied) {
                    // TODO handle needs conversion case
                    value.generateCodeInit(aData, source, rhsRef);
                } else if (isOptional) {
                    leftExpression.expression.append(".get()");
                }
                source.append("{\n");
                source.append(leftExpression.preamble);
                if (reference.refersToStringElement()) {
                    // LHS is a string element
                    aData.addBuiltinTypeImport(typeGenname + "_Element");
                    source.append(MessageFormat.format("{0}_Element {1} = {2};\n", typeGenname, tempID, leftExpression.expression));
                } else {
                    source.append(MessageFormat.format("{0} {1} = {2};\n", typeGenname, tempID, leftExpression.expression));
                }
                source.append(leftExpression.postamble);
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", tempID, rhsCopy));
                } else {
                    // TODO handle needs conversion
                    value.generateCodeInit(aData, source, tempID);
                }
                source.append("}\n");
            }
        } else {
            // left hand side is a single assignment
            final String name = assignment.getGenNameFromScope(aData, source, myScope, null);
            if (!isOptional && value.getValuetype() == Value_type.REFERENCED_VALUE) {
                final Reference rightReference = ((Referenced_Value) value).getReference();
                final Assignment rightAssignment = rightReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), true);
                if (rightAssignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(rightReference.getSubreferences())) {
                    value.generateCodeInitMandatory(aData, source, rhsCopied ? rhsCopy : name);
                } else {
                    value.generateCodeInit(aData, source, rhsCopied ? rhsCopy : name);
                }
            } else {
                value.generateCodeInit(aData, source, rhsCopied ? rhsCopy : name);
            }
            if (rhsCopied) {
                source.append(MessageFormat.format("{0}.assign({1});\n", name, rhsCopy));
            }
        }
        if (rhsCopied) {
            source.append("}\n");
        }
    } else {
        final String rhsCopy = aData.getTemporaryVariableName();
        if (rhsCopied) {
            source.append("{\n");
            source.append(MessageFormat.format("{0} {1} = new {0}();\n", template.getMyGovernor().getGenNameTemplate(aData, source, myScope), rhsCopy));
        }
        // TODO handle needs_conv
        if (reference.getSubreferences().size() > 1) {
            if ((templateRestriction != Restriction_type.TR_NONE || !generateRestrictionCheck) && template.hasSingleExpression()) {
                final ExpressionStruct expression = new ExpressionStruct();
                reference.generateCode(aData, expression);
                source.append(expression.preamble);
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", rhsCopy, template.getSingleExpression(aData, false)));
                    expression.expression.append(MessageFormat.format(".assign({0});\n", rhsCopy));
                } else {
                    expression.expression.append(MessageFormat.format(".assign({0});\n", template.getSingleExpression(aData, false)));
                }
                expression.mergeExpression(source);
            } else {
                final String tempID = aData.getTemporaryVariableName();
                final ExpressionStruct expression = new ExpressionStruct();
                reference.generateCode(aData, expression);
                if (rhsCopied) {
                    // TODO handle needs conversion case
                    template.generateCodeInit(aData, source, rhsCopy);
                }
                source.append("{\n");
                source.append(expression.preamble);
                final IType governor = template.getMyGovernor();
                source.append(MessageFormat.format("{0} {1} = {2};\n", governor.getGenNameTemplate(aData, source, template.getMyScope()), tempID, expression.expression));
                source.append(expression.postamble);
                if (rhsCopied) {
                    source.append(MessageFormat.format("{0}.assign({1});\n", tempID, rhsCopy));
                } else {
                    // TODO handle needs conversion case
                    if (Type_type.TYPE_SEQUENCE_OF.equals(governor.getTypetype()) || Type_type.TYPE_ARRAY.equals(governor.getTypetype())) {
                        source.append(MessageFormat.format("{0}.removeAllPermutations();\n", tempID));
                    }
                    template.generateCodeInit(aData, source, tempID);
                }
                if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
                    TemplateRestriction.generateRestrictionCheckCode(aData, source, location, tempID, templateRestriction);
                }
                source.append("}\n");
            }
        } else {
            // left hand side is a single assignment
            final String rhsName = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false).getGenNameFromScope(aData, source, myScope, "");
            final IType governor = template.getMyGovernor();
            if (Type_type.TYPE_SEQUENCE_OF.equals(governor.getTypetype()) || Type_type.TYPE_ARRAY.equals(governor.getTypetype())) {
                source.append(MessageFormat.format("{0}.removeAllPermutations();\n", rhsCopied ? rhsCopy : rhsName));
            }
            template.generateCodeInit(aData, source, rhsCopied ? rhsCopy : rhsName);
            if (rhsCopied) {
                source.append(MessageFormat.format("{0}.assign({1});\n", rhsName, rhsCopy));
            }
            if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
                TemplateRestriction.generateRestrictionCheckCode(aData, source, location, rhsName, templateRestriction);
            }
        }
        if (rhsCopied) {
            source.append("}\n");
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 15 with Referenced_Value

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

the class ASN1_Integer_Type method checkThisValueLimit.

// this method accepts REAL_VALUE
public void checkThisValueLimit(final CompilationTimeStamp timestamp, final IValue value, final ValueCheckingOptions valueCheckingOptions) {
    super.checkThisValue(timestamp, value, null, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (null == last || last.getIsErroneous(timestamp)) {
        return;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
        case REAL_VALUE:
            break;
        case NAMED_INTEGER_VALUE:
            if (null != namedNumbers) {
                // convert it into an integer value
                final Identifier name = ((Named_Integer_Value) last).getIdentifier();
                final NamedValue namedValue = namedNumbers.getNamedValueByName(name);
                IValue tempValue = namedValue.getValue();
                final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
                referenceChain.release();
                if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
                    final int temp = ((Integer_Value) tempValue).intValue();
                    final Integer_Value converted = new Integer_Value(temp);
                    converted.copyGeneralProperties(value);
                    ((Named_Integer_Value) last).setCalculatedValue(converted);
                } else {
                // FIXME Most probably we were not able
                // to build the semantic structure for
                // something, because it is not yet
                // supported, like referenced values in
                // sets
                }
            }
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(INTEGERVALUEEXPECTED);
            value.setIsErroneous(true);
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)40 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)22 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Reference (org.eclipse.titan.designer.AST.Reference)15 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)13 IType (org.eclipse.titan.designer.AST.IType)11 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ISubReference (org.eclipse.titan.designer.AST.ISubReference)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)5 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)4 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)4 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)4 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)4 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3