Search in sources :

Example 66 with Assignment

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

the class SubType method addTtcnSingle.

/**
 * add TTCN-3 single value sub-type constraint to this sub-type
 */
private boolean addTtcnSingle(final CompilationTimeStamp timestamp, final Value value, final int restrictionIndex) {
    value.setMyScope(myOwner.getMyScope());
    value.setMyGovernor(myOwner);
    final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getTypename() + ".<single_restriction_" + restrictionIndex + ">");
    value.setFullNameParent(bridge);
    IValue last = myOwner.checkThisValueRef(timestamp, value);
    // check if this is type reference, if not then fall through
    final IValue refValue = value.setLoweridToReference(timestamp);
    // Value_type.REFERENCED_VALUE);
    if (refValue.getValuetype() == Value.Value_type.REFERENCED_VALUE) {
        final Reference ref = ((Referenced_Value) refValue).getReference();
        final Assignment ass = ref.getRefdAssignment(timestamp, false);
        if (ass == null) {
            // definition was not found, error was reported
            return false;
        }
        if (ass.getAssignmentType() == Assignment.Assignment_type.A_TYPE) {
            IType t = ass.getType(timestamp);
            t.check(timestamp);
            if (t.getIsErroneous(timestamp)) {
                return false;
            }
            final List<ISubReference> subrefs = ref.getSubreferences();
            if (subrefs.size() > 1) {
                // if there were sub-references then get the referenced field's type
                t = t.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
                if ((t == null) || t.getIsErroneous(timestamp)) {
                    return false;
                }
                t.check(timestamp);
                if (t.getIsErroneous(timestamp)) {
                    return false;
                }
            }
            if (!t.isIdentical(timestamp, myOwner)) {
                value.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' must refer to a type which has the same root type as this type", ref.getDisplayName()));
                return false;
            }
            // check subtype of referenced type
            final SubType tSt = t.getSubtype();
            if ((tSt == null) || (tSt.subtypeConstraint == null)) {
                value.getLocation().reportSemanticError(MessageFormat.format("Type referenced by `{0}'' does not have a subtype", ref.getDisplayName()));
                return false;
            }
            // check circular sub-type reference
            if (!addParentSubtype(tSt)) {
                return false;
            }
            if (tSt.getIsErroneous(timestamp)) {
                return false;
            }
            if (tSt.subtypeType != subtypeType) {
                ErrorReporter.INTERNAL_ERROR();
                return false;
            }
            // add the sub-type as union
            if (subtypeConstraint == null) {
                subtypeConstraint = tSt.subtypeConstraint;
            } else {
                subtypeConstraint = subtypeConstraint.union(tSt.subtypeConstraint);
            }
            return true;
        }
    }
    myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    last = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp) || last.isUnfoldable(timestamp)) {
        return false;
    }
    // create a single value constraint
    SubtypeConstraint sc;
    switch(subtypeType) {
        case ST_INTEGER:
            sc = new RangeListConstraint(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case ST_FLOAT:
            sc = new RealRangeListConstraint(((Real_Value) last).getValue());
            break;
        case ST_BOOLEAN:
            sc = new BooleanListConstraint(((Boolean_Value) last).getValue());
            break;
        case ST_VERDICTTYPE:
            sc = new VerdicttypeListConstraint(((Verdict_Value) last).getValue());
            break;
        case ST_BITSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, ((Bitstring_Value) last).getValue());
            break;
        case ST_HEXSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, ((Hexstring_Value) last).getValue());
            break;
        case ST_OCTETSTRING:
            sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, ((Octetstring_Value) last).getValue());
            break;
        case ST_CHARSTRING:
            if (last.getValuetype() != Value.Value_type.CHARSTRING_VALUE) {
                return false;
            }
            sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new StringValueConstraint(((Charstring_Value) last).getValue()));
            break;
        case ST_UNIVERSAL_CHARSTRING:
            switch(last.getValuetype()) {
                case CHARSTRING_VALUE:
                    sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(new UniversalCharstring(((Charstring_Value) last).getValue())));
                    break;
                case UNIVERSALCHARSTRING_VALUE:
                    sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(((UniversalCharstring_Value) last).getValue()));
                    break;
                default:
                    return false;
            }
            break;
        case ST_OBJID:
        case ST_ENUM:
        case ST_UNION:
        case ST_RECORD:
        case ST_SET:
        case ST_FUNCTION:
        case ST_ALTSTEP:
        case ST_TESTCASE:
            sc = new ValueListConstraint(last);
            break;
        case ST_RECORDOF:
        case ST_SETOF:
            sc = new ValueListAndSizeConstraint(last);
            break;
        default:
            ErrorReporter.INTERNAL_ERROR();
            return false;
    }
    // add next value using union operation
    if (subtypeConstraint == null) {
        subtypeConstraint = sc;
    } else {
        subtypeConstraint = subtypeConstraint.union(sc);
    }
    return true;
}
Also used : IType(org.eclipse.titan.designer.AST.IType) Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) ISubReference(org.eclipse.titan.designer.AST.ISubReference)

