Search in sources :

Example 6 with WithAttributesPath

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

the class Def_Var_Template method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    wasAssigned = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_VARTEMPLATE, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        lastTimeChecked = timestamp;
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    if (initialValue == null) {
        return;
    }
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        default:
            break;
    }
    TTCN3Template realInitialValue = initialValue;
    initialValue.setMyGovernor(type);
    // Needed in case of universal charstring templates
    if (initialValue.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
        realInitialValue = initialValue.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
    // FIXME implement setting the pattern type, once
    // universal charstring pattern are supported.
    }
    final ITTCN3Template temporalValue = type.checkThisTemplateRef(timestamp, realInitialValue);
    temporalValue.checkThisTemplateGeneric(timestamp, type, true, true, true, true, false, this);
    generateRestrictionCheck = TemplateRestriction.check(timestamp, this, realInitialValue, null);
    realInitialValue.setCodeSection(CodeSectionType.CS_INLINE);
    // here
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    if (mFormalParList != null) {
        mFormalParList.reset();
        mFormalParList.check(timestamp, getAssignmentType());
        // template variable is always local
        location.reportSemanticError(MessageFormat.format(PARAMETRIZED_LOCAL_TEMPLATE_VAR, getIdentifier()));
    }
    initialValue.setGenNameRecursive(getGenName());
    initialValue.setCodeSection(CodeSectionType.CS_INLINE);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) IType(org.eclipse.titan.designer.AST.IType)

Example 7 with WithAttributesPath

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

the class AbstractOfType method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        lastTimeChecked = null;
        boolean handled = false;
        if (ofType instanceof IIncrementallyUpdateable && reparser.envelopsDamage(ofType.getLocation())) {
            ((IIncrementallyUpdateable) ofType).updateSyntax(reparser, true);
            reparser.updateLocation(ofType.getLocation());
            handled = true;
        }
        if (subType != null) {
            subType.updateSyntax(reparser, false);
            handled = true;
        }
        if (handled) {
            return;
        }
        throw new ReParseException();
    }
    if (ofType instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) ofType).updateSyntax(reparser, false);
        reparser.updateLocation(ofType.getLocation());
    } else if (ofType != null) {
        throw new ReParseException();
    }
    if (subType != null) {
        subType.updateSyntax(reparser, false);
    }
    if (withAttributesPath != null) {
        withAttributesPath.updateSyntax(reparser, false);
        reparser.updateLocation(withAttributesPath.getLocation());
    }
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 8 with WithAttributesPath

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

the class Anytype_Type method analyzeExtensionAttributes.

