Search in sources :

Example 46 with IReferenceChain

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

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

the class Referenced_Template method getTemplateReferencedLast.

@Override
public /**
 * {@inheritDoc}
 */
TTCN3Template getTemplateReferencedLast(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (reference == null) {
        setIsErroneous(true);
        return this;
    }
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    TTCN3Template template = this;
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass != null) {
        switch(ass.getAssignmentType()) {
            case A_TEMPLATE:
                tempReferenceChain.markState();
                if (tempReferenceChain.add(this)) {
                    final ITTCN3Template refd = getTemplateReferenced(timestamp, tempReferenceChain);
                    if (refd != this) {
                        template = refd.getTemplateReferencedLast(timestamp, referenceChain);
                    }
                } else {
                    setIsErroneous(true);
                }
                tempReferenceChain.previousState();
                break;
            case A_VAR_TEMPLATE:
            case A_FUNCTION_RTEMP:
            case A_MODULEPAR_TEMPLATE:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                return this;
            default:
                setIsErroneous(true);
        }
    } else {
        setIsErroneous(true);
    }
    if (newChain) {
        tempReferenceChain.release();
    }
    return template;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 48 with IReferenceChain

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

the class SingleLenghtRestriction method checkArraySize.

@Override
public /**
 * {@inheritDoc}
 */
void checkArraySize(final CompilationTimeStamp timestamp, final ArrayDimension dimension) {
    if (lastTimeChecked == null || dimension.getIsErroneous(timestamp) || value == null) {
        return;
    }
    boolean errorFlag = false;
    final long arraySize = dimension.getSize();
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(timestamp, chain);
    chain.release();
    if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
        final BigInteger length = ((Integer_Value) last).getValueValue();
        final int compareResult = length.compareTo(BigInteger.valueOf(arraySize));
        if (compareResult != 0) {
            final String message = MessageFormat.format("There number of elements allowed by the length restriction ({0}) contradicts the array size ({1})", length, arraySize);
            value.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 49 with IReferenceChain

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

the class Port_Utility method checkConnectionEndpoint.

/**
 * Checks a reference to see if it really references a valid component
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the statement to report an error to, in case it is in
 *                a control part.
 * @param componentReference
 *                the reference of the component to be checked.
 * @param portReference
 *                the reference to a port of the component to be
 *                checked.
 * @param allowSystem
 *                tells if the system component should be allowed or not
 *                as an endpoint.
 *
 * @return the referenced component type, or null if there were
 *         problems.
 */
public static IType checkConnectionEndpoint(final CompilationTimeStamp timestamp, final Statement source, final Value componentReference, final PortReference portReference, final boolean allowSystem) {
    final IType componentType = checkComponentReference(timestamp, source, componentReference, true, allowSystem);
    if (portReference == null) {
        return componentType;
    }
    if (componentType == null) {
        // the component type can not be determined
        final List<ISubReference> subreferences = portReference.getSubreferences();
        if (subreferences.size() > 1) {
            // check array indices
            for (int i = 0; i < subreferences.size(); i++) {
                final ISubReference subreference = subreferences.get(i);
                if (subreference instanceof ArraySubReference) {
                    final Value value = ((ArraySubReference) subreference).getValue();
                    value.setLoweridToReference(timestamp);
                    final Type_type temporalType1 = value.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                    switch(temporalType1) {
                        case TYPE_INTEGER:
                            {
                                final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                                final IValue last1 = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
                                referenceChain.release();
                                if (!last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
                                    if (((Integer_Value) last1).signum() < 0) {
                                        value.getLocation().reportSemanticError(ArraySubReference.NATIVEINTEGEREXPECTED);
                                        value.setIsErroneous(true);
                                    }
                                }
                                break;
                            }
                        case TYPE_UNDEFINED:
                            value.setIsErroneous(true);
                            break;
                        default:
                            if (!value.getIsErroneous(timestamp)) {
                                value.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
                                value.setIsErroneous(true);
                            }
                            break;
                    }
                }
            }
        }
        return null;
    }
    final ComponentTypeBody componentBody = ((Component_Type) componentType).getComponentBody();
    portReference.setBaseScope(componentBody);
    portReference.setComponent((Component_Type) componentType);
    // for compatibility
    portReference.getRefdAssignment(timestamp, false);
    final Identifier portIdentifier = portReference.getId();
    if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
        portReference.getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
        return null;
    }
    final Assignment assignment = componentBody.getLocalAssignmentById(portIdentifier);
    if (assignment == null) {
        return null;
    }
    if (!Assignment_type.A_PORT.semanticallyEquals(assignment.getAssignmentType())) {
        portReference.getLocation().reportSemanticError(MessageFormat.format(DEFINITIONNOTPORT, portIdentifier.getDisplayName(), componentType.getTypename(), assignment.getAssignmentName()));
        return null;
    }
    final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
    if (dimensions != null) {
        dimensions.checkIndices(timestamp, portReference, "port", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    } else if (portReference.getSubreferences().size() > 1) {
        portReference.getLocation().reportSemanticError(MessageFormat.format("Port `{0}'' is not an array. The reference cannot have field or array sub-references", portIdentifier.getDisplayName()));
    }
    Port_Type portType = ((Def_Port) assignment).getType(timestamp);
    if (portType != null) {
        final PortTypeBody portBody = portType.getPortBody();
        if (PortType_type.PT_USER.equals(portBody.getPortType())) {
            final IType providerType = portBody.getProviderType();
            if (providerType instanceof Port_Type) {
                portType = (Port_Type) providerType;
            }
        }
    }
    return portType;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) PortType_type(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody.PortType_type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)

Example 50 with IReferenceChain

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

the class Start_Referenced_Component_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = dereferredValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
        Definition definition = ((Function_Reference_Value) last).getReferredFunction();
        expression.expression.append(MessageFormat.format("{0}(", definition.getGenNameFromScope(aData, source, myScope, "start_")));
    } else {
        dereferredValue.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".start(");
    }
    componentReference.generateCodeExpression(aData, expression, false);
    if (actualParameterList2.getNofParameters() > 0) {
        expression.expression.append(", ");
        actualParameterList2.generateCodeNoAlias(aData, expression);
    }
    expression.expression.append(')');
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value)

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