Search in sources :

Example 66 with Definition

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

the class Assignment_Statement method checkTemplateRestriction.

/**
 * Checks the template restriction on the assignment referenced on the left hand side.
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 */
private void checkTemplateRestriction(final CompilationTimeStamp timestamp) {
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass == null) {
        return;
    }
    switch(ass.getAssignmentType()) {
        case A_VAR_TEMPLATE:
            templateRestriction = ((Def_Var_Template) ass).getTemplateRestriction();
            break;
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            templateRestriction = ((FormalParameter) ass).getTemplateRestriction();
            break;
        default:
            templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
            break;
    }
    templateRestriction = TemplateRestriction.getSubRestriction(templateRestriction, timestamp, reference);
    generateRestrictionCheck = TemplateRestriction.check(timestamp, (Definition) ass, template, reference);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 67 with Definition

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

the class Type method checkEncode.

/**
 * Checks the encodings supported by the type (when using new codec handling).
 * TTCN-3 types need to have an 'encode' attribute to support an encoding.
 * ASN.1 types automatically support BER, PER and JSON encodings, and XER
 * encoding, if set by the compiler option.
 */
public void checkEncode(final CompilationTimeStamp timestamp) {
    switch(getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
        case TYPE_NULL:
        case TYPE_BOOL:
        case TYPE_INTEGER:
        case TYPE_REAL:
        case TYPE_TTCN3_ENUMERATED:
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
        case TYPE_OBJECTID:
        case TYPE_TTCN3_CHOICE:
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
        case TYPE_TTCN3_SEQUENCE:
        case TYPE_TTCN3_SET:
        case TYPE_VERDICT:
        case TYPE_ARRAY:
        case TYPE_ANYTYPE:
            if (!isAsn()) {
                final WithAttributesPath attributePath = getAttributePath();
                if (attributePath != null) {
                    final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
                    if (multipleWithAttributes != null) {
                        for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
                            final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
                            if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
                                final Attribute_Modifier_type mod = singleWithAttribute.getModifier();
                                final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
                                if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
                                    for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
                                        final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
                                        final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
                                        for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
                                            fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
                                        }
                                        final Reference reference = new Reference(null, fieldsOrArrays);
                                        final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
                                        if (type != null) {
                                            if (type.getMyScope() != myScope) {
                                                qualifier.getLocation().reportSemanticWarning("Encode attribute is ignored, because it refers to a type from a different type definition");
                                            } else {
                                                type.addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
                                            }
                                        }
                                    }
                                } else {
                                    addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
                                }
                            }
                        }
                    }
                    if (ownerType != TypeOwner_type.OT_TYPE_DEF) {
                        return;
                    }
                    WithAttributesPath globalAttributesPath;
                    final Def_Type def = (Def_Type) owner;
                    final Group nearest_group = def.getParentGroup();
                    if (nearest_group == null) {
                        // no group, use the module
                        Module myModule = myScope.getModuleScope();
                        globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
                    } else {
                        globalAttributesPath = nearest_group.getAttributePath();
                    }
                    if (globalAttributesPath != null) {
                        boolean hasGlobalOverride = false;
                        boolean modifierConflict = false;
                        Attribute_Modifier_type firstModifier = Attribute_Modifier_type.MOD_NONE;
                        final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
                        for (int i = 0; i < realAttributes.size(); i++) {
                            final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
                            if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
                                Attribute_Modifier_type modifier = singleWithAttribute.getModifier();
                                if (i == 0) {
                                    firstModifier = modifier;
                                } else if (!modifierConflict && modifier != firstModifier) {
                                    modifierConflict = true;
                                    singleWithAttribute.getLocation().reportSemanticError("All 'encode' attributes of a group or module must have the same modifier ('override', '@local' or none)");
                                }
                                if (modifier == Attribute_Modifier_type.MOD_OVERRIDE) {
                                    hasGlobalOverride = true;
                                }
                                if (hasGlobalOverride && modifierConflict) {
                                    break;
                                }
                            }
                        }
                        // make a list of the type and its field and element types that inherit
                        // the global 'encode' attributes
                        // overriding global attributes are inherited by types with no coding
                        // table (no 'encode' attributes) of their own
                        // non-overriding global attributes are inherited by types that have
                        // no coding table of their own and cannot use the coding table of any
                        // other type
                        final ArrayList<IType> typeList = new ArrayList<IType>();
                        getTypesWithNoCodingTable(timestamp, typeList, hasGlobalOverride);
                        if (!typeList.isEmpty()) {
                            for (int i = 0; i < realAttributes.size(); i++) {
                                final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
                                if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
                                    for (int j = typeList.size() - 1; j >= 0; j--) {
                                        typeList.get(j).addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), Attribute_Modifier_type.MOD_NONE, true);
                                    }
                                }
                            }
                            typeList.clear();
                        }
                    }
                }
            } else {
                // ASN.1 types automatically have BER, PER, XER, OER and JSON encoding
                switch(ownerType) {
                    case OT_TYPE_ASS:
                    case OT_RECORD_OF:
                    case OT_COMP_FIELD:
                    case OT_SELTYPE:
                    case OT_FIELDSETTING:
                        // FIXME implement once PER, JSON, OER or XER gets supported
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            // the rest of the types can't have 'encode' attributes
            break;
    }
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath) Group(org.eclipse.titan.designer.AST.TTCN3.definitions.Group) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Attribute_Modifier_type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 68 with Definition

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

