Search in sources :

Example 81 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class UniversalCharstring_Type method checkThisTemplateString.

/**
 * Checks if the provided template is valid for the provided type.
 * <p>
 * The type must be equivalent with the TTCN-3 universal charstring type
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 * @param type the universal charstring type used for the check.
 * @param template the template to be checked by the type.
 * @param isModified true if the template is a modified template
 */
public static void checkThisTemplateString(final CompilationTimeStamp timestamp, final Type type, final ITTCN3Template template, final boolean isModified) {
    template.setMyGovernor(type);
    PatternString ps = null;
    switch(template.getTemplatetype()) {
        case VALUE_RANGE:
            {
                final ValueRange range = ((Value_Range_Template) template).getValueRange();
                final IValue lower = checkBoundary(timestamp, type, range.getMin(), template, "lower");
                final IValue upper = checkBoundary(timestamp, type, range.getMax(), template, "upper");
                range.setTypeType(type.getTypetypeTtcn3());
                if (lower != null && upper != null) {
                    UniversalCharstring value1;
                    if (Value_type.CHARSTRING_VALUE.equals(lower.getValuetype())) {
                        value1 = new UniversalCharstring(((Charstring_Value) lower).getValue());
                    } else {
                        value1 = ((UniversalCharstring_Value) lower).getValue();
                    }
                    UniversalCharstring value2;
                    if (Value_type.CHARSTRING_VALUE.equals(upper.getValuetype())) {
                        value2 = new UniversalCharstring(((Charstring_Value) upper).getValue());
                    } else {
                        value2 = ((UniversalCharstring_Value) upper).getValue();
                    }
                    if (value1.compareWith(value2) > 0) {
                        template.getLocation().reportSemanticError(INCORRECTBOUNDARIES);
                    }
                }
                break;
            }
        case CSTR_PATTERN:
            {
                // Change the pattern type
                final CharString_Pattern_Template cstrpt = (CharString_Pattern_Template) template;
                ps = cstrpt.getPatternstring();
                ps.setPatterntype(PatternType.UNIVCHARSTRING_PATTERN);
                // FIXME might need some implementation
                break;
            }
        case USTR_PATTERN:
            // FIXME implement as soon as charstring pattern templates become handled
            ps = ((UnivCharString_Pattern_Template) template).getPatternstring();
            break;
        default:
            template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), type.getTypename()));
            break;
    }
}
Also used : ValueRange(org.eclipse.titan.designer.AST.TTCN3.templates.ValueRange) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) PatternString(org.eclipse.titan.designer.AST.TTCN3.templates.PatternString) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) CharString_Pattern_Template(org.eclipse.titan.designer.AST.TTCN3.templates.CharString_Pattern_Template) UnivCharString_Pattern_Template(org.eclipse.titan.designer.AST.TTCN3.templates.UnivCharString_Pattern_Template)

Example 82 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Template method hasTemplateImpliciteOmit.

/**
 * Returns whether in the chain of referenced templates there is one
 * which was defined to have the implicit omit attribute set
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param referenceChain
 *                the ReferenceChain used to detect circular references
 *
 * @return true if it has, false otherwise.
 */
private boolean hasTemplateImpliciteOmit(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    boolean result = false;
    if (reference != null) {
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (ass != null && ass.getAssignmentType() == Assignment_type.A_TEMPLATE) {
            final Def_Template templateDefinition = (Def_Template) ass;
            if (templateDefinition.hasImplicitOmitAttribute(timestamp)) {
                result = true;
            } else {
                tempReferenceChain.markState();
                if (tempReferenceChain.add(this)) {
                    final ITTCN3Template refd = getTemplateReferenced(timestamp, tempReferenceChain);
                    if (refd != this && refd instanceof Referenced_Template) {
                        result = ((Referenced_Template) refd).hasTemplateImpliciteOmit(timestamp, referenceChain);
                    }
                } else {
                    setIsErroneous(true);
                }
                tempReferenceChain.previousState();
            }
        }
    }
    if (newChain) {
        tempReferenceChain.release();
    }
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 83 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Template method checkValueomitRestriction.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkValueomitRestriction(final CompilationTimeStamp timestamp, final String definitionName, final boolean omitAllowed, final Location usageLocation) {
    if (reference == null) {
        if (omitAllowed) {
            checkRestrictionCommon(timestamp, getTemplateTypeName(), TemplateRestriction.Restriction_type.TR_OMIT, usageLocation);
        } else {
            checkRestrictionCommon(timestamp, getTemplateTypeName(), TemplateRestriction.Restriction_type.TR_VALUE, usageLocation);
        }
    } else {
        // if (reference != null):
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (Assignment_type.A_TEMPLATE == ass.getAssignmentType()) {
            final ITTCN3Template templateLast = getTemplateReferencedLast(timestamp);
            if (!this.equals(templateLast)) {
                templateLast.checkValueomitRestriction(timestamp, getTemplateTypeName(), omitAllowed, usageLocation);
            }
        }
        switch(ass.getAssignmentType()) {
            case A_TEMPLATE:
            case A_VAR_TEMPLATE:
            case A_EXT_FUNCTION_RTEMP:
            case A_FUNCTION_RTEMP:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                if (ass instanceof Definition) {
                    TemplateRestriction.Restriction_type refdTemplateRestriction = ((Definition) ass).getTemplateRestriction();
                    refdTemplateRestriction = TemplateRestriction.getSubRestriction(refdTemplateRestriction, timestamp, reference);
                    // if restriction is not satisfied issue warning
                    if (TemplateRestriction.isLessRestrictive(omitAllowed ? TemplateRestriction.Restriction_type.TR_OMIT : TemplateRestriction.Restriction_type.TR_VALUE, refdTemplateRestriction)) {
                        getLocation().reportSemanticWarning(MessageFormat.format(INADEQUATETEMPLATERESTRICTION, ass.getAssignmentName(), reference.getDisplayName()));
                        return true;
                    }
                }
                return false;
            default:
                return false;
        }
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)

Example 84 with ITTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Template method checkRecursions.

@Override
public /**
 * {@inheritDoc}
 */
void checkRecursions(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (referenceChain.add(this) && reference != null) {
        final ISubReference subReference = reference.getSubreferences().get(0);
        if (subReference instanceof ParameterisedSubReference) {
            final ActualParameterList parameterList = ((ParameterisedSubReference) subReference).getActualParameters();
            if (parameterList != null) {
                parameterList.checkRecursions(timestamp, referenceChain);
            }
        }
        final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final ITTCN3Template template = getTemplateReferenced(timestamp, tempReferenceChain);
        tempReferenceChain.release();
        if (template != null && !template.getIsErroneous(timestamp) && !this.equals(template)) {
            template.checkRecursions(timestamp, referenceChain);
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)67 IType (org.eclipse.titan.designer.AST.IType)42 IValue (org.eclipse.titan.designer.AST.IValue)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)19 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)19 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Type (org.eclipse.titan.designer.AST.Type)13 ISubReference (org.eclipse.titan.designer.AST.ISubReference)12 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)12 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)12 Reference (org.eclipse.titan.designer.AST.Reference)10 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)6 HashMap (java.util.HashMap)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)5