Search in sources :

Example 11 with Assignment

use of org.eclipse.titan.designer.AST.Assignment 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 12 with Assignment

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

the class ObjectIdentifierComponent method checkDefdValueOID.

/**
 * Checks the defined value form in an OID component.
 *
 * @param timestamp the timestamp of the actual compilation cycle.
 * @param refChain the reference chain used to detect cyclic references.
 * @param state the state of checking.
 *
 * @param the new state after this check was done.
 */
private oidState_type checkDefdValueOID(final CompilationTimeStamp timestamp, final IReferenceChain refChain, final oidState_type state) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue value = definedValue.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (value.getIsErroneous(timestamp)) {
        return oidState_type.LATER;
    }
    switch(value.getValuetype()) {
        case INTEGER_VALUE:
            final ObjectIdentifierComponent temp = new ObjectIdentifierComponent(null, definedValue);
            temp.setFullNameParent(this);
            temp.setMyScope(myScope);
            return temp.checkNumberFormOID(timestamp, state);
        case OBJECTID_VALUE:
            if (!oidState_type.START.equals(state)) {
                definedValue.getLocation().reportSemanticError("INTEGER or RELATIVE-OID value was expected");
            }
            ((ObjectIdentifier_Value) value).checkOID(timestamp, refChain);
            return oidState_type.LATER;
        case RELATIVEOBJECTIDENTIFIER_VALUE:
            switch(state) {
                case ITU_REC:
                    return oidState_type.LATER;
                case LATER:
                    return oidState_type.LATER;
                default:
                    definedValue.getLocation().reportSemanticError(MessageFormat.format("RELATIVE-OID value cannot be used as the {0} component of an OBJECTIDENTIFIER value", oidState_type.START.equals(state) ? "first" : "second"));
                    return oidState_type.LATER;
            }
        case REFERENCED_VALUE:
            {
                final Reference reference = ((Referenced_Value) value).getReference();
                final Assignment assignment = reference.getRefdAssignment(timestamp, false);
                final IType type = assignment.getType(timestamp).getTypeRefdLast(timestamp);
                if (type.getTypetype() == Type_type.TYPE_INTEGER) {
                // FIXME implement handling of the variable form
                } else {
                    definedValue.getLocation().reportSemanticError("INTEGER variable was expected");
                }
                return oidState_type.LATER;
            }
        default:
            if (oidState_type.START.equals(state)) {
                definedValue.getLocation().reportSemanticError("INTEGER or OBJECT IDENTIFIER value was expected for the first component");
            } else {
                definedValue.getLocation().reportSemanticError("INTEGER or RELATIVE-OID value was expected");
            }
            return oidState_type.LATER;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) RelativeObjectIdentifier_Value(org.eclipse.titan.designer.AST.ASN1.values.RelativeObjectIdentifier_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 13 with Assignment

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

the class ComponentCreateExpression method checkCreate.

private Component_Type checkCreate(final CompilationTimeStamp timestamp) {
    if (checkCreateTimestamp != null && !checkCreateTimestamp.isLess(timestamp)) {
        return checkCreateCache;
    }
    checkCreateTimestamp = timestamp;
    checkCreateCache = null;
    final Assignment assignment = componentReference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
        return null;
    }
    if (!Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
        componentReference.getLocation().reportSemanticError(MessageFormat.format(COMPONENTEXPECTED, assignment.getDescription()));
        setIsErroneous(true);
        return null;
    }
    final IType type = ((Def_Type) assignment).getType(timestamp).getFieldType(timestamp, componentReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (type == null) {
        setIsErroneous(true);
        return null;
    }
    if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
        componentReference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH1, type.getTypename()));
        setIsErroneous(true);
        return null;
    }
    if (myGovernor != null) {
        final IType last = myGovernor.getTypeRefdLast(timestamp);
        if (Type_type.TYPE_COMPONENT.equals(last.getTypetype()) && !last.isCompatible(timestamp, type, null, null, null)) {
            componentReference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, last.getTypename(), type.getTypename()));
            setIsErroneous(true);
            return null;
        }
    }
    checkCreateCache = (Component_Type) type;
    return checkCreateCache;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IType(org.eclipse.titan.designer.AST.IType)

Example 14 with Assignment

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

the class DecodeExpression method checkSecondExpressionOperand.

