Search in sources :

Example 16 with Assignment

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

the class DecvalueUnicharExpression method checkExpressionOperand2.

/**
 * Checks the 2nd operand
 * out any_type
 * @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 checkExpressionOperand2(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference1 == null) {
        setIsErroneous(true);
        return;
    }
    final Assignment temporalAssignment = reference2.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    temporalType = temporalType.getTypeRefdLast(timestamp);
    switch(temporalType.getTypetype()) {
        case TYPE_UNDEFINED:
        case TYPE_NULL:
        case TYPE_REFERENCED:
        case TYPE_VERDICT:
        case TYPE_PORT:
        case TYPE_COMPONENT:
        case TYPE_DEFAULT:
        case TYPE_SIGNATURE:
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            reference2.getLocation().reportSemanticError(OPERAND2_ERROR1);
            setIsErroneous(true);
            break;
        default:
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IType(org.eclipse.titan.designer.AST.IType)

Example 17 with Assignment

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

the class DecvalueUnicharExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * inout universal charstring
 * @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 checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference1 == null) {
        setIsErroneous(true);
        return;
    }
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR2, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR3, last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR4, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    final Type_type type_type = temporalType.getTypeRefdLast(timestamp).getTypetype();
    if (type_type != Type_type.TYPE_UCHARSTRING) {
        if (!isErroneous) {
            location.reportSemanticError(OPERAND1_ERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 18 with Assignment

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

the class ActivateExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    expression.expression.append(assignment.getGenNameFromScope(aData, aData.getSrc(), myScope, "activate_"));
    expression.expression.append('(');
    if (!reference.getSubreferences().isEmpty()) {
        final ISubReference subReference = reference.getSubreferences().get(0);
        if (Subreference_type.parameterisedSubReference.equals(subReference.getReferenceType())) {
            ((ParameterisedSubReference) subReference).getActualParameters().generateCodeNoAlias(aData, expression);
        }
    }
    expression.expression.append(')');
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference)

Example 19 with Assignment

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

the class OccurencesMarker method findOccurrencesReferenceBased.

/**
 * Finds the occurrences of the element located on the given offset.
 * This solution can be used, when the locations are not correct. (e.g.
 * in case of an ASN.1 file)
 *
 * @param document
 * @param reference
 * @param module
 *                The module to search the occurrences in
 * @param offset
 *                An offset in the module
 * @return The found references. Includes the definition of the element.
 */
protected List<Hit> findOccurrencesReferenceBased(final IDocument document, final Reference reference, final Module module, final int offset) {
    Scope scope = module.getSmallestEnclosingScope(offset);
    if (scope == null) {
        removeOccurences(false);
        error(document, offset, "Can not determine the smallest enclosing scope.");
        return new ArrayList<ReferenceFinder.Hit>();
    }
    reference.setMyScope(scope);
    if (reference.getId() == null) {
        removeOccurences(false);
        error(document, offset, "The identifier of the reference is null.");
        return new ArrayList<ReferenceFinder.Hit>();
    }
    if (reference.getSubreferences().size() > 1) {
        // highlighting the subreferences is not yet supported
        removeOccurences(false);
        return new ArrayList<ReferenceFinder.Hit>();
    }
    ReferenceFinder referenceFinder;
    List<Hit> result = null;
    boolean found = false;
    if (scope.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), reference.getId()) || (scope.getModuleScope().hasImportedAssignmentWithID(CompilationTimeStamp.getBaseTimestamp(), reference.getId()))) {
        Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment == null) {
            error(document, offset, "The assignment could not be determined from the reference: " + reference.getDisplayName());
            removeOccurences(false);
            return new ArrayList<ReferenceFinder.Hit>();
        }
        if (!assignment.shouldMarkOccurrences()) {
            removeOccurences(false);
            return new ArrayList<ReferenceFinder.Hit>();
        }
        try {
            referenceFinder = new ReferenceFinder(assignment);
        } catch (final IllegalArgumentException e) {
            removeOccurences(false);
            return new ArrayList<ReferenceFinder.Hit>();
        }
        result = referenceFinder.findReferencesInModule(module);
        // Hack to eliminate false positive results
        if (assignment.getLocation().containsOffset(offset)) {
            found = true;
        } else {
            for (Hit hit : result) {
                if (hit.identifier.getLocation().containsOffset(offset)) {
                    found = true;
                    break;
                }
            }
        }
        if (found && assignment.getMyScope().getModuleScope() == module && assignment.getIdentifier() != null) {
            result.add(new Hit(assignment.getIdentifier()));
        }
    }
    if (!found) {
        // Check if the reference points to a field of a type
        // definition
        referenceFinder = new ReferenceFinder();
        referenceFinder.detectAssignmentDataByOffset(module, offset, editor, false, false);
        Assignment assignment = referenceFinder.assignment;
        if (assignment == null) {
            removeOccurences(false);
            error(document, offset, "Could not detect the assignment.");
            return new ArrayList<ReferenceFinder.Hit>();
        }
        if (assignment.getAssignmentType() != null && assignment.getAssignmentType() != Assignment_type.A_TYPE || referenceFinder.fieldId == null || !assignment.shouldMarkOccurrences()) {
            removeOccurences(false);
            return new ArrayList<ReferenceFinder.Hit>();
        }
        result = referenceFinder.findReferencesInModule(module);
        if (referenceFinder.fieldId != null) {
            result.add(new Hit(referenceFinder.fieldId));
        }
    }
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) Scope(org.eclipse.titan.designer.AST.Scope) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) ArrayList(java.util.ArrayList)

Example 20 with Assignment

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

the class For_Loop_Definitions method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastCompilationTimeStamp != null && !lastCompilationTimeStamp.isLess(timestamp)) {
        return;
    }
    lastCompilationTimeStamp = timestamp;
    lastUniquenessCheckTimeStamp = timestamp;
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(definitions.size());
    }
    definitionMap.clear();
    String definitionName;
    Definition definition;
    Identifier identifier;
    for (int i = 0, size = definitions.size(); i < size; i++) {
        definition = definitions.get(i);
        identifier = definition.getIdentifier();
        definitionName = identifier.getName();
        if (definitionMap.containsKey(definitionName)) {
            final Location otherLocation = definitionMap.get(definitionName).getIdentifier().getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            definitionMap.put(definitionName, definition);
            if (parentScope != null && definition.getLocation() != null) {
                if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                    definition.getLocation().reportSemanticError(MessageFormat.format(StatementBlock.HIDINGSCOPEELEMENT, identifier.getDisplayName()));
                    final List<ISubReference> subReferences = new ArrayList<ISubReference>();
                    subReferences.add(new FieldSubReference(identifier));
                    final Reference reference = new Reference(null, subReferences);
                    final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
                    if (assignment != null && assignment.getLocation() != null) {
                        assignment.getLocation().reportSingularSemanticError(MessageFormat.format(StatementBlock.HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                    }
                } else if (parentScope.isValidModuleId(identifier)) {
                    definition.getLocation().reportSemanticWarning(MessageFormat.format(StatementBlock.HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
                }
            }
        }
        definition.check(timestamp);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

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