Search in sources :

Example 26 with TTCN3Template

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

the class IsChoosenExpression 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 (lastTimeoperandsChecked != null && !lastTimeoperandsChecked.isLess(timestamp)) {
        return;
    }
    lastTimeoperandsChecked = timestamp;
    value = null;
    identifier = null;
    if (reference == null || reference.getSubreferences().size() < 2) {
        setIsErroneous(true);
        return;
    }
    final Reference tempReference = reference.newInstance();
    tempReference.setFullNameParent(this);
    tempReference.setMyScope(getMyScope());
    final ISubReference subreference = tempReference.removeLastSubReference();
    if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
        identifier = ((FieldSubReference) subreference).getId();
    } else {
        setIsErroneous(true);
        return;
    }
    final Assignment assignment = tempReference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return;
    }
    IType governor;
    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:
            {
                value = new Referenced_Value(tempReference);
                value.setLocation(tempReference.getLocation());
                value.setMyScope(getMyScope());
                final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
                value.setFullNameParent(tempNamedNode);
                governor = value.getExpressionGovernor(timestamp, expectedValue);
                if (governor == null) {
                    setIsErroneous(true);
                } else {
                    value.setMyGovernor(governor);
                    final IValue tempValue2 = governor.checkThisValueRef(timestamp, value);
                    if (tempValue2.getIsErroneous(timestamp)) {
                        setIsErroneous(true);
                    }
                }
                break;
            }
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                template = new Referenced_Template(tempReference);
                template.setLocation(tempReference.getLocation());
                template.setMyScope(getMyScope());
                final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
                template.setFullNameParent(tempNamedNode);
                if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) || Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
                    governor = template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
                } else {
                    governor = template.getExpressionGovernor(timestamp, expectedValue);
                }
                if (governor == null) {
                    setIsErroneous(true);
                } else {
                    template.setMyGovernor(governor);
                    final TTCN3Template last = template.getTemplateReferencedLast(timestamp, referenceChain);
                    if (last.getIsErroneous(timestamp)) {
                        setIsErroneous(true);
                    }
                }
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && !Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
                    if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
                        template.getLocation().reportSemanticError(MessageFormat.format(CONSTANTREFERENCEEXPECTED, assignment.getDescription()));
                    } else {
                        template.getLocation().reportSemanticError(MessageFormat.format(STATICREFERENCEEXPECTED, assignment.getDescription()));
                    }
                    setIsErroneous(true);
                }
                break;
            }
        default:
            tempReference.getLocation().reportSemanticError(MessageFormat.format(VALUETEMPLATEEXPECTED, assignment.getDescription()));
            setIsErroneous(true);
            return;
    }
    if (governor != null) {
        governor = governor.getTypeRefdLast(timestamp);
        if (!governor.getIsErroneous(timestamp)) {
            CompField field = null;
            switch(governor.getTypetype()) {
                case TYPE_ASN1_CHOICE:
                    if (((ASN1_Choice_Type) governor).hasComponentWithName(identifier)) {
                        field = ((ASN1_Choice_Type) governor).getComponentByName(identifier);
                    }
                    break;
                case TYPE_TTCN3_CHOICE:
                    if (((TTCN3_Choice_Type) governor).hasComponentWithName(identifier.getName())) {
                        field = ((TTCN3_Choice_Type) governor).getComponentByName(identifier.getName());
                    }
                    break;
                case TYPE_OPENTYPE:
                    if (((Open_Type) governor).hasComponentWithName(identifier)) {
                        field = ((Open_Type) governor).getComponentByName(identifier);
                    }
                    break;
                case TYPE_ANYTYPE:
                    if (((Anytype_Type) governor).hasComponentWithName(identifier.getName())) {
                        field = ((Anytype_Type) governor).getComponentByName(identifier.getName());
                    }
                    break;
                default:
                    location.reportSemanticError(MessageFormat.format(OPERANDERROR, governor.getTypename()));
                    setIsErroneous(true);
                    return;
            }
            if (null == field) {
                location.reportSemanticError(MessageFormat.format(MISSINGFIELD, governor.getTypename(), identifier.getDisplayName()));
                setIsErroneous(true);
            }
        }
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) Assignment(org.eclipse.titan.designer.AST.Assignment) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)

