Search in sources :

Example 66 with Identifier

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

the class TTCN3_Set_Seq_Choice_BaseType method getFieldTypesAsArray.

@Override
public /**
 * {@inheritDoc}
 */
boolean getFieldTypesAsArray(final Reference reference, final int actualSubReference, final List<IType> typeArray) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return true;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            if (compFieldMap == null) {
                return false;
            }
            final Identifier id = subreference.getId();
            final CompField compField = compFieldMap.getCompWithName(id);
            if (compField == null) {
                return false;
            }
            final IType fieldType = compField.getType();
            if (fieldType == null) {
                return false;
            }
            typeArray.add(this);
            return fieldType.getFieldTypesAsArray(reference, actualSubReference + 1, typeArray);
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) IType(org.eclipse.titan.designer.AST.IType)

Example 67 with Identifier

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

the class CompFieldMap method checkUniqueness.

/**
 * Checks the uniqueness of the definitions, and also builds a hashmap of
 * them to speed up further searches.
 *
 * @param timestamp the timestamp of the actual semantic check cycle, or -1
 *            in silent check mode.
 */
protected void checkUniqueness(final CompilationTimeStamp timestamp) {
    if (lastUniquenessCheck != null && !lastUniquenessCheck.isLess(timestamp)) {
        return;
    }
    if (doubleComponents != null) {
        doubleComponents.clear();
    }
    componentFieldMap = new HashMap<String, CompField>(fields.size());
    if (fields.size() == 0) {
        // too early check
        return;
    }
    lastUniquenessCheck = timestamp;
    for (int i = 0, size = fields.size(); i < size; i++) {
        final CompField field = fields.get(i);
        final Identifier fieldIdentifier = field.getIdentifier();
        if (fieldIdentifier == null) {
            continue;
        }
        final String fieldName = fieldIdentifier.getName();
        if (componentFieldMap.containsKey(fieldName)) {
            if (doubleComponents == null) {
                doubleComponents = new ArrayList<CompField>();
            }
            doubleComponents.add(field);
        } else {
            componentFieldMap.put(fieldName, field);
        }
    }
    // FIXME: Perhaps this class should be copied under asn1 to handle this ASN1 problem
    if (doubleComponents != null) {
        final INamedNode p = getNameParent();
        if (p instanceof Open_Type) {
            return;
        }
        for (int i = 0, size = doubleComponents.size(); i < size; i++) {
            final CompField field = doubleComponents.get(i);
            // remove duplication from fields - not used anymore
            // fields.remove(field);
            // report duplication:
            final Identifier fieldIdentifier = field.getIdentifier();
            final String fieldName = fieldIdentifier.getName();
            componentFieldMap.get(fieldName).getIdentifier().getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEFIRST, fieldIdentifier.getDisplayName()));
            fieldIdentifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEREPEATED, fieldIdentifier.getDisplayName()));
        }
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Identifier(org.eclipse.titan.designer.AST.Identifier) INamedNode(org.eclipse.titan.designer.AST.INamedNode)

Example 68 with Identifier

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

the class ComponentTypeBody method addDeclaration.

public void addDeclaration(final DeclarationCollector declarationCollector, final int i) {
    final Identifier identifier = declarationCollector.getReference().getId();
    Definition definition = definitions.getDefinition(identifier.getName());
    if (definition != null) {
        definition.addDeclaration(declarationCollector, i);
    }
    definition = extendsGainedDefinitions.get(identifier.getName());
    if (definition != null) {
        definition.addDeclaration(declarationCollector, i);
    }
    definition = attributeGainedDefinitions.get(identifier.getName());
    if (definition != null) {
        definition.addDeclaration(declarationCollector, i);
    }
    if (i == 0) {
        super.addDeclaration(declarationCollector);
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 69 with Identifier

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

the class EnumItem method getDeclaration.

@Override
public /**
 * {@inheritDoc}
 */
Declaration getDeclaration() {
    if (getMyScope() == null) {
        return null;
    }
    final Module module = getMyScope().getModuleScope();
    final Assignment assignment = module.getEnclosingAssignment(getLocation().getOffset());
    final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
    if (type instanceof ITypeWithComponents) {
        final Identifier id = ((ITypeWithComponents) type).getComponentIdentifierByName(getId());
        return Declaration.createInstance(assignment, id);
    }
    return null;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) ITypeWithComponents(org.eclipse.titan.designer.AST.ITypeWithComponents) Module(org.eclipse.titan.designer.AST.Module) IType(org.eclipse.titan.designer.AST.IType)

Example 70 with Identifier

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

the class TTCN3_Set_Type method checkThisValueSet.

/**
 * Checks the Set_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for sure
 * that the value is of set type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of value we expect to find.
 * @param incompleteAllowed wheather incomplete value is allowed or not.
 * @param impliciOmit true if the implicit omit optional attribute was set
 *            for the value, false otherwise
 */
private boolean checkThisValueSet(final CompilationTimeStamp timestamp, final Set_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean impliciOmit, final boolean strElem) {
    value.removeGeneratedValues();
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    final boolean isAsn = value.isAsn();
    final int nofValueComponents = value.getNofComponents();
    for (int i = 0; i < nofValueComponents; i++) {
        final NamedValue namedValue = value.getSequenceValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!realComponents.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDASN1 : NONEXISTENTFIELDTTCN3, namedValue.getName().getDisplayName(), getTypename()));
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDAGAINASN1 : DUPLICATEFIELDAGAINTTCN3, valueId.getDisplayName()));
                componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDFIRSTASN1 : DUPLICATEFIELDFIRSTTTCN3, valueId.getDisplayName()));
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = realComponents.get(valueId.getName());
            final Type type = componentField.getType();
            final IValue componentValue = namedValue.getValue();
            if (componentValue != null) {
                componentValue.setMyGovernor(type);
                if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
                    if (!incompleteAllowed) {
                        componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                    }
                } else {
                    final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
                    selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, impliciOmit, strElem));
                }
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        final int nofTypeComponents = realComponents.size();
        CompField field;
        for (int i = 0; i < nofTypeComponents; i++) {
            field = compFieldMap.fields.get(i);
            final Identifier id = field.getIdentifier();
            if (!componentMap.containsKey(id.getName())) {
                if (field.isOptional() && impliciOmit) {
                    value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
                }
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)

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