Search in sources :

Example 11 with FormalParameterList

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

the class TooManyParameters method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof FormalParameterList) {
        final FormalParameterList s = (FormalParameterList) node;
        if (s.getNofParameters() > reportTooManyParametersSize) {
            final String msg = MessageFormat.format(TOOMANYPARAMETERS, reportTooManyParametersSize, s.getNofParameters());
            problems.report(s.getLocation(), msg);
        }
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)

Example 12 with FormalParameterList

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

the class TemplateParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof Identifier) {
        name = node.toString();
        // TODO : find a more sophisticated way of storing symbols (e.g. SymbolTable)
        myASTVisitor.nodeNameNodeTypeHashMap.put(name, "template");
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
        template = new Template(name, type);
        return Action.skip(Type.class, this);
    }
    if (node instanceof FormalParameterList) {
        return new FormalParameterParser(this, template);
    }
    // is a modification
    if (node instanceof Reference) {
        Reference reference = (Reference) node;
        String basename = reference.getId().toString();
        Template base = registry.find(basename);
        // TODO : templates need a base value as a fallback
        // TODO : this base value should be used as a reference, to diff against
        // TODO : this was a hotfix for the union types to work
        String type = base.getValue().getType();
        template.setValue(new Value(type, (code, indent) -> code.append("(", type, ") ").append(basename, "()")));
        isModification = true;
        return Action.skip(Reference.class, this);
    }
    if (node instanceof TTCN3Template) {
        if (isModification) {
            return ModificationParser.getScope(this, template, "", type, node);
        }
        return TemplateValueParser.getScope(this, template, type, node);
    }
    return this;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Reference(org.eclipse.titan.designer.AST.Reference) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Identifier(org.eclipse.titan.designer.AST.Identifier) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Type(org.eclipse.titan.designer.AST.Type) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 13 with FormalParameterList

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

the class Reference method getRefdAssignment.

public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList, final IReferenceChain referenceChain) {
    if (myScope == null || getId() == null) {
        return null;
    }
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp) && !checkParameterList) {
        return referredAssignment;
    }
    lastTimeChecked = timestamp;
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    isErroneous = false;
    detectedModuleId = false;
    detectModid();
    referredAssignment = myScope.getAssBySRef(timestamp, this, referenceChain);
    if (referredAssignment == null) {
        isErroneous = true;
        return referredAssignment;
    }
    referredAssignment.check(timestamp, tempReferenceChain);
    referredAssignment.setUsed();
    if (referredAssignment instanceof Definition) {
        final String referingModuleName = getMyScope().getModuleScope().getName();
        if (!((Definition) referredAssignment).referingHere.contains(referingModuleName)) {
            ((Definition) referredAssignment).referingHere.add(referingModuleName);
        }
    }
    if (checkParameterList) {
        FormalParameterList formalParameterList = null;
        if (referredAssignment instanceof IParameterisedAssignment) {
            formalParameterList = ((IParameterisedAssignment) referredAssignment).getFormalParameterList();
        }
        if (formalParameterList == null) {
            if (!subReferences.isEmpty() && subReferences.get(0) instanceof ParameterisedSubReference) {
                final String message = MessageFormat.format("The referenced {0} cannot have actual parameters", referredAssignment.getDescription());
                getLocation().reportSemanticError(message);
                setIsErroneous(true);
            }
        } else if (!subReferences.isEmpty()) {
            final ISubReference firstSubReference = subReferences.get(0);
            if (firstSubReference instanceof ParameterisedSubReference) {
                formalParameterList.check(timestamp, referredAssignment.getAssignmentType());
                isErroneous = ((ParameterisedSubReference) firstSubReference).checkParameters(timestamp, formalParameterList);
            } else {
                // default values
                if (!Assignment.Assignment_type.A_TEMPLATE.semanticallyEquals(referredAssignment.getAssignmentType()) || !formalParameterList.hasOnlyDefaultValues()) {
                    final String message = MessageFormat.format("Reference to parameterized definition `{0}'' without actual parameter list", referredAssignment.getIdentifier().getDisplayName());
                    getLocation().reportSemanticError(message);
                    setIsErroneous(true);
                }
            }
        }
    }
    return referredAssignment;
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment)

Example 14 with FormalParameterList

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

the class Reference method checkActivateArgument.

/**
 * Checks whether this is a correct altstep activation reference.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 *
 * @return true if the altstep reference is correct, false otherwise.
 */
public final boolean checkActivateArgument(final CompilationTimeStamp timestamp) {
    final Assignment assignment = getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return false;
    }
    if (!Assignment_type.A_ALTSTEP.semanticallyEquals(assignment.getAssignmentType())) {
        getLocation().reportSemanticError(MessageFormat.format(ALTSTEPEXPECTED, assignment.getDescription()));
        setIsErroneous(true);
        return false;
    }
    if (myScope != null) {
        myScope.checkRunsOnScope(timestamp, assignment, this, "activate");
    }
    if (!subReferences.isEmpty()) {
        if (Subreference_type.parameterisedSubReference.equals(subReferences.get(0).getReferenceType())) {
            final ActualParameterList actualParameters = ((ParameterisedSubReference) subReferences.get(0)).getActualParameters();
            final FormalParameterList formalParameterList = ((Def_Altstep) assignment).getFormalParameterList();
            if (formalParameterList != null) {
                return formalParameterList.checkActivateArgument(timestamp, actualParameters, assignment.getDescription());
            }
        }
    }
    return false;
}
Also used : IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)

Example 15 with FormalParameterList

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

the class ReferenceFinder method detectSmallestScope.

/**
 * Detect the smallest scope where the references should be searched
 *
 * @param assignment
 *                The assignment
 * @return The detected scope
 */
private Scope detectSmallestScope(final Assignment assignment) {
    Scope localScope = assignment.getMyScope();
    final Module module = localScope.getModuleScope();
    if (localScope instanceof StatementBlock) {
        final StatementBlock statementBlock = (StatementBlock) localScope;
        if (statementBlock.getMyDefinition() instanceof Def_Altstep) {
            localScope = localScope.getParentScope();
        }
        if (statementBlock.hasEnclosingLoopOrAltguard()) {
            localScope = localScope.getParentScope();
        }
    }
    if (localScope instanceof NamedBridgeScope) {
        localScope = localScope.getParentScope();
    }
    // control,function,testcase,altstep then it is global
    if (localScope instanceof Assignments && localScope.getParentScope() == module) {
        localScope = module;
    } else // treat it as global definition
    if (localScope instanceof ComponentTypeBody) {
        // FIXME this still does not make them global, that is something completely different.
        localScope = module;
    } else // search for actual named parameters everywhere
    if (localScope instanceof FormalParameterList || localScope instanceof RunsOnScope) {
        localScope = module;
    } else // For_Statement that must be searched
    if (localScope instanceof For_Loop_Definitions) {
        localScope = localScope.getParentScope();
    }
    return localScope;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) For_Loop_Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.For_Loop_Definitions) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Aggregations

FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)22 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)14 IType (org.eclipse.titan.designer.AST.IType)10 Assignment (org.eclipse.titan.designer.AST.Assignment)4 IValue (org.eclipse.titan.designer.AST.IValue)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)3 IParameterisedAssignment (org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment)3 Altstep_Type (org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type)3 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)3 ASN1Assignment (org.eclipse.titan.designer.AST.ASN1.ASN1Assignment)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)2 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)2