Search in sources :

Example 91 with Assignment

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

the class All_From_Template method checkThisTemplateParameterizedReference.

private boolean checkThisTemplateParameterizedReference(final Reference reference, final Assignment lhs) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.isEmpty() || !(subreferences.get(0) instanceof ParameterisedSubReference)) {
        return false;
    }
    final ParameterisedSubReference subReference = (ParameterisedSubReference) subreferences.get(0);
    final ActualParameterList actualParameterList = subReference.getActualParameters();
    if (actualParameterList == null) {
        return false;
    }
    final int nofParameters = actualParameterList.getNofParameters();
    for (int i = 0; i < nofParameters; i++) {
        Reference parameterReference = null;
        final ActualParameter actualParameter = actualParameterList.getParameter(i);
        if (actualParameter instanceof Template_ActualParameter) {
            TemplateInstance templateInstance = ((Template_ActualParameter) actualParameter).getTemplateInstance();
            ITTCN3Template template = templateInstance.getTemplateBody();
            template = template.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
            if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
                parameterReference = ((Referenced_Template) template).getReference();
            }
        } else if (actualParameter instanceof Referenced_ActualParameter) {
            parameterReference = ((Referenced_ActualParameter) actualParameter).getReference();
        }
        if (parameterReference != null) {
            final Assignment assignment = parameterReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            if (assignment == lhs) {
                return true;
            }
            // check their parameters as well
            switch(assignment.getAssignmentType()) {
                case A_TEMPLATE:
                case A_FUNCTION_RVAL:
                case A_FUNCTION_RTEMP:
                case A_EXT_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RTEMP:
                    if (checkThisTemplateParameterizedReference(parameterReference, lhs)) {
                        return true;
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Template_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter) ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter) Referenced_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter) Template_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Referenced_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter)

Example 92 with Assignment

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

the class All_From_Template method checkThisTemplateGeneric.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisTemplateGeneric(final CompilationTimeStamp timestamp, final IType type, final boolean isModified, final boolean allowOmit, final boolean allowAnyOrOmit, final boolean subCheck, final boolean implicitOmit, final Assignment lhs) {
    if (allFrom == null) {
        ErrorReporter.INTERNAL_ERROR();
        return false;
    }
    if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError(SPECIFICVALUEEXPECTED);
        allFrom.setIsErroneous(true);
        return false;
    }
    if (!((SpecificValue_Template) allFrom).isReference()) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return false;
    }
    // isReference branch:
    final Reference reference = ((SpecificValue_Template) allFrom).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        allFrom.getLocation().reportSemanticError("Assignment not found");
        allFrom.setIsErroneous(true);
        return false;
    }
    boolean selfReference = lhs == assignment;
    // ES 201 873-1 - V4.7.1 B.1.2.1.a:
    // The type of the template list and the member type of the template in
    // the all from clause shall be
    // compatible.
    final IType assType = assignment.getType(timestamp);
    if (assType != null) {
        final IType atype = assType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
        if (atype == null) {
            allFrom.setIsErroneous(true);
            return false;
        }
        final IType referredType = atype.getTypeRefdLast(timestamp);
        // type of the fields of the sequence/set
        IType it = null;
        if (referredType != null) {
            switch(referredType.getTypetype()) {
                case TYPE_SEQUENCE_OF:
                    it = ((SequenceOf_Type) referredType).getOfType();
                    break;
                case TYPE_SET_OF:
                    it = ((SetOf_Type) referredType).getOfType();
                    break;
                case TYPE_TTCN3_SEQUENCE:
                    // interruptIfOptional)
                    break;
                default:
                    allFrom.getLocation().reportSemanticError(LISTEXPECTED);
                    allFrom.setIsErroneous(true);
            }
        }
        if (it != null) {
            if (!it.isCompatible(timestamp, type, null, null, null)) {
                allFrom.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH, type.getTypename()));
                allFrom.setIsErroneous(true);
            }
        }
    }
    // ES 201 873-1 - V4.7.1 B.1.2.1.
    // b) The template in the all from clause as a whole shall not resolve
    // into a matching mechanism (i.e. its
    // elements may contain any of the matching mechanisms or matching
    // attributes with the exception of those
    // described in the following restriction).
    // c) Individual fields of the template in the all from clause shall not
    // resolve to any of the following matching
    // mechanisms: AnyElementsOrNone, permutation
    ITTCN3Template body = null;
    IValue value = null;
    switch(assignment.getAssignmentType()) {
        case A_TEMPLATE:
            body = ((Def_Template) assignment).getTemplate(timestamp);
            selfReference |= checkThisTemplateParameterizedReference(reference, lhs);
            break;
        case A_VAR_TEMPLATE:
            body = ((Def_Var_Template) assignment).getInitialValue();
            break;
        case A_CONST:
            break;
        case A_MODULEPAR:
            value = ((Def_ModulePar) assignment).getDefaultValue();
            break;
        case A_MODULEPAR_TEMPLATE:
            body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
            break;
        case A_VAR:
            value = ((Def_Var) assignment).getInitialValue();
            break;
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            selfReference |= checkThisTemplateParameterizedReference(reference, lhs);
            break;
        default:
            return selfReference;
    }
    if (body != null) {
        switch(body.getTemplatetype()) {
            case TEMPLATE_LIST:
                // TODO: if "all from" is in a permutation list it anyoromit and any is permitted
                if (!allowAnyOrOmit && ((Template_List) body).containsAnyornoneOrPermutation()) {
                    allFrom.getLocation().reportSemanticError(ANYOROMITANDPERMUTATIONPRHOHIBITED);
                    allFrom.setIsErroneous(true);
                }
                break;
            case NAMED_TEMPLATE_LIST:
                ((Named_Template_List) body).checkSpecificValue(timestamp, true);
                break;
            case SPECIFIC_VALUE:
                break;
            default:
                allFrom.getLocation().reportSemanticError(LISTEXPECTED);
                allFrom.setIsErroneous(true);
                return selfReference;
        }
    }
    return selfReference;
}
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) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) IType(org.eclipse.titan.designer.AST.IType)

