Search in sources :

Example 71 with CompField

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

the class IsChoosenExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @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 checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeoperandsChecked != null && !lastTimeoperandsChecked.isLess(timestamp)) {
        return;
    }
    lastTimeoperandsChecked = timestamp;
    value = null;
    identifier = null;
    if (reference == null || reference.getSubreferences().size() < 2) {
        setIsErroneous(true);
        return;
    }
    final Reference tempReference = reference.newInstance();
    tempReference.setFullNameParent(this);
    tempReference.setMyScope(getMyScope());
    final ISubReference subreference = tempReference.removeLastSubReference();
    if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
        identifier = ((FieldSubReference) subreference).getId();
    } else {
        setIsErroneous(true);
        return;
    }
    final Assignment assignment = tempReference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    IType governor;
    switch(assignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            {
                value = new Referenced_Value(tempReference);
                value.setLocation(tempReference.getLocation());
                value.setMyScope(getMyScope());
                final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
                value.setFullNameParent(tempNamedNode);
                governor = value.getExpressionGovernor(timestamp, expectedValue);
                if (governor == null) {
                    setIsErroneous(true);
                } else {
                    value.setMyGovernor(governor);
                    final IValue tempValue2 = governor.checkThisValueRef(timestamp, value);
                    if (tempValue2.getIsErroneous(timestamp)) {
                        setIsErroneous(true);
                    }
                }
                break;
            }
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                template = new Referenced_Template(tempReference);
                template.setLocation(tempReference.getLocation());
                template.setMyScope(getMyScope());
                final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
                template.setFullNameParent(tempNamedNode);
                if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) || Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
                    governor = template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
                } else {
                    governor = template.getExpressionGovernor(timestamp, expectedValue);
                }
                if (governor == null) {
                    setIsErroneous(true);
                } else {
                    template.setMyGovernor(governor);
                    final TTCN3Template last = template.getTemplateReferencedLast(timestamp, referenceChain);
                    if (last.getIsErroneous(timestamp)) {
                        setIsErroneous(true);
                    }
                }
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && !Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
                    if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
                        template.getLocation().reportSemanticError(MessageFormat.format(CONSTANTREFERENCEEXPECTED, assignment.getDescription()));
                    } else {
                        template.getLocation().reportSemanticError(MessageFormat.format(STATICREFERENCEEXPECTED, assignment.getDescription()));
                    }
                    setIsErroneous(true);
                }
                break;
            }
        default:
            tempReference.getLocation().reportSemanticError(MessageFormat.format(VALUETEMPLATEEXPECTED, assignment.getDescription()));
            setIsErroneous(true);
            return;
    }
    if (governor != null) {
        governor = governor.getTypeRefdLast(timestamp);
        if (!governor.getIsErroneous(timestamp)) {
            CompField field = null;
            switch(governor.getTypetype()) {
                case TYPE_ASN1_CHOICE:
                    if (((ASN1_Choice_Type) governor).hasComponentWithName(identifier)) {
                        field = ((ASN1_Choice_Type) governor).getComponentByName(identifier);
                    }
                    break;
                case TYPE_TTCN3_CHOICE:
                    if (((TTCN3_Choice_Type) governor).hasComponentWithName(identifier.getName())) {
                        field = ((TTCN3_Choice_Type) governor).getComponentByName(identifier.getName());
                    }
                    break;
                case TYPE_OPENTYPE:
                    if (((Open_Type) governor).hasComponentWithName(identifier)) {
                        field = ((Open_Type) governor).getComponentByName(identifier);
                    }
                    break;
                case TYPE_ANYTYPE:
                    if (((Anytype_Type) governor).hasComponentWithName(identifier.getName())) {
                        field = ((Anytype_Type) governor).getComponentByName(identifier.getName());
                    }
                    break;
                default:
                    location.reportSemanticError(MessageFormat.format(OPERANDERROR, governor.getTypename()));
                    setIsErroneous(true);
                    return;
            }
            if (null == field) {
                location.reportSemanticError(MessageFormat.format(MISSINGFIELD, governor.getTypename(), identifier.getDisplayName()));
                setIsErroneous(true);
            }
        }
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) Assignment(org.eclipse.titan.designer.AST.Assignment) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)

Example 72 with CompField

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