the class ReadingOutParBeforeWritten method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    this.problems = problems;
    if (!(node instanceof FormalParameter)) {
        return;
    }
    final FormalParameter fp = (FormalParameter) node;
    this.toFind = fp;
    final Assignment_type at = fp.getAssignmentType();
    if (at != Assignment_type.A_PAR_VAL_OUT && at != Assignment_type.A_PAR_TEMP_OUT) {
        return;
    }
    final Definition d = fp.getMyParameterList().getMyDefinition();
    final NewFuncVisitor visitor = new NewFuncVisitor();
    // call visitor on function in which the out parameter was found
    d.accept(visitor);
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Assignment_type(org.eclipse.titan.designer.AST.Assignment.Assignment_type) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 69 with Definition

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

the class ConsecutiveAssignments method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof StatementBlock)) {
        return;
    }
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    int count = 0;
    boolean limitReached = false;
    Location smellLoc = null;
    Assignment_Statement lastAs = null;
    Assignment toMatch = null;
    final StatementBlock sb = (StatementBlock) node;
    // iterate statements in block
    for (int i = 0; i < sb.getSize(); i++) {
        final Statement s = sb.getStatementByIndex(i);
        if (!(s instanceof Assignment_Statement)) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = null;
            continue;
        }
        final Assignment_Statement as = (Assignment_Statement) s;
        final Reference ref = as.getReference();
        final Assignment a = ref.getRefdAssignment(timestamp, false);
        if (a == null) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = null;
            continue;
        }
        // consecutive assignments: consecutive Assignment_Statements have the same definition
        if (toMatch == null) {
            toMatch = a;
        } else if (toMatch != a) {
            if (limitReached) {
                smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
                problems.report(smellLoc, ERROR_MESSAGE);
                limitReached = false;
            }
            count = 0;
            toMatch = a;
        }
        if (count == 0) {
            smellLoc = new Location(as.getLocation());
        }
        lastAs = as;
        count++;
        if (count >= minCountToMark) {
            limitReached = true;
        }
    }
    if (limitReached) {
        smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
        problems.report(smellLoc, ERROR_MESSAGE);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Reference(org.eclipse.titan.designer.AST.Reference) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Location(org.eclipse.titan.designer.AST.Location)

Example 70 with Definition

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

the class Referenced_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = false;
    final IType tempType = getTypeRefdLast(timestamp);
    if (tempType != this) {
        selfReference = tempType.checkThisValue(timestamp, value, lhs, new ValueCheckingOptions(valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.omit_allowed, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem));
        final Definition def = value.getDefiningAssignment();
        if (def != null) {
            final String referingModuleName = getMyScope().getModuleScope().getName();
            if (!def.referingHere.contains(referingModuleName)) {
                def.referingHere.add(referingModuleName);
            }
        }
    }
    if (valueCheckingOptions.sub_check && (subType != null)) {
        subType.checkThisValue(timestamp, value);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IType(org.eclipse.titan.designer.AST.IType)

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