Search in sources :

Example 31 with Identifier

use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.

the class CTs_EE_CTs method checkComponentField.

// This function checks only name uniqueness and fill in  structures "componentsMap" and "components"
protected void checkComponentField(final CompField componentField, final String typeName, final String componentName) {
    final Identifier identifier = componentField.getIdentifier();
    final String name = identifier.getName();
    if (componentsMap.containsKey(name)) {
        final Location tempLocation = componentsMap.get(name).getIdentifier().getLocation();
        tempLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATECOMPONENTFIRST, componentName, identifier.getDisplayName()));
        identifier.getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATECOMPONENTREPEATED, componentName, typeName, identifier.getDisplayName()));
    } else {
        componentsMap.put(name, componentField);
        components.add(componentField);
        if (!identifier.getHasValid(Identifier_type.ID_TTCN)) {
            identifier.getLocation().reportSingularSemanticWarning(MessageFormat.format(ASN1Assignment.UNREACHABLE, identifier.getDisplayName()));
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Location(org.eclipse.titan.designer.AST.Location)

Example 32 with Identifier

use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.

the class Imports method checkImports.

/**
 * Checks the import hierarchies of this importation (and the ones in
 * the imported module recursively).
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param referenceChain
 *                a chain of references used to find circularly imported
 *                modules.
 * @param moduleStack
 *                the stack of modules visited so far, from the starting
 *                point.
 */
public void checkImports(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final List<Module> moduleStack) {
    if (null != lastImportCheckTimeStamp && !lastImportCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    lastImportCheckTimeStamp = timestamp;
    if (null == project) {
        return;
    }
    importedModules_map.clear();
    singularImportedSymbols_map.clear();
    pluralImportedSymbols.clear();
    final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    if (null == parser) {
        return;
    }
    for (ImportModule importModule : importedModules_v) {
        final Identifier identifier = importModule.getIdentifier();
        if (null == identifier || null == identifier.getLocation()) {
            continue;
        }
        final Module referredModule = parser.getModuleByName(identifier.getName());
        if (null == referredModule) {
            identifier.getLocation().reportSemanticError(MessageFormat.format(ImportModule.MISSINGMODULE, identifier.getDisplayName()));
            continue;
        } else if (!(referredModule instanceof ASN1Module)) {
            identifier.getLocation().reportSemanticError(TTCN3IMPORT);
            continue;
        } else if (referredModule == module) {
            identifier.getLocation().reportSemanticError(SELFIMPORT);
            continue;
        }
        String name = identifier.getName();
        if (importedModules_map.containsKey(name)) {
            final Location importedLocation = importedModules_map.get(name).getIdentifier().getLocation();
            importedLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEIMPORTFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEIMPORTREPEATED, identifier.getDisplayName()));
        } else {
            importedModules_map.put(name, importModule);
        }
        final Symbols symbols = importModule.getSymbols();
        if (null == symbols) {
            continue;
        }
        for (int i = 0; i < symbols.size(); i++) {
            name = symbols.getNthElement(i).getName();
            if (singularImportedSymbols_map.containsKey(name)) {
                if (!referredModule.equals(singularImportedSymbols_map.get(name))) {
                    singularImportedSymbols_map.remove(name);
                    pluralImportedSymbols.add(name);
                }
            } else if (!pluralImportedSymbols.contains(name)) {
                singularImportedSymbols_map.put(name, referredModule);
            }
        }
        importModule.setUnhandledChange(false);
        LoadBalancingUtilities.astNodeChecked();
    }
    for (ImportModule importModule : importedModules_v) {
        // check the imports recursively
        referenceChain.markState();
        importModule.checkImports(timestamp, referenceChain, moduleStack);
        referenceChain.previousState();
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 33 with Identifier

use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.

the class ASN1_BitString_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);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // 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;
    }
    if (last.isAsn()) {
        if (last instanceof IReferencingType) {
            final IType type = last.getMyGovernor().getTypeRefdLast(timestamp);
            switch(type.getTypetype()) {
                case TYPE_BITSTRING:
                case TYPE_BITSTRING_A:
                    break;
                default:
                    value.getLocation().reportSemanticError("(reference to) BIT STRING value was expected");
                    value.setIsErroneous(true);
                    value.setLastTimeChecked(timestamp);
                    return selfReference;
            }
        }
        switch(last.getValuetype()) {
            case BITSTRING_VALUE:
                break;
            case HEXSTRING_VALUE:
                last.setValuetype(timestamp, Value_type.BITSTRING_VALUE);
                break;
            case UNDEFINED_BLOCK:
                {
                    last = last.setValuetype(timestamp, Value_type.NAMED_BITS);
                    if (namedValues == null) {
                        value.getLocation().reportSemanticError(MessageFormat.format("No named bits are defined in type `{0}''", getTypename()));
                        value.setIsErroneous(true);
                        value.setLastTimeChecked(timestamp);
                        return selfReference;
                    }
                    final Named_Bits namedBits = (Named_Bits) last;
                    final StringBuilder builder = new StringBuilder(namedBits.getNofIds());
                    for (int i = 0; i < namedBits.getNofIds(); i++) {
                        final Identifier id = namedBits.getIdByIndex(i);
                        if (!namedValues.hasNamedValueWithName(id)) {
                            id.getLocation().reportSemanticError(MessageFormat.format("No named bit with name `{0}'' is defined in type `{1}''", id.getDisplayName(), getTypename()));
                            value.setIsErroneous(true);
                            value.setLastTimeChecked(timestamp);
                            return selfReference;
                        }
                        IValue tempValue = namedValues.getNamedValueByName(id).getValue();
                        final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
                        referenceChain.release();
                        if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
                            final int bitIndex = ((Integer_Value) tempValue).intValue();
                            while (builder.length() <= bitIndex) {
                                builder.append('0');
                            }
                            builder.setCharAt(bitIndex, '1');
                        } else {
                        // FIXME Most probably we were
                        // not able to build the
                        // semantic structure for
                        // something, because it is not
                        // yet supported, like
                        // referenced values in sets
                        }
                    }
                    last = new Bitstring_Value(builder.toString());
                    last.copyGeneralProperties(value);
                    namedBits.setRealValue((Bitstring_Value) last);
                    break;
                }
            default:
                value.getLocation().reportSemanticError(BITSTRINGVALUEEXPECTED1);
                value.setIsErroneous(true);
                value.setLastTimeChecked(timestamp);
                return selfReference;
        }
    } else {
        switch(last.getValuetype()) {
            case BITSTRING_VALUE:
                break;
            case EXPRESSION_VALUE:
            case MACRO_VALUE:
                // already checked
                break;
            default:
                value.getLocation().reportSemanticError(BITSTRINGVALUEEXPECTED2);
                value.setIsErroneous(true);
        }
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) Named_Bits(org.eclipse.titan.designer.AST.ASN1.values.Named_Bits) IType(org.eclipse.titan.designer.AST.IType)

