Search in sources :

Example 6 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class Reference method chkComponentypeReference.

/**
 * Checks and returns the type of the component referred to by this
 * reference.
 * <p>
 * This is used to detect the type of "runs on" and "system" clause
 * elements. In any other case a semantic error will be reported.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 *
 * @return the type of the referred component or null in case of
 *         problems.
 */
public final Component_Type chkComponentypeReference(final CompilationTimeStamp timestamp) {
    final Assignment assignment = getRefdAssignment(timestamp, true);
    if (assignment != null) {
        if (Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
            IType type = assignment.getType(timestamp);
            if (type != null) {
                type = type.getTypeRefdLast(timestamp);
                if (type != null && !type.getIsErroneous(timestamp)) {
                    switch(type.getTypetype()) {
                        case TYPE_COMPONENT:
                            return (Component_Type) type;
                        case TYPE_REFERENCED:
                            return null;
                        default:
                            getLocation().reportSemanticError(COMPONENTEXPECTED);
                            setIsErroneous(true);
                            break;
                    }
                }
            }
        } else {
            getLocation().reportSemanticError(TYPEEXPECTED);
            setIsErroneous(true);
        }
    }
    return null;
}
Also used : IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)

Example 7 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class ComponentCreateExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    expression.expression.append("TTCN_Runtime.create_component(");
    // the type of the component (module name and identifier)
    final Assignment assignment = componentReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (assignment == null || !Assignment_type.A_TYPE.equals(assignment.getAssignmentType())) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    IType componentType = assignment.getType(CompilationTimeStamp.getBaseTimestamp()).getFieldType(CompilationTimeStamp.getBaseTimestamp(), componentReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (componentType == null) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    componentType = componentType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (!Type_type.TYPE_COMPONENT.equals(componentType.getTypetype())) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    ((Component_Type) componentType).getComponentBody().generateCodeComponentTypeName(expression);
    expression.expression.append(", ");
    // third argument: component name
    if (name != null) {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = name.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
            // TODO check why translate
            expression.expression.append(MessageFormat.format("\"{0}\"", ((Charstring_Value) last).getValue()));
        } else {
            name.generateCodeExpressionMandatory(aData, expression, false);
        }
    } else {
        expression.expression.append("null");
    }
    expression.expression.append(", ");
    // fourth argument location
    if (location != null) {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = location.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
            // TODO check why translate
            expression.expression.append(MessageFormat.format("\"{0}\"", ((Charstring_Value) last).getValue()));
        } else {
            location.generateCodeExpressionMandatory(aData, expression, false);
        }
    } else {
        expression.expression.append("null");
    }
    // fifth argument: alive flag
    expression.expression.append(MessageFormat.format(", {0})", isAlive ? "true" : "false"));
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Example 8 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class Start_Component_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    final Component_Type componentType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
    final Assignment assignment = functionInstanceReference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RTEMP:
        case A_FUNCTION_RVAL:
            break;
        default:
            functionInstanceReference.getLocation().reportSemanticError(MessageFormat.format(REFERENCETOFUNCTIONWASEXPECTED, assignment.getDescription()));
            return;
    }
    final Def_Function function = (Def_Function) assignment;
    if (!function.checkStartable(timestamp, getLocation())) {
        return;
    }
    final IType runsOnType = function.getRunsOnType(timestamp);
    if (componentType == null || runsOnType == null) {
        return;
    }
    if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
        componentReference.getLocation().reportSemanticError(MessageFormat.format(COMPONENTTYPEMISMATCH, componentType.getTypename(), function.getDescription(), runsOnType.getTypename()));
    }
    switch(function.getAssignmentType()) {
        case A_FUNCTION_RTEMP:
            functionInstanceReference.getLocation().reportSemanticWarning(MessageFormat.format(TEMPLATERETURN, function.getFullName(), function.getType(timestamp).getTypename()));
            break;
        case A_FUNCTION_RVAL:
            {
                IType type = function.getType(timestamp);
                boolean returnTypeCorrect = false;
                while (!returnTypeCorrect) {
                    if (type.hasDoneAttribute()) {
                        returnTypeCorrect = true;
                        break;
                    }
                    if (type instanceof IReferencingType) {
                        final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        final IType refd = ((IReferencingType) type).getTypeRefd(timestamp, refChain);
                        refChain.release();
                        if (type != refd) {
                            type = refd;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (!returnTypeCorrect) {
                    final String message = MessageFormat.format(RETURNWITHOUTDONE, function.getDescription(), function.getType(timestamp).getTypename());
                    functionInstanceReference.getLocation().reportSemanticWarning(message);
                }
                break;
            }
        default:
            break;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) IType(org.eclipse.titan.designer.AST.IType)

Example 9 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class Port_Utility method checkComponentReference.

/**
 * Checks a reference to see if it really references a valid component
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param source
 *                the source statement to report errors to.
 * @param value
 *                the value reference to check.
 * @param allowMtc
 *                tells if the mtc component is allowed or not.
 * @param allowSystem
 *                tells if the system component is allowed or not.
 *
 * @return the referenced component type, or null if there were
 *         problems.
 */
public static Component_Type checkComponentReference(final CompilationTimeStamp timestamp, final Statement source, final IValue value, final boolean allowMtc, final boolean allowSystem) {
    if (source.getMyStatementBlock() != null && source.getMyStatementBlock().getMyDefinition() == null) {
        source.getLocation().reportSemanticError(COMPONENTOPINCONTROLPART);
    }
    if (value == null || value.getIsErroneous(timestamp)) {
        return null;
    }
    final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
    switch(last.getValuetype()) {
        case REFERENCED_VALUE:
            break;
        case TTCN3_NULL_VALUE:
            value.getLocation().reportSemanticError(MessageFormat.format(NULLCOMPONENTREFERENCE, source.getStatementName()));
            break;
        case EXPRESSION_VALUE:
            final Expression_Value expression = (Expression_Value) last;
            switch(expression.getOperationType()) {
                case APPLY_OPERATION:
                    if (!Type_type.TYPE_COMPONENT.equals(last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
                        value.getLocation().reportSemanticError(VALUERETURNEXPECTED);
                    }
                    break;
                case COMPONENT_NULL_OPERATION:
                    value.getLocation().reportSemanticError(MessageFormat.format(NULLCOMPONENTREFERENCE, source.getStatementName()));
                    break;
                case MTC_COMPONENT_OPERATION:
                    if (!allowMtc) {
                        value.getLocation().reportSemanticError(MessageFormat.format(MTCCOMPONENTREFERENCE, source.getStatementName()));
                    }
                    break;
                case SYSTEM_COMPONENT_OPERATION:
                    if (!allowSystem) {
                        value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCOMPONENTREFERENCE, source.getStatementName()));
                    }
                    break;
                case SELF_COMPONENT_OPERATION:
                    break;
                case COMPONENT_CREATE_OPERATION:
                    break;
                case VALUEOF_OPERATION:
                    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    ((ValueofExpression) expression).evaluateValue(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
                    referenceChain.release();
                    break;
                default:
                    value.getLocation().reportSemanticError(COMPONENTREFERENCEEXPECTED);
                    return null;
            }
            break;
        default:
            value.getLocation().reportSemanticError(COMPONENTREFERENCEEXPECTED);
            return null;
    }
    IType result = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (result == null) {
        return null;
    }
    result = result.getTypeRefdLast(timestamp);
    if (result.getIsErroneous(timestamp)) {
        return null;
    } else if (Type_type.TYPE_COMPONENT.equals(result.getTypetype())) {
        return (Component_Type) result;
    }
    value.getLocation().reportSemanticError(MessageFormat.format(COMPONENTTYPEMISMATCH, result.getTypename()));
    return null;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueofExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ValueofExpression) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with Component_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Component_Type in project titan.EclipsePlug-ins by eclipse.

the class RunsOnScopeReduction method process.

@Override
protected void process(IVisitableNode node, Problems problems) {
    final Set<Identifier> definitions = new HashSet<Identifier>();
    final Identifier componentIdentifier;
    final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
    final Identifier identifier;
    boolean isTestCase = false;
    if (node instanceof Def_Function) {
        final Def_Function variable = (Def_Function) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else if (node instanceof Def_Altstep) {
        final Def_Altstep variable = (Def_Altstep) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
    } else {
        final Def_Testcase variable = (Def_Testcase) node;
        final Component_Type componentType = variable.getRunsOnType(timestamp);
        if (componentType == null) {
            return;
        }
        componentIdentifier = componentType.getComponentBody().getIdentifier();
        identifier = variable.getIdentifier();
        isTestCase = true;
    }
    final ReferenceCheck chek = new ReferenceCheck();
    node.accept(chek);
    definitions.addAll(chek.getIdentifiers());
    if (definitions.isEmpty()) {
        if (isTestCase) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
        } else {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
        }
    } else if (!definitions.contains(componentIdentifier)) {
        ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
        if (definitions.size() == 1) {
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
        } else {
            // FIXME: implement other cases
            problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) ArrayList(java.util.ArrayList) Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) HashSet(java.util.HashSet)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)8 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)6 IValue (org.eclipse.titan.designer.AST.IValue)6 Assignment (org.eclipse.titan.designer.AST.Assignment)5 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)4 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)4 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)3 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Scope (org.eclipse.titan.designer.AST.Scope)2 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)2 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)2 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)2 CompilationTimeStamp (org.eclipse.titan.designer.parsers.CompilationTimeStamp)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1