Search in sources :

Example 46 with IType

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

the class EncvalueUnicharExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * in template (value) any_type
 * @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 (templateInstance1 == null) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    IType type = templateInstance1.getExpressionGovernor(timestamp, internalExpectation);
    ITTCN3Template template = templateInstance1.getTemplateBody();
    if (type == null) {
        template = template.setLoweridToReference(timestamp);
        type = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (type == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance1.getLocation().reportSemanticError(OPERAND1_ERROR1);
        }
        setIsErroneous(true);
        return;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance1, type, referenceChain, expectedValue);
    if (getIsErroneous(timestamp)) {
        return;
    }
    template.checkSpecificValue(timestamp, false);
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_UNDEFINED:
        case TYPE_NULL:
        case TYPE_REFERENCED:
        case TYPE_VERDICT:
        case TYPE_PORT:
        case TYPE_COMPONENT:
        case TYPE_DEFAULT:
        case TYPE_SIGNATURE:
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (!isErroneous) {
                location.reportSemanticError(OPERAND1_ERROR2);
                setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) IType(org.eclipse.titan.designer.AST.IType)

Example 47 with IType

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

the class Enum2IntExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    IType governor = value.getMyGovernor();
    if (governor == null) {
        governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    if (governor == null) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    final String name = governor.getGenNameValue(aData, expression.expression, myScope);
    expression.expression.append(name);
    expression.expression.append(".enum2int(");
    value.generateCodeExpressionMandatory(aData, expression, false);
    expression.expression.append(")");
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 48 with IType

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

the class Enum2IntExpression 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 == null || last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    IType type = last.getExpressionGovernor(timestamp, expectedValue);
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_ASN1_ENUMERATED:
            {
                final EnumItem item = ((ASN1_Enumerated_Type) type).getEnumItemWithName(((Enumerated_Value) last).getValue());
                lastValue = new Integer_Value(((Integer_Value) item.getValue()).getValue());
                lastValue.copyGeneralProperties(this);
                break;
            }
        case TYPE_TTCN3_ENUMERATED:
            {
                final EnumItem item = ((TTCN3_Enumerated_Type) type).getEnumItemWithName(((Enumerated_Value) last).getValue());
                lastValue = new Integer_Value(((Integer_Value) item.getValue()).getValue());
                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) 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)

Example 49 with IType

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

the class Set_Value method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final boolean forceObject) {
    if (canGenerateSingleExpression()) {
        expression.expression.append(generateSingleExpression(aData));
        return;
    }
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    final String tempId = aData.getTemporaryVariableName();
    final String genName = governor.getGenNameValue(aData, expression.expression, myScope);
    expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", genName, tempId));
    setGenNamePrefix(tempId);
    generateCodeInit(aData, expression.preamble, tempId);
    expression.expression.append(tempId);
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 50 with IType

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

the class Set_Value method evaluateIspresent.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SET:
                    if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
                        return false;
                    }
                    break;
                case TYPE_ASN1_SET:
                    if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                // we can move on with the check
                return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
                return false;
            }
            final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
            } else if (compField.hasDefault()) {
                return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)414 IValue (org.eclipse.titan.designer.AST.IValue)94 ISubReference (org.eclipse.titan.designer.AST.ISubReference)82 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)65 Identifier (org.eclipse.titan.designer.AST.Identifier)49 Assignment (org.eclipse.titan.designer.AST.Assignment)40 Value (org.eclipse.titan.designer.AST.Value)34 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)27 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)21 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)21 Reference (org.eclipse.titan.designer.AST.Reference)21 Type (org.eclipse.titan.designer.AST.Type)20 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)18 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)17 ArrayList (java.util.ArrayList)16 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)15 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)14 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)13