Search in sources :

Example 6 with Assignment

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

the class TimerRunningExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
            {
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
                }
                break;
            }
        case A_PAR_TIMER:
            if (reference.getSubreferences().size() > 1) {
                reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR, assignment.getIdentifier().getDisplayName()));
            }
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR2, assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, true, false);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)

Example 7 with Assignment

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

the class UndefRunningExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    setIsErroneous(false);
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_TIMER:
        case A_PAR_TIMER:
            {
                realExpression = new TimerRunningExpression(reference);
                realExpression.setMyScope(getMyScope());
                realExpression.setFullNameParent(this);
                realExpression.setLocation(getLocation());
                realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
                break;
            }
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            {
                final Referenced_Value value = new Referenced_Value(reference);
                value.setMyScope(getMyScope());
                value.setFullNameParent(this);
                value.getValueRefdLast(timestamp, referenceChain);
                realExpression = new ComponentRunnningExpression(value);
                realExpression.setMyScope(getMyScope());
                realExpression.setFullNameParent(this);
                realExpression.setLocation(getLocation());
                realExpression.evaluateValue(timestamp, expectedValue, referenceChain);
                break;
            }
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format("First operand of operation `<timer or component> running'' should be timer or component reference instead of {0}", assignment.getDescription()));
            setIsErroneous(true);
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 8 with Assignment

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

the class AssignmentHandlerAFTRerences method visit.

@Override
public int visit(final IVisitableNode node) {
    if (node instanceof ASN1Assignment) {
        final ASN1Assignment assignment = (ASN1Assignment) node;
        if (assignment.getAssPard() != null) {
            return V_SKIP;
        }
    }
    if (node instanceof StatementBlock) {
        final ReferenceCollector referenceCollector = new ReferenceCollector();
        node.accept(referenceCollector);
        // TODO: broken if reference does not point anywhere
        final Set<Reference> references = referenceCollector.getReferences();
        addNonContagiousReferences(computeReferences(references));
        if (containsErroneousReference(references)) {
            setIsInfected(true);
        }
        return V_SKIP;
    }
    if (node instanceof Reference) {
        final Identifier identifier = ((Reference) node).getId();
        if (identifier != null) {
            addContagiousReference(identifier.getDisplayName());
        }
        if (((Reference) node).getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
            setIsInfected(true);
            setIsContagious(true);
            return V_CONTINUE;
        }
        final Assignment assignment = ((Reference) node).getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false, null);
        if (assignment == null || assignment.getIdentifier() == null || !assignment.getIdentifier().equals(identifier)) {
            setIsInfected(true);
            setIsContagious(true);
            return V_CONTINUE;
        }
    }
    return V_CONTINUE;
}
Also used : ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 9 with Assignment

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

the class BrokenPartsViaReferences method collectBrokenModulesViaInvertedImports.

protected List<Module> collectBrokenModulesViaInvertedImports(final List<Module> startModules, final Map<Module, List<Module>> invertedImports) {
    final List<Module> startModulesCopy = new ArrayList<Module>(startModules);
    final List<Module> result = new ArrayList<Module>();
    final MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
    if (writeDebugInfo) {
        for (Module startModule : startModules) {
            TITANDebugConsole.println("  ** Module " + startModule.getName() + " can not be skipped as it was not yet analyzed.", stream);
        }
    }
    for (int s = 0; s < startModulesCopy.size(); ++s) {
        final Module startModule = startModulesCopy.get(s);
        if (!result.contains(startModule)) {
            result.add(startModule);
        }
        final List<Module> whereStartModuleUsed = invertedImports.get(startModule);
        for (int d = 0; d < whereStartModuleUsed.size(); ++d) {
            final Module dependentModule = whereStartModuleUsed.get(d);
            if (!startModulesCopy.contains(dependentModule)) {
                startModulesCopy.add(dependentModule);
                if (writeDebugInfo) {
                    TITANDebugConsole.println("  ** Module " + dependentModule.getName() + " can not be skipped as it depends on " + startModule.getName() + " which needs to be checked.", stream);
                }
            }
        }
        startModule.notCheckRoot();
        final Assignments assignments = startModule.getAssignments();
        for (int d = 0; d < assignments.getNofAssignments(); ++d) {
            final Assignment assignment = assignments.getAssignmentByIndex(d);
            assignment.notCheckRoot();
        }
    }
    return result;
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) ArrayList(java.util.ArrayList) Assignments(org.eclipse.titan.designer.AST.Assignments) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 10 with Assignment

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

