Search in sources :

Example 16 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class CompFieldMap method updateSyntax.

@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        lastCompilationTimeStamp = null;
        if (doubleComponents != null) {
            fields.addAll(doubleComponents);
            doubleComponents = null;
            lastUniquenessCheck = null;
        }
        boolean enveloped = false;
        int nofDamaged = 0;
        int leftBoundary = location.getOffset();
        int rightBoundary = location.getEndOffset();
        final int damageOffset = reparser.getDamageStart();
        IAppendableSyntax lastAppendableBeforeChange = null;
        IAppendableSyntax lastPrependableBeforeChange = null;
        for (int i = 0, size = fields.size(); i < size && !enveloped; i++) {
            final CompField field = fields.get(i);
            final Location tempLocation = field.getLocation();
            // move offset to commentLocation
            if (field.getCommentLocation() != null) {
                tempLocation.setOffset(field.getCommentLocation().getOffset());
            }
            if (reparser.envelopsDamage(tempLocation)) {
                enveloped = true;
                leftBoundary = tempLocation.getOffset();
                rightBoundary = tempLocation.getEndOffset();
            } else if (reparser.isDamaged(tempLocation)) {
                nofDamaged++;
                if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
                    lastAppendableBeforeChange = field;
                } else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
                    lastPrependableBeforeChange = field;
                }
            } else {
                if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                    leftBoundary = tempLocation.getEndOffset();
                    lastAppendableBeforeChange = field;
                }
                if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                    rightBoundary = tempLocation.getOffset();
                    lastPrependableBeforeChange = field;
                }
            }
        }
        // extend the reparser to the calculated values if the damage was not enveloped
        if (!enveloped) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        }
        // correct
        if (lastAppendableBeforeChange != null) {
            final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
            if (isBeingExtended) {
                leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (lastPrependableBeforeChange != null) {
            final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
            if (temp != null && reparser.endsWithToken(temp)) {
                rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
                nofDamaged++;
                enveloped = false;
                reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            }
        }
        if (nofDamaged != 0) {
            removeStuffInRange(reparser);
        }
        for (int i = 0; i < fields.size(); i++) {
            final CompField field = fields.get(i);
            final Location tempLocation = field.getLocation();
            if (reparser.isAffectedAppended(tempLocation)) {
                try {
                    field.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
                    reparser.updateLocation(field.getLocation());
                } catch (ReParseException e) {
                    if (e.getDepth() == 1) {
                        enveloped = false;
                        fields.remove(i);
                        i--;
                        reparser.extendDamagedRegion(tempLocation);
                    } else {
                        e.decreaseDepth();
                        throw e;
                    }
                }
            }
        }
        if (!enveloped) {
            reparser.extendDamagedRegion(leftBoundary, rightBoundary);
            int result = reparse(reparser);
            if (result == 0) {
                return;
            }
            throw new ReParseException(Math.max(--result, 0));
        }
        return;
    }
    for (int i = 0, size = fields.size(); i < size; i++) {
        final CompField field = fields.get(i);
        field.updateSyntax(reparser, false);
        reparser.updateLocation(field.getLocation());
    }
    if (doubleComponents != null) {
        for (int i = 0, size = doubleComponents.size(); i < size; i++) {
            final CompField field = doubleComponents.get(i);
            field.updateSyntax(reparser, false);
            reparser.updateLocation(field.getLocation());
        }
    }
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 17 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class UStringValueConstraint method except.

/**
 * return (first - second) set
 */
@Override
public UStringValueConstraint except(final SubtypeConstraint other) {
    final UStringValueConstraint o = (UStringValueConstraint) other;
    final Set<UniversalCharstring> returnValue = new TreeSet<UniversalCharstring>();
    for (UniversalCharstring str : values) {
        if (!o.values.contains(str)) {
            returnValue.add(str);
        }
    }
    return new UStringValueConstraint(returnValue);
}
Also used : TreeSet(java.util.TreeSet) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Example 18 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values 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 19 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Referenced_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last == this) {
        final ExpressionStruct expression = new ExpressionStruct();
        expression.expression.append(name);
        expression.expression.append(".assign(");
        reference.generateConstRef(aData, expression);
        expression.expression.append(")");
        expression.mergeExpression(source);
        return source;
    }
    // the code generation is based on the referred value
    if (last.canGenerateSingleExpression() && myScope.getModuleScope() == last.getMyScope().getModuleScope()) {
        // simple substitution for in-line values within the same module
        source.append(MessageFormat.format("{0}.assign({1});\n", name, last.generateSingleExpression(aData)));
    } else {
        // TODO might need initialization see needs_init_precede
        // TODO Value.cc:generate_code_init_refd
        source.append(MessageFormat.format("{0}.assign({1});\n", name, last.getGenNameOwn(myScope)));
    }
    return source;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 20 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Sequence_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 * generate_code_init_se in the compiler
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (convertedValue != null) {
        return convertedValue.generateCodeInit(aData, source, name);
    }
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    int nofComps = 0;
    switch(type.getTypetype()) {
        case TYPE_TTCN3_SEQUENCE:
            nofComps = ((TTCN3_Sequence_Type) type).getNofComponents();
            break;
        case TYPE_ASN1_SEQUENCE:
            nofComps = ((ASN1_Sequence_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
    }
    if (nofComps == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
        return source;
    }
    CompField compField = null;
    for (int i = 0; i < nofComps; i++) {
        switch(type.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                compField = ((TTCN3_Sequence_Type) type).getComponentByIndex(i);
                break;
            case TYPE_ASN1_SEQUENCE:
                compField = ((ASN1_Sequence_Type) type).getComponentByIndex(i);
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
        }
        final Identifier fieldName = compField.getIdentifier();
        IValue fieldValue;
        if (hasComponentWithName(fieldName)) {
            fieldValue = getComponentByName(fieldName).getValue();
            if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
                continue;
            } else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
                fieldValue = null;
            }
        } else // TODO add support for asn default values when needed
        {
            continue;
        }
        final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
        if (fieldValue != null) {
            // TODO handle the case when temporary reference is needed
            final StringBuilder embeddedName = new StringBuilder();
            embeddedName.append(name);
            embeddedName.append(".get");
            embeddedName.append(javaGetterName);
            embeddedName.append("()");
            if (compField.isOptional()) /*&& fieldValue.isCompound() */
            {
                embeddedName.append(".get()");
            }
            // TODO add extra handling for optional fields
            fieldValue.generateCodeInit(aData, source, embeddedName.toString());
        } else {
            aData.addBuiltinTypeImport("Base_Template.template_sel");
            source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
        }
    }
    return source;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Identifier (org.eclipse.titan.designer.AST.Identifier)9 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)9 HashMap (java.util.HashMap)8 IType (org.eclipse.titan.designer.AST.IType)6 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Value (org.eclipse.titan.designer.AST.Value)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Module (org.eclipse.titan.designer.AST.Module)3 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)3 List (java.util.List)2 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2