Search in sources :

Example 1 with Def_ExternalConst

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst 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 2 with Def_ExternalConst

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst in project titan.EclipsePlug-ins by eclipse.

the class TypenameInDef method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
        return;
    }
    final Definition s = (Definition) node;
    check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
Also used : Def_ExternalConst(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Aggregations

Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 IType (org.eclipse.titan.designer.AST.IType)1 IValue (org.eclipse.titan.designer.AST.IValue)1 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Def_ExternalConst (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst)1 Def_Extfunction (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction)1 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)1 Def_ModulePar (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar)1 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)1 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)1 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)1 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)1 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)1