Search in sources :

Example 1 with Real_Value

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

the class Def_Type_Visit_Handler method visitDefTypeChildrenNodes.

public void visitDefTypeChildrenNodes(IVisitableNode node) {
    if (node instanceof Def_Port) {
        Def_Port port = (Def_Port) node;
        componentPortNames.add(port.getIdentifier().toString());
    }
    if (node instanceof Def_Var) {
        Def_Var var = (Def_Var) node;
        componentVarNames.add(var.getIdentifier().toString());
        if (var.getType(compilationCounter) instanceof Integer_Type) {
            componentVarTypes.add("INTEGER");
        }
    }
    if (waitForCompReference && (node instanceof Reference)) {
        componentPortTypes.add(((Reference) node).getId().toString());
    }
    if (waitForSetOfFieldType) {
        if (node instanceof Reference) {
            setOfFieldType = node.toString();
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SetOf_Type)) {
            Type type = (Type) node;
            setOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        }
    }
    if (waitForRecordOfFieldType) {
        if (node instanceof Reference) {
            recordOfFieldType = node.toString();
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SequenceOf_Type)) {
            Type type = (Type) node;
            recordOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        }
    }
    if (node instanceof CompField) {
        // component
        CompField compFieldNode = (CompField) node;
        if (compFieldNode.getType() instanceof Referenced_Type) {
            compFieldTypes.add(((Referenced_Type) compFieldNode.getType()).getReference().getId().toString());
        } else {
            compFieldTypes.add(myASTVisitor.cutModuleNameFromBeginning(compFieldNode.getType().getTypename()));
        }
        compFieldNames.add(compFieldNode.getIdentifier().toString());
    }
    if (node instanceof Charstring_Value) {
        // charstring
        Charstring_Value singleValuedNode = (Charstring_Value) node;
        charstringValue = singleValuedNode.getValue();
    }
    if (node instanceof Integer_Value) {
        String value = ((Integer_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add("new INTEGER(\"" + value + "\")");
    }
    if (node instanceof Real_Value) {
        String value = ((Real_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        if (value.equals("-Infinity") || value.equals("Infinity")) {
            value = "null";
        }
        expressionValue.add(value);
    }
    if (node instanceof Undefined_LowerIdentifier_Value) {
        String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add(value);
    }
    if (node instanceof EnumerationItems) {
        for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) {
            enumItems.add(((EnumerationItems) node).getItems().get(i).getId().toString());
            if (((EnumerationItems) node).getItems().get(i).getValue() != null) {
                enumItemValues.add(((EnumerationItems) node).getItems().get(i).getValue().toString());
            } else {
                enumItemValues.add(null);
            }
        }
    }
    if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) {
        isPortTypeAReferencedType = true;
    }
    if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) {
        PortTypeBody body = (PortTypeBody) node;
        int inCount = body.getInMessages().getNofTypes();
        int outCount = body.getOutMessage().getNofTypes();
        for (int i = 0; i < inCount; i++) {
            inMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getInMessages().getTypeByIndex(i).getTypename()));
        }
        for (int i = 0; i < outCount; i++) {
            outMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getOutMessage().getTypeByIndex(i).getTypename()));
        }
        int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName.size() : outMessageName.size();
        // if inout delete from both lists and add to inout
        for (int i = 0; i < inMessageName.size(); i++) {
            for (int j = 0; j < outMessageName.size(); j++) {
                if (inMessageName.get(i).equals(outMessageName.get(j))) {
                    inOutMessageName.add(inMessageName.get(i));
                    inMessageName.remove(i);
                    if (j == (outMessageName.size() - 1)) {
                        i--;
                    }
                    outMessageName.remove(j);
                    j--;
                }
            }
        }
        myASTVisitor.portNamePortTypeHashMap.put(currentPortName, body.getTestportType().toString());
        portTypeList.add(body.getTestportType().toString());
    }
}
Also used : Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Reference(org.eclipse.titan.designer.AST.Reference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) EnumerationItems(org.eclipse.titan.designer.AST.TTCN3.types.EnumerationItems) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 2 with Real_Value

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

the class SizeOfExpression method evaluateTemplate.

/**
 * Evaluates a checked template.
 *
 * @param template
 *                The template to evaluate
 * @param timestamp
 *                The compilation timestamp
 * @return The folded value or -1 if the template is unfoldable.
 */
