Search in sources :

Example 66 with IReferenceChain

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

the class Referenced_Type method getTypeRefdLast.

@Override
public /**
 * {@inheritDoc}
 */
IType getTypeRefdLast(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    IType t = this;
    while (t != null && t instanceof IReferencingType && !t.getIsErroneous(timestamp)) {
        t = ((IReferencingType) t).getTypeRefd(timestamp, tempReferenceChain);
    }
    if (newChain) {
        tempReferenceChain.release();
    }
    if (t != null && t.getIsErroneous(timestamp)) {
        setIsErroneous(true);
    }
    return t;
}
Also used : IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Example 67 with IReferenceChain

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

the class ComponentTypeBody method addDefinitionsOfExtendAttributeParents.

private void addDefinitionsOfExtendAttributeParents(final CompilationTimeStamp timestamp) {
    attributeGainedDefinitions.clear();
    if (attrExtendsReferences != null) {
        attrExtendsReferences.check(timestamp);
        final IReferenceChain referenceChain = ReferenceChain.getInstance(CIRCULAREXTENSIONCHAIN, true);
        if (referenceChain.add(this)) {
            attrExtendsReferences.checkRecursion(referenceChain);
        }
        referenceChain.release();
        initCompatibility(attrExtendsReferences);
        collectDefinitionsFromAttributeExtends();
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 68 with IReferenceChain

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

the class Component_Type method checkExpressionOperandComponentRefernce.

/**
 * Checks if the provided value is a reference to a component or not.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expected_value the value kind expected from the actual parameter.
 */
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
    switch(value.getValuetype()) {
        case EXPRESSION_VALUE:
            {
                final Expression_Value expression = (Expression_Value) value;
                if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final IValue last = value.getValueRefdLast(timestamp, chain);
                    chain.release();
                    if (last == null || last.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        return;
                    }
                    IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                    if (type == null) {
                        value.setIsErroneous(true);
                        return;
                    }
                    type = type.getTypeRefdLast(timestamp);
                    if (type.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        // don't let spread an earlier mistake
                        return;
                    }
                    if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                        value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                        value.setIsErroneous(true);
                        return;
                    }
                }
                break;
            }
        case REFERENCED_VALUE:
            {
                final Reference reference = ((Referenced_Value) value).getReference();
                final Assignment assignment = reference.getRefdAssignment(timestamp, true);
                if (assignment == null) {
                    value.setIsErroneous(true);
                    return;
                }
                switch(assignment.getAssignmentType()) {
                    case A_CONST:
                        {
                            IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            IValue tempValue = ((Def_Const) assignment).getValue();
                            if (tempValue == null) {
                                return;
                            }
                            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
                            chain.release();
                            if (tempValue == null) {
                                return;
                            }
                            chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getValueRefdLast(timestamp, chain);
                            chain.release();
                            if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                value.setIsErroneous(true);
                                return;
                            }
                            if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
                                return;
                            }
                            switch(((Expression_Value) tempValue).getOperationType()) {
                                case MTC_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case COMPONENT_NULL_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case SYSTEM_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                default:
                                    break;
                            }
                            break;
                        }
                    case A_EXT_CONST:
                        {
                            IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_MODULEPAR:
                        {
                            IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_VAR:
                        {
                            IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_EXT_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_PAR_VAL:
                    case A_PAR_VAL_IN:
                    case A_PAR_VAL_OUT:
                    case A_PAR_VAL_INOUT:
                        {
                            IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    default:
                        reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
                        value.setIsErroneous(true);
                        return;
                }
                break;
            }
        default:
            // the error was already reported if possible.
            return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) IType(org.eclipse.titan.designer.AST.IType)

Example 69 with IReferenceChain

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

the class ObjectID_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    value.setIsErroneous(false);
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    if (Value_type.UNDEFINED_BLOCK.equals(last.getValuetype())) {
        last = last.setValuetype(timestamp, Value_type.OBJECTID_VALUE);
    }
    if (last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    switch(last.getValuetype()) {
        case OBJECTID_VALUE:
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            ((ObjectIdentifier_Value) last).checkOID(timestamp, referenceChain);
            referenceChain.release();
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            if (value.isAsn()) {
                value.getLocation().reportSemanticError(OBJIDVALUEEXPECTED1);
            } else {
                value.getLocation().reportSemanticError(OBJIDVALUEEXPECTED2);
            }
            value.setIsErroneous(true);
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ObjectIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.ObjectIdentifier_Value)

Example 70 with IReferenceChain

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

the class SubType method addParentSubtype.

private boolean addParentSubtype(final SubType st) {
    if (myParents.contains(st)) {
        // it was already successfully added -> ignore
        return true;
    }
    final IReferenceChain refch = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    // current type
    refch.add(myOwner);
    // recursive check for all parents of referenced type
    if (!st.checkRecursion(refch)) {
        refch.release();
        return false;
    }
    // if no recursion was detected then add the referenced type as
    // parent
    myParents.add(st);
    refch.release();
    return true;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)154 IValue (org.eclipse.titan.designer.AST.IValue)102 IType (org.eclipse.titan.designer.AST.IType)55 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)21 ISubReference (org.eclipse.titan.designer.AST.ISubReference)18 Value (org.eclipse.titan.designer.AST.Value)18 Assignment (org.eclipse.titan.designer.AST.Assignment)16 BigInteger (java.math.BigInteger)15 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)14 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)13 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Reference (org.eclipse.titan.designer.AST.Reference)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)7 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)7 HashMap (java.util.HashMap)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)6 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)5