Search in sources :

Example 11 with WithAttributesPath

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

the class Group method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param allImportedModules
 *                the list of module importations found in the same
 *                module.
 * @param allDefinitions
 *                the list of definitions found in the same module.
 * @param allFriends
 *                the list of friend module declarations found in the
 *                same module.
 * @return in case of processing error the minimum amount of semantic
 *         levels that must be destroyed to handle the syntactic
 *         changes, otherwise 0.
 */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> allImportedModules, final List<Definition> allDefinitions, final List<FriendModule> allFriends) throws ReParseException {
    int result = 0;
    Location tempLocation = identifier.getLocation();
    if (reparser.isDamaged(tempLocation)) {
        if (reparser.envelopsDamage(tempLocation) || reparser.isExtending(tempLocation)) {
            reparser.extendDamagedRegion(tempLocation);
            result = reparseIdentifier(reparser);
            if (result != 0) {
                throw new ReParseException(result);
            }
        } else {
            throw new ReParseException();
        }
    } else {
        reparser.updateLocation(tempLocation);
    }
    if (reparser.isDamaged(innerLocation) && !reparser.envelopsDamage(innerLocation)) {
        throw new ReParseException();
    }
    boolean enveloped = false;
    int nofDamaged = 0;
    int leftBoundary = innerLocation.getOffset();
    int rightBoundary = innerLocation.getEndOffset();
    final int damageOffset = reparser.getDamageStart();
    IAppendableSyntax lastAppendableBeforeChange = null;
    IAppendableSyntax lastPrependableBeforeChange = null;
    for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
            if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
                lastAppendableBeforeChange = temp;
            } else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
                lastPrependableBeforeChange = temp;
            }
        // reparser.extendDamagedRegion(temp_location);
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
        final Location tempCommentLocation = temp.getCommentLocation();
        if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
            rightBoundary = tempCommentLocation.getOffset();
            lastPrependableBeforeChange = temp;
        }
    }
    // was not enveloped
    if (!enveloped && reparser.envelopsDamage(location)) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
    }
    // correct
    if (lastAppendableBeforeChange != null) {
        final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
        if (isBeingExtended) {
            leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
            nofDamaged++;
            enveloped = false;
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
    }
    if (lastPrependableBeforeChange != null) {
        final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
        if (temp != null && reparser.endsWithToken(temp)) {
            rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
            nofDamaged++;
            enveloped = false;
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
    }
    if (nofDamaged != 0) {
        // remove damaged stuff
        removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
    }
    // update what is left
    for (int i = 0; i < groups.size(); i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, allImportedModules, allDefinitions, friendModules);
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    groups.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < importedModules.size(); i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    importedModules.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < friendModules.size(); i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    friendModules.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                temp.updateSyntax(reparser, isDamaged);
                if (reparser.getNameChanged()) {
                    lastUniquenessCheckTimeStamp = null;
                    reparser.setNameChanged(false);
                }
                if (isDamaged) {
                    temp.checkRoot();
                }
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    definitions.remove(temp);
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
    }
    for (int i = 0, size = groups.size(); i < size; i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = importedModules.size(); i < size; i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = friendModules.size(); i < size; i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    if (withAttributesPath != null && reparser.isAffected(withAttributesPath.getLocation())) {
        if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
            reparser.extendDamagedRegion(withAttributesPath.getLocation());
            result = reparseOptionalWithStatement(reparser);
            if (result != 0) {
                throw new ReParseException(result);
            }
            return;
        }
        withAttributesPath.updateSyntax(reparser, reparser.envelopsDamage(withAttributesPath.getLocation()));
        reparser.updateLocation(withAttributesPath.getLocation());
    }
    if (!enveloped && reparser.envelopsDamage(innerLocation)) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        result = reparseModuleDefinitionsList(reparser);
    }
    reparser.updateLocation(innerLocation);
    if (result > 1) {
        throw new ReParseException(result - 1);
    }
    return;
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) Location(org.eclipse.titan.designer.AST.Location)

Example 12 with WithAttributesPath

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