the class TTCN3_Choice_Type method checkThisTemplate.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    registerUsage(template);
    template.setMyGovernor(this);
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = false;
    if (Template_type.NAMED_TEMPLATE_LIST.equals(template.getTemplatetype())) {
        final Named_Template_List namedTemplateList = (Named_Template_List) template;
        final int nofTemplates = namedTemplateList.getNofTemplates();
        if (nofTemplates != 1) {
            template.getLocation().reportSemanticError(ONEFIELDEXPECTED);
        }
        for (int i = 0; i < nofTemplates; i++) {
            final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
            final Identifier name = namedTemplate.getName();
            final CompField field = compFieldMap.getCompWithName(name);
            if (field == null) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
            } else {
                final Type fieldType = field.getType();
                ITTCN3Template namedTemplateTemplate = namedTemplate.getTemplate();
                namedTemplateTemplate.setMyGovernor(fieldType);
                namedTemplateTemplate = fieldType.checkThisTemplateRef(timestamp, namedTemplateTemplate);
                final Completeness_type completeness = namedTemplateList.getCompletenessConditionChoice(timestamp, isModified, name);
                selfReference |= namedTemplateTemplate.checkThisTemplateGeneric(timestamp, fieldType, Completeness_type.MAY_INCOMPLETE.equals(completeness), false, false, true, implicitOmit, lhs);
            }
        }
    } else {
        template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Completeness_type(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Completeness_type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)

Example 73 with CompField

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

the class TTCN3_Choice_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = getGenNameOwn();
    final String displayName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final List<FieldInfo> fieldInfos = new ArrayList<FieldInfo>();
    boolean hasOptional = false;
    for (final CompField compField : compFieldMap.fields) {
        final IType cfType = compField.getType();
        final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
        hasOptional |= compField.isOptional();
        fieldInfos.add(fi);
    }
    for (final CompField compField : compFieldMap.fields) {
        final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
        compField.getType().generateCode(aData, tempSource);
    }
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    RawASTStruct raw = null;
    if (hasRaw) {
        RawAST dummy_raw;
        if (rawAttribute == null) {
            dummy_raw = new RawAST(getDefaultRawFieldLength());
        } else {
            dummy_raw = rawAttribute;
        }
        raw = new RawASTStruct(dummy_raw);
        // building taglist
        final int taglistSize = dummy_raw.taglist == null ? 0 : dummy_raw.taglist.size();
        for (int c = 0; c < taglistSize; c++) {
            final rawAST_single_tag singleTag = dummy_raw.taglist.get(c);
            final rawAST_coding_taglist codingSingleTag = raw.taglist.list.get(c);
            if (singleTag.keyList != null) {
                codingSingleTag.fields = new ArrayList<RawASTStruct.rawAST_coding_field_list>(singleTag.keyList.size());
            }
            codingSingleTag.fieldname = singleTag.fieldName.getName();
            codingSingleTag.varName = FieldSubReference.getJavaGetterName(codingSingleTag.fieldname);
            final Identifier idf = singleTag.fieldName;
            codingSingleTag.fieldnum = getComponentIndexByName(idf);
            final int keyListSize = singleTag.keyList == null ? 0 : singleTag.keyList.size();
            for (int a = 0; a < keyListSize; a++) {
                final rawAST_tag_field_value key = singleTag.keyList.get(a);
                final RawASTStruct.rawAST_coding_field_list codingKey = new RawASTStruct.rawAST_coding_field_list();
                codingSingleTag.fields.add(codingKey);
                codingKey.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(key.keyField.names.size());
                // codingKey.value = key.value;
                final ExpressionStruct expression = new ExpressionStruct();
                key.v_value.generateCodeExpression(aData, expression, true);
                codingKey.expression = expression;
                codingKey.isOmitValue = key.v_value.getValuetype() == Value_type.OMIT_VALUE;
                codingKey.start_pos = 0;
                final CompField cf = getComponentByIndex(codingSingleTag.fieldnum);
                IType t = cf.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
                final RawASTStruct.rawAST_coding_fields tempField = new rawAST_coding_fields();
                tempField.nthfield = codingSingleTag.fieldnum;
                tempField.nthfieldname = singleTag.fieldName.getName();
                tempField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                tempField.type = t.getGenNameValue(aData, source, myScope);
                tempField.typedesc = t.getGenNameTypeDescriptor(aData, source, myScope);
                codingKey.fields.add(tempField);
                for (int b = 0; b < key.keyField.names.size(); b++) {
                    final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
                    codingKey.fields.add(newField);
                    final Identifier idf2 = key.keyField.names.get(b);
                    int comp_index = 0;
                    CompField cf2;
                    switch(t.getTypetype()) {
                        case TYPE_TTCN3_CHOICE:
                            comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
                            cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
                            newField.nthfield = comp_index;
                            newField.nthfieldname = idf2.getName();
                            newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
                            break;
                        case TYPE_TTCN3_SEQUENCE:
                        case TYPE_TTCN3_SET:
                            comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
                            cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
                            newField.nthfield = comp_index;
                            newField.nthfieldname = idf2.getName();
                            if (cf2.isOptional()) {
                                newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
                            } else {
                                newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
                            }
                            break;
                        default:
                            // internal error
                            return;
                    }
                    final IType field_type = cf2.getType();
                    newField.type = field_type.getGenNameValue(aData, source, myScope);
                    newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
                    if (field_type.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE && ((TTCN3_Sequence_Type) field_type).rawAttribute != null && (((TTCN3_Sequence_Type) field_type).rawAttribute.pointerto == null || ((TTCN3_Sequence_Type) field_type).rawAttribute.lengthto != null)) {
                        codingKey.start_pos = -1;
                    }
                    if (t.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE) {
                        IType t2;
                        for (int i = 0; i < comp_index && codingKey.start_pos >= 0; i++) {
                            t2 = ((TTCN3_Sequence_Type) t).getComponentByIndex(i).getType();
                            if (t2.getRawLength() >= 0) {
                                if (((Type) t2).rawAttribute != null) {
                                    codingKey.start_pos += ((Type) t2).rawAttribute.padding;
                                }
                                codingKey.start_pos += ((Type) t2).getRawLength();
                            } else {
                                codingKey.start_pos = -1;
                            }
                        }
                    }
                    t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
                }
            }
        }
    }
    UnionGenerator.generateValueClass(aData, source, genName, displayName, fieldInfos, hasOptional, hasRaw, raw);
    UnionGenerator.generateTemplateClass(aData, source, genName, displayName, fieldInfos, hasOptional);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : RawAST(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST) RawASTStruct.rawAST_coding_taglist(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_taglist) ArrayList(java.util.ArrayList) RawASTStruct.rawAST_coding_fields(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_fields) IType(org.eclipse.titan.designer.AST.IType) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) RawASTStruct(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct) RawASTStruct.rawAST_coding_fields(org.eclipse.titan.designer.AST.TTCN3.attributes.RawASTStruct.rawAST_coding_fields) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) RawAST.rawAST_tag_field_value(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_tag_field_value) FieldInfo(org.eclipse.titan.designer.AST.TTCN3.types.UnionGenerator.FieldInfo) RawAST.rawAST_single_tag(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag)

