Search in sources :

Example 61 with ITTCN3Template

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

the class Def_Template method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_TEMPLATE, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_TEMPLATE, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp, refChain);
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, true);
        withAttributesPath.checkAttributes(timestamp, type.getTypeRefdLast(timestamp, refChain).getTypetype());
    }
    if (body == null) {
        return;
    }
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        default:
            break;
    }
    body.setMyGovernor(type);
    realBody = body;
    // Needed in case of universal charstring templates
    if (body.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
        realBody = body.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
    // FIXME implement setting the pattern type, once
    // universal charstring pattern are supported.
    }
    if (formalParList != null) {
        formalParList.reset();
        formalParList.check(timestamp, getAssignmentType());
        if (isLocal()) {
            location.reportSemanticError(MessageFormat.format(PARAMETRIZED_LOCAL_TEMPLATE, getIdentifier()));
        }
    }
    final ITTCN3Template tempBody = type.checkThisTemplateRef(timestamp, realBody);
    checkDefault(timestamp);
    checkModified(timestamp);
    checkRecursiveDerivation(timestamp);
    tempBody.checkThisTemplateGeneric(timestamp, type, derivedReference != null, true, true, true, hasImplicitOmitAttribute(timestamp), null);
    checkErroneousAttributes(timestamp);
    final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(CIRCULAREMBEDDEDRECURSION, true);
    tempReferenceChain.add(this);
    tempBody.checkRecursions(timestamp, tempReferenceChain);
    tempReferenceChain.release();
    if (templateRestriction != TemplateRestriction.Restriction_type.TR_NONE) {
        generateRestrictionCheck = TemplateRestriction.check(timestamp, this, tempBody, null);
        if (formalParList != null && templateRestriction != TemplateRestriction.Restriction_type.TR_PRESENT) {
            final int nofFps = formalParList.getNofParameters();
            for (int i = 0; i < nofFps; i++) {
                final FormalParameter fp = formalParList.getParameterByIndex(i);
                // parameters
                if (fp.getAssignmentType() != Assignment.Assignment_type.A_PAR_TEMP_IN) {
                    continue;
                }
                final TemplateRestriction.Restriction_type fpTemplateRestriction = fp.getTemplateRestriction();
                switch(templateRestriction) {
                    case TR_VALUE:
                    case TR_OMIT:
                        switch(fpTemplateRestriction) {
                            case TR_VALUE:
                            case TR_OMIT:
                                // allowed
                                break;
                            case TR_PRESENT:
                                fp.getLocation().reportSemanticError(MessageFormat.format(WITHTEMPRESTNOTALLOWED, fpTemplateRestriction.getDisplayName()));
                                break;
                            case TR_NONE:
                                fp.getLocation().reportSemanticError(WITHOUTTEMPRESTNOTALLOWED);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
    if (formalParList != null) {
        formalParList.setGenName(getGenName());
    }
    // body.setGenNamePrefix("template_");//currently does not need the prefix
    body.setGenNameRecursive(getGenName());
    body.setCodeSection(CodeSectionType.CS_POST_INIT);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) TemplateRestriction(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction) IType(org.eclipse.titan.designer.AST.IType)

Example 62 with ITTCN3Template

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

the class ErroneousAttributeSpecification method check.

public void check(final CompilationTimeStamp timestamp, final Scope scope) {
    templateInst.setMyScope(scope);
    if (isOmit()) {
        // special case, no type needed
        if (indicator == Indicator_Type.Before_Indicator || indicator == Indicator_Type.After_Indicator) {
            if (!hasAllKeyword) {
                final String message = MessageFormat.format("Keyword `all'' is expected after `omit'' when omitting all fields {0} the specified field", indicator.getDisplayName());
                templateInst.getLocation().reportSemanticError(message);
            }
        } else {
            if (hasAllKeyword) {
                templateInst.getLocation().reportSemanticError("Unexpected `all' keyword after `omit' when omitting one field");
            }
        }
        type = null;
        return;
    }
    if (hasAllKeyword) {
        templateInst.getLocation().reportSemanticError("Unexpected `all' keyword after the in-line template");
    }
    // determine the type of the tmpl_inst
    type = templateInst.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (type == null) {
        templateInst.getTemplateBody().setLoweridToReference(timestamp);
        type = templateInst.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (type == null) {
        templateInst.getLocation().reportSemanticError("Cannot determine the type of the in-line template");
        return;
    }
    type.check(timestamp);
    final IType typeLast = type.getTypeRefdLast(timestamp);
    if (typeLast == null || typeLast.getIsErroneous(timestamp)) {
        type = null;
        return;
    }
    if (isRaw) {
        switch(typeLast.getTypetypeTtcn3()) {
            case TYPE_BITSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            default:
                templateInst.getLocation().reportSemanticError(MessageFormat.format("An in-line template of type `{0}'' cannot be used as a `raw'' erroneous value", typeLast.getTypename()));
        }
    }
    if (templateInst.getDerivedReference() != null) {
        templateInst.getLocation().reportSemanticError("Reference to a constant value was expected instead of an in-line modified template");
        type = null;
        return;
    }
    final ITTCN3Template templ = templateInst.getTemplateBody();
    if (templ.isValue(timestamp)) {
        value = templ.getValue();
        value.setMyGovernor(type);
        type.checkThisValueRef(timestamp, value);
        type.checkThisValue(timestamp, value, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, true, false, false));
    } else {
        templateInst.getLocation().reportSemanticError("A specific value without matching symbols was expected");
        type = null;
        return;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 63 with ITTCN3Template

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

the class ValueofExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance == null) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    IType governor = myGovernor;
    if (governor == null) {
        governor = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (governor == null) {
        template = template.setLoweridToReference(timestamp);
        governor = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (governor == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance.getLocation().reportSemanticError(OPERANDERROR);
        }
        setIsErroneous(true);
        return;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
    if (getIsErroneous(timestamp)) {
        return;
    }
    templateInstance.getTemplateBody().checkSpecificValue(timestamp, false);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) IType(org.eclipse.titan.designer.AST.IType)

Example 64 with ITTCN3Template

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

the class Type method checkThisTemplateRef.

@Override
public /**
 * {@inheritDoc}
 */
ITTCN3Template checkThisTemplateRef(final CompilationTimeStamp timestamp, final ITTCN3Template t, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    switch(t.getTemplatetype()) {
        case SUPERSET_MATCH:
        case SUBSET_MATCH:
            final IType it1 = getTypeRefdLast(timestamp);
            final Type_type tt = it1.getTypetype();
            if (Type_type.TYPE_SEQUENCE_OF.equals(tt) || Type_type.TYPE_SET_OF.equals(tt)) {
                return t;
            } else {
                t.getLocation().reportSemanticError(MessageFormat.format("{0} cannot be used for type {1}", t.getTemplateTypeName(), getTypename()));
                t.setIsErroneous(true);
                return t;
            }
        case SPECIFIC_VALUE:
            // cont below
            break;
        default:
            return t;
    }
    // Case of specific value:
    final ITTCN3Template template = t;
    IValue value = ((SpecificValue_Template) template).getSpecificValue();
    if (value == null) {
        return template;
    }
    value = checkThisValueRef(timestamp, value);
    switch(value.getValuetype()) {
        case REFERENCED_VALUE:
            // FIXME: referenceChain or null?
            final Assignment assignment = ((Referenced_Value) value).getReference().getRefdAssignment(timestamp, false, referenceChain);
            if (assignment == null) {
                template.setIsErroneous(true);
            } else {
                switch(assignment.getAssignmentType()) {
                    case A_VAR_TEMPLATE:
                        if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                            template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                            template.setIsErroneous(true);
                        }
                        final IType type = ((Def_Var_Template) assignment).getType(timestamp);
                        switch(type.getTypetype()) {
                            case TYPE_BITSTRING:
                            case TYPE_BITSTRING_A:
                            case TYPE_HEXSTRING:
                            case TYPE_OCTETSTRING:
                            case TYPE_CHARSTRING:
                            case TYPE_UCHARSTRING:
                            case TYPE_UTF8STRING:
                            case TYPE_NUMERICSTRING:
                            case TYPE_PRINTABLESTRING:
                            case TYPE_TELETEXSTRING:
                            case TYPE_VIDEOTEXSTRING:
                            case TYPE_IA5STRING:
                            case TYPE_GRAPHICSTRING:
                            case TYPE_VISIBLESTRING:
                            case TYPE_GENERALSTRING:
                            case TYPE_UNIVERSALSTRING:
                            case TYPE_BMPSTRING:
                            case TYPE_UTCTIME:
                            case TYPE_GENERALIZEDTIME:
                            case TYPE_OBJECTDESCRIPTOR:
                                {
                                    final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
                                    final int nofSubreferences = subReferences.size();
                                    if (nofSubreferences > 1) {
                                        final ISubReference subreference = subReferences.get(nofSubreferences - 1);
                                        if (subreference instanceof ArraySubReference) {
                                            template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
                                            template.setIsErroneous(true);
                                            return template;
                                        }
                                    }
                                    break;
                                }
                            default:
                                break;
                        }
                        return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
                    case A_CONST:
                        IType type1;
                        if (assignment instanceof Value_Assignment) {
                            type1 = ((Value_Assignment) assignment).getType(timestamp);
                        } else {
                            type1 = ((Def_Const) assignment).getType(timestamp);
                        }
                        switch(type1.getTypetype()) {
                            case TYPE_BITSTRING:
                            case TYPE_BITSTRING_A:
                            case TYPE_HEXSTRING:
                            case TYPE_OCTETSTRING:
                            case TYPE_CHARSTRING:
                            case TYPE_UCHARSTRING:
                            case TYPE_UTF8STRING:
                            case TYPE_NUMERICSTRING:
                            case TYPE_PRINTABLESTRING:
                            case TYPE_TELETEXSTRING:
                            case TYPE_VIDEOTEXSTRING:
                            case TYPE_IA5STRING:
                            case TYPE_GRAPHICSTRING:
                            case TYPE_VISIBLESTRING:
                            case TYPE_GENERALSTRING:
                            case TYPE_UNIVERSALSTRING:
                            case TYPE_BMPSTRING:
                            case TYPE_UTCTIME:
                            case TYPE_GENERALIZEDTIME:
                            case TYPE_OBJECTDESCRIPTOR:
                                {
                                    final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
                                    final int nofSubreferences = subReferences.size();
                                    if (nofSubreferences > 1) {
                                        final ISubReference subreference = subReferences.get(nofSubreferences - 1);
                                        if (subreference instanceof ArraySubReference) {
                                            template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
                                            template.setIsErroneous(true);
                                            return template;
                                        }
                                    }
                                    break;
                                }
                            default:
                                break;
                        }
                        break;
                    case A_TEMPLATE:
                    case A_MODULEPAR_TEMPLATE:
                    case A_PAR_TEMP_IN:
                    case A_PAR_TEMP_OUT:
                    case A_PAR_TEMP_INOUT:
                    case A_FUNCTION_RTEMP:
                    case A_EXT_FUNCTION_RTEMP:
                        if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                            template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                            template.setIsErroneous(true);
                        }
                        return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
                    default:
                        break;
                }
            }
            break;
        case EXPRESSION_VALUE:
            {
                final Expression_Value expression = (Expression_Value) value;
                if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
                    IType type = expression.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
                    if (type == null) {
                        break;
                    }
                    type = type.getTypeRefdLast(timestamp);
                    if (type != null && Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
                        return template.setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
                    }
                }
                break;
            }
        default:
            break;
    }
    return template;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) List(java.util.List) ArrayList(java.util.ArrayList) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 65 with ITTCN3Template

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

the class ReplaceExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance1 == null || templateInstance4 == null || getIsErroneous(timestamp)) {
        return true;
    }
    final ITTCN3Template template1 = templateInstance1.getTemplateBody();
    if (template1 == null || !Template_type.SPECIFIC_VALUE.equals(template1.getTemplatetype())) {
        return true;
    }
    final ITTCN3Template template4 = templateInstance4.getTemplateBody();
    if (template4 == null || !Template_type.SPECIFIC_VALUE.equals(template4.getTemplatetype())) {
        return true;
    }
    final IValue value1 = ((SpecificValue_Template) template1).getSpecificValue();
    final IValue value4 = ((SpecificValue_Template) template4).getSpecificValue();
    if (value1 == null || value4 == null) {
        return true;
    }
    if (value2 == null || value3 == null) {
        return true;
    }
    if (value1.isUnfoldable(timestamp, expectedValue, referenceChain) || value2.isUnfoldable(timestamp, expectedValue, referenceChain) || value3.isUnfoldable(timestamp, expectedValue, referenceChain) || value4.isUnfoldable(timestamp, expectedValue, referenceChain)) {
        return true;
    }
    value1.setLoweridToReference(timestamp);
    final Type_type tempType = value1.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            return false;
        default:
            return true;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

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