Search in sources :

Example 6 with LengthRestriction

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

the class Named_Template_List method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (lengthRestriction != null) {
        lengthRestriction.updateSyntax(reparser, false);
        reparser.updateLocation(lengthRestriction.getLocation());
    }
    if (baseTemplate instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) baseTemplate).updateSyntax(reparser, false);
        reparser.updateLocation(baseTemplate.getLocation());
    } else if (baseTemplate != null) {
        throw new ReParseException();
    }
    namedTemplates.updateSyntax(reparser, false);
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 7 with LengthRestriction

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

the class Referenced_Template method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        throw new ReParseException();
    }
    if (lengthRestriction != null) {
        lengthRestriction.updateSyntax(reparser, false);
        reparser.updateLocation(lengthRestriction.getLocation());
    }
    if (baseTemplate instanceof IIncrementallyUpdateable) {
        ((IIncrementallyUpdateable) baseTemplate).updateSyntax(reparser, false);
        reparser.updateLocation(baseTemplate.getLocation());
    } else if (baseTemplate != null) {
        throw new ReParseException();
    }
    if (reference != null) {
        reference.updateSyntax(reparser, false);
        reparser.updateLocation(reference.getLocation());
    }
}
Also used : IIncrementallyUpdateable(org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)

Example 8 with LengthRestriction

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

the class Referenced_Template method reArrangeInitCode.

@Override
public /**
 * {@inheritDoc}
 */
void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
    final ISubReference tempSubreference = reference.getSubreferences().get(0);
    if (tempSubreference instanceof ParameterisedSubReference) {
        // generate code for the templates that are used in the actual parameter
        // list of the reference
        final ActualParameterList actualParameterList = ((ParameterisedSubReference) tempSubreference).getActualParameters();
        if (actualParameterList != null) {
            actualParameterList.reArrangeInitCode(aData, source, usageModule);
        }
    }
    final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (assignment.getAssignmentType() != Assignment_type.A_TEMPLATE) {
        return;
    }
    ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
    final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
    if (formalParameterList != null) {
        // the reference points to a parameterized template
        // we must perform the rearrangement for all non-parameterized templates
        // that are referred by the parameterized template regardless of the
        // sub-references of reference
        template.reArrangeInitCode(aData, source, usageModule);
        // be generated when the template's definition is reached)
        if (assignment.getMyScope().getModuleScope() == usageModule) {
            formalParameterList.generateCodeDefaultValues(aData, source);
        }
    } else {
        // the reference points to a non-parameterized template
        final List<ISubReference> subReferences = reference.getSubreferences();
        if (subReferences != null && subReferences.size() > 1) {
            // and perform the rearrangement for the referred field only
            for (int i = 1; i < subReferences.size(); i++) {
                final ISubReference subReference = subReferences.get(i);
                if (subReference instanceof FieldSubReference) {
                    // stop if the body does not have fields
                    if (template.getTemplatetype() != Template_type.NAMED_TEMPLATE_LIST) {
                        break;
                    }
                    // the field reference can be followed
                    final Identifier fieldId = ((FieldSubReference) subReference).getId();
                    template = ((Named_Template_List) template).getNamedTemplate(fieldId).getTemplate();
                } else {
                    // stop if the body is not a list
                    if (template.getTemplatetype() != Template_type.TEMPLATE_LIST) {
                        break;
                    }
                    IValue arrayIndex = ((ArraySubReference) subReference).getValue();
                    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    arrayIndex = arrayIndex.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
                    referenceChain.release();
                    if (arrayIndex.getValuetype() != Value_type.INTEGER_VALUE) {
                        break;
                    }
                    // the index is available at compilation time
                    long index = ((Integer_Value) arrayIndex).getValue();
                    // index transformation in case of arrays
                    if (template.getMyGovernor().getTypetype() == Type_type.TYPE_ARRAY) {
                        index = index - ((Array_Type) template.getMyGovernor()).getDimension().getOffset();
                    }
                    template = ((Template_List) template).getTemplateByIndex((int) index);
                }
            }
        }
        // we should initialize its entire body
        if (assignment.getMyScope().getModuleScope() == usageModule) {
            template.generateCodeInit(aData, source, template.get_lhs_name());
        }
    }
    if (lengthRestriction != null) {
        lengthRestriction.reArrangeInitCode(aData, source, usageModule);
    }
}
Also used : FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Example 9 with LengthRestriction

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

