Search in sources :

Example 91 with Identifier

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

the class ASN1_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 actualIndex = subRefIdx;
    while (actualIndex < subreferences.size() && subreferences.get(actualIndex) instanceof ArraySubReference) {
        ++actualIndex;
    }
    if (actualIndex == subreferences.size()) {
        return null;
    }
    final Identifier fieldID = subreferences.get(actualIndex).getId();
    if (subreferences.get(actualIndex) == lastSubreference) {
        return Declaration.createInstance(getDefiningAssignment(), fieldID);
    }
    final CompField compField = getComponentByName(fieldID);
    final IType compFieldType = compField.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (compFieldType instanceof IReferenceableElement) {
        final Declaration decl = ((IReferenceableElement) compFieldType).resolveReference(reference, actualIndex + 1, lastSubreference);
        return decl != null ? decl : Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
    }
    return null;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) 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 92 with Identifier

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

the class ASN1_Set_Seq_Choice_BaseType 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, 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 FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    final CompField compField = getComponentByName(fieldId);
    final Type nextType = compField.getType();
    final boolean nextOptional = !isTemplate && compField.isOptional();
    if (nextOptional) {
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        closingBrackets.insert(0, "}\n");
        final String temporalId = aData.getTemporaryVariableName();
        expression.expression.append(MessageFormat.format("Optional<{0}{1}> {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
        if (subReferenceIndex == subreferences.size() - 1) {
            expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
            expression.expression.append("case OPTIONAL_UNBOUND:\n");
            expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
            expression.expression.append("break;\n");
            expression.expression.append("case OPTIONAL_OMIT:\n");
            expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, optype == Operation_type.ISBOUND_OPERATION ? "true" : "false"));
            expression.expression.append("break;\n");
            expression.expression.append("default:\n");
            expression.expression.append("{\n");
            final String temporalId2 = aData.getTemporaryVariableName();
            expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
            if (optype == Operation_type.ISBOUND_OPERATION) {
                expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
            } else if (optype == Operation_type.ISPRESENT_OPERATION) {
                expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
            } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
                expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
            }
            expression.expression.append("break;}\n");
            expression.expression.append("}\n");
            // at the end of the reference chain
            nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
        } else {
            // still more to go
            expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
            expression.expression.append("case OPTIONAL_UNBOUND:\n");
            expression.expression.append("case OPTIONAL_OMIT:\n");
            expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
            expression.expression.append("break;\n");
            expression.expression.append("default:\n");
            expression.expression.append("break;\n");
            expression.expression.append("}\n");
            expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
            closingBrackets.insert(0, "}\n");
            final String temporalId2 = aData.getTemporaryVariableName();
            expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
            expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
            nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
        }
    } else {
        expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
        closingBrackets.insert(0, "}\n");
        final String temporalId = aData.getTemporaryVariableName();
        final String temporalId2 = aData.getTemporaryVariableName();
        expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
        expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
        if (optype == Operation_type.ISBOUND_OPERATION) {
            expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
        } else if (optype == Operation_type.ISPRESENT_OPERATION) {
            expression.expression.append(MessageFormat.format("{0} = {1}.{2}({3});\n", globalId, temporalId2, subReferenceIndex != subreferences.size() - 1 ? "isBound" : "isPresent", subReferenceIndex == subreferences.size() - 1 && isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
        } else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
            expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
            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, temporalId2, field));
                expression.expression.append("}\n");
            }
        }
        nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
    }
    expression.expression.append(closingBrackets);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Type(org.eclipse.titan.designer.AST.Type) ASN1Type(org.eclipse.titan.designer.AST.ASN1.ASN1Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField)

Example 93 with Identifier

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

the class ASN1_Set_Type method getSubrefsAsArray.

