Search in sources :

Example 36 with ArraySubReference

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

the class ASN1_BitString_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Value(org.eclipse.titan.designer.AST.Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 37 with ArraySubReference

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

the class TTCN3_Set_Seq_Choice_BaseType method resolveReference.

@Override
public /**
 * {@inheritDoc}
 */
Declaration resolveReference(final Reference reference, final int subRefIdx, final ISubReference lastSubreference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    int localIndex = subRefIdx;
    while (localIndex < subreferences.size() && subreferences.get(localIndex) instanceof ArraySubReference) {
        ++localIndex;
    }
    if (localIndex == subreferences.size()) {
        return null;
    }
    final CompField compField = getComponentByName(subreferences.get(localIndex).getId().getName());
    if (compField == null) {
        return null;
    }
    if (subreferences.get(localIndex) == lastSubreference) {
        return Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    final IType compFieldType = compField.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (compFieldType instanceof IReferenceableElement) {
        final Declaration decl = ((IReferenceableElement) compFieldType).resolveReference(reference, localIndex + 1, lastSubreference);
        return decl != null ? decl : Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    return null;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) IReferenceableElement(org.eclipse.titan.designer.AST.IReferenceableElement) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 38 with ArraySubReference

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

the class SequenceOf_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            if (indexValue != null) {
                indexValue.setLoweridToReference(timestamp);
                final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
                switch(tempType) {
                    case TYPE_INTEGER:
                        final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
                        if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
                            final Integer_Value lastInteger = (Integer_Value) last;
                            if (lastInteger.isNative()) {
                                final long temp = lastInteger.getValue();
                                if (temp < 0) {
                                    indexValue.getLocation().reportSemanticError(MessageFormat.format(NONNEGATIVINDEXEXPECTED, temp));
                                    indexValue.setIsErroneous(true);
                                }
                            } else {
                                indexValue.getLocation().reportSemanticError(MessageFormat.format(TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
                                indexValue.setIsErroneous(true);
                            }
                        }
                        break;
                    case TYPE_UNDEFINED:
                        indexValue.setIsErroneous(true);
                        break;
                    default:
                        indexValue.getLocation().reportSemanticError(INTEGERINDEXEXPECTED);
                        indexValue.setIsErroneous(true);
                        break;
                }
            }
            if (getOfType() != null) {
                return getOfType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
            }
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 39 with ArraySubReference

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

the class AbstractOfType method generateCodeIsPresentBoundChosen.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, final String field) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return;
    }
    if (subReferenceIndex >= subreferences.size()) {
        return;
    }
    final StringBuilder closingBrackets = new StringBuilder();
    if (isTemplate) {
        boolean anyvalueReturnValue = true;
        if (optype == Operation_type.ISPRESENT_OPERATION) {
            anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
        } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
            anyvalueReturnValue = false;
        }
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
        expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
        expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
        expression.expression.append("break;\n");
        expression.expression.append("case ANY_VALUE:\n");
        expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
        expression.expression.append("break;\n");
        expression.expression.append("case SPECIFIC_VALUE:{\n");
        closingBrackets.append("break;}\n");
        closingBrackets.append("default:\n");
        closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
        closingBrackets.append("break;\n");
        closingBrackets.append("}\n");
        closingBrackets.append("}\n");
    }
    final ISubReference subReference = subreferences.get(subReferenceIndex);
    if (!(subReference instanceof ArraySubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return;
    }
    final IType nextType = ofType;
    final Value indexValue = ((ArraySubReference) subReference).getValue();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = indexValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    closingBrackets.insert(0, "}\n");
    final String temporalIndexId = aData.getTemporaryVariableName();
    expression.expression.append(MessageFormat.format("TitanInteger {0} = ", temporalIndexId));
    last.generateCodeExpressionMandatory(aData, expression, true);
    expression.expression.append(";\n");
    expression.expression.append(MessageFormat.format("{0} = {1}.isGreaterThanOrEqual(0) && {1}.isLessThan({2}.{3});\n", globalId, temporalIndexId, externalId, isTemplate ? "n_elem()" : "sizeOf()"));
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    closingBrackets.insert(0, "}\n");
    final String temporalId = aData.getTemporaryVariableName();
    if (isTemplate) {
        expression.expression.append(MessageFormat.format("{0} {1} = {2}.constGetAt({3});\n", nextType.getGenNameTemplate(aData, expression.expression, myScope), temporalId, externalId, temporalIndexId));
    } else {
        expression.expression.append(MessageFormat.format("{0} {1} = {2}.constGetAt({3});\n", nextType.getGenNameValue(aData, expression.expression, myScope), temporalId, externalId, temporalIndexId));
    }
    final boolean isLast = subReferenceIndex == (subreferences.size() - 1);
    if (optype == Operation_type.ISBOUND_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId));
    } else if (optype == Operation_type.ISPRESENT_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.{2}({3});\n", globalId, temporalId, !isLast ? "isBound" : "isPresent", isLast && isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
    } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
        expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId));
        if (subReferenceIndex == subreferences.size() - 1) {
            expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
            expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId, field));
            expression.expression.append("}\n");
        }
    }
    nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId, isTemplate, optype, field);
    expression.expression.append(closingBrackets);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 40 with ArraySubReference

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

the class AbstractOfType method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            if (indexValue != null) {
                indexValue.setLoweridToReference(timestamp);
                final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
                switch(tempType) {
                    case TYPE_INTEGER:
                        final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
                        if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
                            final Integer_Value lastInteger = (Integer_Value) last;
                            if (lastInteger.isNative()) {
                                final long temp = lastInteger.getValue();
                                if (temp < 0) {
                                    indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.NONNEGATIVINDEXEXPECTED, temp));
                                    indexValue.setIsErroneous(true);
                                }
                            } else {
                                indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
                                indexValue.setIsErroneous(true);
                            }
                        }
                        break;
                    case TYPE_UNDEFINED:
                        indexValue.setIsErroneous(true);
                        break;
                    default:
                        indexValue.getLocation().reportSemanticError(SequenceOf_Type.INTEGERINDEXEXPECTED);
                        indexValue.setIsErroneous(true);
                        break;
                }
            }
            if (getOfType() != null) {
                return getOfType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
            }
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Aggregations

ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)47 ISubReference (org.eclipse.titan.designer.AST.ISubReference)46 IValue (org.eclipse.titan.designer.AST.IValue)42 Value (org.eclipse.titan.designer.AST.Value)39 IType (org.eclipse.titan.designer.AST.IType)19 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)11 Identifier (org.eclipse.titan.designer.AST.Identifier)5 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)4 Assignment (org.eclipse.titan.designer.AST.Assignment)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)3 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)3 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BigInteger (java.math.BigInteger)2 IReferenceableElement (org.eclipse.titan.designer.AST.IReferenceableElement)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Array_Value (org.eclipse.titan.designer.AST.TTCN3.values.Array_Value)2 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)2