Search in sources :

Example 1 with ITTCN3Template

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

the class SizeOfExpression method evaluateTemplate.

/**
 * Evaluates a checked template.
 *
 * @param template
 *                The template to evaluate
 * @param timestamp
 *                The compilation timestamp
 * @return The folded value or -1 if the template is unfoldable.
 */
private long evaluateTemplate(final ITTCN3Template template, final CompilationTimeStamp timestamp) {
    switch(template.getTemplatetype()) {
        case TEMPLATE_LIST:
            {
                final Template_List temp = (Template_List) template;
                if (temp.templateContainsAnyornone()) {
                    final LengthRestriction lengthRestriction = temp.getLengthRestriction();
                    if (lengthRestriction == null) {
                        templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without length restriction");
                        setIsErroneous(true);
                        return -1;
                    }
                    if (lengthRestriction instanceof RangeLenghtRestriction) {
                        final IValue upper = ((RangeLenghtRestriction) lengthRestriction).getUpperValue(timestamp);
                        if (Value_type.REAL_VALUE.equals(upper.getValuetype()) && ((Real_Value) upper).isPositiveInfinity()) {
                            templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without upper boundary in the length restriction");
                            setIsErroneous(true);
                            return -1;
                        }
                        if (Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
                            final int nofComponents = temp.getNofTemplatesNotAnyornone(timestamp);
                            if (nofComponents == ((Integer_Value) upper).intValue()) {
                                return nofComponents;
                            }
                            final IValue lower = ((RangeLenghtRestriction) lengthRestriction).getLowerValue(timestamp);
                            if (lower != null && Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && ((Integer_Value) upper).intValue() == ((Integer_Value) lower).intValue()) {
                                return ((Integer_Value) upper).intValue();
                            }
                            templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates without exact size");
                            setIsErroneous(true);
                            return -1;
                        }
                    } else {
                        final IValue restriction = ((SingleLenghtRestriction) lengthRestriction).getRestriction(timestamp);
                        if (Value_type.INTEGER_VALUE.equals(restriction.getValuetype())) {
                            return ((Integer_Value) restriction).intValue();
                        }
                    }
                } else {
                    int result = 0;
                    for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                        final ITTCN3Template tmp = temp.getTemplateByIndex(i);
                        switch(tmp.getTemplatetype()) {
                            case SPECIFIC_VALUE:
                                if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
                                    ++result;
                                }
                                break;
                            default:
                                ++result;
                        }
                    }
                    return result;
                }
                break;
            }
        case NAMED_TEMPLATE_LIST:
            {
                int result = 0;
                final Named_Template_List temp = (Named_Template_List) template;
                for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                    final ITTCN3Template tmp = temp.getTemplateByIndex(i).getTemplate();
                    switch(tmp.getTemplatetype()) {
                        case SPECIFIC_VALUE:
                            if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
                                ++result;
                            }
                            break;
                        default:
                            ++result;
                    }
                }
                return result;
            }
        case SUBSET_MATCH:
            {
                final LengthRestriction restriction = template.getLengthRestriction();
                if (restriction instanceof SingleLenghtRestriction) {
                    final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
                    if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
                        return ((Integer_Value) value).getValue();
                    } else {
                        return -1;
                    }
                } else if (restriction instanceof RangeLenghtRestriction) {
                    final IValue minValue = ((RangeLenghtRestriction) restriction).getLowerValue(timestamp);
                    if (minValue.getValuetype() != Value_type.INTEGER_VALUE || minValue.isUnfoldable(timestamp)) {
                        return -1;
                    }
                    final SubsetMatch_Template temp = (SubsetMatch_Template) template;
                    if (temp.getNofTemplates() != ((Integer_Value) minValue).getValue()) {
                        return -1;
                    }
                    for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                        final ITTCN3Template tmp = temp.getTemplateByIndex(i);
                        switch(tmp.getTemplatetype()) {
                            case SPECIFIC_VALUE:
                                break;
                            default:
                                return -1;
                        }
                    }
                    return temp.getNofTemplates();
                }
                return -1;
            }
        case SUPERSET_MATCH:
            {
                final LengthRestriction restriction = template.getLengthRestriction();
                if (restriction instanceof SingleLenghtRestriction) {
                    final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
                    if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
                        return ((Integer_Value) value).getValue();
                    } else {
                        return -1;
                    }
                } else if (restriction instanceof RangeLenghtRestriction) {
                    final IValue maxValue = ((RangeLenghtRestriction) restriction).getUpperValue(timestamp);
                    if (maxValue.getValuetype() != Value_type.INTEGER_VALUE || maxValue.isUnfoldable(timestamp)) {
                        return -1;
                    }
                    final SupersetMatch_Template temp = (SupersetMatch_Template) template;
                    if (temp.getNofTemplates() != ((Integer_Value) maxValue).getValue()) {
                        return -1;
                    }
                    for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                        final ITTCN3Template tmp = temp.getTemplateByIndex(i);
                        switch(tmp.getTemplatetype()) {
                            case SPECIFIC_VALUE:
                                break;
                            default:
                                return -1;
                        }
                    }
                    return temp.getNofTemplates();
                }
                return -1;
            }
        default:
            return -1;
    }
    return -1;
}
Also used : LengthRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Template_List) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) IValue(org.eclipse.titan.designer.AST.IValue) RangeLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.RangeLenghtRestriction) SubsetMatch_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) SupersetMatch_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)