Example 34 with Identifier

use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Choice_Type method checkThisValueChoice.

private boolean checkThisValueChoice(final CompilationTimeStamp timestamp, final Choice_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed) {
    boolean selfReference = false;
    final Identifier name = value.getName();
    if (!hasComponentWithName(name)) {
        if (value.isAsn()) {
            value.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTCHOICE, name.getDisplayName(), getFullName()));
            value.setIsErroneous(true);
        } else {
            value.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTUNION, name.getDisplayName(), getFullName()));
            value.setIsErroneous(true);
        }
        value.setLastTimeChecked(timestamp);
        return selfReference;
    }
    IValue alternativeValue = value.getValue();
    if (alternativeValue == null) {
        return selfReference;
    }
    final Type alternativeType = getComponentByName(name).getType();
    alternativeValue.setMyGovernor(alternativeType);
    alternativeValue = alternativeType.checkThisValueRef(timestamp, alternativeValue);
    selfReference = alternativeType.checkThisValue(timestamp, alternativeValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, false, false));
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue)

Example 35 with Identifier

use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Choice_Type method checkThisTemplate.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
    registerUsage(template);
    template.setMyGovernor(this);
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = false;
    if (Template_type.NAMED_TEMPLATE_LIST.equals(template.getTemplatetype())) {
        final Named_Template_List namedTemplateList = (Named_Template_List) template;
        final int nofTemplates = namedTemplateList.getNofTemplates();
        if (nofTemplates != 1) {
            template.getLocation().reportSemanticError(ONEFIELDEXPECTED);
            template.setIsErroneous(true);
        }
        for (int i = 0; i < nofTemplates; i++) {
            final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
            final Identifier name = namedTemplate.getName();
            final CompField field = components.getCompByName(name);
            if (field == null) {
                namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
            } else {
                final Type fieldType = field.getType();
                if (fieldType != null && !fieldType.getIsErroneous(timestamp)) {
                    ITTCN3Template namedTemplateTemplate = namedTemplate.getTemplate();
                    namedTemplateTemplate.setMyGovernor(fieldType);
                    namedTemplateTemplate = fieldType.checkThisTemplateRef(timestamp, namedTemplateTemplate);
                    final Completeness_type completeness = namedTemplateList.getCompletenessConditionChoice(timestamp, isModified, name);
                    selfReference |= namedTemplateTemplate.checkThisTemplateGeneric(timestamp, fieldType, Completeness_type.MAY_INCOMPLETE.equals(completeness), false, false, true, implicitOmit, lhs);
                }
            }
        }
    } else {
        template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
        template.setIsErroneous(true);
    }
    if (template.getLengthRestriction() != null) {
        template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
        template.setIsErroneous(true);
    }
    return selfReference;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Completeness_type(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template.Completeness_type) IASN1Type(org.eclipse.titan.designer.AST.ASN1.IASN1Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedTemplate(org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)

Aggregations

Identifier (org.eclipse.titan.designer.AST.Identifier)176 IType (org.eclipse.titan.designer.AST.IType)75 ISubReference (org.eclipse.titan.designer.AST.ISubReference)57 IValue (org.eclipse.titan.designer.AST.IValue)39 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)38 Type (org.eclipse.titan.designer.AST.Type)35 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 Assignment (org.eclipse.titan.designer.AST.Assignment)25 ArrayList (java.util.ArrayList)24 Location (org.eclipse.titan.designer.AST.Location)24 Reference (org.eclipse.titan.designer.AST.Reference)22 Module (org.eclipse.titan.designer.AST.Module)21 HashMap (java.util.HashMap)16 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)15 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)12 Value (org.eclipse.titan.designer.AST.Value)12 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10