Search in sources :

Example 11 with FormalParameter

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

the class FormalParameterParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof FormalParameter) {
        FormalParameter parameter = (FormalParameter) node;
        name = parameter.getIdentifier().toString();
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
    }
    return this;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Type(org.eclipse.titan.designer.AST.Type)

Example 12 with FormalParameter

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

the class Parameter_Redirect method checkVariableReference.

/**
 * Check whether the reference points to a variable of the provided
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference to check
 * @param type
 *                the type the parameter is expected to have.
 */
public final void checkVariableReference(final CompilationTimeStamp timestamp, final Reference reference, final IType type) {
    if (reference == null) {
        return;
    }
    final IType variableType = reference.checkVariableReference(timestamp);
    if (type != null && variableType != null && !type.isIdentical(timestamp, variableType)) {
        final String message = MessageFormat.format("Type mismatch in parameter redirect: A variable of type `{0}'' was expected instead of `{1}''", type.getTypename(), variableType.getTypename());
        reference.getLocation().reportSemanticError(message);
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment != null) {
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                break;
            default:
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) IType(org.eclipse.titan.designer.AST.IType)

Example 13 with FormalParameter

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

the class Port_Utility method checkPortReference.

/**
 * Checks a port reference.
 * Statement independent version.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 * @param portReference
 *                the port reference to be checked
 *
 * @return the port type of the reference if it is a correct port
 *         reference, or null otherwise
 */
public static Port_Type checkPortReference(final CompilationTimeStamp timestamp, final Reference portReference) {
    if (portReference == null) {
        return null;
    }
    final Assignment assignment = portReference.getRefdAssignment(timestamp, true);
    if (assignment == null || assignment.getIsErroneous()) {
        return null;
    }
    IType result = null;
    switch(assignment.getAssignmentType()) {
        case A_PORT:
            final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
            if (dimensions != null) {
                dimensions.checkIndices(timestamp, portReference, "port", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
            } else if (portReference.getSubreferences().size() > 1) {
                portReference.getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
            }
            result = ((Def_Port) assignment).getType(timestamp);
            break;
        case A_PAR_PORT:
            if (portReference.getSubreferences().size() > 1) {
                portReference.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} cannot have field or array sub-references", assignment.getDescription()));
            }
            result = ((FormalParameter) assignment).getType(timestamp);
            break;
        default:
            portReference.getLocation().reportSemanticError(MessageFormat.format(PORTREFERENCEEXPECTED, assignment.getAssignmentName()));
            break;
    }
    if (result == null) {
        return null;
    }
    result = result.getTypeRefdLast(timestamp);
    if (Type_type.TYPE_PORT.equals(result.getTypetype())) {
        return (Port_Type) result;
    }
    return null;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) Port_Type(org.eclipse.titan.designer.AST.TTCN3.types.Port_Type) IType(org.eclipse.titan.designer.AST.IType) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port)

Example 14 with FormalParameter

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

the class Port_Utility method checkValueRedirect.

/**
 * Calculates the type of a variable when it was to be used as a value
 * redirect target.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 * @param redirectValue
 *                the reference to which the redirection is targeted
 * @param type
 *                the expected type of the value redirection.
 *
 * @return the the type of a variable referenced when it was to be used
 *         as a value redirection target.
 */
public static IType checkValueRedirect(final CompilationTimeStamp timestamp, final Reference redirectValue, final IType type) {
    if (redirectValue == null) {
        return null;
    }
    final IType variableType = redirectValue.checkVariableReference(timestamp);
    if (type != null && variableType != null && !type.isCompatible(timestamp, variableType, null, null, null)) {
        redirectValue.getLocation().reportSemanticError(MessageFormat.format(VALUEREDIRECTTYPEMISSMATCH, type.getTypename(), variableType.getTypename()));
    }
    final Assignment assignment = redirectValue.getRefdAssignment(timestamp, true);
    if (assignment != null) {
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                break;
            default:
                break;
        }
    }
    return variableType;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) IType(org.eclipse.titan.designer.AST.IType)

Example 15 with FormalParameter

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

the class ChangeCreator method calculateEditLocations.

private WorkspaceJob calculateEditLocations(final List<FormalParameter> fparamlist, final IFile file, final List<Location> locations_out) throws CoreException {
    final WorkspaceJob job = new WorkspaceJob("LazyficationRefactoring: calculate edit locations") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            for (FormalParameter fparam : fparamlist) {
                System.out.println("reading: " + file.getName());
                Location typeloc = fparam.getType(CompilationTimeStamp.getBaseTimestamp()).getLocation();
                locations_out.add(0, new Location(fparam.getLocation().getFile(), fparam.getLocation().getLine(), typeloc.getOffset(), typeloc.getOffset()));
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)18 IType (org.eclipse.titan.designer.AST.IType)12 Assignment (org.eclipse.titan.designer.AST.Assignment)9 Type (org.eclipse.titan.designer.AST.Type)8 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)4 IValue (org.eclipse.titan.designer.AST.IValue)4 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Reference (org.eclipse.titan.designer.AST.Reference)4 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)4 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)4 HashMap (java.util.HashMap)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 FunctionReferenceDefinition (org.eclipse.titan.designer.AST.TTCN3.types.FunctionReferenceGenerator.FunctionReferenceDefinition)3 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 Location (org.eclipse.titan.designer.AST.Location)2 Module (org.eclipse.titan.designer.AST.Module)2