Search in sources :

Example 41 with IReferenceChain

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

the class RangeLenghtRestriction method getLowerValue.

public IValue getLowerValue(final CompilationTimeStamp timestamp) {
    if (lower == null) {
        return null;
    }
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = lower.getValueRefdLast(timestamp, chain);
    chain.release();
    return last;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 42 with IReferenceChain

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

the class RangeLenghtRestriction method getUpperValue.

public IValue getUpperValue(final CompilationTimeStamp timestamp) {
    if (upper == null) {
        return null;
    }
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = upper.getValueRefdLast(timestamp, chain);
    chain.release();
    return last;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 43 with IReferenceChain

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

the class RangeLenghtRestriction method checkArraySize.

@Override
public /**
 * {@inheritDoc}
 */
void checkArraySize(final CompilationTimeStamp timestamp, final ArrayDimension dimension) {
    if (lastTimeChecked == null || dimension.getIsErroneous(timestamp)) {
        return;
    }
    boolean errorFlag = false;
    final long arraySize = dimension.getSize();
    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue lowerLast = lower.getValueRefdLast(timestamp, chain);
    chain.release();
    if (Value_type.INTEGER_VALUE.equals(lowerLast.getValuetype()) && !lowerLast.getIsErroneous(timestamp)) {
        final BigInteger length = ((Integer_Value) lowerLast).getValueValue();
        if (length.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
            final String message = MessageFormat.format("An integer value less then `{0}'' was expected as the lower boundary of the length restriction instead of `{1}''", Integer.MAX_VALUE, length);
            lower.getLocation().reportSemanticError(message);
            errorFlag = true;
        } else if (length.compareTo(BigInteger.valueOf(arraySize)) == 1) {
            final String message = MessageFormat.format("There number of elements allowed by the length restriction (at least {0}) contradicts the array size ({1})", length, arraySize);
            lower.getLocation().reportSemanticError(message);
            errorFlag = true;
        }
    }
    if (upper != null) {
        chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue upperLast = upper.getValueRefdLast(timestamp, chain);
        chain.release();
        if (Value_type.INTEGER_VALUE.equals(upperLast.getValuetype()) && !upperLast.getIsErroneous(timestamp)) {
            final BigInteger length = ((Integer_Value) upperLast).getValueValue();
            if (length.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
                final String message = MessageFormat.format("An integer value less then `{0}'' was expected as the upper boundary of the length restriction instead of `{1}''", Integer.MAX_VALUE, length);
                upper.getLocation().reportSemanticError(message);
                errorFlag = true;
            } else if (length.compareTo(BigInteger.valueOf(arraySize)) == 1) {
                final String message = MessageFormat.format("There number of elements allowed by the length restriction (at most {0}) contradicts the array size ({1})", length, arraySize);
                upper.getLocation().reportSemanticError(message);
                errorFlag = true;
            }
        }
    }
    if (!errorFlag) {
        getLocation().reportSemanticWarning("Length restriction is useless for an array template");
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 44 with IReferenceChain

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

the class Referenced_Template method checkThisTemplateGeneric.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplateGeneric(final CompilationTimeStamp timestamp, final IType type, final boolean isModified, final boolean allowOmit, final boolean allowAnyOrOmit, final boolean subCheck, final boolean implicitOmit, final Assignment lhs) {
    if (getIsErroneous(timestamp) || reference == null) {
        return false;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return false;
    }
    final boolean selfReference = lhs == assignment;
    assignment.check(timestamp);
    IType governor = assignment.getType(timestamp);
    if (governor != null) {
        governor = governor.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    }
    if (governor == null) {
        setIsErroneous(true);
        return selfReference;
    }
    final TypeCompatibilityInfo info = new TypeCompatibilityInfo(type, governor, true);
    if (!type.isCompatible(timestamp, governor, info, null, null)) {
        final IType last = type.getTypeRefdLast(timestamp);
        switch(last.getTypetype()) {
            case TYPE_PORT:
                // no such thing exists, remain silent
                break;
            case TYPE_SIGNATURE:
                getLocation().reportSemanticError(MessageFormat.format(TYPEMISSMATCH1, type.getTypename(), governor.getTypename()));
                setIsErroneous(true);
                break;
            default:
                getLocation().reportSemanticError(MessageFormat.format(TYPEMISSMATCH2, type.getTypename(), governor.getTypename()));
                setIsErroneous(true);
                break;
        }
    }
    // check for circular references
    final ITTCN3Template temp = getTemplateReferencedLast(timestamp);
    if (temp != this) {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
        final boolean referencedHasImplicitOmit = hasTemplateImpliciteOmit(timestamp, referenceChain);
        referenceChain.release();
    }
    return selfReference;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) IType(org.eclipse.titan.designer.AST.IType)

Example 45 with IReferenceChain

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

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)154 IValue (org.eclipse.titan.designer.AST.IValue)102 IType (org.eclipse.titan.designer.AST.IType)55 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)21 ISubReference (org.eclipse.titan.designer.AST.ISubReference)18 Value (org.eclipse.titan.designer.AST.Value)18 Assignment (org.eclipse.titan.designer.AST.Assignment)16 BigInteger (java.math.BigInteger)15 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)14 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)13 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Reference (org.eclipse.titan.designer.AST.Reference)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)7 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)7 HashMap (java.util.HashMap)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)6 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)5