/**
 * Convert and check the anytype attributes applied to the module of this type.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
    clear();
    final TTCN3Module myModule = (TTCN3Module) getMyScope().getModuleScope();
    final WithAttributesPath moduleAttributePath = myModule.getAttributePath();
    if (moduleAttributePath == null) {
        return;
    }
    final List<SingleWithAttribute> realAttributes = moduleAttributePath.getRealAttributes(timestamp);
    SingleWithAttribute attribute;
    List<AttributeSpecification> specifications = null;
    for (int i = 0; i < realAttributes.size(); i++) {
        attribute = realAttributes.get(i);
        if (Attribute_Type.Extension_Attribute.equals(attribute.getAttributeType())) {
            final Qualifiers qualifiers = attribute.getQualifiers();
            if (qualifiers == null || qualifiers.getNofQualifiers() == 0) {
                if (specifications == null) {
                    specifications = new ArrayList<AttributeSpecification>();
                }
                specifications.add(attribute.getAttributeSpecification());
            }
        }
    }
    if (specifications == null) {
        return;
    }
    final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
    AttributeSpecification specification;
    for (int i = 0; i < specifications.size(); i++) {
        specification = specifications.get(i);
        final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
        analyzer.parse(specification);
        final List<ExtensionAttribute> temp = analyzer.getAttributes();
        if (temp != null) {
            attributes.addAll(temp);
        }
    }
    final Scope definitionsScope = myModule.getDefinitions();
    ExtensionAttribute extensionAttribute;
    for (int i = 0; i < attributes.size(); i++) {
        extensionAttribute = attributes.get(i);
        if (ExtensionAttribute_type.ANYTYPE.equals(extensionAttribute.getAttributeType())) {
            final AnytypeAttribute anytypeAttribute = (AnytypeAttribute) extensionAttribute;
            for (int j = 0; j < anytypeAttribute.getNofTypes(); j++) {
                final Type tempType = anytypeAttribute.getType(j);
                String fieldName;
                Identifier identifier = null;
                if (Type_type.TYPE_REFERENCED.equals(tempType.getTypetype())) {
                    final Reference reference = ((Referenced_Type) tempType).getReference();
                    identifier = reference.getId();
                    fieldName = identifier.getTtcnName();
                } else {
                    fieldName = tempType.getTypename();
                    identifier = new Identifier(Identifier_type.ID_TTCN, fieldName);
                }
                tempType.setMyScope(definitionsScope);
                addComp(new CompField(identifier, tempType, false, null));
            }
        }
    }
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) AnytypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.AnytypeAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Example 9 with WithAttributesPath

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

the class Definition method checkErroneousAttributes.

protected void checkErroneousAttributes(final CompilationTimeStamp timestamp) {
    erroneousAttributes = null;
    if (withAttributesPath != null) {
        final MultipleWithAttributes attribs = withAttributesPath.getAttributes();
        if (attribs == null) {
            return;
        }
        for (int i = 0; i < attribs.getNofElements(); i++) {
            final SingleWithAttribute actualAttribute = attribs.getAttribute(i);
            if (actualAttribute.getAttributeType() == Attribute_Type.Erroneous_Attribute) {
                final int nofQualifiers = (actualAttribute.getQualifiers() == null) ? 0 : actualAttribute.getQualifiers().getNofQualifiers();
                final List<IType> referencedTypeArray = new ArrayList<IType>(nofQualifiers);
                final List<ArrayList<Integer>> subrefsArrayArray = new ArrayList<ArrayList<Integer>>(nofQualifiers);
                final List<ArrayList<IType>> typeArrayArray = new ArrayList<ArrayList<IType>>(nofQualifiers);
                if (nofQualifiers == 0) {
                    actualAttribute.getLocation().reportSemanticError("At least one qualifier must be specified for the `erroneous' attribute");
                } else {
                    // existing fields
                    for (int qi = 0; qi < nofQualifiers; qi++) {
                        final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
                        final IType definitionType = getType(timestamp);
                        // construct a reference
                        final Reference reference = new Reference(null);
                        reference.addSubReference(new FieldSubReference(identifier));
                        for (int ri = 0; ri < actualQualifier.getNofSubReferences(); ri++) {
                            reference.addSubReference(actualQualifier.getSubReferenceByIndex(ri));
                        }
                        reference.setLocation(actualQualifier.getLocation());
                        reference.setMyScope(getMyScope());
                        IType fieldType = definitionType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
                        ArrayList<Integer> subrefsArray = null;
                        ArrayList<IType> typeArray = null;
                        if (fieldType != null) {
                            subrefsArray = new ArrayList<Integer>();
                            typeArray = new ArrayList<IType>();
                            final boolean validIndexes = definitionType.getSubrefsAsArray(timestamp, reference, 1, subrefsArray, typeArray);
                            if (!validIndexes) {
                                fieldType = null;
                                subrefsArray = null;
                                typeArray = null;
                            }
                            if (reference.refersToStringElement()) {
                                actualQualifier.getLocation().reportSemanticError("Reference to a string element cannot be used in this context");
                                fieldType = null;
                                subrefsArray = null;
                                typeArray = null;
                            }
                        }
                        referencedTypeArray.add(fieldType);
                        subrefsArrayArray.add(subrefsArray);
                        typeArrayArray.add(typeArray);
                    }
                }
                // parse the attr. spec.
                final ErroneousAttributeSpecification errAttributeSpecification = parseErrAttrSpecString(actualAttribute.getAttributeSpecification());
                if (errAttributeSpecification != null) {
                    if (erroneousAttributes == null) {
                        erroneousAttributes = new ErroneousAttributes(getType(timestamp));
                    }
                    erroneousAttributes.addSpecification(errAttributeSpecification);
                    errAttributeSpecification.check(timestamp, getMyScope());
                    // err.attr.spec. pairs
                    for (int qi = 0; qi < nofQualifiers; qi++) {
                        if (referencedTypeArray.get(qi) != null && errAttributeSpecification.getIndicator() != Indicator_Type.Invalid_Indicator) {
                            final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
                            erroneousAttributes.addFieldErr(actualQualifier, errAttributeSpecification, subrefsArrayArray.get(qi), typeArrayArray.get(qi));
                        }
                    }
                }
            }
        }
        if (erroneousAttributes != null) {
            erroneousAttributes.check(timestamp);
        }
    }
}
Also used : ErroneousAttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) ErroneousAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributes) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) IType(org.eclipse.titan.designer.AST.IType) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)

Example 10 with WithAttributesPath

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

the class Definition method hasImplicitOmitAttribute.

/**
 * Checks if this definition has an implicit omit attribute or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 *
 * @return true if it has an implicit omit attribute, false if no
 *         attribute is given or explicit omit is specified.
 */
public boolean hasImplicitOmitAttribute(final CompilationTimeStamp timestamp) {
    if (withAttributesPath == null) {
        return false;
    }
    final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
    SingleWithAttribute tempAttribute;
    for (int i = realAttributes.size() - 1; i >= 0; i--) {
        tempAttribute = realAttributes.get(i);
        if (tempAttribute != null && Attribute_Type.Optional_Attribute.equals(tempAttribute.getAttributeType())) {
            final String tempSpecification = tempAttribute.getAttributeSpecification().getSpecification();
            if ("implicit omit".equals(tempSpecification)) {
                return true;
            } else if ("explicit omit".equals(tempSpecification)) {
                return false;
            }
        }
    }
    return false;
}
Also used : SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)

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