Search in sources :

Example 11 with ComponentTypeBody

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

the class Def_Const 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_CONSTANT, identifier, this);
    } else if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_CONSTANT, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_CONSTANT, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    T3Doc.check(this.getCommentLocation(), KIND, this.type.getTypetype());
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, true);
        withAttributesPath.checkAttributes(timestamp, type.getTypeRefdLast(timestamp).getTypetype());
    }
    if (value == null) {
        return;
    }
    value.setMyGovernor(type);
    final IValue temporalValue = type.checkThisValueRef(timestamp, value);
    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;
        default:
            break;
    }
    type.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, true, false, true, hasImplicitOmitAttribute(timestamp), false));
    checkErroneousAttributes(timestamp);
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    chain.add(this);
    temporalValue.checkRecursions(timestamp, chain);
    chain.release();
    // value.setGenNamePrefix("const_");//currently does not need the prefix
    value.setGenNameRecursive(getGenName());
    value.setCodeSection(CodeSectionType.CS_PRE_INIT);
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 12 with ComponentTypeBody

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

the class Altstep_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Def_Altstep altstep = null;
    switch(last.getValuetype()) {
        case ALTSTEP_REFERENCE_VALUE:
            altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
            if (altstep == null) {
                setIsErroneous(true);
                return selfReference;
            }
            altstep.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(ALTSTEPREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    formalParList.checkCompatibility(timestamp, altstep.getFormalParameterList(), value.getLocation());
    final IType temporalRunsOnType = altstep.getRunsOnType(timestamp);
    if (temporalRunsOnType != null) {
        if (runsOnSelf) {
            // check against the runs on component type of the scope of the value
            final Scope valueScope = value.getMyScope();
            if (valueScope == null) {
                value.setIsErroneous(true);
                return selfReference;
            }
            final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
            if (runsOnScope != null) {
                final Component_Type componentType = runsOnScope.getComponentType();
                if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope " + "expects component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            } else {
                // compatibility using this component type as the scope
                if (valueScope instanceof ComponentTypeBody) {
                    final ComponentTypeBody body = (ComponentTypeBody) valueScope;
                    if (!runsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' " + "clause and the current component definition is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' clause and the current scope does not have a `runs on'' clause," + " but {1} runs on `{2}''", getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
                }
            }
        } else {
            if (runsOnRef == null) {
                value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                value.setIsErroneous(true);
            } else {
                if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
                    value.setIsErroneous(true);
                }
            }
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, value);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 13 with ComponentTypeBody

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

the class ComponentTypeBody method collectDefinitionsFromAttributeExtends.

/**
 * Collects the definitions coming from extends attributes.
 * In reality no collection is done, but it is checked that the actual component has all definitions from the extended component.
 */
private void collectDefinitionsFromAttributeExtends() {
    final List<ComponentTypeBody> parents = getAttributeExtendsInheritedComponentBodies();
    for (final ComponentTypeBody parent : parents) {
        for (final Definition definition : parent.getDefinitions()) {
            final Identifier id = definition.getIdentifier();
            final String name = id.getName();
            // Check if we have inherited 2 different definitions with the same name
            if (extendsGainedDefinitions.containsKey(name)) {
                final Definition myDefinition = extendsGainedDefinitions.get(name);
                if (definition != myDefinition) {
                    location.reportSemanticError(MessageFormat.format(INHERITANCECOLLISSION, id.getDisplayName(), definition.getMyScope().getFullName(), myDefinition.getMyScope().getFullName()));
                }
                continue;
            }
            if (!definitions.hasDefinition(name)) {
                location.reportSemanticError(MessageFormat.format("Missing local definition of `{0}'', which was inherited from component type `{1}''", id.getDisplayName(), definition.getMyScope().getFullName()));
                continue;
            }
            attributeGainedDefinitions.put(name, definition);
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 14 with ComponentTypeBody

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

the class ComponentTypeBody method generateCode.

/**
 * Add generated java code on this level.
 *
 * @param aData only used to update imports if needed
 * @param source the source code generated
 */
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final StringBuilder init_comp = aData.getInitComp();
    init_comp.append("if(\"").append(identifier.getDisplayName()).append("\".equals(component_type)) {\n");
    if (extendsReferences != null) {
        boolean hasBaseComponents = false;
        for (final ComponentTypeBody cb : compatibleBodies) {
            if (cb.definitions.size() > 0) {
                if (!hasBaseComponents) {
                    init_comp.append("if(init_base_comps) {\n");
                    hasBaseComponents = true;
                }
                // TODO get_scope_mod_gen
                if (getModuleScope().equals(cb.getModuleScope())) {
                    init_comp.append("init_comp_type(\"");
                    init_comp.append(cb.getIdentifier().getDisplayName());
                    init_comp.append("\", false);\n");
                } else {
                    init_comp.append("//TODO implement Module_List");
                    init_comp.append("Module_List::initialize_component(\"");
                    init_comp.append(cb.getModuleScope().getIdentifier().getDisplayName());
                    init_comp.append("\", \"");
                    init_comp.append(cb.getIdentifier().getDisplayName());
                    init_comp.append("\", false);\n");
                }
            }
        }
        if (hasBaseComponents) {
            init_comp.append("}\n");
        }
    }
    for (final Definition def : definitions) {
        if (extendsGainedDefinitions.containsKey(def.getIdentifier().getName())) {
            def.generateCodeInitComp(aData, init_comp, extendsGainedDefinitions.get(def.getIdentifier().getName()));
        } else {
            def.generateCode(aData, true);
        }
    }
    init_comp.append("return true;\n");
    init_comp.append("} else ");
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 15 with ComponentTypeBody

use of org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody 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)

Aggregations

ComponentTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody)8 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7 Assignment (org.eclipse.titan.designer.AST.Assignment)6 IValue (org.eclipse.titan.designer.AST.IValue)6 IType (org.eclipse.titan.designer.AST.IType)5 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Reference (org.eclipse.titan.designer.AST.Reference)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Scope (org.eclipse.titan.designer.AST.Scope)3 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)3 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ASTVisitor (org.eclipse.titan.designer.AST.ASTVisitor)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)2 Module (org.eclipse.titan.designer.AST.Module)2