Search in sources :

Example 56 with Assignment

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

the class TemplateRestriction method getSubRestriction.

/**
 * Calculates the restriction of the sub-fields from the restriction of the template.
 *
 * @param tr the restriction on the definition
 * @param timestamp compilation timestamp
 * @param ref the reference that points to the definition or to one of it's subfields
 *
 * @return the restriction on the sub-field
 */
public static Restriction_type getSubRestriction(final Restriction_type tr, final CompilationTimeStamp timestamp, final Reference ref) {
    if (ref == null || ref.getSubreferences() == null) {
        return tr;
    }
    boolean isOptional = true;
    final Assignment ass = ref.getRefdAssignment(timestamp, false, null);
    if (ass != null) {
        IType type = ass.getType(timestamp);
        if (type != null) {
            // TODO maybe we should have a different function to check if we are referring an optional type.
            type = type.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_TEMPLATE, true);
            if (type != null) {
                isOptional = false;
            }
        }
    }
    switch(tr) {
        case TR_NONE:
            return Restriction_type.TR_NONE;
        case TR_OMIT:
            return Restriction_type.TR_OMIT;
        case TR_VALUE:
            return isOptional ? Restriction_type.TR_OMIT : Restriction_type.TR_VALUE;
        case TR_PRESENT:
            return isOptional ? Restriction_type.TR_NONE : Restriction_type.TR_PRESENT;
        default:
            return tr;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IType(org.eclipse.titan.designer.AST.IType)

Example 57 with Assignment

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

the class Referenced_Type method getTypeRefd.

@Override
public /**
 * {@inheritDoc}
 */
IType getTypeRefd(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (refChain.add(this) && reference != null && !getIsErroneous(timestamp)) {
        if (refd != null) {
            return refd;
        }
        Assignment ass = reference.getRefdAssignment(timestamp, true, refChain);
        if (ass != null && Assignment_type.A_UNDEF.semanticallyEquals(ass.getAssignmentType())) {
            ass = ((Undefined_Assignment) ass).getRealAssignment(timestamp);
        }
        if (ass == null || ass.getIsErroneous()) {
            // The referenced assignment was not found, or is erroneous
            isErroneous = true;
            lastTimeChecked = timestamp;
            return this;
        }
        switch(ass.getAssignmentType()) {
            case A_TYPE:
                {
                    IType tempType = ass.getType(timestamp);
                    if (tempType != null) {
                        if (!tempType.getIsErroneous(timestamp)) {
                            tempType.check(timestamp);
                            tempType = tempType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, refChain, false);
                            if (tempType == null) {
                                setIsErroneous(true);
                                return this;
                            }
                            refd = tempType;
                            return refd;
                        }
                    }
                    break;
                }
            case A_VS:
                {
                    final IType tempType = ass.getType(timestamp);
                    if (tempType == null) {
                        isErroneous = true;
                        lastTimeChecked = timestamp;
                        return this;
                    }
                    refd = tempType;
                    return refd;
                }
            case A_OC:
            case A_OBJECT:
            case A_OS:
                final ISetting setting = reference.getRefdSetting(timestamp);
                if (setting == null || setting.getIsErroneous(timestamp)) {
                    isErroneous = true;
                    lastTimeChecked = timestamp;
                    return this;
                }
                if (!Setting_type.S_T.equals(setting.getSettingtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(TYPEREFERENCEEXPECTED, reference.getDisplayName()));
                    isErroneous = true;
                    lastTimeChecked = timestamp;
                    return this;
                }
                refd = (Type) setting;
                if (refd.getOwnertype() == TypeOwner_type.OT_UNKNOWN) {
                    refd.setOwnertype(TypeOwner_type.OT_REF, this);
                }
                return refd;
            default:
                reference.getLocation().reportSemanticError(MessageFormat.format(TYPEREFERENCEEXPECTED, reference.getDisplayName()));
                break;
        }
    }
    isErroneous = true;
    lastTimeChecked = timestamp;
    return this;
}
Also used : Type_Assignment(org.eclipse.titan.designer.AST.ASN1.Type_Assignment) Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) ISetting(org.eclipse.titan.designer.AST.ISetting) IType(org.eclipse.titan.designer.AST.IType)

Example 58 with Assignment

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

