Search in sources :

Example 11 with Referenced_Template

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

the class DecvalueUnicharExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * inout universal charstring
 * @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 checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference1 == null) {
        setIsErroneous(true);
        return;
    }
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR2, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR3, last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR4, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    final Type_type type_type = temporalType.getTypeRefdLast(timestamp).getTypetype();
    if (type_type != Type_type.TYPE_UCHARSTRING) {
        if (!isErroneous) {
            location.reportSemanticError(OPERAND1_ERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 12 with Referenced_Template

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

the class Referenced_Template method generateRearrangeInitCodeReferenced.

private void generateRearrangeInitCodeReferenced(final JavaGenData aData, final StringBuilder source, final ExpressionStruct expression) {
    /**
     * Initially we can assume that:
     * - this is a referenced template and a part of a non-parameterized template
     * - u.ref.ref points to (a field of) a non-parameterized template within the same module as this.
     * - this ensures that the do-while loop will run at least twice (i.e. the first continue statement will be reached in the first iteration)
     */
    final Stack<ISubReference> referenceStack = new Stack<ISubReference>();
    ITTCN3Template template = this;
    for (; ; ) {
        if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
            final Reference reference = ((Referenced_Template) template).getReference();
            final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            /**
             * Don't follow the reference if:
             *  - the referenced definition is not a template
             *  - the referenced template is parameterized or
             *  - the referenced template is in different module
             */
            if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE && ((Def_Template) assignment).getFormalParameterList() == null && assignment.getMyScope().getModuleScope() == myScope.getModuleScope()) {
                // accumulate the sub-references of the referred reference
                final List<ISubReference> subReferences = reference.getSubreferences();
                if (subReferences != null && subReferences.size() > 1) {
                    for (int i = subReferences.size(); i > 1; i--) {
                        referenceStack.push(subReferences.get(i - 1));
                    }
                }
                // jump to the referred top-level template
                template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
                // start the iteration from the beginning
                continue;
            } else {
                // the reference cannot be followed
                break;
            }
        }
        // stop if there are no sub-references
        if (referenceStack.isEmpty()) {
            break;
        }
        // take the topmost sub-reference
        final ISubReference subReference = referenceStack.peek();
        if (subReference instanceof FieldSubReference) {
            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 {
            // trying to follow an array reference
            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);
        }
        // the topmost sub-reference was processed
        // it can be erased from the stack
        referenceStack.pop();
    }
    // the smallest dependent template is now in t
    // generate the initializer sequence for t
    template.generateCodeInit(aData, source, template.get_lhs_name());
    // the equivalent Java code of the referenced template is composed of the
    // genname of t and the remained sub-references in refstack
    expression.expression.append(template.getGenNameOwn(myScope));
    while (!referenceStack.isEmpty()) {
        final ISubReference subReference = referenceStack.pop();
        if (subReference instanceof FieldSubReference) {
            expression.expression.append(MessageFormat.format(".get{0}()", FieldSubReference.getJavaGetterName(((FieldSubReference) subReference).getId().getName())));
        } else {
            expression.expression.append(".getAt(");
            ((ArraySubReference) subReference).getValue().generateCodeExpression(aData, expression, false);
            expression.expression.append(')');
        }
    }
}
Also used : FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Stack(java.util.Stack) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 13 with Referenced_Template

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

the class DecodeExpression method checkFirstExpressionOperand.

private void checkFirstExpressionOperand(final CompilationTimeStamp timestamp) {
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue'' operation", temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format("Specific value template was expected instead of `{0}''", last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue' operation", temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    if (temporalType.getTypeRefdLast(timestamp).getTypetype() != Type_type.TYPE_BITSTRING) {
        if (!isErroneous) {
            reference1.getLocation().reportSemanticError(OPERANDERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 14 with Referenced_Template

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

the class All_From_Template method checkThisTemplateParameterizedReference.

private boolean checkThisTemplateParameterizedReference(final Reference reference, final Assignment lhs) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.isEmpty() || !(subreferences.get(0) instanceof ParameterisedSubReference)) {
        return false;
    }
    final ParameterisedSubReference subReference = (ParameterisedSubReference) subreferences.get(0);
    final ActualParameterList actualParameterList = subReference.getActualParameters();
    if (actualParameterList == null) {
        return false;
    }
    final int nofParameters = actualParameterList.getNofParameters();
    for (int i = 0; i < nofParameters; i++) {
        Reference parameterReference = null;
        final ActualParameter actualParameter = actualParameterList.getParameter(i);
        if (actualParameter instanceof Template_ActualParameter) {
            TemplateInstance templateInstance = ((Template_ActualParameter) actualParameter).getTemplateInstance();
            ITTCN3Template template = templateInstance.getTemplateBody();
            template = template.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
            if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
                parameterReference = ((Referenced_Template) template).getReference();
            }
        } else if (actualParameter instanceof Referenced_ActualParameter) {
            parameterReference = ((Referenced_ActualParameter) actualParameter).getReference();
        }
        if (parameterReference != null) {
            final Assignment assignment = parameterReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            if (assignment == lhs) {
                return true;
            }
            // check their parameters as well
            switch(assignment.getAssignmentType()) {
                case A_TEMPLATE:
                case A_FUNCTION_RVAL:
                case A_FUNCTION_RTEMP:
                case A_EXT_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RTEMP:
                    if (checkThisTemplateParameterizedReference(parameterReference, lhs)) {
                        return true;
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Template_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter) ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter) Referenced_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter) Template_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Referenced_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter)

Example 15 with Referenced_Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template 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)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)12 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)12 Assignment (org.eclipse.titan.designer.AST.Assignment)11 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)10 Reference (org.eclipse.titan.designer.AST.Reference)8 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)8 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)8 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 IType (org.eclipse.titan.designer.AST.IType)4 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)4 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)2 Stack (java.util.Stack)1 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)1 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1