Search in sources :

Example 11 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Indexed_Template_List method getValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getValue() {
    if (asValue != null) {
        return asValue;
    }
    final Values values = new Values(true);
    for (int i = 0, size = getNofTemplates(); i < size; i++) {
        final IndexedTemplate indexedTemplate = indexedTemplates.getTemplateByIndex(i);
        final IndexedValue indexedValue = new IndexedValue(indexedTemplate.getIndex(), indexedTemplate.getTemplate().getValue());
        indexedValue.setLocation(indexedTemplate.getLocation());
        values.addIndexedValue(indexedValue);
    }
    asValue = new SequenceOf_Value(values);
    asValue.setLocation(getLocation());
    asValue.setMyScope(getMyScope());
    asValue.setFullNameParent(getNameParent());
    asValue.setMyGovernor(getMyGovernor());
    return asValue;
}
Also used : Values(org.eclipse.titan.designer.AST.TTCN3.values.Values) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) IndexedValue(org.eclipse.titan.designer.AST.TTCN3.values.IndexedValue)

Example 12 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Port_Utility method checkToClause.

/**
 * Checks a to clause reference to see if it really references valid
 * component type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the source statement of this check.
 * @param portType
 *                the type of the port used in the statement. Used to
 *                find the address type in effect.
 * @param toClause
 *                the to clause to check
 */
public static void checkToClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final IValue toClause) {
    if (toClause == null) {
        return;
    }
    IType addressType = null;
    if (portType != null) {
        addressType = portType.getPortBody().getAddressType(timestamp);
    } else if (source != null) {
        final Module module = source.getMyStatementBlock().getModuleScope();
        if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
            addressType = ((TTCN3Module) module).getAddressType(timestamp);
        }
    }
    if (addressType == null) {
        checkComponentReference(timestamp, source, toClause, true, true);
    } else {
        // detect possible enumerated values (address may be an
        // enumerated type)
        final IValue temp = addressType.checkThisValueRef(timestamp, toClause);
        // try to figure out whether the argument is a component
        // reference or an SUT address
        boolean isAddress;
        final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (governor == null) {
            isAddress = !Type_type.TYPE_COMPONENT.equals(temp.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE));
        } else {
            isAddress = addressType.isCompatible(timestamp, governor, null, null, null);
        }
        if (isAddress) {
            addressType.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
        } else {
            checkComponentReference(timestamp, source, temp, true, true);
        }
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IValue(org.eclipse.titan.designer.AST.IValue) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IType(org.eclipse.titan.designer.AST.IType)

Example 13 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class AbstractOfType method checkThisValueSetOf.

/**
 * Checks the SequenceOf_value kind value against this type.
 * SequenceOf_value kinds have to be converted before calling this
 * function.
 * <p>
 * Please note, that this function can only be called once we know for
 * sure that the value is of set-of type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 * @param expectedValue
 *                the kind of value expected here.
 * @param incompleteAllowed
 *                wheather incomplete value is allowed or not.
 * @param implicitOmit
 *                true if the implicit omit optional attribute was set
 *                for the value, false otherwise
 */
public boolean checkThisValueSetOf(final CompilationTimeStamp timestamp, final SetOf_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    if (value.isIndexed()) {
        boolean checkHoles = Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
        BigInteger maxIndex = BigInteger.valueOf(-1);
        final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(value.getNofComponents());
        for (int i = 0, size = value.getNofComponents(); i < size; i++) {
            final IValue component = value.getValueByIndex(i);
            final Value index = value.getIndexByIndex(i);
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(indexLast.getValuetype())) {
                checkHoles = false;
            } else {
                final BigInteger tempIndex = ((Integer_Value) indexLast).getValueValue();
                if (tempIndex.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
                    index.getLocation().reportSemanticError(MessageFormat.format("A integer value less than `{0}'' was expected for indexing type `{1}'' instead of `{2}''", Integer.MAX_VALUE, getTypename(), tempIndex));
                    checkHoles = false;
                } else if (tempIndex.compareTo(BigInteger.ZERO) == -1) {
                    index.getLocation().reportSemanticError(MessageFormat.format("A non-negative integer value was expected for indexing type `{0}'' instead of `{1}''", getTypename(), tempIndex));
                    checkHoles = false;
                } else if (indexMap.containsKey(tempIndex)) {
                    index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value `{0}'' for components {1} and {2}", tempIndex, indexMap.get(tempIndex), i + 1));
                    checkHoles = false;
                } else {
                    indexMap.put(tempIndex, Integer.valueOf(i + 1));
                    if (maxIndex.compareTo(tempIndex) == -1) {
                        maxIndex = tempIndex;
                    }
                }
            }
            component.setMyGovernor(getOfType());
            final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
            selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
        }
        if (checkHoles && maxIndex.compareTo(BigInteger.valueOf(indexMap.size() - 1)) != 0) {
            value.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
        }
    } else {
        for (int i = 0, size = value.getNofComponents(); i < size; i++) {
            final IValue component = value.getValueByIndex(i);
            component.setMyGovernor(getOfType());
            if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
                if (!incompleteAllowed) {
                    component.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                }
            } else {
                final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
                selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : BigInteger(java.math.BigInteger) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 14 with Values

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

Example 15 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Template_List method getValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getValue() {
    if (asValue != null) {
        return asValue;
    }
    if (converted != null) {
        return converted.getValue();
    }
    final Values values = new Values(false);
    for (int i = 0, size = getNofTemplates(); i < size; i++) {
        values.addValue(templates.getTemplateByIndex(i).getValue());
    }
    asValue = new SequenceOf_Value(values);
    asValue.setLocation(getLocation());
    asValue.setMyScope(getMyScope());
    asValue.setFullNameParent(getNameParent());
    asValue.setMyGovernor(getMyGovernor());
    return asValue;
}
Also used : Values(org.eclipse.titan.designer.AST.TTCN3.values.Values) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Identifier (org.eclipse.titan.designer.AST.Identifier)9 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)9 HashMap (java.util.HashMap)8 IType (org.eclipse.titan.designer.AST.IType)6 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Value (org.eclipse.titan.designer.AST.Value)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Module (org.eclipse.titan.designer.AST.Module)3 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)3 List (java.util.List)2 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2