Search in sources :

Example 1 with ValueCheckingOptions

use of org.eclipse.titan.designer.AST.IType.ValueCheckingOptions in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Value method checkExpressionSelfReferenceValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkExpressionSelfReferenceValue(final CompilationTimeStamp timestamp, final Assignment lhs) {
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    }
    if (governor == null) {
        return false;
    }
    final boolean isStringElement = reference.refersToStringElement();
    return governor.checkThisValue(timestamp, this, lhs, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, true, false, false, isStringElement));
}
Also used : ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with ValueCheckingOptions

use of org.eclipse.titan.designer.AST.IType.ValueCheckingOptions in project titan.EclipsePlug-ins by eclipse.

the class Def_ModulePar method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (((Function_Type) lastType).isRunsOnSelf()) {
                location.reportSemanticError(MessageFormat.format(RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
            }
            break;
        default:
            break;
    }
    if (defaultValue != null) {
        defaultValue.setMyGovernor(type);
        final IValue temporalValue = type.checkThisValueRef(timestamp, defaultValue);
        type.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, true, false, true, hasImplicitOmitAttribute(timestamp), false));
        defaultValue.setCodeSection(CodeSectionType.CS_PRE_INIT);
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 3 with ValueCheckingOptions

use of org.eclipse.titan.designer.AST.IType.ValueCheckingOptions in project titan.EclipsePlug-ins by eclipse.

the class Def_Var method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    wasAssigned = false;
    if (getMyScope() instanceof ComponentTypeBody) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_COMPONENT_VARIABLE, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_VARIABLE, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        default:
            break;
    }
    if (initialValue != null) {
        initialValue.setMyGovernor(type);
        final IValue temporalValue = type.checkThisValueRef(timestamp, initialValue);
        if (isLocal()) {
            type.checkThisValue(timestamp, temporalValue, this, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, true, false, false));
        } else {
            type.checkThisValue(timestamp, temporalValue, this, new ValueCheckingOptions(Expected_Value_type.EXPECTED_STATIC_VALUE, true, false, true, false, false));
        }
        initialValue.setGenNameRecursive(getGenName());
        initialValue.setCodeSection(CodeSectionType.CS_INLINE);
    }
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IValue(org.eclipse.titan.designer.AST.IValue) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with ValueCheckingOptions

use of org.eclipse.titan.designer.AST.IType.ValueCheckingOptions in project titan.EclipsePlug-ins by eclipse.

the class Assignment_Statement method checkVarAssignment.

private void checkVarAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final IValue value) {
    final IType varType = getType(timestamp, assignment);
    if (varType == null || value == null) {
        isErroneous = true;
        return;
    }
    final IType type = varType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (type == null) {
        isErroneous = true;
        return;
    }
    value.setMyGovernor(type);
    IValue lastValue = type.checkThisValueRef(timestamp, value);
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    lastValue = lastValue.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (Value_type.OMIT_VALUE.equals(lastValue.getValuetype())) {
        final ISubReference lastReference = reference.removeLastSubReference();
        if (lastReference == null || lastReference.getId() == null) {
            value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
            isErroneous = true;
            reference.addSubReference(lastReference);
            return;
        }
        final Identifier lastField = lastReference.getId();
        final List<ISubReference> baseReference = reference.getSubreferences(0, reference.getSubreferences().size() - 1);
        reference.addSubReference(lastReference);
        final Reference newReference = new TemporalReference(null, baseReference);
        newReference.clearStringElementReferencing();
        IType baseType = varType.getFieldType(timestamp, newReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
        if (baseType == null) {
            isErroneous = true;
            return;
        }
        baseType = baseType.getTypeRefdLast(timestamp);
        if (baseType.getIsErroneous(timestamp)) {
            isErroneous = true;
            return;
        }
        CompField componentField;
        switch(baseType.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                componentField = ((TTCN3_Sequence_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SEQUENCE:
                componentField = ((ASN1_Sequence_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_TTCN3_SET:
                componentField = ((TTCN3_Set_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SET:
                componentField = ((ASN1_Set_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            default:
                // TODO:check this!!!
                value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
                value.setIsErroneous(true);
                isErroneous = true;
                break;
        }
    } else {
        final boolean isStringElement = reference.refersToStringElement();
        selfReference = type.checkThisValue(timestamp, value, assignment, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, !isStringElement, false, isStringElement));
        if (isStringElement) {
            // The length of the right hand side should be 1
            final IType lastType = type.getTypeRefdLast(timestamp);
            int stringLength = 1;
            switch(lastType.getTypetype()) {
                case TYPE_BITSTRING:
                case TYPE_BITSTRING_A:
                    if (!Value_type.BITSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Bitstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_HEXSTRING:
                    if (!Value_type.HEXSTRING_VALUE.equals(lastValue.getValuetype())) {
                        lastValue = null;
                    } else {
                        stringLength = ((Hexstring_Value) lastValue).getValueLength();
                    }
                    break;
                case TYPE_OCTETSTRING:
                    if (!Value_type.OCTETSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Octetstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_CHARSTRING:
                case TYPE_NUMERICSTRING:
                case TYPE_PRINTABLESTRING:
                case TYPE_IA5STRING:
                case TYPE_VISIBLESTRING:
                case TYPE_UTCTIME:
                case TYPE_GENERALIZEDTIME:
                    if (!Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Charstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_UCHARSTRING:
                case TYPE_UTF8STRING:
                case TYPE_TELETEXSTRING:
                case TYPE_VIDEOTEXSTRING:
                case TYPE_GRAPHICSTRING:
                case TYPE_GENERALSTRING:
                case TYPE_UNIVERSALSTRING:
                case TYPE_BMPSTRING:
                case TYPE_OBJECTDESCRIPTOR:
                    if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((UniversalCharstring_Value) lastValue).getValueLength();
                    } else if (Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((Charstring_Value) lastValue).getValueLength();
                    } else {
                        return;
                    }
                    break;
                default:
                    lastValue = null;
                    return;
            }
            if (stringLength != 1) {
                final String message = MessageFormat.format("The length of the string to be assigned to a string element of type `{0}'' should be 1 instead of {1}", type.getTypename(), stringLength);
                value.getLocation().reportSemanticError(message);
                value.setIsErroneous(true);
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) IType(org.eclipse.titan.designer.AST.IType) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 5 with ValueCheckingOptions

use of org.eclipse.titan.designer.AST.IType.ValueCheckingOptions in project titan.EclipsePlug-ins by eclipse.

the class FixedTypeValue_FieldSpecification method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (null != fixedType) {
        fixedType.setGenName(myObjectClass.getGenNameOwn(), identifier.getName());
        fixedType.check(timestamp);
        if (null != defaultValue) {
            defaultValue.setMyGovernor(fixedType);
            final IValue tempValue = fixedType.checkThisValueRef(timestamp, defaultValue);
            fixedType.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, true, false, false));
            defaultValue.setCodeSection(CodeSectionType.CS_PRE_INIT);
        }
    }
    lastTimeChecked = timestamp;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Aggregations

ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)24 IValue (org.eclipse.titan.designer.AST.IValue)22 IType (org.eclipse.titan.designer.AST.IType)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)5 Reference (org.eclipse.titan.designer.AST.Reference)4 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 Module (org.eclipse.titan.designer.AST.Module)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 Scope (org.eclipse.titan.designer.AST.Scope)2 ComponentTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)2 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)2 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)2