// This is the same as in ASN1_Sequence_type
@Override
public /**
 * {@inheritDoc}
 */
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return true;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
            return false;
        case fieldSubReference:
            {
                final Identifier id = subreference.getId();
                final CompField compField = components.getCompByName(id);
                if (compField == null) {
                    subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
                    return false;
                }
                final IType fieldType = compField.getType();
                if (fieldType == null) {
                    return false;
                }
                final int fieldIndex = components.indexOf(compField);
                subrefsArray.add(fieldIndex);
                typeArray.add(this);
                return fieldType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
            }
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return false;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            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) IType(org.eclipse.titan.designer.AST.IType)

Example 94 with Identifier

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

the class ASN1_Set_Type method isPresentAnyvalueEmbeddedField.

@Override
public /**
 * {@inheritDoc}
 */
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return true;
    }
    if (beginIndex >= subreferences.size()) {
        return true;
    }
    final ISubReference subReference = subreferences.get(beginIndex);
    if (!(subReference instanceof FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return true;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    final CompField compField = getComponentByName(fieldId);
    if (compField.isOptional()) {
        return false;
    }
    return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
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)

Example 95 with Identifier

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

the class ASN1_Set_Type method checkThisNamedTemplateList.

/**
 * Checks the provided named template list against this type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param templateList
 *                the template list to check
 * @param isModified
 *                true if the template is modified otherwise false.
 * @param implicitOmit
 *                true it the template has implicit omit attribute set,
 *                false otherwise.
 * @param lhs
 *                the assignment to check against
 * @return true if the value contains a reference to lhs
 */
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List templateList, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    templateList.removeGeneratedValues();
    boolean selfReference = false;
    final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
    final int nofTypeComponents = getNofComponents(timestamp);
    final int nofTemplateComponents = templateList.getNofTemplates();
    for (int i = 0; i < nofTemplateComponents; i++) {
        final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
        final Identifier identifier = namedTemplate.getName();
        final String templateName = identifier.getName();
        if (hasComponentWithName(identifier)) {
            if (componentMap.containsKey(templateName)) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDFIRST, identifier.getDisplayName()));
                componentMap.get(templateName).getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDAGAIN, identifier.getDisplayName()));
            } else {
                componentMap.put(templateName, namedTemplate);
            }
            final CompField componentField = getComponentByName(identifier);
            final Type type = componentField.getType();
            if (type != null && !type.getIsErroneous(timestamp)) {
                ITTCN3Template componentTemplate = namedTemplate.getTemplate();
                componentTemplate.setMyGovernor(type);
                componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
                boolean isOptional = componentField.isOptional();
                if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
                    isOptional = true;
                }
                selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
            }
        } else {
            namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
        }
    }
    if (!isModified && strictConstantCheckingSeverity) {
        // check missing fields
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier identifier = getComponentIdentifierByIndex(i);
            if (!componentMap.containsKey(identifier.getName())) {
                if (getComponentByIndex(i).isOptional() && implicitOmit) {
                    templateList.addNamedValue(new NamedTemplate(new Identifier(Identifier_type.ID_TTCN, identifier.getDisplayName()), new OmitValue_Template(), false));
                } else {
                    templateList.getLocation().reportSemanticError(MessageFormat.format(MISSINGTEMPLATEFIELD, identifier.getDisplayName(), getTypename()));
                }
            }
        }
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) HashMap(java.util.HashMap) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

Aggregations

Identifier (org.eclipse.titan.designer.AST.Identifier)176 IType (org.eclipse.titan.designer.AST.IType)75 ISubReference (org.eclipse.titan.designer.AST.ISubReference)57 IValue (org.eclipse.titan.designer.AST.IValue)39 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)38 Type (org.eclipse.titan.designer.AST.Type)35 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 Assignment (org.eclipse.titan.designer.AST.Assignment)25 ArrayList (java.util.ArrayList)24 Location (org.eclipse.titan.designer.AST.Location)24 Reference (org.eclipse.titan.designer.AST.Reference)22 Module (org.eclipse.titan.designer.AST.Module)21 HashMap (java.util.HashMap)16 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)15 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)12 Value (org.eclipse.titan.designer.AST.Value)12 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10