Search in sources :

Example 1 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class Def_Type_Visit_Handler method visitDefTypeChildrenNodes.

public void visitDefTypeChildrenNodes(IVisitableNode node) {
    if (node instanceof Def_Port) {
        Def_Port port = (Def_Port) node;
        componentPortNames.add(port.getIdentifier().toString());
    }
    if (node instanceof Def_Var) {
        Def_Var var = (Def_Var) node;
        componentVarNames.add(var.getIdentifier().toString());
        if (var.getType(compilationCounter) instanceof Integer_Type) {
            componentVarTypes.add("INTEGER");
        }
    }
    if (waitForCompReference && (node instanceof Reference)) {
        componentPortTypes.add(((Reference) node).getId().toString());
    }
    if (waitForSetOfFieldType) {
        if (node instanceof Reference) {
            setOfFieldType = node.toString();
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SetOf_Type)) {
            Type type = (Type) node;
            setOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        }
    }
    if (waitForRecordOfFieldType) {
        if (node instanceof Reference) {
            recordOfFieldType = node.toString();
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SequenceOf_Type)) {
            Type type = (Type) node;
            recordOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        }
    }
    if (node instanceof CompField) {
        // component
        CompField compFieldNode = (CompField) node;
        if (compFieldNode.getType() instanceof Referenced_Type) {
            compFieldTypes.add(((Referenced_Type) compFieldNode.getType()).getReference().getId().toString());
        } else {
            compFieldTypes.add(myASTVisitor.cutModuleNameFromBeginning(compFieldNode.getType().getTypename()));
        }
        compFieldNames.add(compFieldNode.getIdentifier().toString());
    }
    if (node instanceof Charstring_Value) {
        // charstring
        Charstring_Value singleValuedNode = (Charstring_Value) node;
        charstringValue = singleValuedNode.getValue();
    }
    if (node instanceof Integer_Value) {
        String value = ((Integer_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add("new INTEGER(\"" + value + "\")");
    }
    if (node instanceof Real_Value) {
        String value = ((Real_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        if (value.equals("-Infinity") || value.equals("Infinity")) {
            value = "null";
        }
        expressionValue.add(value);
    }
    if (node instanceof Undefined_LowerIdentifier_Value) {
        String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add(value);
    }
    if (node instanceof EnumerationItems) {
        for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) {
            enumItems.add(((EnumerationItems) node).getItems().get(i).getId().toString());
            if (((EnumerationItems) node).getItems().get(i).getValue() != null) {
                enumItemValues.add(((EnumerationItems) node).getItems().get(i).getValue().toString());
            } else {
                enumItemValues.add(null);
            }
        }
    }
    if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) {
        isPortTypeAReferencedType = true;
    }
    if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) {
        PortTypeBody body = (PortTypeBody) node;
        int inCount = body.getInMessages().getNofTypes();
        int outCount = body.getOutMessage().getNofTypes();
        for (int i = 0; i < inCount; i++) {
            inMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getInMessages().getTypeByIndex(i).getTypename()));
        }
        for (int i = 0; i < outCount; i++) {
            outMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getOutMessage().getTypeByIndex(i).getTypename()));
        }
        int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName.size() : outMessageName.size();
        // if inout delete from both lists and add to inout
        for (int i = 0; i < inMessageName.size(); i++) {
            for (int j = 0; j < outMessageName.size(); j++) {
                if (inMessageName.get(i).equals(outMessageName.get(j))) {
                    inOutMessageName.add(inMessageName.get(i));
                    inMessageName.remove(i);
                    if (j == (outMessageName.size() - 1)) {
                        i--;
                    }
                    outMessageName.remove(j);
                    j--;
                }
            }
        }
        myASTVisitor.portNamePortTypeHashMap.put(currentPortName, body.getTestportType().toString());
        portTypeList.add(body.getTestportType().toString());
    }
}
Also used : Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Reference(org.eclipse.titan.designer.AST.Reference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) EnumerationItems(org.eclipse.titan.designer.AST.TTCN3.types.EnumerationItems) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 2 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class Type method fieldIsOptional.

@Override
public /**
 * {@inheritDoc}
 */
