Search in sources :

Example 76 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method getLocalAssignmentById.

/**
 * Returns the assignment of this component fitting the provided identifier.
 *
 * @param identifier the identifier of the assignment
 * @return the assignment identified, or null in case of an error.
 */
public Definition getLocalAssignmentById(final Identifier identifier) {
    if (lastUniquenessCheck == null) {
        checkUniqueness(CompilationTimeStamp.getBaseTimestamp());
    }
    final String name = identifier.getName();
    Definition definition = definitions.getDefinition(name);
    if (definition != null) {
        return definition;
    }
    definition = extendsGainedDefinitions.get(name);
    if (definition != null) {
        if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
            return definition;
        } else {
            identifier.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, identifier.getDisplayName(), this.identifier.getDisplayName()));
        }
    }
    definition = attributeGainedDefinitions.get(name);
    if (definition != null) {
        if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
            return definition;
        } else {
            identifier.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, identifier.getDisplayName(), this.identifier.getDisplayName()));
        }
    }
    return null;
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 77 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method addDefinitionsOfExtendsParents.

private void addDefinitionsOfExtendsParents(final CompilationTimeStamp timestamp) {
    extendsGainedDefinitions.clear();
    if (extendsReferences == null) {
        return;
    }
    extendsReferences.check(timestamp);
    final IReferenceChain referenceChain = ReferenceChain.getInstance(CIRCULAREXTENSIONCHAIN, true);
    if (referenceChain.add(this)) {
        extendsReferences.checkRecursion(referenceChain);
    }
    referenceChain.release();
    initCompatibility(extendsReferences);
    // collect definitions
    final List<ComponentTypeBody> bodies = getExtendsInheritedComponentBodies();
    for (final ComponentTypeBody body : bodies) {
        final Map<String, Definition> subDefinitionMap = body.getDefinitionMap();
        for (final Definition definition : subDefinitionMap.values()) {
            final String name = definition.getIdentifier().getName();
            if (definitions.hasDefinition(name)) {
                final Definition localDefinition = definitions.getDefinition(name);
                localDefinition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(LOCALINHERTANCECOLLISSION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
            } else if (extendsGainedDefinitions.containsKey(name)) {
                final Definition previousDefinition = extendsGainedDefinitions.get(name);
                if (!previousDefinition.equals(definition)) {
                    // it is not the same definition inherited on two paths
                    if (this.equals(previousDefinition.getMyScope())) {
                        previousDefinition.getLocation().reportSemanticError(MessageFormat.format(LOCALINHERTANCECOLLISSION, previousDefinition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
                        definition.getIdentifier().getLocation().reportSemanticWarning(MessageFormat.format(INHERITEDLOCATION, definition.getIdentifier().getDisplayName()));
                    } else if (identifier != null && identifier.getLocation() != null) {
                        identifier.getLocation().reportSemanticError(MessageFormat.format(INHERITANCECOLLISSION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName(), previousDefinition.getMyScope().getFullName()));
                        definition.getIdentifier().getLocation().reportSingularSemanticWarning(MessageFormat.format(INHERITEDDEFINITIONLOCATION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
                        previousDefinition.getIdentifier().getLocation().reportSingularSemanticWarning(MessageFormat.format(INHERITEDDEFINITIONLOCATION, previousDefinition.getIdentifier().getDisplayName(), previousDefinition.getMyScope().getFullName()));
                    }
                }
            } else {
                extendsGainedDefinitions.put(name, definition);
                if (!definition.getMyScope().getModuleScope().equals(parentScope.getModuleScope())) {
                    if (parentScope.hasAssignmentWithId(timestamp, definition.getIdentifier())) {
                        if (identifier != null && identifier.getLocation() != null) {
                            identifier.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, definition.getIdentifier().getDisplayName()));
                            final List<ISubReference> subReferences = new ArrayList<ISubReference>();
                            subReferences.add(new FieldSubReference(definition.getIdentifier()));
                            final Reference reference = new Reference(null, subReferences);
                            final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
                            if (assignment != null && assignment.getLocation() != null) {
                                assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, definition.getIdentifier().getDisplayName()));
                            }
                            definition.getIdentifier().getLocation().reportSingularSemanticWarning(MessageFormat.format(INHERITEDDEFINITIONLOCATION, definition.getIdentifier().getDisplayName(), definition.getMyScope().getFullName()));
                        }
                    } else if (parentScope.isValidModuleId(definition.getIdentifier())) {
                        definition.getLocation().reportSingularSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, definition.getIdentifier().getDisplayName()));
                    }
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 78 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class DefinitionContainer method checkUniqueness.

public void checkUniqueness() {
    definitionMap.clear();
    for (final Definition definition : definitions) {
        final String definitionName = definition.getIdentifier().getName();
        if (definitionMap.containsKey(definitionName)) {
            definitionMap.get(definitionName).getIdentifier().getLocation().reportSingularSemanticError(MessageFormat.format(CompFieldMap.DUPLICATEFIELDNAMEFIRST, definition.getIdentifier().getDisplayName()));
            definition.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(CompFieldMap.DUPLICATEFIELDNAMEREPEATED, definition.getIdentifier().getDisplayName()));
        } else {
            definitionMap.put(definitionName, definition);
        }
    }
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 79 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class SpecificValue_Template method isValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean isValue(final CompilationTimeStamp timestamp) {
    if (lengthRestriction != null || isIfpresent || getIsErroneous(timestamp)) {
        return false;
    }
    if (realTemplate != null && realTemplate != this) {
        return realTemplate.isValue(timestamp);
    }
    if (Value_type.FUNCTION_REFERENCE_VALUE.equals(specificValue.getValuetype())) {
        final IType governor = ((Function_Reference_Value) specificValue).getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (governor == null) {
            return true;
        }
        final IType last = governor.getTypeRefdLast(timestamp);
        if (Type_type.TYPE_FUNCTION.equals(last.getTypetype()) && ((Function_Type) last).returnsTemplate()) {
            return false;
        }
    } else if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
        final Reference reference = ((Referenced_Value) specificValue).getReference();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true);
        if (assignment == null) {
            return true;
        }
        switch(assignment.getAssignmentType()) {
            case A_CONST:
            case A_TIMER:
            case A_EXT_CONST:
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
            case A_VAR:
            case A_FUNCTION_RVAL:
            case A_EXT_FUNCTION_RVAL:
            case A_MODULEPAR:
            case A_MODULEPAR_TEMPLATE:
                // runtime evaluation!
                return true;
            case A_TEMPLATE:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_INOUT:
            case A_FUNCTION_RTEMP:
            case A_VAR_TEMPLATE:
                boolean result = true;
                final Restriction_type rt = ((Definition) assignment).getTemplateRestriction();
                if (TemplateRestriction.Restriction_type.TR_OMIT.equals(rt) || TemplateRestriction.Restriction_type.TR_PRESENT.equals(rt)) {
                    result = false;
                }
                final TTCN3Template ttemplate = getTemplateReferencedLast(timestamp);
                if ((!ttemplate.equals(this)) && (ttemplate.isValue(timestamp))) {
                    // ok
                    return result;
                } else {
                    return false;
                }
            default:
                return false;
        }
    }
    return true;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Reference(org.eclipse.titan.designer.AST.Reference) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 80 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Template method checkValueomitRestriction.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkValueomitRestriction(final CompilationTimeStamp timestamp, final String definitionName, final boolean omitAllowed, final Location usageLocation) {
    if (reference == null) {
        if (omitAllowed) {
            checkRestrictionCommon(timestamp, getTemplateTypeName(), TemplateRestriction.Restriction_type.TR_OMIT, usageLocation);
        } else {
            checkRestrictionCommon(timestamp, getTemplateTypeName(), TemplateRestriction.Restriction_type.TR_VALUE, usageLocation);
        }
    } else {
        // if (reference != null):
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (Assignment_type.A_TEMPLATE == ass.getAssignmentType()) {
            final ITTCN3Template templateLast = getTemplateReferencedLast(timestamp);
            if (!this.equals(templateLast)) {
                templateLast.checkValueomitRestriction(timestamp, getTemplateTypeName(), omitAllowed, usageLocation);
            }
        }
        switch(ass.getAssignmentType()) {
            case A_TEMPLATE:
            case A_VAR_TEMPLATE:
            case A_EXT_FUNCTION_RTEMP:
            case A_FUNCTION_RTEMP:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                if (ass instanceof Definition) {
                    TemplateRestriction.Restriction_type refdTemplateRestriction = ((Definition) ass).getTemplateRestriction();
                    refdTemplateRestriction = TemplateRestriction.getSubRestriction(refdTemplateRestriction, timestamp, reference);
                    // if restriction is not satisfied issue warning
                    if (TemplateRestriction.isLessRestrictive(omitAllowed ? TemplateRestriction.Restriction_type.TR_OMIT : TemplateRestriction.Restriction_type.TR_VALUE, refdTemplateRestriction)) {
                        getLocation().reportSemanticWarning(MessageFormat.format(INADEQUATETEMPLATERESTRICTION, ass.getAssignmentName(), reference.getDisplayName()));
                        return true;
                    }
                }
                return false;
            default:
                return false;
        }
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)

Aggregations

Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)52 Assignment (org.eclipse.titan.designer.AST.Assignment)16 IValue (org.eclipse.titan.designer.AST.IValue)12 Location (org.eclipse.titan.designer.AST.Location)11 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)10 IType (org.eclipse.titan.designer.AST.IType)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 Module (org.eclipse.titan.designer.AST.Module)10 ArrayList (java.util.ArrayList)9 Reference (org.eclipse.titan.designer.AST.Reference)9 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)6 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)6 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)5 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)5 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)5 IFile (org.eclipse.core.resources.IFile)4 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)4