Search in sources :

Example 6 with Referenced_Value

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

the class IsPresentExpression method checkExpressionTemplateInstance.

/**
 * Checks if the templateinstance parameter (which is a parameter of the
 * expression parameter) is actually a constant or static value or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expression
 *                the expression to report the possible errors to.
 * @param instance
 *                the template instance parameter of the expression to
 *                be checked.
 * @param type
 *                the type against which the template instance shall be
 *                checked.
 * @param referenceChain
 *                the reference chain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
private static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
    Expected_Value_type internalExpectation;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
    } else {
        internalExpectation = expectedValue;
    }
    final ITTCN3Template body = instance.getTemplateBody();
    if (Template_type.TEMPLATE_REFD.equals(body.getTemplatetype())) {
        // FIXME
        ((Referenced_Template) body).getReference().setUsedInIsbound();
    } else if (Template_type.SPECIFIC_VALUE.equals(body.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) body).getValue();
        if (value != null && Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            // FIXME
            ((Referenced_Value) value).getReference().setUsedInIsbound();
        }
    }
    instance.check(timestamp, type);
    if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
        if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
            instance.getLocation().reportSemanticError(CONSTEXPECTED1);
        } else {
            instance.getLocation().reportSemanticError(STATICEXPECTED1);
        }
        expression.setIsErroneous(true);
    }
    ITTCN3Template template = instance.getTemplateBody();
    if (template.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    switch(template.getTemplatetype()) {
        case TEMPLATE_REFD:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
                template = template.getTemplateReferencedLast(timestamp, referenceChain);
                if (template.getIsErroneous(timestamp)) {
                    expression.setIsErroneous(true);
                }
            } else {
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
                    instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                } else {
                    instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                }
                expression.setIsErroneous(true);
            }
            break;
        case SPECIFIC_VALUE:
            final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
            switch(tempValue.getValuetype()) {
                case REFERENCED_VALUE:
                    type.checkThisValueRef(timestamp, tempValue);
                    break;
                case EXPRESSION_VALUE:
                    tempValue.getValueRefdLast(timestamp, referenceChain);
                    break;
                default:
                    break;
            }
            if (tempValue.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 7 with Referenced_Value

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

the class IsPresentExpression 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 (templateInstance == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (template.getIfPresent()) {
        lastValue = new Boolean_Value(false);
        lastValue.copyGeneralProperties(this);
        return lastValue;
    }
    template = template.getTemplateReferencedLast(timestamp);
    if (template.getIfPresent()) {
        lastValue = new Boolean_Value(false);
        lastValue.copyGeneralProperties(this);
        return lastValue;
    }
    boolean result = false;
    if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
        final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
        if (last != null && Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
            result = ((SpecificValue_Template) last).getValue().evaluateIspresent(timestamp, ((Referenced_Template) template).getReference(), 1);
        }
    } else if (template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
        final IValue value = ((SpecificValue_Template) template).getValue();
        if (value.getValuetype() == Value_type.REFERENCED_VALUE) {
            result = value.evaluateIspresent(timestamp, ((Referenced_Value) value).getReference(), 1);
        } else if (value.getValuetype() == Value_type.OMIT_VALUE) {
            result = false;
        } else {
            result = !value.getIsErroneous(timestamp);
        }
    }
    lastValue = new Boolean_Value(result);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) IValue(org.eclipse.titan.designer.AST.IValue) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 8 with Referenced_Value

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

the class IsPresentExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    final TTCN3Template template = templateInstance.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) template).getSpecificValue();
        if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            final Reference reference = ((Referenced_Value) value).getReference();
            if (reference != null) {
                final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
                if (assignment != null) {
                    switch(assignment.getAssignmentType()) {
                        case A_TEMPLATE:
                        case A_VAR_TEMPLATE:
                        case A_MODULEPAR_TEMPLATE:
                        case A_EXT_FUNCTION_RTEMP:
                        case A_FUNCTION_RTEMP:
                        case A_PAR_TEMP_IN:
                        case A_PAR_TEMP_OUT:
                        case A_PAR_TEMP_INOUT:
                            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
                            return;
                        default:
                            break;
                    }
                }
                reference.generateCodeIsPresentBoundChosen(aData, expression, false, getOperationType(), null);
                return;
            }
        } else {
            // FIXME cast_needed case
            value.generateCodeExpressionMandatory(aData, expression, true);
        }
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        if (reference != null) {
            reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
            return;
        }
    } else {
        templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(".isPresent()");
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 9 with Referenced_Value

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

the class IsPresentExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance == null) {
        return true;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody().setLoweridToReference(timestamp);
    if (templateInstance.getDerivedReference() != null) {
        return true;
    }
    if (template.getIfPresent()) {
        return false;
    }
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue specificValue = ((SpecificValue_Template) template).getValue();
        if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
            final Reference reference = ((Referenced_Value) specificValue).getReference();
            final Assignment ass = reference.getRefdAssignment(timestamp, false);
            if (ass == null) {
                return true;
            }
            switch(ass.getAssignmentType()) {
                case A_OBJECT:
                case A_OS:
                case A_CONST:
                case A_EXT_CONST:
                case A_MODULEPAR:
                case A_VAR:
                case A_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RVAL:
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                case A_PAR_VAL_OUT:
                case A_PAR_VAL_INOUT:
                    break;
                default:
                    return true;
            }
            // TODO improve to better detect unbound
            // elements
            final IValue last = specificValue.getValueRefdLast(timestamp, expectedValue, null);
            if (last == null) {
                return true;
            }
            if (last == this) {
                return getIsErroneous(timestamp);
            }
            return last.isUnfoldable(timestamp, expectedValue, referenceChain);
        }
        return specificValue.isUnfoldable(timestamp, expectedValue, referenceChain);
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (ass == null) {
            return true;
        }
        switch(ass.getAssignmentType()) {
            case A_CONST:
                // const is foldable
                return false;
            case A_TEMPLATE:
                break;
            default:
                return true;
        }
        // TODO improve to better detect unbound elements
        final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
        if (last == null) {
            return true;
        }
        if (last == template) {
            return last.getIsErroneous(timestamp);
        }
        if (last.getIfPresent()) {
            return false;
        }
        if (Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
            return ((SpecificValue_Template) last).getValue().isUnfoldable(timestamp, expectedValue, referenceChain);
        }
    }
    return true;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 10 with Referenced_Value

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

the class Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    value.setIsErroneous(false);
    final Assignment assignment = getDefiningAssignment();
    if (assignment != null && assignment instanceof Definition) {
        final Scope scope = value.getMyScope();
        if (scope != null) {
            final Module module = scope.getModuleScope();
            if (module != null) {
                final String referingModuleName = module.getName();
                if (!((Definition) assignment).referingHere.contains(referingModuleName)) {
                    ((Definition) assignment).referingHere.add(referingModuleName);
                }
            } else {
                ErrorReporter.logError("The value `" + value.getFullName() + "' does not appear to be in a module");
                value.setIsErroneous(true);
            }
        } else {
            ErrorReporter.logError("The value `" + value.getFullName() + "' does not appear to be in a scope");
            value.setIsErroneous(true);
        }
    }
    check(timestamp);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp) || getIsErroneous(timestamp)) {
        return false;
    }
    if (Value_type.OMIT_VALUE.equals(last.getValuetype()) && !valueCheckingOptions.omit_allowed) {
        value.getLocation().reportSemanticError("`omit' value is not allowed in this context");
        value.setIsErroneous(true);
        return false;
    }
    boolean selfReference = false;
    switch(value.getValuetype()) {
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                selfReference = checkThisReferencedValue(timestamp, last, lhs, valueCheckingOptions.expected_value, chain, valueCheckingOptions.sub_check, valueCheckingOptions.str_elem);
                chain.release();
                return selfReference;
            }
            return false;
        case REFERENCED_VALUE:
            {
                final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                selfReference = checkThisReferencedValue(timestamp, value, lhs, valueCheckingOptions.expected_value, chain, valueCheckingOptions.sub_check, valueCheckingOptions.str_elem);
                chain.release();
                return selfReference;
            }
        case EXPRESSION_VALUE:
            selfReference = value.checkExpressionSelfReference(timestamp, lhs);
            if (value.isUnfoldable(timestamp, null)) {
                final Type_type temporalType = value.getExpressionReturntype(timestamp, valueCheckingOptions.expected_value);
                if (!Type_type.TYPE_UNDEFINED.equals(temporalType) && !isCompatible(timestamp, this.getTypetype(), temporalType, false, value.isAsn())) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEVALUE, getTypename()));
                    value.setIsErroneous(true);
                }
            }
            return selfReference;
        case MACRO_VALUE:
            selfReference = value.checkExpressionSelfReference(timestamp, lhs);
            if (value.isUnfoldable(timestamp, null)) {
                final Type_type temporalType = value.getExpressionReturntype(timestamp, valueCheckingOptions.expected_value);
                if (!Type_type.TYPE_UNDEFINED.equals(temporalType) && !isCompatible(timestamp, this.getTypetype(), temporalType, false, value.isAsn())) {
                    value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEVALUE, getTypename()));
                    value.setIsErroneous(true);
                }
                return selfReference;
            }
            break;
        default:
            break;
    }
    return selfReference;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)40 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)22 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Reference (org.eclipse.titan.designer.AST.Reference)15 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)13 IType (org.eclipse.titan.designer.AST.IType)11 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ISubReference (org.eclipse.titan.designer.AST.ISubReference)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)5 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)4 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)4 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)4 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)4 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3