Search in sources :

Example 16 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class Return_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    // TODO more nuanced code generation
    getLocation().release_location_object(aData, source);
    final ExpressionStruct expression = new ExpressionStruct();
    expression.expression.append("return ");
    // No return value:
    if (template == null) {
        expression.mergeExpression(source);
        return;
    }
    final Definition definition = myStatementBlock.getMyDefinition();
    if (definition.getAssignmentType() == Assignment_type.A_FUNCTION_RVAL && template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
        final IValue value = ((SpecificValue_Template) template).getValue();
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        final Definition myDefinition = myStatementBlock.getMyDefinition();
        if (myDefinition.getTemplateRestriction() != TemplateRestriction.Restriction_type.TR_NONE && genRestrictionCheck) {
            template.generateCodeExpression(aData, expression, myDefinition.getTemplateRestriction());
        } else {
            template.generateCodeExpression(aData, expression, Restriction_type.TR_NONE);
        }
    }
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 17 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class Scope method checkRunsOnScope.

/**
 * Checks that operations that can only be executed in definitions that
 * have a runs on scope, are really executed in such a definition. And
 * that the required runs on component is compatible with the runs on
 * component of the definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param type
 *                the fat type to check (used or referred to by the
 *                location).
 * @param errorLocation
 *                the location to report the error to.
 * @param operation
 *                the name of the operation.
 */
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final IType type, final ILocateableNode errorLocation, final String operation) {
    if (type == null) {
        return;
    }
    Component_Type referencedComponent;
    String typename;
    switch(type.getTypetype()) {
        case TYPE_FUNCTION:
            referencedComponent = ((Function_Type) type).getRunsOnType(timestamp);
            typename = "function";
            break;
        case TYPE_ALTSTEP:
            referencedComponent = ((Altstep_Type) type).getRunsOnType(timestamp);
            typename = "altstep";
            break;
        default:
            return;
    }
    if (referencedComponent == null) {
        return;
    }
    final RunsOnScope runsOnScope = getScopeRunsOn();
    if (runsOnScope == null) {
        errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED2, operation, typename, type.getTypename(), referencedComponent.getTypename()));
    } else {
        final Component_Type localType = runsOnScope.getComponentType();
        if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
            errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH2, localType.getTypename(), operation, typename, type.getTypename(), referencedComponent.getTypename()));
        }
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 18 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class Scope method checkRunsOnScope.

/**
 * Checks that operations that can only be executed in definitions that
 * have a runs on scope, are really executed in such a definition. And
 * that the required runs on component is compatible with the runs on
 * component of the definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param assignment
 *                the assignment to check (used or referred to by the
 *                statement).
 * @param errorLocation
 *                the location to report the error to.
 * @param operation
 *                the name of the operation.
 */
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final Assignment assignment, final ILocateableNode errorLocation, final String operation) {
    Component_Type referencedComponent;
    switch(assignment.getAssignmentType()) {
        case A_ALTSTEP:
            referencedComponent = ((Def_Altstep) assignment).getRunsOnType(timestamp);
            break;
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            referencedComponent = ((Def_Function) assignment).getRunsOnType(timestamp);
            break;
        case A_TESTCASE:
            referencedComponent = ((Def_Testcase) assignment).getRunsOnType(timestamp);
            break;
        default:
            return;
    }
    if (referencedComponent == null) {
        return;
    }
    final RunsOnScope runsOnScope = getScopeRunsOn();
    if (runsOnScope == null) {
        errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED, operation, assignment.getDescription(), referencedComponent.getTypename()));
    } else {
        final Component_Type localType = runsOnScope.getComponentType();
        if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
            errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH, localType.getTypename(), operation, assignment.getDescription(), referencedComponent.getTypename()));
        }
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 19 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class PortReference method getRefdAssignment.

@Override
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList) {
    if (myScope == null || componentType == null) {
        return null;
    }
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return referredAssignment;
    }
    // just for error compatibility with...
    super.getRefdAssignment(timestamp, checkParameterList);
    final Identifier portIdentifier = getId();
    final ComponentTypeBody componentBody = componentType.getComponentBody();
    if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
        getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
        setIsErroneous(true);
        referredAssignment = null;
        lastTimeChecked = timestamp;
        return null;
    }
    referredAssignment = componentBody.getLocalAssignmentById(portIdentifier);
    if (referredAssignment != null) {
        referredAssignment.check(timestamp);
        referredAssignment.setUsed();
        if (referredAssignment instanceof Definition) {
            final String referingModuleName = getMyScope().getModuleScope().getName();
            if (!((Definition) referredAssignment).referingHere.contains(referingModuleName)) {
                ((Definition) referredAssignment).referingHere.add(referingModuleName);
            }
        }
    }
    lastTimeChecked = timestamp;
    return referredAssignment;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 20 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class TemplateRestriction method check.

public static boolean check(final CompilationTimeStamp timestamp, final Definition definition, final ITTCN3Template template, final Reference ref) {
    if (template.getIsErroneous(timestamp)) {
        return false;
    }
    final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
    Restriction_type tr = definition.getTemplateRestriction();
    tr = getSubRestriction(tr, timestamp, ref);
    switch(tr) {
        case TR_NONE:
            return false;
        case TR_VALUE:
            return last.checkValueomitRestriction(timestamp, definition.getAssignmentName(), false, template.getLocation());
        case TR_OMIT:
            return last.checkValueomitRestriction(timestamp, definition.getAssignmentName(), true, template.getLocation());
        case TR_PRESENT:
            return last.checkPresentRestriction(timestamp, definition.getAssignmentName(), template.getLocation());
        default:
            return false;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)

Aggregations

Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)52 Assignment (org.eclipse.titan.designer.AST.Assignment)16 IValue (org.eclipse.titan.designer.AST.IValue)12 Location (org.eclipse.titan.designer.AST.Location)11 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)10 IType (org.eclipse.titan.designer.AST.IType)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 Module (org.eclipse.titan.designer.AST.Module)10 ArrayList (java.util.ArrayList)9 Reference (org.eclipse.titan.designer.AST.Reference)9 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)6 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)6 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)5 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)5 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)5 IFile (org.eclipse.core.resources.IFile)4 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)4