private void checkSecondExpressionOperand(final CompilationTimeStamp timestamp) {
    final Assignment temporalAssignment = reference2.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    temporalType = temporalType.getTypeRefdLast(timestamp);
    switch(temporalType.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) {
            reference2.getLocation().reportSemanticError(OPERANDERROR2);
            setIsErroneous(true);
            // }
            break;
        default:
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IType(org.eclipse.titan.designer.AST.IType)

Example 15 with Assignment

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

the class DecvalueUnicharExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addBuiltinTypeImport("TitanOctetString");
    aData.addCommonLibraryImport("AdditionalFunctions");
    final ExpressionStruct expression1 = new ExpressionStruct();
    final ExpressionStruct expression2 = new ExpressionStruct();
    reference1.generateCode(aData, expression1);
    reference2.generateCode(aData, expression2);
    final Assignment tempAssignment = reference2.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final IType type = tempAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
    final IType fieldType = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (expression1.preamble.length() > 0) {
        expression.preamble.append(expression1.preamble);
    }
    if (expression2.preamble.length() > 0) {
        expression.preamble.append(expression2.preamble);
    }
    String v3_code;
    if (value3 == null) {
        v3_code = "\"UTF-8\"";
    } else {
        final ExpressionStruct tempExpression = new ExpressionStruct();
        value3.generateCodeExpressionMandatory(aData, tempExpression, true);
        final String tempID = aData.getTemporaryVariableName();
        expression.preamble.append(MessageFormat.format("TitanCharString {0} = {1};\n", tempID, tempExpression.expression));
        expression.preamble.append(MessageFormat.format("if ({0}.operatorNotEquals(\"UTF-8\") && {0}.operatorNotEquals(\"UTF-16\") && {0}.operatorNotEquals(\"UTF-16LE\") && {0}.operatorNotEquals(\"UTF-16BE\") && {0}.operatorNotEquals(\"UTF-32\") && {0}.operatorNotEquals(\"UTF-32LE\") && {0}.operatorNotEquals(\"UTF-32BE\")) '{'\n", tempID));
        expression.preamble.append(MessageFormat.format("throw new TtcnError(MessageFormat.format(\"decvalue_unichar: Invalid encoding parameter: '{'0'}'\", {0}));\n", tempID));
        expression.preamble.append("}\n");
        v3_code = tempID;
    }
    final Scope scope = reference2.getMyScope();
    final boolean isOptional = fieldType.fieldIsOptional(reference2.getSubreferences());
    final ExpressionStruct expression3 = new ExpressionStruct();
    // TODO add support for 4th parameter
    expression3.expression.append(MessageFormat.format("{0}_default_coding", fieldType.getGenNameDefaultCoding(aData, expression.expression, scope)));
    final String bufferID = aData.getTemporaryVariableName();
    final String returnValueID = aData.getTemporaryVariableName();
    // TOOD add handling for non-built-in encoding
    expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_WARNING);\n");
    expression.preamble.append("TTCN_EncDec.clear_error();\n");
    expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString(AdditionalFunctions.unichar2oct({1}, {2}));\n", bufferID, expression1.expression, v3_code));
    expression.preamble.append(MessageFormat.format("TitanInteger {0} = new TitanInteger({1}_decoder({2}, {3}{4}, {5}));\n", returnValueID, fieldType.getGenNameCoder(aData, expression.expression, scope), bufferID, expression2.expression, isOptional ? ".get()" : "", expression3.expression));
    expression.preamble.append(MessageFormat.format("if ({0}.operatorEquals(0)) '{'\n", returnValueID));
    expression.preamble.append(MessageFormat.format("{0} = AdditionalFunctions.oct2unichar({1}, {2});\n", expression1.expression, bufferID, v3_code));
    expression.preamble.append("}\n");
    // TOOD add handling for non-built-in encoding
    expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_DEFAULT);\n");
    expression.preamble.append("TTCN_EncDec.clear_error();\n");
    expression.expression.append(returnValueID);
    if (expression1.postamble.length() > 0) {
        expression.postamble.append(expression1.postamble);
    }
    if (expression2.postamble.length() > 0) {
        expression.postamble.append(expression2.postamble);
    }
    if (expression3.postamble.length() > 0) {
        expression.postamble.append(expression3.postamble);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Scope(org.eclipse.titan.designer.AST.Scope) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)141 Reference (org.eclipse.titan.designer.AST.Reference)48 IType (org.eclipse.titan.designer.AST.IType)41 ISubReference (org.eclipse.titan.designer.AST.ISubReference)39 IValue (org.eclipse.titan.designer.AST.IValue)31 Identifier (org.eclipse.titan.designer.AST.Identifier)25 ArrayList (java.util.ArrayList)24 Module (org.eclipse.titan.designer.AST.Module)22 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)16 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)14 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)14 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)14 Assignments (org.eclipse.titan.designer.AST.Assignments)13 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 Location (org.eclipse.titan.designer.AST.Location)9 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)7 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)6