Search in sources :

Example 6 with Reference

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

the class IsPresentExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template template = templateInstance.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) template).getSpecificValue();
        if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            final Reference reference = ((Referenced_Value) value).getReference();
            if (reference != null) {
                final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
                if (assignment != null) {
                    switch(assignment.getAssignmentType()) {
                        case A_TEMPLATE:
                        case A_VAR_TEMPLATE:
                        case A_MODULEPAR_TEMPLATE:
                        case A_EXT_FUNCTION_RTEMP:
                        case A_FUNCTION_RTEMP:
                        case A_PAR_TEMP_IN:
                        case A_PAR_TEMP_OUT:
                        case A_PAR_TEMP_INOUT:
                            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
                            return;
                        default:
                            break;
                    }
                }
                reference.generateCodeIsPresentBoundChosen(aData, expression, false, getOperationType(), null);
                return;
            }
        } else {
            // FIXME cast_needed case
            value.generateCodeExpressionMandatory(aData, expression, true);
        }
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        if (reference != null) {
            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
            return;
        }
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".isPresent()");
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 7 with Reference

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

the class IsPresentExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance == null) {
        return true;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody().setLoweridToReference(timestamp);
    if (templateInstance.getDerivedReference() != null) {
        return true;
    }
    if (template.getIfPresent()) {
        return false;
    }
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue specificValue = ((SpecificValue_Template) template).getValue();
        if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
            final Reference reference = ((Referenced_Value) specificValue).getReference();
            final Assignment ass = reference.getRefdAssignment(timestamp, false);
            if (ass == null) {
                return true;
            }
            switch(ass.getAssignmentType()) {
                case A_OBJECT:
                case A_OS:
                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:
                    break;
                default:
                    return true;
            }
            // TODO improve to better detect unbound
            // elements
            final IValue last = specificValue.getValueRefdLast(timestamp, expectedValue, null);
            if (last == null) {
                return true;
            }
            if (last == this) {
                return getIsErroneous(timestamp);
            }
            return last.isUnfoldable(timestamp, expectedValue, referenceChain);
        }
        return specificValue.isUnfoldable(timestamp, expectedValue, referenceChain);
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (ass == null) {
            return true;
        }
        switch(ass.getAssignmentType()) {
            case A_CONST:
                // const is foldable
                return false;
            case A_TEMPLATE:
                break;
            default:
                return true;
        }
        // TODO improve to better detect unbound elements
        final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
        if (last == null) {
            return true;
        }
        if (last == template) {
            return last.getIsErroneous(timestamp);
        }
        if (last.getIfPresent()) {
            return false;
        }
        if (Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
            return ((SpecificValue_Template) last).getValue().isUnfoldable(timestamp, expectedValue, referenceChain);
        }
    }
    return true;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 8 with Reference

use of org.eclipse.titan.designer.AST.Reference 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 Reference

use of org.eclipse.titan.designer.AST.Reference 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)

Example 10 with Reference

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

the class ObjectIdentifierComponent method checkDefdValueOID.

/**
 * Checks the defined value form in an OID component.
 *
 * @param timestamp the timestamp of the actual compilation cycle.
 * @param refChain the reference chain used to detect cyclic references.
 * @param state the state of checking.
 *
 * @param the new state after this check was done.
 */
private oidState_type checkDefdValueOID(final CompilationTimeStamp timestamp, final IReferenceChain refChain, final oidState_type state) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue value = definedValue.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (value.getIsErroneous(timestamp)) {
        return oidState_type.LATER;
    }
    switch(value.getValuetype()) {
        case INTEGER_VALUE:
            final ObjectIdentifierComponent temp = new ObjectIdentifierComponent(null, definedValue);
            temp.setFullNameParent(this);
            temp.setMyScope(myScope);
            return temp.checkNumberFormOID(timestamp, state);
        case OBJECTID_VALUE:
            if (!oidState_type.START.equals(state)) {
                definedValue.getLocation().reportSemanticError("INTEGER or RELATIVE-OID value was expected");
            }
            ((ObjectIdentifier_Value) value).checkOID(timestamp, refChain);
            return oidState_type.LATER;
        case RELATIVEOBJECTIDENTIFIER_VALUE:
            switch(state) {
                case ITU_REC:
                    return oidState_type.LATER;
                case LATER:
                    return oidState_type.LATER;
                default:
                    definedValue.getLocation().reportSemanticError(MessageFormat.format("RELATIVE-OID value cannot be used as the {0} component of an OBJECTIDENTIFIER value", oidState_type.START.equals(state) ? "first" : "second"));
                    return oidState_type.LATER;
            }
        case REFERENCED_VALUE:
            {
                final Reference reference = ((Referenced_Value) value).getReference();
                final Assignment assignment = reference.getRefdAssignment(timestamp, false);
                final IType type = assignment.getType(timestamp).getTypeRefdLast(timestamp);
                if (type.getTypetype() == Type_type.TYPE_INTEGER) {
                // FIXME implement handling of the variable form
                } else {
                    definedValue.getLocation().reportSemanticError("INTEGER variable was expected");
                }
                return oidState_type.LATER;
            }
        default:
            if (oidState_type.START.equals(state)) {
                definedValue.getLocation().reportSemanticError("INTEGER or OBJECT IDENTIFIER value was expected for the first component");
            } else {
                definedValue.getLocation().reportSemanticError("INTEGER or RELATIVE-OID value was expected");
            }
            return oidState_type.LATER;
    }
}
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) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) RelativeObjectIdentifier_Value(org.eclipse.titan.designer.AST.ASN1.values.RelativeObjectIdentifier_Value) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Reference (org.eclipse.titan.designer.AST.Reference)88 Assignment (org.eclipse.titan.designer.AST.Assignment)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)37 IValue (org.eclipse.titan.designer.AST.IValue)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)23 IType (org.eclipse.titan.designer.AST.IType)23 Identifier (org.eclipse.titan.designer.AST.Identifier)22 ArrayList (java.util.ArrayList)19 Module (org.eclipse.titan.designer.AST.Module)16 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)15 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)13 IFile (org.eclipse.core.resources.IFile)11 Location (org.eclipse.titan.designer.AST.Location)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)8 Type (org.eclipse.titan.designer.AST.Type)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7