Search in sources :

Example 11 with TemplateRestriction

use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction 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 12 with TemplateRestriction

use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction 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 13 with TemplateRestriction

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

the class SpecificValue_Template method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        return;
    }
    final String genName = governor.getGenNameTemplate(aData, expression.expression, myScope);
    if (realTemplate != null && realTemplate != this) {
        realTemplate.generateCodeExpression(aData, expression, templateRestriction);
        return;
    }
    if (lengthRestriction == null && !isIfpresent && templateRestriction == Restriction_type.TR_NONE) {
        // The single expression must be tried first because this rule might cover some referenced templates.
        if (hasSingleExpression()) {
            expression.expression.append(MessageFormat.format("new {0}(", genName));
            if (governor.getTypetype() == Type_type.TYPE_ARRAY) {
                final Array_Type array_type = (Array_Type) governor;
                expression.expression.append(MessageFormat.format(" {0}.class, ", array_type.getElementType().getGenNameTemplate(aData, expression.expression, myScope)));
            }
            expression.expression.append(getSingleExpression(aData, true));
            expression.expression.append(')');
            return;
        }
        expression.expression.append(MessageFormat.format("new {0}(", genName));
        specificValue.generateCodeExpression(aData, expression, false);
        expression.expression.append(')');
        return;
    }
    final String tempId = aData.getTemporaryVariableName();
    expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", governor.getGenNameTemplate(aData, expression.expression, myScope), tempId));
    generateCodeInit(aData, expression.preamble, tempId);
    if (templateRestriction != Restriction_type.TR_NONE) {
        TemplateRestriction.generateRestrictionCheckCode(aData, expression.expression, location, tempId, templateRestriction);
    }
    expression.expression.append(tempId);
}
Also used : Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 14 with TemplateRestriction

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

the class TemplateInstance method generateCode.

/**
 * Add generated java code on this level.
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param expression the expression code generated
 * @param templateRestriction the template restriction to check in runtime
 */
public void generateCode(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
    if (derivedReference != null) {
        final ExpressionStruct derivedExpression = new ExpressionStruct();
        derivedReference.generateCode(aData, derivedExpression);
        final String tempId = aData.getTemporaryVariableName();
        expression.preamble.append(derivedExpression.preamble);
        expression.preamble.append(MessageFormat.format("{0} {1} = new {0}({2});\n", templateBody.getMyGovernor().getGenNameTemplate(aData, expression.expression, myScope), tempId, derivedExpression.expression));
        // perform the modifications on the temporary variable
        templateBody.generateCodeInit(aData, expression.preamble, tempId);
        // TODO implement runtime restriction check
        expression.expression.append(tempId);
    } else {
        // TODO handle decoded redirect
        templateBody.generateCodeExpression(aData, expression, templateRestriction);
    // TODO handle decoded redirect
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)6 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)6 Assignment (org.eclipse.titan.designer.AST.Assignment)5 IValue (org.eclipse.titan.designer.AST.IValue)3 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 TemplateRestriction (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)2 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 Scope (org.eclipse.titan.designer.AST.Scope)1 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)1 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)1 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)1 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)1 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)1 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)1 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)1