Example 67 with Assignment

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

the class UnusedGlobalDefinition method process.

@Override
protected void process(IProject project, Problems problems) {
    TITANDebugConsole.println("Unused global definition");
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    final List<Module> modules = new ArrayList<Module>();
    final Set<Assignment> unused = new HashSet<Assignment>();
    for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
        Module module = projectSourceParser.getModuleByName(moduleName);
        modules.add(module);
        final GlobalDefinitionCheck chek = new GlobalDefinitionCheck();
        module.accept(chek);
        unused.addAll(chek.getDefinitions());
    }
    for (Module module : modules) {
        final GlobalUsedDefinitionCheck chekUsed = new GlobalUsedDefinitionCheck();
        module.accept(chekUsed);
        unused.removeAll(chekUsed.getDefinitions());
    }
    for (Assignment ass : unused) {
        final String name = ass.getIdentifier().getDisplayName();
        final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used globally", ass.getAssignmentName(), name);
        problems.report(ass.getIdentifier().getLocation(), msg);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) HashSet(java.util.HashSet)

Example 68 with Assignment

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

the class UnusedRetval method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof Unknown_Instance_Statement) {
        final Unknown_Instance_Statement u = (Unknown_Instance_Statement) node;
        final Statement s = u.getRealStatement();
        if (s instanceof Function_Instance_Statement) {
            final Function_Instance_Statement f = (Function_Instance_Statement) s;
            final Assignment assignment = f.getReference().getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            if (assignment != null) {
                String msg;
                switch(assignment.getAssignmentType()) {
                    case A_FUNCTION_RVAL:
                    case A_EXT_FUNCTION_RVAL:
                        msg = MessageFormat.format(UNUSEDRETURN1, assignment.getIdentifier().getDisplayName());
                        problems.report(f.getLocation(), msg);
                        break;
                    case A_FUNCTION_RTEMP:
                    case A_EXT_FUNCTION_RTEMP:
                        msg = MessageFormat.format(UNUSEDRETURN2, assignment.getIdentifier().getDisplayName());
                        problems.report(f.getLocation(), msg);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Unknown_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Instance_Statement) Function_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Function_Instance_Statement) Function_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Function_Instance_Statement) Unknown_Instance_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Instance_Statement)

Example 69 with Assignment

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

the class IterateOnWrongArray method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof For_Statement)) {
        return;
    }
    final For_Statement fs = (For_Statement) node;
    // find the loop variable
    final LoopVariableFinder lvVisitor = new LoopVariableFinder();
    fs.accept(lvVisitor);
    final Reference loopVar = lvVisitor.getLoopVariable();
    if (loopVar == null) {
        return;
    }
    final Assignment loopVarDef = loopVar.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (loopVarDef == null) {
        return;
    }
    // find the array over which the loop iterates
    final Value finalExpr = fs.getFinalExpression();
    if (finalExpr == null) {
        return;
    }
    final FinalExprVisitor exprVisitor = new FinalExprVisitor();
    finalExpr.accept(exprVisitor);
    final List<Reference> arraysIterated = exprVisitor.getArraysIterated();
    if (arraysIterated.isEmpty()) {
        return;
    }
    /* search every statement block for references that has the loop variable in them and the
		 * reference differs from the reference of the array over which the for loop iterates */
    final StatementBlock sb = fs.getStatementBlock();
    if (sb == null) {
        return;
    }
    final StatementBlockVisitor sbVisitor = new StatementBlockVisitor(loopVar, arraysIterated);
    sb.accept(sbVisitor);
    final List<Reference> matchingRefs = sbVisitor.getMatchingReferences();
    for (final Reference r : matchingRefs) {
        if (r.getUsedOnLeftHandSide()) {
            continue;
        }
        problems.report(r.getLocation(), MessageFormat.format(ERR_MSG, loopVar));
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) Reference(org.eclipse.titan.designer.AST.Reference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Value(org.eclipse.titan.designer.AST.Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) IValue(org.eclipse.titan.designer.AST.IValue) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 70 with Assignment

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

the class EffCouplingDetector method visit.

@Override
public int visit(final IVisitableNode node) {
    if (node instanceof Reference) {
        final Reference reference = (Reference) node;
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment != null) {
            final Module referencedModule = assignment.getMyScope().getModuleScope();
            if (!ownModule.equals(referencedModule)) {
                efferentCoupling.get(ownModule).add(assignment);
            }
        }
    }
    return V_CONTINUE;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Reference(org.eclipse.titan.designer.AST.Reference) Module(org.eclipse.titan.designer.AST.Module)

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