Example 27 with TTCN3Template

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

the class IsValueExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template templateBody = templateInstance.getTemplateBody();
    // FIXME actually a bit more complex
    if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
        final IValue value = ((SpecificValue_Template) templateBody).getValue();
        // FIXME implement support for cast
        value.generateCodeExpression(aData, expression, true);
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".isValue()");
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 28 with TTCN3Template

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

the class LengthofExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template templateBody = templateInstance.getTemplateBody();
    // FIXME actually a bit more complex
    if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
        final IValue value = ((SpecificValue_Template) templateBody).getValue();
        // FIXME implement support for cast
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".lengthOf()");
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 29 with TTCN3Template

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

the class SpecificValue_Template method isValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean isValue(final CompilationTimeStamp timestamp) {
    if (lengthRestriction != null || isIfpresent || getIsErroneous(timestamp)) {
        return false;
    }
    if (realTemplate != null && realTemplate != this) {
        return realTemplate.isValue(timestamp);
    }
    if (Value_type.FUNCTION_REFERENCE_VALUE.equals(specificValue.getValuetype())) {
        final IType governor = ((Function_Reference_Value) specificValue).getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (governor == null) {
            return true;
        }
        final IType last = governor.getTypeRefdLast(timestamp);
        if (Type_type.TYPE_FUNCTION.equals(last.getTypetype()) && ((Function_Type) last).returnsTemplate()) {
            return false;
        }
    } else if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
        final Reference reference = ((Referenced_Value) specificValue).getReference();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true);
        if (assignment == null) {
            return true;
        }
        switch(assignment.getAssignmentType()) {
            case A_CONST:
            case A_TIMER:
            case A_EXT_CONST:
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
            case A_VAR:
            case A_FUNCTION_RVAL:
            case A_EXT_FUNCTION_RVAL:
            case A_MODULEPAR:
            case A_MODULEPAR_TEMPLATE:
                // runtime evaluation!
                return true;
            case A_TEMPLATE:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_INOUT:
            case A_FUNCTION_RTEMP:
            case A_VAR_TEMPLATE:
                boolean result = true;
                final Restriction_type rt = ((Definition) assignment).getTemplateRestriction();
                if (TemplateRestriction.Restriction_type.TR_OMIT.equals(rt) || TemplateRestriction.Restriction_type.TR_PRESENT.equals(rt)) {
                    result = false;
                }
                final TTCN3Template ttemplate = getTemplateReferencedLast(timestamp);
                if ((!ttemplate.equals(this)) && (ttemplate.isValue(timestamp))) {
                    // ok
                    return result;
                } else {
                    return false;
                }
            default:
                return false;
        }
    }
    return true;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Reference(org.eclipse.titan.designer.AST.Reference) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 30 with TTCN3Template

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

the class SupersetMatch_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 superset 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.SUPERSET_MATCH, {1}", name, fixedPart));
        for (int v = 0; v < variables.size(); v++) {
            final TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
            // the template must be all from
            TTCN3Template template2 = template;
            if (template instanceof All_From_Template) {
                template2 = ((All_From_Template) template).getAllFrom();
            }
            final Reference reference = ((SpecificValue_Template) template2).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.SUPERSET_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)

Aggregations

TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)23 IValue (org.eclipse.titan.designer.AST.IValue)18 Reference (org.eclipse.titan.designer.AST.Reference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)12 Assignment (org.eclipse.titan.designer.AST.Assignment)11 IType (org.eclipse.titan.designer.AST.IType)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)9 ArrayList (java.util.ArrayList)4 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)4 Type (org.eclipse.titan.designer.AST.Type)4 Identifier (org.eclipse.titan.designer.AST.Identifier)3 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)3 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)3 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)3 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)2