private long evaluateTemplate(final ITTCN3Template template, final CompilationTimeStamp timestamp) {
    switch(template.getTemplatetype()) {
        case TEMPLATE_LIST:
            {
                final Template_List temp = (Template_List) template;
                if (temp.templateContainsAnyornone()) {
                    final LengthRestriction lengthRestriction = temp.getLengthRestriction();
                    if (lengthRestriction == null) {
                        templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without length restriction");
                        setIsErroneous(true);
                        return -1;
                    }
                    if (lengthRestriction instanceof RangeLenghtRestriction) {
                        final IValue upper = ((RangeLenghtRestriction) lengthRestriction).getUpperValue(timestamp);
                        if (Value_type.REAL_VALUE.equals(upper.getValuetype()) && ((Real_Value) upper).isPositiveInfinity()) {
                            templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without upper boundary in the length restriction");
                            setIsErroneous(true);
                            return -1;
                        }
                        if (Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
                            final int nofComponents = temp.getNofTemplatesNotAnyornone(timestamp);
                            if (nofComponents == ((Integer_Value) upper).intValue()) {
                                return nofComponents;
                            }
                            final IValue lower = ((RangeLenghtRestriction) lengthRestriction).getLowerValue(timestamp);
                            if (lower != null && Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && ((Integer_Value) upper).intValue() == ((Integer_Value) lower).intValue()) {
                                return ((Integer_Value) upper).intValue();
                            }
                            templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates without exact size");
                            setIsErroneous(true);
                            return -1;
                        }
                    } else {
                        final IValue restriction = ((SingleLenghtRestriction) lengthRestriction).getRestriction(timestamp);
                        if (Value_type.INTEGER_VALUE.equals(restriction.getValuetype())) {
                            return ((Integer_Value) restriction).intValue();
                        }
                    }
                } else {
                    int result = 0;
                    for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                        final ITTCN3Template tmp = temp.getTemplateByIndex(i);
                        switch(tmp.getTemplatetype()) {
                            case SPECIFIC_VALUE:
                                if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
                                    ++result;
                                }
                                break;
                            default:
                                ++result;
                        }
                    }
                    return result;
                }
                break;
            }
        case NAMED_TEMPLATE_LIST:
            {
                int result = 0;
                final Named_Template_List temp = (Named_Template_List) template;
                for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                    final ITTCN3Template tmp = temp.getTemplateByIndex(i).getTemplate();
                    switch(tmp.getTemplatetype()) {
                        case SPECIFIC_VALUE:
                            if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
                                ++result;
                            }
                            break;
                        default:
                            ++result;
                    }
                }
                return result;
            }
        case SUBSET_MATCH:
            {
                final LengthRestriction restriction = template.getLengthRestriction();
                if (restriction instanceof SingleLenghtRestriction) {
                    final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
                    if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
                        return ((Integer_Value) value).getValue();
                    } else {
                        return -1;
                    }
                } else if (restriction instanceof RangeLenghtRestriction) {
                    final IValue minValue = ((RangeLenghtRestriction) restriction).getLowerValue(timestamp);
                    if (minValue.getValuetype() != Value_type.INTEGER_VALUE || minValue.isUnfoldable(timestamp)) {
                        return -1;
                    }
                    final SubsetMatch_Template temp = (SubsetMatch_Template) template;
                    if (temp.getNofTemplates() != ((Integer_Value) minValue).getValue()) {
                        return -1;
                    }
                    for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                        final ITTCN3Template tmp = temp.getTemplateByIndex(i);
                        switch(tmp.getTemplatetype()) {
                            case SPECIFIC_VALUE:
                                break;
                            default:
                                return -1;
                        }
                    }
                    return temp.getNofTemplates();
                }
                return -1;
            }
        case SUPERSET_MATCH:
            {
                final LengthRestriction restriction = template.getLengthRestriction();
                if (restriction instanceof SingleLenghtRestriction) {
                    final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
                    if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
                        return ((Integer_Value) value).getValue();
                    } else {
                        return -1;
                    }
                } else if (restriction instanceof RangeLenghtRestriction) {
                    final IValue maxValue = ((RangeLenghtRestriction) restriction).getUpperValue(timestamp);
                    if (maxValue.getValuetype() != Value_type.INTEGER_VALUE || maxValue.isUnfoldable(timestamp)) {
                        return -1;
                    }
                    final SupersetMatch_Template temp = (SupersetMatch_Template) template;
                    if (temp.getNofTemplates() != ((Integer_Value) maxValue).getValue()) {
                        return -1;
                    }
                    for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
                        final ITTCN3Template tmp = temp.getTemplateByIndex(i);
                        switch(tmp.getTemplatetype()) {
                            case SPECIFIC_VALUE:
                                break;
                            default:
                                return -1;
                        }
                    }
                    return temp.getNofTemplates();
                }
                return -1;
            }
        default:
            return -1;
    }
    return -1;
}
Also used : LengthRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.LengthRestriction) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Template_List) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) IValue(org.eclipse.titan.designer.AST.IValue) RangeLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.RangeLenghtRestriction) SubsetMatch_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) SupersetMatch_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)

Example 3 with Real_Value

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

the class Str2FloatExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last.getIsErroneous(timestamp)) {
        return lastValue;
    }
    switch(last.getValuetype()) {
        case CHARSTRING_VALUE:
            {
                String string = ((Charstring_Value) last).getValue();
                string = string.trim();
                double number;
                if ("-infinity".equals(string)) {
                    number = Float.NEGATIVE_INFINITY;
                } else if ("infinity".equals(string)) {
                    number = Float.POSITIVE_INFINITY;
                } else if ("not_a_number".equals(string)) {
                    number = Float.NaN;
                } else {
                    try {
                        number = Double.parseDouble(string);
                    } catch (NumberFormatException e) {
                        number = 0;
                    }
                }
                lastValue = new Real_Value(number);
                break;
            }
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 4 with Real_Value

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

the class Int2FloatExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            lastValue = new Real_Value(((Integer_Value) last).floatValue());
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : 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 5 with Real_Value

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

the class LessThanExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) < 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) < 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() < ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() < ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)33 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)27 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 IType (org.eclipse.titan.designer.AST.IType)9 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)9 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)5 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)5 Assignment (org.eclipse.titan.designer.AST.Assignment)4 EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)4 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)4 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)2 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2