Search in sources :

Example 56 with Value

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

the class Def_Timer method checkSingleDuration.

private void checkSingleDuration(final CompilationTimeStamp timestamp, final IValue duration) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) duration.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (v.getValuetype() == Value_type.REAL_VALUE) {
        final Real_Value value = (Real_Value) v;
        final double valueReal = value.getValue();
        if (valueReal < 0.0 || value.isSpecialFloat()) {
            duration.getLocation().reportSemanticError("A non-negative float value was expected as timer duration instead of" + valueReal);
        }
    } else {
        duration.getLocation().reportSemanticError("Value is not real");
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 57 with Value

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

the class Def_Timer method generateCodeArrayDuration.

private void generateCodeArrayDuration(final JavaGenData aData, final StringBuilder source, final String genName, final ArrayList<String> classNames, final Value defaultDuration2, final int startDim) {
    final ArrayDimension dim = dimensions.get(startDim);
    final int dim_size = (int) dim.getSize();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) defaultDuration2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (v.getValuetype() != Value_type.SEQUENCEOF_VALUE) {
        // ErrorReporter.INTERNAL_ERROR()
        return;
    }
    final SequenceOf_Value value = (SequenceOf_Value) v;
    if (value.getNofComponents() != dim_size && !value.isIndexed()) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    // Value-list notation.
    if (!value.isIndexed()) {
        if (startDim + 1 < dimensions.size()) {
            // boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
            for (int i = 0; i < dim_size; i++) {
                // get_comp_byIndex(i);
                final IValue v_elem = value.getValueByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final String embeddedName = MessageFormat.format("{0}.getAt({1})", genName, i + dim.getOffset());
                generateCodeArrayDuration(aData, source, embeddedName, classNames, (Value) v_elem, startDim + 1);
            }
        } else {
            // We are in the last dimension, the elements of "value" are floats.
            for (int i = 0; i < dim_size; i++) {
                final IValue v_elem = value.getValueByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final ExpressionStruct expression = new ExpressionStruct();
                expression.expression.append(genName);
                expression.expression.append(".getAt(").append(i + dim.getOffset()).append(")");
                // originally set_default_duration(obj_name, i)
                expression.expression.append(".assign(");
                v_elem.generateCodeExpression(aData, expression, true);
                expression.expression.append(')');
                expression.mergeExpression(source);
            }
        }
    // Indexed-list notation.
    } else {
        if (startDim + 1 < dimensions.size()) {
            // boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
            for (int i = 0; i < value.getNofComponents(); ++i) {
                final IValue v_elem = value.getValueByIndex(i);
                final IValue index = value.getIndexByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final String tempId1 = aData.getTemporaryVariableName();
                final String tempIdX = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
                index.generateCodeInit(aData, source, tempIdX);
                source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", classNames.get(classNames.size() - startDim - 2), tempId1, genName, tempIdX));
                generateCodeArrayDuration(aData, source, tempId1, classNames, (Value) v_elem, startDim + 1);
                source.append("}\n");
            }
        } else {
            for (int i = 0; i < value.getNofComponents(); ++i) {
                final IValue v_elem = value.getValueByIndex(i);
                final IValue v_elemIndex = value.getIndexByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final ExpressionStruct expression = new ExpressionStruct();
                final String tempIdX = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
                v_elemIndex.generateCodeInit(aData, source, tempIdX);
                final String embeddedName = MessageFormat.format("{0}.getAt(", genName);
                expression.expression.append(embeddedName).append(tempIdX).append(")");
                // originally set_default_duration(obj_name, i)
                expression.expression.append(".assign(");
                v_elem.generateCodeExpression(aData, expression, true);
                expression.expression.append(')');
                expression.mergeExpression(source);
                source.append("}\n");
            }
        }
    }
    return;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Example 58 with Value

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

the class SelectWithNumbersSorted method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof SelectCase_Statement)) {
        return;
    }
    final SelectCase_Statement s = (SelectCase_Statement) node;
    final Value v = s.getExpression();
    if (v == null || v.getIsErroneous(timestamp)) {
        return;
    }
    final SelectCases scs = s.getSelectCases();
    if (scs == null || scs.getSelectCaseArray() == null) {
        return;
    }
    // if there is an else branch, no smell will be reported
    for (final SelectCase sc : scs.getSelectCaseArray()) {
        if (sc.hasElse()) {
            return;
        }
    }
    IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    // TODO Kristof: az ellenorzes folosleges.
    if (itype instanceof Referenced_Type) {
        itype = itype.getTypeRefdLast(timestamp);
    }
    if (itype == null || !(itype instanceof Integer_Type)) {
        return;
    }
    // count number of cases in select, get used integer type case-items
    final CaseVisitorInteger caseVisitorInteger = new CaseVisitorInteger();
    scs.accept(caseVisitorInteger);
    if (caseVisitorInteger.containsUnfoldable()) {
        return;
    }
    final List<Long> usedIntegerItems = caseVisitorInteger.getItemsUsed();
    if (!checkIfIntegerCasesSorted(usedIntegerItems)) {
        problems.report(s.getLocation(), ERR_MSG);
    }
}
Also used : SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SelectCases(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCases) SelectCase(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 59 with Value

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

the class VerdictWithoutReason method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Setverdict_Statement)) {
        return;
    }
    final Setverdict_Statement s = (Setverdict_Statement) node;
    final Value verdictValue = s.getVerdictValue();
    if (verdictValue == null) {
        return;
    }
    final CompilationTimeStamp ct = CompilationTimeStamp.getBaseTimestamp();
    final Type_type temp = verdictValue.getExpressionReturntype(ct, Expected_Value_type.EXPECTED_TEMPLATE);
    if (Type_type.TYPE_VERDICT != temp) {
        return;
    }
    final LogArguments verdictReason = s.getVerdictReason();
    if (Value_type.VERDICT_VALUE.equals(verdictValue.getValuetype()) && !Verdict_type.PASS.equals(((Verdict_Value) verdictValue).getValue()) && verdictReason == null) {
        final String msg = MessageFormat.format(WITHOUT_REASON, ((Verdict_Value) verdictValue).getValue());
        problems.report(s.getLocation(), msg);
    }
}
Also used : LogArguments(org.eclipse.titan.designer.AST.TTCN3.statements.LogArguments) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Value(org.eclipse.titan.designer.AST.Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 60 with Value

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

the class TTCN3_Enumerated_Type method check.

/**
 * Does the semantic checking of the enumerations.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 */
@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    parseAttributes(timestamp);
    nameMap = new HashMap<String, EnumItem>(items.getItems().size());
    final Map<Long, EnumItem> valueMap = new HashMap<Long, EnumItem>(items.getItems().size());
    final List<EnumItem> enumItems = items.getItems();
    // check duplicated names and values
    for (int i = 0, size = enumItems.size(); i < size; i++) {
        final EnumItem item = enumItems.get(i);
        final Identifier id = item.getId();
        final String fieldName = id.getName();
        if (nameMap.containsKey(fieldName)) {
            nameMap.get(fieldName).getId().getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERFIRST, id.getDisplayName()));
            id.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERREPEATED, id.getDisplayName()));
        } else {
            nameMap.put(fieldName, item);
        }
        final Value value = item.getValue();
        if (value != null && item.isOriginal()) {
            if (value.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(value.getValuetype())) {
                value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", id.getDisplayName()));
                setIsErroneous(true);
            } else {
                final Integer_Value enumValue = (Integer_Value) value;
                if (!enumValue.isNative()) {
                    enumValue.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERERROR, enumValue.getValueValue()));
                    setIsErroneous(true);
                } else {
                    final Long enumLong = enumValue.getValue();
                    if (valueMap.containsKey(enumLong)) {
                        valueMap.get(enumLong).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumLong, valueMap.get(enumLong).getId().getDisplayName()));
                        value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumLong, id.getDisplayName()));
                        setIsErroneous(true);
                    } else {
                        valueMap.put(enumLong, item);
                    }
                }
            }
        }
    }
    // Assign default values
    if (!getIsErroneous(timestamp) && lastTimeChecked == null) {
        Long firstUnused = Long.valueOf(0);
        while (valueMap.containsKey(firstUnused)) {
            firstUnused++;
        }
        for (int i = 0, size = enumItems.size(); i < size; i++) {
            final EnumItem item = enumItems.get(i);
            if (!item.isOriginal()) {
                // optimization: if the same value was already assigned, there is no need to create it again.
                final IValue value = item.getValue();
                if (value == null || ((Integer_Value) value).getValue() != firstUnused) {
                    final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
                    tempValue.setLocation(item.getLocation());
                    item.setValue(tempValue);
                }
                valueMap.put(firstUnused, item);
                firstUnused = Long.valueOf(firstUnused.longValue() + 1);
                while (valueMap.containsKey(firstUnused)) {
                    firstUnused++;
                }
            }
        }
    }
    valueMap.clear();
    lastTimeChecked = timestamp;
    checkSubtypeRestrictions(timestamp);
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Aggregations

Value (org.eclipse.titan.designer.AST.Value)71 IValue (org.eclipse.titan.designer.AST.IValue)63 ISubReference (org.eclipse.titan.designer.AST.ISubReference)50 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)41 IType (org.eclipse.titan.designer.AST.IType)34 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)18 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)18 Identifier (org.eclipse.titan.designer.AST.Identifier)12 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)6 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)6 BigInteger (java.math.BigInteger)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)5 HashMap (java.util.HashMap)4 SelectCase_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement)4 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Reference (org.eclipse.titan.designer.AST.Reference)3