Search in sources :

Example 1 with WithAttributesPath

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath in project titan.EclipsePlug-ins by eclipse.

the class Type method checkVariants.

/**
 * Checks the type's variant attributes (when using the new codec handling).
 */
public void checkVariants(final CompilationTimeStamp timestamp) {
    if (isAsn() || ownerType != TypeOwner_type.OT_TYPE_DEF) {
        return;
    }
    WithAttributesPath globalAttributesPath;
    final Def_Type def = (Def_Type) owner;
    final Group nearest_group = def.getParentGroup();
    if (nearest_group == null) {
        // no group, use the module
        Module myModule = myScope.getModuleScope();
        globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
    } else {
        globalAttributesPath = nearest_group.getAttributePath();
    }
    if (globalAttributesPath != null) {
        // process all global variants, not just the closest group
        final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
        for (int i = 0; i < realAttributes.size(); i++) {
            final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
            if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
                checkThisVariant(timestamp, singleWithAttribute, true);
            }
        }
    }
    // check local variant attributes second, so they overwrite global ones if they
    // conflict with each other
    final WithAttributesPath attributePath = getAttributePath();
    if (attributePath != null) {
        final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
        if (multipleWithAttributes != null) {
            for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
                final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
                if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
                    final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
                    if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
                        for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
                            final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
                            final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
                            for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
                                fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
                            }
                            final Reference reference = new Reference(null, fieldsOrArrays);
                            final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
                            if (type != null) {
                                if (type.getMyScope() != myScope) {
                                    qualifier.getLocation().reportSemanticWarning("Variant attribute is ignored, because it refers to a type from a different type definition");
                                } else {
                                    type.checkThisVariant(timestamp, singleWithAttribute, false);
                                }
                            }
                        }
                    } else {
                        checkThisVariant(timestamp, singleWithAttribute, false);
                    }
                }
            }
        }
    }
    // check the coding attributes set by the variants
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    checkCodingAttributes(timestamp, chain);
    chain.release();
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath) Group(org.eclipse.titan.designer.AST.TTCN3.definitions.Group) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 2 with WithAttributesPath

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath in project titan.EclipsePlug-ins by eclipse.

the class Type method hasVariantAttributes.

@Override
public final /**
 * {@inheritDoc}
 */
boolean hasVariantAttributes(final CompilationTimeStamp timestamp) {
    if (withAttributesPath == null) {
        return false;
    }
    final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
    for (int i = 0; i < realAttributes.size(); i++) {
        if (SingleWithAttribute.Attribute_Type.Variant_Attribute.equals(realAttributes.get(i).getAttributeType())) {
            return true;
        }
    }
    final MultipleWithAttributes localAttributes = withAttributesPath.getAttributes();
    if (localAttributes == null) {
        return false;
    }
    for (int i = 0; i < localAttributes.getNofElements(); i++) {
        final SingleWithAttribute tempSingle = localAttributes.getAttribute(i);
        if (Attribute_Type.Variant_Attribute.equals(tempSingle.getAttributeType())) {
            return true;
        }
    }
    return false;
}
Also used : SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)

Example 3 with WithAttributesPath

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath in project titan.EclipsePlug-ins by eclipse.

the class Def_ModulePar method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (((Function_Type) lastType).isRunsOnSelf()) {
                location.reportSemanticError(MessageFormat.format(RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
            }
            break;
        default:
            break;
    }
    if (defaultValue != null) {
        defaultValue.setMyGovernor(type);
        final IValue temporalValue = type.checkThisValueRef(timestamp, defaultValue);
        type.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, true, false, true, hasImplicitOmitAttribute(timestamp), false));
        defaultValue.setCodeSection(CodeSectionType.CS_PRE_INIT);
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with WithAttributesPath

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath in project titan.EclipsePlug-ins by eclipse.

the class Def_ModulePar_Template method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(Def_ModulePar.PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(Def_ModulePar.SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (((Function_Type) lastType).isRunsOnSelf()) {
                location.reportSemanticError(MessageFormat.format(Def_ModulePar.RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
            }
            break;
        default:
            break;
    }
    if (defaultTemplate != null) {
        realTemplate = defaultTemplate;
        // Needed in case of universal charstring templates
        if (defaultTemplate.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
            realTemplate = defaultTemplate.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
        // FIXME implement setting the pattern type,
        // once universal charstring pattern are
        // supported.
        }
        final ITTCN3Template temporalTemplate = type.checkThisTemplateRef(timestamp, realTemplate);
        temporalTemplate.checkThisTemplateGeneric(timestamp, type, false, true, true, true, false, null);
        final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(Def_Template.CIRCULAREMBEDDEDRECURSION, true);
        tempReferenceChain.add(this);
        temporalTemplate.checkRecursions(timestamp, tempReferenceChain);
        tempReferenceChain.release();
        // defaultTemplate.setGenNamePrefix("modulepar_");//currently does not need the prefix
        defaultTemplate.setGenNameRecursive(getGenName());
        defaultTemplate.setCodeSection(CodeSectionType.CS_PRE_INIT);
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with WithAttributesPath

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath in project titan.EclipsePlug-ins by eclipse.

the class Def_Type method setWithAttributes.

@Override
public /**
 * {@inheritDoc}
 */
void setWithAttributes(final MultipleWithAttributes attributes) {
    if (type == null) {
        return;
    }
    if (withAttributesPath == null) {
        withAttributesPath = new WithAttributesPath();
        type.setAttributeParentPath(withAttributesPath);
    }
    type.setWithAttributes(attributes);
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)

Aggregations

SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)11 ArrayList (java.util.ArrayList)8 IType (org.eclipse.titan.designer.AST.IType)8 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)7 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)5 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)5 ExtensionAttributeAnalyzer (org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer)5 MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)4 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)4 WithAttributesPath (org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)4 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 IValue (org.eclipse.titan.designer.AST.IValue)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)2 Group (org.eclipse.titan.designer.AST.TTCN3.definitions.Group)2