the class Def_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;
    if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_TEMPLATE, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_TEMPLATE, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp, refChain);
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, true);
        withAttributesPath.checkAttributes(timestamp, type.getTypeRefdLast(timestamp, refChain).getTypetype());
    }
    if (body == null) {
        return;
    }
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        default:
            break;
    }
    body.setMyGovernor(type);
    realBody = body;
    // Needed in case of universal charstring templates
    if (body.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
        realBody = body.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
    // FIXME implement setting the pattern type, once
    // universal charstring pattern are supported.
    }
    if (formalParList != null) {
        formalParList.reset();
        formalParList.check(timestamp, getAssignmentType());
        if (isLocal()) {
            location.reportSemanticError(MessageFormat.format(PARAMETRIZED_LOCAL_TEMPLATE, getIdentifier()));
        }
    }
    final ITTCN3Template tempBody = type.checkThisTemplateRef(timestamp, realBody);
    checkDefault(timestamp);
    checkModified(timestamp);
    checkRecursiveDerivation(timestamp);
    tempBody.checkThisTemplateGeneric(timestamp, type, derivedReference != null, true, true, true, hasImplicitOmitAttribute(timestamp), null);
    checkErroneousAttributes(timestamp);
    final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(CIRCULAREMBEDDEDRECURSION, true);
    tempReferenceChain.add(this);
    tempBody.checkRecursions(timestamp, tempReferenceChain);
    tempReferenceChain.release();
    if (templateRestriction != TemplateRestriction.Restriction_type.TR_NONE) {
        generateRestrictionCheck = TemplateRestriction.check(timestamp, this, tempBody, null);
        if (formalParList != null && templateRestriction != TemplateRestriction.Restriction_type.TR_PRESENT) {
            final int nofFps = formalParList.getNofParameters();
            for (int i = 0; i < nofFps; i++) {
                final FormalParameter fp = formalParList.getParameterByIndex(i);
                // parameters
                if (fp.getAssignmentType() != Assignment.Assignment_type.A_PAR_TEMP_IN) {
                    continue;
                }
                final TemplateRestriction.Restriction_type fpTemplateRestriction = fp.getTemplateRestriction();
                switch(templateRestriction) {
                    case TR_VALUE:
                    case TR_OMIT:
                        switch(fpTemplateRestriction) {
                            case TR_VALUE:
                            case TR_OMIT:
                                // allowed
                                break;
                            case TR_PRESENT:
                                fp.getLocation().reportSemanticError(MessageFormat.format(WITHTEMPRESTNOTALLOWED, fpTemplateRestriction.getDisplayName()));
                                break;
                            case TR_NONE:
                                fp.getLocation().reportSemanticError(WITHOUTTEMPRESTNOTALLOWED);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    if (formalParList != null) {
        formalParList.setGenName(getGenName());
    }
    // body.setGenNamePrefix("template_");//currently does not need the prefix
    body.setGenNameRecursive(getGenName());
    body.setCodeSection(CodeSectionType.CS_POST_INIT);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction) IType(org.eclipse.titan.designer.AST.IType)

Example 13 with WithAttributesPath

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

the class Def_Timer method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    if (getMyScope() instanceof ComponentTypeBody) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_COMPONENT_TIMER, identifier, this);
    } else if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_TIMER, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_TIMER, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (dimensions != null) {
        dimensions.check(timestamp);
    }
    if (defaultDuration != null) {
        if (dimensions == null) {
            defaultDuration.setLoweridToReference(timestamp);
            final Type_type tempType = defaultDuration.getExpressionReturntype(timestamp, isLocal() ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : Expected_Value_type.EXPECTED_STATIC_VALUE);
            switch(tempType) {
                case TYPE_REAL:
                    final IValue last = defaultDuration.getValueRefdLast(timestamp, null);
                    if (!last.isUnfoldable(timestamp)) {
                        final Real_Value real = (Real_Value) last;
                        final double value = real.getValue();
                        if (value < 0.0f) {
                            defaultDuration.getLocation().reportSemanticError(MessageFormat.format(NEGATIVDURATIONERROR, value));
                        } else if (real.isPositiveInfinity()) {
                            final String message = MessageFormat.format(INFINITYDURATIONERROR, real.createStringRepresentation());
                            defaultDuration.getLocation().reportSemanticError(message);
                        }
                    }
                    return;
                default:
                    defaultDuration.getLocation().reportSemanticError(OPERANDERROR);
            }
        } else {
            checkArrayDuration(timestamp, defaultDuration, 0);
        }
        defaultDuration.setCodeSection(CodeSectionType.CS_POST_INIT);
    }
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    lastTimeChecked = timestamp;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 14 with WithAttributesPath

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

the class Def_Type method analyzeExtensionAttributes.

/**
 * Convert and check the encoding attributes applied to this function.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
public void analyzeExtensionAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
    final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
    SingleWithAttribute attribute;
    List<AttributeSpecification> specifications = null;
    for (int i = 0, size = realAttributes.size(); i < 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());
            } else {
                for (int j = 0, size2 = qualifiers.getNofQualifiers(); j < size2; j++) {
                    final Qualifier tempQualifier = qualifiers.getQualifierByIndex(i);
                    final ISubReference tempSubReference = tempQualifier.getSubReferenceByIndex(0);
                    if (tempSubReference.getReferenceType() == Subreference_type.arraySubReference) {
                        tempQualifier.getLocation().reportSemanticError(Qualifier.INVALID_INDEX_QUALIFIER);
                    } else {
                        tempQualifier.getLocation().reportSemanticError(MessageFormat.format(Qualifier.INVALID_FIELD_QUALIFIER, tempSubReference.getId().getDisplayName()));
                    }
                }
            }
        }
    }
    if (specifications == null) {
        return;
    }
    final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
    for (int i = 0; i < specifications.size(); i++) {
        final AttributeSpecification specification = specifications.get(i);
        final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
        analyzer.parse(specification);
        final List<ExtensionAttribute> temp = analyzer.getAttributes();
        if (temp != null) {
            attributes.addAll(temp);
        }
    }
    for (int i = 0; i < attributes.size(); i++) {
        final ExtensionAttribute extensionAttribute = attributes.get(i);
        switch(extensionAttribute.getAttributeType()) {
            case ANYTYPE:
            case VERSION:
            case REQUIRES:
            case TITANVERSION:
                break;
            default:
                // only extension attributes are allowed ... and
                // only because they can not be stopped earlier.
                extensionAttribute.getLocation().reportSemanticError("Extension attributes are not supported for types");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) ISubReference(org.eclipse.titan.designer.AST.ISubReference) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Example 15 with WithAttributesPath

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

the class TTCN3Module method analyzeExtensionAttributes.

/**
 * Convert and check the version, requires and titan version extension attributes.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
    if (withAttributesPath == null) {
        return;
    }
    final List<SingleWithAttribute> realAttributes = withAttributesPath.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);
        }
    }
    ExtensionAttribute extensionAttribute;
    for (int i = 0; i < attributes.size(); i++) {
        extensionAttribute = attributes.get(i);
        switch(extensionAttribute.getAttributeType()) {
            case VERSION:
                {
                    final ModuleVersionAttribute moduleVersion = (ModuleVersionAttribute) extensionAttribute;
                    moduleVersion.parse();
                    if (versionNumber != null) {
                        moduleVersion.getLocation().reportSemanticError("Duplicate version attribute");
                    } else {
                        setVersion(moduleVersion.getVersionNumber());
                    }
                    break;
                }
            case REQUIRES:
                {
                    final VersionRequirementAttribute versionReq = (VersionRequirementAttribute) extensionAttribute;
                    versionReq.parse();
                    ImportModule theImport = null;
                    final String requiredModuleName = versionReq.getRequiredModule().getName();
                    for (final ImportModule impMod : importedModules) {
                        if (requiredModuleName.equals(impMod.getIdentifier().getName())) {
                            theImport = impMod;
                            break;
                        }
                    }
                    if (theImport == null) {
                        final String message = MessageFormat.format(ImportModule.MISSINGMODULE, versionReq.getRequiredModule().getDisplayName());
                        versionReq.getRequiredModule().getLocation().reportSemanticError(message);
                    } else {
                        final TTCN3Module theImportedModule = (TTCN3Module) theImport.getReferredModule();
                        // make sure the version attribute is parsed (if any)
                        theImportedModule.check(timestamp);
                        final ProductIdentity requiredVersion = versionReq.getVersionNumber();
                        if (requiredVersion != null && theImportedModule.versionNumber != null && theImportedModule.versionNumber.compareTo(requiredVersion) < 0) {
                            final String message = MessageFormat.format("Module `{0}'' requires version {1} of module `{2}'', but only version {3} is available", identifier.getDisplayName(), requiredVersion.toString(), theImportedModule.getIdentifier().getDisplayName(), theImportedModule.versionNumber.toString());
                            versionReq.getLocation().reportSemanticError(message);
                        }
                    }
                    break;
                }
            case TITANVERSION:
                {
                    final TitanVersionAttribute titanReq = (TitanVersionAttribute) extensionAttribute;
                    titanReq.parse();
                    final ProductIdentity requiredTITANVersion = titanReq.getVersionNumber();
                    final String temp = CompilerVersionInformationCollector.getCompilerProductNumber();
                    final ProductIdentity compilerVersion = ProductIdentityHelper.getProductIdentity(temp, null);
                    if (requiredTITANVersion != null && compilerVersion != null && compilerVersion.compareTo(requiredTITANVersion) < 0) {
                        final String message = MessageFormat.format("Module `{0}'' requires TITAN version {1}, but version {2} is used right now", identifier.getDisplayName(), requiredTITANVersion.toString(), compilerVersion.toString());
                        titanReq.getLocation().reportSemanticError(message);
                    }
                    if (requiredTITANVersion != null && GeneralConstants.ON_THE_FLY_ANALYZER_VERSION != null && GeneralConstants.ON_THE_FLY_ANALYZER_VERSION.compareTo(requiredTITANVersion) < 0) {
                        final String message = MessageFormat.format("Module `{0}'' requires TITAN version {1}, but the on-the-fly analyzer is of version {2}", identifier.getDisplayName(), requiredTITANVersion.toString(), GeneralConstants.ON_THE_FLY_ANALYZER_VERSION.toString());
                        titanReq.getLocation().reportSemanticError(message);
                    }
                    break;
                }
            default:
                // we don't care
                break;
        }
    }
}
Also used : ModuleVersionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ModuleVersionAttribute) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) VersionRequirementAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.VersionRequirementAttribute) ProductIdentity(org.eclipse.titan.common.product.ProductIdentity) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) TitanVersionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.TitanVersionAttribute) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

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