Search in sources :

Example 56 with Expected_Value_type

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

the class Or4bExpression 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)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    String str1;
    String str2;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            str1 = ((Bitstring_Value) last1).getValue();
            str2 = ((Bitstring_Value) last2).getValue();
            lastValue = new Bitstring_Value(or4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            str1 = ((Hexstring_Value) last1).getValue();
            str2 = ((Hexstring_Value) last2).getValue();
            lastValue = new Hexstring_Value(or4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            str1 = ((Octetstring_Value) last1).getValue();
            str2 = ((Octetstring_Value) last2).getValue();
            lastValue = new Octetstring_Value(or4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 57 with Expected_Value_type

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

the class OrExpression 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);
    if (Value_type.BOOLEAN_VALUE.equals(last1.getValuetype())) {
        if (((Boolean_Value) last1).getValue()) {
            lastValue = new Boolean_Value(true);
            lastValue.copyGeneralProperties(this);
        } else {
            final Boolean_Value temp = (Boolean_Value) value2.getValueRefdLast(timestamp, referenceChain);
            lastValue = new Boolean_Value(temp.getValue());
            lastValue.copyGeneralProperties(this);
        }
    } else {
        // we must keep the left operand because of the
        // potential side effects
        // the right operand can only be eliminated if it is a
        // literal "false"
        final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
        if (Value_type.BOOLEAN_VALUE.equals(last2.getValuetype()) && !((Boolean_Value) last2).getValue()) {
            final Boolean_Value temp = (Boolean_Value) value1.getValueRefdLast(timestamp, referenceChain);
            lastValue = new Boolean_Value(temp.getValue());
            lastValue.copyGeneralProperties(this);
        }
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Example 58 with Expected_Value_type

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

the class Referenced_Value method getValueRefdLast.

@Override
public /**
 * {@inheritDoc}
 */
IValue getValueRefdLast(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return referencedValue;
    }
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    referencedValue = this;
    isErroneous = false;
    if (reference == null) {
        return referencedValue;
    }
    reference.setIsErroneous(false);
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass == null) {
        isErroneous = true;
        return referencedValue;
    }
    switch(ass.getAssignmentType()) {
        case A_OBJECT:
        case A_OS:
            {
                final ISetting setting = reference.getRefdSetting(timestamp);
                if (setting == null || setting.getIsErroneous(timestamp)) {
                    isErroneous = true;
                } else if (!Setting_type.S_V.equals(setting.getSettingtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(INFORMATIONFROMOBJECTNOTVALUE, reference));
                    isErroneous = true;
                } else {
                    tempReferenceChain.markState();
                    if (tempReferenceChain.add(this)) {
                        referencedValue = ((IValue) setting).getValueRefdLast(timestamp, expectedValue, referenceChain);
                    } else {
                        isErroneous = true;
                    }
                    tempReferenceChain.previousState();
                }
                break;
            }
        case A_CONST:
            {
                tempReferenceChain.markState();
                if (tempReferenceChain.add(this)) {
                    if (ass instanceof Def_Const) {
                        referencedValue = ((Def_Const) ass).getValue();
                    } else if (ass instanceof Value_Assignment) {
                        referencedValue = ((Value_Assignment) ass).getValue();
                    } else {
                        isErroneous = true;
                    }
                    if (referencedValue != null && !isErroneous) {
                        referencedValue = referencedValue.getReferencedSubValue(timestamp, reference, 1, tempReferenceChain);
                    } else {
                        referencedValue = this;
                        tempReferenceChain.previousState();
                        return referencedValue;
                    }
                    if (referencedValue != null) {
                        referencedValue = referencedValue.getValueRefdLast(timestamp, tempReferenceChain);
                    } else if (reference.hasUnfoldableIndexSubReference(timestamp)) {
                        referencedValue = this;
                        tempReferenceChain.previousState();
                        return referencedValue;
                    } else if (reference.getUsedInIsbound()) {
                        referencedValue = this;
                        tempReferenceChain.previousState();
                        return referencedValue;
                    } else {
                        isErroneous = true;
                    }
                } else {
                    isErroneous = true;
                }
                tempReferenceChain.previousState();
                break;
            }
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_MODULEPAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_INOUT:
        case A_PAR_TEMP_OUT:
            referencedValue = this;
            break;
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
            // the referred definition is not a constant
            // errors will be reported in Types.java
            referencedValue = this;
            if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
            }
            break;
        case A_FUNCTION:
        case A_EXT_FUNCTION:
            reference.getLocation().reportSemanticError(MessageFormat.format(VALUERETURNEXPECTED, ass.getDescription()));
            isErroneous = true;
            break;
        default:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT1, ass.getDescription()));
            } else {
                getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
            }
            isErroneous = true;
            break;
    }
    if (newChain) {
        tempReferenceChain.release();
    }
    lastTimeChecked = timestamp;
    if (referencedValue == null) {
        referencedValue = this;
        isErroneous = true;
    }
    return referencedValue;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) ISetting(org.eclipse.titan.designer.AST.ISetting)