the class Referenced_Template method getSingleExpression.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder getSingleExpression(final JavaGenData aData, final boolean castIsNeeded) {
    final StringBuilder result = new StringBuilder();
    if (castIsNeeded && (lengthRestriction != null || isIfpresent)) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing referenced template `" + getFullName() + "''");
        return result;
    }
    final ExpressionStruct expression = new ExpressionStruct();
    reference.generateCode(aData, expression);
    if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing referenced template `" + getFullName() + "''");
        return result;
    }
    result.append(expression.expression);
    return result;
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 10 with LengthRestriction

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

the class ComplementedList_Template method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    aData.addBuiltinTypeImport("Base_Template.template_sel");
    final ArrayList<Integer> variables = new ArrayList<Integer>();
    long fixedPart = 0;
    for (int i = 0; i < templates.getNofTemplates(); i++) {
        final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
        if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
            variables.add(i);
        } else {
            fixedPart++;
        }
    }
    final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
    if (variables.size() > 0) {
        final StringBuilder preamble = new StringBuilder();
        final StringBuilder setType = new StringBuilder();
        final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
        setType.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1}", name, fixedPart));
        for (int v = 0; v < variables.size(); v++) {
            TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
            // the template must be all from
            if (template instanceof All_From_Template) {
                template = ((All_From_Template) template).getAllFrom();
            }
            final Reference reference = ((SpecificValue_Template) template).getReference();
            final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            setType.append(" + ");
            final ExpressionStruct expression = new ExpressionStruct();
            reference.generateCode(aData, expression);
            if (expression.preamble.length() > 0) {
                preamble.append(expression.preamble);
            }
            switch(assignment.getAssignmentType()) {
                case A_CONST:
                case A_EXT_CONST:
                case A_MODULEPAR:
                case A_VAR:
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                case A_PAR_VAL_OUT:
                case A_PAR_VAL_INOUT:
                case A_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RVAL:
                    if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
                        setType.append(".get()");
                    }
                    break;
                default:
                    break;
            }
            variableReferences[variables.get(v)] = expression.expression;
            setType.append(expression.expression);
            setType.append(".n_elem().getInt()");
        }
        source.append(preamble);
        source.append(setType);
        source.append(");\n");
        final StringBuilder shifty = new StringBuilder();
        for (int i = 0; i < templates.getNofTemplates(); i++) {
            final TTCN3Template template = templates.getTemplateByIndex(i);
            switch(template.getTemplatetype()) {
                case ALL_FROM:
                    {
                        // the template must be all from
                        final StringBuilder storedExpression = variableReferences[i];
                        source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
                        String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
                        ((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
                        source.append("}\n");
                        shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
                        break;
                    }
                default:
                    if (template.needsTemporaryReference()) {
                        final String tempId = aData.getTemporaryVariableName();
                        source.append("{\n");
                        source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
                        template.generateCodeInit(aData, source, tempId);
                        source.append("}\n");
                    } else {
                        final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
                        template.generateCodeInit(aData, source, embeddedName);
                    }
                    break;
            }
        }
    } else {
        source.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1});\n", name, templates.getNofTemplates()));
        for (int i = 0; i < templates.getNofTemplates(); i++) {
            final TTCN3Template template = templates.getTemplateByIndex(i);
            if (template.needsTemporaryReference()) {
                final String tempId = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
                template.generateCodeInit(aData, source, tempId);
                source.append("}\n");
            } else {
                final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
                template.generateCodeInit(aData, source, embeddedName);
            }
        }
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignment(org.eclipse.titan.designer.AST.Assignment) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)8 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 IIncrementallyUpdateable (org.eclipse.titan.designer.AST.TTCN3.IIncrementallyUpdateable)7 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)7 IType (org.eclipse.titan.designer.AST.IType)6 Reference (org.eclipse.titan.designer.AST.Reference)6 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)6 IValue (org.eclipse.titan.designer.AST.IValue)5 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)5 ArrayList (java.util.ArrayList)4 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)4 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)4 SingleLenghtRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 LengthRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction)2 RangeLenghtRestriction (org.eclipse.titan.designer.AST.TTCN3.templates.RangeLenghtRestriction)2 SubsetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template)2 SupersetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template)2