Example 74 with CompField

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

the class TTCN3_Choice_Type 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 FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
    expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2}.union_selection_type.ALT_{3});\n", globalId, externalId, getGenNameValue(aData, expression.expression, myScope), FieldSubReference.getJavaGetterName(fieldId.getName())));
    expression.expression.append("}\n");
    final CompField compField = getComponentByName(fieldId.getName());
    final Type nextType = compField.getType();
    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}.isPresent({2});\n", globalId, temporalId2, 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) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference)

Example 75 with CompField

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

the class TTCN3_Sequence_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
 *                is the template modified or not ?
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the template, false otherwise
 */
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();
    final int nofTemplateComponents = templateList.getNofTemplates();
    boolean inSync = true;
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    CompField lastComponentField = null;
    int nextIndex = 0;
    for (int i = 0; i < nofTemplateComponents; i++) {
        final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
        final Identifier identifier = namedTemplate.getName();
        final String templateName = identifier.getName();
        if (realComponents.containsKey(templateName)) {
            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.getName());
            if (inSync) {
                if (isModified) {
                    boolean found = false;
                    for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                        final CompField componentField2 = getComponentByIndex(j);
                        if (templateName.equals(componentField2.getIdentifier().getName())) {
                            lastComponentField = componentField2;
                            nextIndex = j + 1;
                            found = true;
                        }
                    }
                    if (!found && lastComponentField != null) {
                        final String message = MessageFormat.format(INCORRECTTEMPLATEFIELDORDER, identifier.getDisplayName(), lastComponentField.getIdentifier().getDisplayName(), getFullName());
                        namedTemplate.getLocation().reportSemanticError(message);
                        inSync = false;
                    }
                } else if (strictConstantCheckingSeverity) {
                    final CompField componentField2 = getComponentByIndex(i);
                    if (componentField2 != componentField) {
                        if (!componentField2.isOptional() || (componentField2.isOptional() && !implicitOmit)) {
                            final String message = MessageFormat.format(UNEXPECTEDTEMPLATEFIELD, identifier.getDisplayName(), componentField2.getIdentifier().getDisplayName());
                            namedTemplate.getLocation().reportSemanticError(message);
                            inSync = false;
                        }
                    }
                }
            }
            Type type = componentField.getType();
            if (type == null) {
                // report Internal error?
                return selfReference;
            }
            type = (Type) type.getTypeRefdLast(timestamp);
            if (type == null) {
                // report Internal error?
                return selfReference;
            }
            ITTCN3Template componentTemplate = namedTemplate.getTemplate();
            componentTemplate.setMyGovernor(type);
            componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
            final boolean isOptional = componentField.isOptional();
            selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
        } else {
            namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
            inSync = false;
        }
    }
    if (!isModified && strictConstantCheckingSeverity) {
        // check missing fields
        for (int i = 0; i < nofTypeComponents; i++) {
            final Identifier identifier = getComponentIdentifierByIndex(i);
            if (identifier == null) {
                continue;
            }
            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) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) 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) OmitValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.OmitValue_Template)

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