the class Referenced_Value method checkExpressionOmitComparison.

@Override
public /**
 * {@inheritDoc}
 */
void checkExpressionOmitComparison(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (getIsErroneous(timestamp)) {
        return;
    }
    final List<ISubReference> subreferences = new ArrayList<ISubReference>();
    subreferences.addAll(reference.getSubreferences());
    if (subreferences.size() <= 1) {
        return;
    }
    final ISubReference subreference = subreferences.remove(subreferences.size() - 1);
    final Identifier id = subreference.getId();
    if (id == null) {
        getLocation().reportSemanticError("Only a reference pointing to an optional record or set field can be compared with `omit'");
        setIsErroneous(true);
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    IType type = assignment.getType(timestamp);
    if (type == null) {
        setIsErroneous(true);
        return;
    }
    final Reference tempReference = new Reference(null, subreferences);
    tempReference.setFullNameParent(this);
    tempReference.setMyScope(myScope);
    type = type.getFieldType(timestamp, tempReference, 1, expectedValue, false);
    if (type == null) {
        setIsErroneous(true);
        return;
    }
    type = type.getTypeRefdLast(timestamp);
    if (type == null || type.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return;
    }
    switch(type.getTypetype()) {
        case TYPE_ASN1_SEQUENCE:
            if (!((ASN1_Sequence_Type) type).hasComponentWithName(id)) {
                getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
                setIsErroneous(true);
            } else if (!((ASN1_Sequence_Type) type).getComponentByName(id).isOptional()) {
                getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
                setIsErroneous(true);
            }
            break;
        case TYPE_TTCN3_SEQUENCE:
            if (!((TTCN3_Sequence_Type) type).hasComponentWithName(id.getName())) {
                getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
                setIsErroneous(true);
            } else if (!((TTCN3_Sequence_Type) type).getComponentByName(id.getName()).isOptional()) {
                getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
                setIsErroneous(true);
            }
            break;
        case TYPE_ASN1_SET:
            if (!((ASN1_Set_Type) type).hasComponentWithName(id)) {
                getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
                setIsErroneous(true);
            } else if (!((ASN1_Set_Type) type).getComponentByName(id).isOptional()) {
                getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
                setIsErroneous(true);
            }
            break;
        case TYPE_TTCN3_SET:
            if (!((TTCN3_Set_Type) type).hasComponentWithName(id.getName())) {
                getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
                setIsErroneous(true);
            } else if (!((TTCN3_Set_Type) type).getComponentByName(id.getName()).isOptional()) {
                getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
                setIsErroneous(true);
            }
            break;
        default:
            getLocation().reportSemanticError("Only a reference pointing to an optional record or set field can be compared with `omit'");
            setIsErroneous(true);
            break;
    }
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ArrayList(java.util.ArrayList) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)141 Reference (org.eclipse.titan.designer.AST.Reference)48 IType (org.eclipse.titan.designer.AST.IType)41 ISubReference (org.eclipse.titan.designer.AST.ISubReference)39 IValue (org.eclipse.titan.designer.AST.IValue)31 Identifier (org.eclipse.titan.designer.AST.Identifier)25 ArrayList (java.util.ArrayList)24 Module (org.eclipse.titan.designer.AST.Module)22 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)16 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)14 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)14 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)14 Assignments (org.eclipse.titan.designer.AST.Assignments)13 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 Location (org.eclipse.titan.designer.AST.Location)9 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)7 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)6