Example 2 with ITTCN3Template

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

the class SizeOfExpression 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.
 *
 * @return the size of the expression, or -1 in case of error
 */
private long checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    Expected_Value_type internalExpectedValue;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        internalExpectedValue = Expected_Value_type.EXPECTED_TEMPLATE;
    } else {
        internalExpectedValue = expectedValue;
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    template.setLoweridToReference(timestamp);
    template = template.getTemplateReferencedLast(timestamp, referenceChain);
    if (template.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return -1;
    }
    // Timer and port arrays are handled separately
    if (template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
        final SpecificValue_Template specValTempl = (SpecificValue_Template) template;
        IValue val = specValTempl.getSpecificValue();
        val.setMyGovernor(specValTempl.getMyGovernor());
        if (val.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
            val = val.setLoweridToReference(timestamp);
        }
        if (val != null && val.getValuetype() == Value_type.REFERENCED_VALUE) {
            final Referenced_Value referencedValue = (Referenced_Value) val;
            final Reference ref = referencedValue.getReference();
            final Assignment temporalAss = ref.getRefdAssignment(timestamp, true);
            if (temporalAss != null) {
                final Assignment_type asstype = temporalAss.getAssignmentType();
                ArrayDimensions dimensions;
                if (asstype == Assignment_type.A_PORT) {
                    dimensions = ((Def_Port) temporalAss).getDimensions();
                    return checkTimerPort(timestamp, ref, dimensions, temporalAss);
                } else if (asstype == Assignment_type.A_TIMER) {
                    dimensions = ((Def_Timer) temporalAss).getDimensions();
                    return checkTimerPort(timestamp, ref, dimensions, temporalAss);
                }
            }
        }
    }
    IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectedValue);
    if (governor == null) {
        final ITTCN3Template templ = template.setLoweridToReference(timestamp);
        governor = templ.getExpressionGovernor(timestamp, internalExpectedValue);
    }
    if (governor == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance.getLocation().reportSemanticError("Cannot determine the type of the argument in the `sizeof' operation. If type is known, use valueof(<type>: ...) as argument.");
        }
        setIsErroneous(true);
        return -1;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, internalExpectedValue);
    if (isErroneous) {
        return -1;
    }
    IType type = governor.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
        case TYPE_TTCN3_SEQUENCE:
        case TYPE_TTCN3_SET:
        case TYPE_ASN1_SEQUENCE:
        case TYPE_ASN1_SET:
        case TYPE_ARRAY:
        case TYPE_OBJECTID:
        case TYPE_ROID:
        case TYPE_UNDEFINED:
            break;
        default:
            templateInstance.getLocation().reportSemanticError("Reference to a value or template of type record, record of, set, set of, objid or array was expected");
            setIsErroneous(true);
            return -1;
    }
    IValue value = null;
    Reference reference = null;
    Assignment assignment = null;
    List<ISubReference> subreferences = null;
    switch(template.getTemplatetype()) {
        case INDEXED_TEMPLATE_LIST:
            return -1;
        case TEMPLATE_REFD:
            reference = ((Referenced_Template) template).getReference();
            assignment = reference.getRefdAssignment(timestamp, false);
            subreferences = reference.getSubreferences();
            break;
        case TEMPLATE_LIST:
        case NAMED_TEMPLATE_LIST:
        case SUBSET_MATCH:
        case SUPERSET_MATCH:
            // compute later
            break;
        case SPECIFIC_VALUE:
            value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
            if (value != null) {
                switch(value.getValuetype()) {
                    case SEQUENCEOF_VALUE:
                    case SETOF_VALUE:
                    case ARRAY_VALUE:
                    case RELATIVEOBJECTIDENTIFIER_VALUE:
                    case OBJECTID_VALUE:
                    case SEQUENCE_VALUE:
                    case SET_VALUE:
                        break;
                    case REFERENCED_VALUE:
                        {
                            reference = ((Referenced_Value) value).getReference();
                            assignment = reference.getRefdAssignment(timestamp, false);
                            subreferences = reference.getSubreferences();
                            break;
                        }
                    default:
                        templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to `{0}''", value.createStringRepresentation()));
                        setIsErroneous(true);
                        return -1;
                }
            }
            break;
        default:
            templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to {0}", template.getTemplateTypeName()));
            setIsErroneous(true);
            return -1;
    }
    if (assignment != null) {
        if (assignment.getIsErroneous()) {
            setIsErroneous(true);
            return -1;
        }
        switch(assignment.getAssignmentType()) {
            case A_CONST:
                value = ((Def_Const) assignment).getValue();
                break;
            case A_EXT_CONST:
            case A_MODULEPAR:
            case A_MODULEPAR_TEMPLATE:
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectedValue)) {
                    templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluable) constant value was expected instead of {0}", assignment.getDescription()));
                    setIsErroneous(true);
                    return -1;
                }
                break;
            case A_VAR:
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                switch(internalExpectedValue) {
                    case EXPECTED_CONSTANT:
                        templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
                        setIsErroneous(true);
                        return -1;
                    case EXPECTED_STATIC_VALUE:
                        templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
                        setIsErroneous(true);
                        return -1;
                    default:
                        break;
                }
                break;
            case A_TEMPLATE:
                template = ((Def_Template) assignment).getTemplate(timestamp);
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
                    templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of {0}", assignment.getDescription()));
                    setIsErroneous(true);
                    return -1;
                }
                break;
            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(internalExpectedValue)) {
                    templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of {0}", assignment.getDescription()));
                    setIsErroneous(true);
                    return -1;
                }
                break;
            case A_FUNCTION_RVAL:
            case A_EXT_FUNCTION_RVAL:
                switch(internalExpectedValue) {
                    case EXPECTED_CONSTANT:
                        templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription()));
                        setIsErroneous(true);
                        return -1;
                    case EXPECTED_STATIC_VALUE:
                        templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription()));
                        setIsErroneous(true);
                        return -1;
                    default:
                        break;
                }
                break;
            case A_FUNCTION_RTEMP:
            case A_EXT_FUNCTION_RTEMP:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
                    templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of a call of {0}, which returns a template", assignment.getDescription()));
                    setIsErroneous(true);
                    return -1;
                }
                break;
            case A_TIMER:
            case A_PORT:
                // were already checked separately.
                break;
            default:
                templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue) ? "value or template" : "value", assignment.getDescription()));
                setIsErroneous(true);
                return -1;
        }
        type = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
        if (type == null || type.getIsErroneous(timestamp)) {
            setIsErroneous(true);
            return -1;
        }
        type = type.getTypeRefdLast(timestamp);
        switch(type.getTypetype()) {
            case TYPE_SEQUENCE_OF:
            case TYPE_SET_OF:
            case TYPE_TTCN3_SEQUENCE:
            case TYPE_TTCN3_SET:
            case TYPE_ASN1_SEQUENCE:
            case TYPE_ASN1_SET:
            case TYPE_ARRAY:
            case TYPE_OBJECTID:
            case TYPE_ROID:
            case TYPE_UNDEFINED:
                break;
            default:
                templateInstance.getLocation().reportSemanticError("Reference to a value or template of type record, record of, set, set of, objid or array was expected");
                setIsErroneous(true);
                return -1;
        }
    }
    // check for index overflows in subrefs if possible
    if (value != null) {
        switch(value.getValuetype()) {
            case SEQUENCEOF_VALUE:
                if (((SequenceOf_Value) value).isIndexed()) {
                    return -1;
                }
                break;
            case SETOF_VALUE:
                if (((SetOf_Value) value).isIndexed()) {
                    return -1;
                }
                break;
            case ARRAY_VALUE:
                if (((Array_Value) value).isIndexed()) {
                    return -1;
                }
                break;
            default:
                break;
        }
        /* The reference points to a constant.  */
        if (subreferences != null && !reference.hasUnfoldableIndexSubReference(timestamp)) {
            value = value.getReferencedSubValue(timestamp, reference, 1, referenceChain);
            if (value == null) {
                setIsErroneous(true);
                return -1;
            }
            value = value.getValueRefdLast(timestamp, referenceChain);
        } else {
            // stop processing
            value = null;
        }
    } else if (template != null) {
        /* The size of INDEXED_TEMPLATE_LIST nodes is unknown at compile
		         time.  Don't try to evaluate it at compile time.  */
        if (reference != null && reference.hasUnfoldableIndexSubReference(timestamp)) {
            return -1;
        }
        if (reference != null && subreferences != null) {
            template = template.getReferencedSubTemplate(timestamp, reference, referenceChain);
            if (template == null) {
                setIsErroneous(true);
                return -1;
            }
            template = template.getTemplateReferencedLast(timestamp);
        }
    }
    if (template != null) {
        if (template.getIsErroneous(timestamp)) {
            setIsErroneous(true);
            return -1;
        }
        switch(template.getTemplatetype()) {
            case TEMPLATE_REFD:
                template = null;
                break;
            case SPECIFIC_VALUE:
                value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
                template = null;
                break;
            case TEMPLATE_LIST:
            case NAMED_TEMPLATE_LIST:
            case SUBSET_MATCH:
            case SUPERSET_MATCH:
                break;
            default:
                // FIXME this can not happen
                templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to {0}", template.getTemplateTypeName()));
                setIsErroneous(true);
                return -1;
        }
    }
    if (value != null) {
        switch(value.getValuetype()) {
            case SEQUENCEOF_VALUE:
            case SETOF_VALUE:
            case ARRAY_VALUE:
            case RELATIVEOBJECTIDENTIFIER_VALUE:
            case OBJECTID_VALUE:
            case SEQUENCE_VALUE:
            case SET_VALUE:
                break;
            default:
                value = null;
                return -1;
        }
    }
    /* evaluation */
    if (Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
        return ((Array_Type) type).getDimension().getSize();
    } else if (template != null) {
        return evaluateTemplate(template, timestamp);
    } else if (value != null) {
        return evaluateValue(value);
    } else {
        return -1;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment_type(org.eclipse.titan.designer.AST.Assignment.Assignment_type) Array_Value(org.eclipse.titan.designer.AST.TTCN3.values.Array_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) Def_Timer(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) IType(org.eclipse.titan.designer.AST.IType) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) IValue(org.eclipse.titan.designer.AST.IValue) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 3 with ITTCN3Template

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

the class SubstrExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    if (lastValue != null && lastValue != this) {
        lastValue.generateCodeExpression(aData, expression, true);
        return;
    }
    final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    // TODO handle the needs conversion case
    final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    switch(expressionType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            {
                aData.addCommonLibraryImport("AdditionalFunctions");
                expression.expression.append("AdditionalFunctions.subString( ");
                final ITTCN3Template temp = templateInstance1.getTemplateBody();
                if (temp.isValue(CompilationTimeStamp.getBaseTimestamp())) {
                    final IValue value = temp.getValue();
                    value.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
                }
                expression.expression.append(", ");
                if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                    lastValue2.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    final long tempNative = ((Integer_Value) lastValue2).getValue();
                    expression.expression.append(tempNative);
                }
                expression.expression.append(", ");
                if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                    lastValue3.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    final long tempNative = ((Integer_Value) lastValue3).getValue();
                    expression.expression.append(tempNative);
                }
                expression.expression.append(')');
                break;
            }
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(".substr( ");
            if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                lastValue2.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue2).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                lastValue3.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue3).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(')');
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 4 with ITTCN3Template

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

the class SubstrExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (templateInstance1 == null || value2 == null || value3 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final ITTCN3Template temp = templateInstance1.getTemplateBody();
    final IValue value1 = ((SpecificValue_Template) temp).getSpecificValue();
    final IValue v1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue v2 = value2.getValueRefdLast(timestamp, referenceChain);
    final IValue v3 = value3.getValueRefdLast(timestamp, referenceChain);
    final int index = (int) ((Integer_Value) v2).getValue();
    final int len = (int) ((Integer_Value) v3).getValue();
    switch(v1.getValuetype()) {
        case BITSTRING_VALUE:
            lastValue = new Bitstring_Value(((Bitstring_Value) v1).getValue().substring(index, index + len));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            lastValue = new Hexstring_Value(((Hexstring_Value) v1).getValue().substring(index, index + len));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            lastValue = new Octetstring_Value(((Octetstring_Value) v1).getValue().substring(index * 2, (index + len) * 2));
            lastValue.copyGeneralProperties(this);
            break;
        case CHARSTRING_VALUE:
            lastValue = new Charstring_Value(((Charstring_Value) v1).getValue().substring(index, index + len));
            lastValue.copyGeneralProperties(this);
            break;
        case UNIVERSALCHARSTRING_VALUE:
            lastValue = new UniversalCharstring_Value(((UniversalCharstring_Value) v1).getValue().substring(index, index + len));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 5 with ITTCN3Template

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

the class SubstrExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance1 == null || value2 == null || value3 == null || getIsErroneous(timestamp)) {
        return true;
    }
    ITTCN3Template template = templateInstance1.getTemplateBody();
    if (template == null || !Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        return true;
    }
    final IValue value1 = ((SpecificValue_Template) template).getSpecificValue();
    if (value1 == null) {
        return true;
    }
    template = template.setLoweridToReference(timestamp);
    final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            break;
        default:
            return true;
    }
    return value1.isUnfoldable(timestamp, expectedValue, referenceChain) || value2.isUnfoldable(timestamp, expectedValue, referenceChain) || value3.isUnfoldable(timestamp, expectedValue, referenceChain);
}
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) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)67 IType (org.eclipse.titan.designer.AST.IType)42 IValue (org.eclipse.titan.designer.AST.IValue)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)19 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)19 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Type (org.eclipse.titan.designer.AST.Type)13 ISubReference (org.eclipse.titan.designer.AST.ISubReference)12 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)12 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)12 Reference (org.eclipse.titan.designer.AST.Reference)10 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)6 HashMap (java.util.HashMap)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)5