Search in sources :

Example 71 with Identifier

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

the class TTCN3_Set_Type method isPresentAnyvalueEmbeddedField.

@Override
public /**
 * {@inheritDoc}
 */
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
    if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
        return true;
    }
    if (beginIndex >= subreferences.size()) {
        return true;
    }
    final ISubReference subReference = subreferences.get(beginIndex);
    if (!(subReference instanceof FieldSubReference)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
        expression.expression.append("FATAL_ERROR encountered");
        return true;
    }
    final Identifier fieldId = ((FieldSubReference) subReference).getId();
    final CompField compField = getComponentByName(fieldId.getName());
    if (compField.isOptional()) {
        return false;
    }
    return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference)

Example 72 with Identifier

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

the class Anytype_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_ANY:
                    if (!((Anytype_Type) type).hasComponentWithName(fieldId.getDisplayName())) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    break;
                default:
                    return null;
            }
            if (name.getDisplayName().equals(fieldId.getDisplayName())) {
                return value.getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
            }
            subreference.getLocation().reportSemanticError(MessageFormat.format(INACTIVEFIELD, fieldId.getDisplayName(), type.getTypename(), name.getDisplayName()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 73 with Identifier

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

the class SelectCoverage method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof SelectCase_Statement)) {
        return;
    }
    final SelectCase_Statement s = (SelectCase_Statement) node;
    final Value v = s.getExpression();
    if (v == null || v.getIsErroneous(timestamp)) {
        return;
    }
    // if there is an else branch, no smell will be reported
    final SelectCases scs = s.getSelectCases();
    if (scs == null || scs.getSelectCaseArray() == null) {
        return;
    }
    for (final SelectCase sc : scs.getSelectCaseArray()) {
        if (sc.hasElse()) {
            return;
        }
    }
    IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (itype instanceof Referenced_Type) {
        itype = itype.getTypeRefdLast(timestamp);
    }
    if (itype == null || !(itype instanceof TTCN3_Enumerated_Type)) {
        return;
    }
    final TTCN3_Enumerated_Type enumType = (TTCN3_Enumerated_Type) itype;
    // count number of items in enum, get all items from enum
    final EnumItemVisitor enumVisitor = new EnumItemVisitor();
    enumType.accept(enumVisitor);
    // count number of TemplateInstances in select, get used enum items
    final CaseVisitor caseVisitor = new CaseVisitor();
    scs.accept(caseVisitor);
    if (caseVisitor.isContainsUnfoldable()) {
        return;
    }
    final int casesSize = caseVisitor.getCount();
    final int enumSize = enumVisitor.getCount();
    if (enumSize > casesSize) {
        final List<Identifier> allEnumItems = enumVisitor.getItemsFound();
        final List<Identifier> usedEnumItems = caseVisitor.getItemsUsed();
        final String enumName = itype.getTypename();
        final String itemsNotCovered = getItemsNotCovered(allEnumItems, usedEnumItems);
        problems.report(v.getLocation(), MessageFormat.format(ERR_MSG, enumName, enumSize, casesSize, itemsNotCovered));
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Example 74 with Identifier

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

the class Visibility method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof FormalParameter) {
        return;
    } else if (node instanceof Definition) {
        final Definition s = (Definition) node;
        final Identifier identifier = s.getIdentifier();
        check(identifier, s.getDescription(), problems);
    } else if (node instanceof Group) {
        final Group s = (Group) node;
        final Identifier identifier = s.getIdentifier();
        check(identifier, "group", problems);
    } else {
        return;
    }
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Group(org.eclipse.titan.designer.AST.TTCN3.definitions.Group) Identifier(org.eclipse.titan.designer.AST.Identifier) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 75 with Identifier

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

the class TypenameInDef method check.

private void check(final Identifier identifier, final IType type, final String description, final Problems problems) {
    if (type == null) {
        return;
    }
    final String displayName = identifier.getDisplayName();
    Identifier typeId = null;
    if (type instanceof Referenced_Type) {
        final Referenced_Type referencedType = (Referenced_Type) type;
        typeId = referencedType.getReference().getId();
    }
    String typeName;
    if (typeId == null) {
        typeName = type.getTypename();
    } else {
        typeName = typeId.getDisplayName();
    }
    if (displayName.contains(typeName)) {
        final String msg = MessageFormat.format(REPORT, description, displayName, typeName);
        problems.report(identifier.getLocation(), msg);
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

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