Search in sources :

Example 16 with Charstring_Value

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

the class Unichar2CharExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @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 checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (value == null) {
        return;
    }
    value.setLoweridToReference(timestamp);
    final Type_type tempType = value.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_UCHARSTRING:
            final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last.isUnfoldable(timestamp)) {
                UniversalCharstring string;
                if (last instanceof Charstring_Value) {
                    // check not necessary, trivial case
                    return;
                } else if (last instanceof UniversalCharstring_Value) {
                    string = ((UniversalCharstring_Value) last).getValue();
                    if (string == null) {
                        setIsErroneous(true);
                        return;
                    }
                } else {
                    value.getLocation().reportSemanticError(OPERANDERROR1);
                    setIsErroneous(true);
                    return;
                }
                for (int i = 0; i < string.length(); i++) {
                    final UniversalChar uchar = string.get(i);
                    if (uchar.group() != 0 || uchar.plane() != 0 || uchar.row() != 0 || uchar.cell() > 127) {
                        value.getLocation().reportSemanticError(OPERANDERROR2);
                        setIsErroneous(true);
                        return;
                    }
                }
            }
            return;
        case TYPE_CHARSTRING:
            break;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            break;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            return;
    }
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) UniversalChar(org.eclipse.titan.designer.AST.TTCN3.values.UniversalChar) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Example 17 with Charstring_Value

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

the class Oct2CharExpression 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 OCTETSTRING_VALUE:
            {
                final String octetString = ((Octetstring_Value) last).getValue();
                lastValue = new Charstring_Value(oct2char(octetString));
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)

Example 18 with Charstring_Value

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

the class Oct2StrExpression 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 OCTETSTRING_VALUE:
            final String octetString = ((Octetstring_Value) last).getValue();
            lastValue = new Charstring_Value(octetString);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 19 with Charstring_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value 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 20 with Charstring_Value

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

the class DecvalueUnicharExpression method checkExpressionOperand3.

/**
 * Checks the 3rd operand
 * in charstring (optional)
 * @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 checkExpressionOperand3(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (value3 == null) {
        return;
    }
    value3.setLoweridToReference(timestamp);
    final Type_type tempType = value3.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_CHARSTRING:
            final IValue last = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last.isUnfoldable(timestamp)) {
                final String originalString = ((Charstring_Value) last).getValue();
                final CharstringExtractor cs = new CharstringExtractor(originalString);
                if (cs.isErrorneous()) {
                    value3.getLocation().reportSemanticError(cs.getErrorMessage());
                    setIsErroneous(true);
                }
            }
            break;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            break;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERAND3_ERROR1);
                setIsErroneous(true);
            }
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) CharstringExtractor(org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)53 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)44 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)17 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)16 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)13 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)12 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)11 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)9 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 IType (org.eclipse.titan.designer.AST.IType)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)4 Reference (org.eclipse.titan.designer.AST.Reference)4 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)4 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)4 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3