Example 59 with Expected_Value_type

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

the class Macro_Value method evaluateMacro.

/**
 * Evaluates the value of the macro.
 *
 * @param expectedValue the kind of the value to be expected
 *
 * @return the actual or the evaluated value
 */
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    lastTimeChecked = timestamp;
    lastValue = this;
    switch(value) {
        case MODULEID:
            if (myScope != null && myScope.getModuleScope() != null) {
                final Module module = myScope.getModuleScope();
                if (module.getIdentifier() != null) {
                    lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
                    lastValue.copyGeneralProperties(this);
                }
            }
            break;
        case DEFINITIONID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition != null) {
                        lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                        lastValue.copyGeneralProperties(this);
                    }
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case TESTCASEID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition == null) {
                        location.reportSemanticError(TESCASEIDINCONTROLPART);
                        setIsErroneous(true);
                    } else {
                        if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
                            // folding is possible in testcases only
                            lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                            lastValue.copyGeneralProperties(this);
                        }
                    }
                } else {
                    location.reportSemanticError(TESTCASEIDNOTALLOWED);
                    setIsErroneous(true);
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case FILENAME:
        case BFILENAME:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(location.getFile().getName());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case FILEPATH:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                String canonicalPath;
                final IPath absolutePath = location.getFile().getLocation();
                if (absolutePath == null) {
                    location.reportSemanticError(UNDETERMINABLEPATH);
                    canonicalPath = location.getFile().getName();
                    setIsErroneous(true);
                } else {
                    final File file = absolutePath.toFile();
                    try {
                        canonicalPath = file.getCanonicalPath();
                    } catch (IOException e) {
                        location.reportSemanticError(UNDETERMINABLEPATH);
                        canonicalPath = location.getFile().getName();
                        setIsErroneous(true);
                    }
                }
                lastValue = new Charstring_Value(canonicalPath);
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(Long.toString(location.getLine()));
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER_C:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Integer_Value(location.getLine());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case SCOPE:
            if (myScope != null) {
                lastValue = new Charstring_Value(myScope.getScopeMacroName());
                lastValue.copyGeneralProperties(this);
            } else {
                location.reportSemanticError(UNDETERMINABLESCOPE);
                setIsErroneous(true);
            }
            break;
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IOException(java.io.IOException) Module(org.eclipse.titan.designer.AST.Module) File(java.io.File) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 60 with Expected_Value_type

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

the class DecvalueUnicharExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * inout universal charstring
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (reference1 == null) {
        setIsErroneous(true);
        return;
    }
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR2, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR3, last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR4, temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    final Type_type type_type = temporalType.getTypeRefdLast(timestamp).getTypetype();
    if (type_type != Type_type.TYPE_UCHARSTRING) {
        if (!isErroneous) {
            location.reportSemanticError(OPERAND1_ERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)149 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)54 IType (org.eclipse.titan.designer.AST.IType)47 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)45 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)39 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)31 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)24 ISubReference (org.eclipse.titan.designer.AST.ISubReference)21 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)21 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)20 Identifier (org.eclipse.titan.designer.AST.Identifier)17 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)17 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)14 Type (org.eclipse.titan.designer.AST.Type)14 Assignment (org.eclipse.titan.designer.AST.Assignment)13 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Value (org.eclipse.titan.designer.AST.Value)11