Example 93 with Assignment

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

the class All_From_Template method generateCodeInitAllFrom.

public void generateCodeInitAllFrom(final JavaGenData aData, final StringBuilder source, final String name) {
    final IValue value = ((SpecificValue_Template) allFrom).getValue();
    Reference reference;
    if (value.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
        // value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
        reference = ((Undefined_LowerIdentifier_Value) value).getAsReference();
    } else {
        reference = ((Referenced_Value) value).getReference();
    }
    final ExpressionStruct expression = new ExpressionStruct();
    reference.generateCode(aData, expression);
    final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    switch(assignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
            if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
                expression.expression.append(".get()");
            }
            break;
        default:
            break;
    }
    // The caller will have to provide the for cycle with this variable
    source.append(MessageFormat.format("{0}.assign({1}.getAt(i_i));\n", name, expression.expression));
}
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) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 94 with Assignment

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

the class All_From_Template method getNofTemplatesNotAnyornone.

/**
 * Calculates the number of list members which are not the any or none
 * symbol.
 *
 * @return the number calculated.
 */
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
    int result = 0;
    if (allFrom == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    if (!((SpecificValue_Template) allFrom).isReference()) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    // isReference branch:
    final Reference reference = ((SpecificValue_Template) allFrom).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        allFrom.getLocation().reportSemanticError("Assignment not found");
        allFrom.setIsErroneous(true);
        return result;
    }
    ITTCN3Template body = null;
    switch(assignment.getAssignmentType()) {
        case A_TEMPLATE:
            body = ((Def_Template) assignment).getTemplate(timestamp);
            break;
        case A_VAR_TEMPLATE:
            body = ((Def_Var_Template) assignment).getInitialValue();
            break;
        case A_CONST:
            final IValue value = ((Def_Const) assignment).getValue();
            return getNofValues(value, timestamp);
        case A_MODULEPAR:
            final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
            return getNofValues(mvalue, timestamp);
        case A_MODULEPAR_TEMPLATE:
            body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
            break;
        default:
            return result;
    }
    if (body == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
        allFrom.setIsErroneous(true);
        return result;
    }
    result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
    return result;
}
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) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)

Example 95 with Assignment

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

the class Unknown_Start_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_PORT:
        case A_PAR_PORT:
            if (value != null) {
                value.getLocation().reportSemanticError(NOARGUMENTEXPECTED);
            }
            if (realStatement == null || !Statement_type.S_START_PORT.equals(realStatement.getType())) {
                realStatement = new Start_Port_Statement(reference);
                realStatement.setMyScope(getMyScope());
                realStatement.setFullNameParent(this);
                realStatement.setLocation(location);
                realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
            }
            realStatement.check(timestamp);
            break;
        case A_TIMER:
        case A_PAR_TIMER:
            if (realStatement == null || !Statement_type.S_START_TIMER.equals(realStatement.getType())) {
                realStatement = new Start_Timer_Statement(reference, value);
                realStatement.setMyScope(getMyScope());
                realStatement.setFullNameParent(this);
                realStatement.setLocation(location);
                realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
            }
            realStatement.check(timestamp);
            break;
        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:
            if (value == null) {
                location.reportSemanticError(MISSINGARGUMENT);
                return;
            }
            if (!Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
                value.getLocation().reportSemanticError(FUNCTIONARGUMENTEXPECTED);
                return;
            }
            if (realStatement == null || !Statement_type.S_START_COMPONENT.equals(realStatement.getType())) {
                realStatement = new Start_Component_Statement(new Referenced_Value(reference), ((Referenced_Value) value).getReference());
                realStatement.setMyScope(getMyScope());
                realStatement.setFullNameParent(this);
                realStatement.setLocation(location);
                realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
            }
            realStatement.check(timestamp);
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(UNEXPECEDSTARTREFERENCE, assignment.getDescription()));
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

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