the class SpecificValue_Template method setLoweridToReference.

@Override
public /**
 * {@inheritDoc}
 */
ITTCN3Template setLoweridToReference(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return realTemplate;
    }
    lastTimeChecked = timestamp;
    realTemplate = this;
    isErroneous = false;
    final IValue temp = specificValue.setLoweridToReference(timestamp);
    if (Value_type.REFERENCED_VALUE.equals(temp.getValuetype())) {
        final Assignment assignment = ((Referenced_Value) temp).getReference().getRefdAssignment(timestamp, false);
        if (assignment != null) {
            switch(assignment.getAssignmentType()) {
                case A_TEMPLATE:
                case A_VAR_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:
                    realTemplate = setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
                    break;
                default:
                    break;
            }
        } else {
            isErroneous = true;
        }
    }
    return realTemplate;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue)

Example 59 with Assignment

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

the class SubsetMatch_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");
    String ofTypeName;
    switch(myGovernor.getTypetype()) {
        case TYPE_SEQUENCE_OF:
            ofTypeName = ((SequenceOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
            break;
        case TYPE_SET_OF:
            ofTypeName = ((SetOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
            break;
        case TYPE_ARRAY:
            ofTypeName = ((Array_Type) myGovernor).getElementType().getGenNameTemplate(aData, source, myScope);
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing subset match template `" + getFullName() + "''");
            return;
    }
    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++;
        }
    }
    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.SUBSET_MATCH, {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())) {
                        expression.expression.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));
                        final String embeddedName = MessageFormat.format("{0}.setItem({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}.setItem({3}{4});\n", ofTypeName, tempId, name, i, shifty));
                        template.generateCodeInit(aData, source, tempId);
                        source.append("}\n");
                    } else {
                        final String embeddedName = MessageFormat.format("{0}.setItem({1}{2})", name, i, shifty);
                        template.generateCodeInit(aData, source, embeddedName);
                    }
                    break;
            }
        }
    } else {
        source.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {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}.setItem({3});\n", ofTypeName, tempId, name, i));
                template.generateCodeInit(aData, source, tempId);
                source.append("}\n");
            } else {
                final String embeddedName = MessageFormat.format("{0}.setItem({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) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)

Example 60 with Assignment

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

the class TemplateInstance method reArrangeInitCode.

/**
 * Walks through the templateinstance recursively and appends the java
 * initialization sequence of all (directly or indirectly) referenced
 * non-parameterized templates and the default values of all
 * parameterized templates to source and returns the resulting string.
 * Only objects belonging to module usageModule are initialized.
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source for code generated
 * @param usageModule the module where the template is to be used.
 */
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
    if (derivedReference != null) {
        final List<ISubReference> subreferences = derivedReference.getSubreferences();
        if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
            final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
            final ActualParameterList actualParameterList = subreference.getActualParameters();
            if (actualParameterList != null) {
                actualParameterList.reArrangeInitCode(aData, source, usageModule);
            }
        }
        final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment == null) {
            return;
        }
        if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
            final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
            final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
            if (formalParameterList != null) {
                // the referred template is parameterized
                // the embedded referenced templates shall be visited
                template.reArrangeInitCode(aData, source, usageModule);
            // FIXME implement
            } else {
                // its entire body has to be initialized now
                if (assignment.getMyScope().getModuleScope() == usageModule) {
                    template.generateCodeInit(aData, source, template.get_lhs_name());
                }
            }
        }
    }
    if (templateBody != null) {
        templateBody.reArrangeInitCode(aData, source, usageModule);
    }
}
Also used : 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) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)141 Reference (org.eclipse.titan.designer.AST.Reference)48 IType (org.eclipse.titan.designer.AST.IType)41 ISubReference (org.eclipse.titan.designer.AST.ISubReference)39 IValue (org.eclipse.titan.designer.AST.IValue)31 Identifier (org.eclipse.titan.designer.AST.Identifier)25 ArrayList (java.util.ArrayList)24 Module (org.eclipse.titan.designer.AST.Module)22 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)16 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)14 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)14 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)14 Assignments (org.eclipse.titan.designer.AST.Assignments)13 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 Location (org.eclipse.titan.designer.AST.Location)9 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)7 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)6