boolean fieldIsOptional(final List<ISubReference> subReferences) {
    // TODO there must be a better implementation
    if (subReferences == null) {
        return false;
    }
    if (subReferences.isEmpty()) {
        return false;
    }
    final ISubReference lastSubReference = subReferences.get(subReferences.size() - 1);
    if (!(lastSubReference instanceof FieldSubReference)) {
        return false;
    }
    IType type = this;
    CompField compField = null;
    for (int i = 1; i < subReferences.size(); i++) {
        if (type != null) {
            type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        }
        final ISubReference subreference = subReferences.get(i);
        if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
            final Identifier id = ((FieldSubReference) subreference).getId();
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
                        break;
                    case TYPE_ANYTYPE:
                        compField = ((Anytype_Type) type).getComponentByName(id.getName());
                        break;
                    case TYPE_OPENTYPE:
                        compField = ((Open_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SEQUENCE:
                        ((ASN1_Sequence_Type) type).parseBlockSequence();
                        compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SET:
                        ((ASN1_Set_Type) type).parseBlockSet();
                        compField = ((ASN1_Set_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_CHOICE:
                        ((ASN1_Choice_Type) type).parseBlockChoice();
                        compField = ((ASN1_Choice_Type) type).getComponentByName(id);
                        break;
                    default:
                        // TODO fatal error:
                        return false;
                }
                if (compField == null) {
                    // TODO fatal error
                    return false;
                }
                type = compField.getType();
            }
        } else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
            final Value value = ((ArraySubReference) subreference).getValue();
            // TODO actually should get the last governor
            final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_SEQUENCE_OF:
                    case TYPE_SET_OF:
                        type = ((AbstractOfType) type).getOfType();
                        break;
                    case TYPE_ARRAY:
                        type = ((Array_Type) type).getElementType();
                        break;
                    default:
                        type = null;
                        return false;
                }
            }
        }
    }
    if (compField != null && compField.isOptional()) {
        return true;
    }
    return false;
}
Also used : ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) AbstractOfType(org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 3 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class Sequence_Value method evaluateIspresent.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    if (convertedValue != null && convertedValue != this) {
        return convertedValue.evaluateIsbound(timestamp, reference, actualSubReference);
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SEQUENCE:
                    if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
                        return false;
                    }
                    break;
                case TYPE_ASN1_SEQUENCE:
                    if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                // we can move on with the check
                return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            if (Type_type.TYPE_TTCN3_SEQUENCE.equals(type.getTypetype())) {
                return false;
            }
            final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
            } else if (compField.hasDefault()) {
                return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class Sequence_Value method evaluateIsbound.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIsbound(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    if (convertedValue != null && convertedValue != this) {
        return convertedValue.evaluateIsbound(timestamp, reference, actualSubReference);
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SEQUENCE:
                    if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
                        return false;
                    }
                    break;
                case TYPE_ASN1_SEQUENCE:
                    if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                // we can move on with the check
                return values.getNamedValueByName(fieldId).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
            }
            if (Type_type.TYPE_TTCN3_SEQUENCE.equals(type.getTypetype())) {
                return false;
            }
            final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.evaluateIsbound(timestamp, reference, actualSubReference + 1);
            } else if (compField.hasDefault()) {
                return compField.getDefault().evaluateIsbound(timestamp, reference, actualSubReference + 1);
            }
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with CompField

use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.

the class Set_Value method evaluateIspresent.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SET:
                    if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
                        return false;
                    }
                    break;
                case TYPE_ASN1_SET:
                    if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                // we can move on with the check
                return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
                return false;
            }
            final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
            } else if (compField.hasDefault()) {
                return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)64 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)62 Identifier (org.eclipse.titan.designer.AST.Identifier)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)32 Type (org.eclipse.titan.designer.AST.Type)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)19 IValue (org.eclipse.titan.designer.AST.IValue)19 ArrayList (java.util.ArrayList)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 HashMap (java.util.HashMap)9 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)9 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)9 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)9 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)8 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)8 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)8 Value (org.eclipse.titan.designer.AST.Value)8 Reference (org.eclipse.titan.designer.AST.Reference)6