Search in sources :

Example 61 with Definition

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

the class For_Loop_Definitions method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param isDamaged
 *                true if the location contains the damaged area, false
 *                if only its' location needs to be updated.
 */
@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (!isDamaged) {
        // handle the simple case quickly
        for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
            final Definition temp = iterator.next();
            final Location temporalLocation = temp.getLocation();
            final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
            if (reparser.isAffected(temporalLocation)) {
                if (!temporalLocation.equals(cumulativeLocation)) {
                    reparser.updateLocation(cumulativeLocation);
                }
                reparser.updateLocation(temporalLocation);
            }
        }
        return;
    }
    // calculate damaged region
    int result = 0;
    lastCompilationTimeStamp = 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 (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        final Location tempLocation = temp.getLocation();
        final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
        if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
            enveloped = true;
            leftBoundary = cumulativeLocation.getOffset();
            rightBoundary = cumulativeLocation.getEndOffset();
        } else if (reparser.isDamaged(cumulativeLocation)) {
            nofDamaged++;
            if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
                lastAppendableBeforeChange = temp;
            } else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
                lastPrependableBeforeChange = temp;
            }
        } else {
            if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
                leftBoundary = cumulativeLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
                rightBoundary = cumulativeLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    // was not enveloped
    if (!enveloped && isDamaged) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        // the extension might be 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) {
            // remove damaged stuff
            removeStuffInRange(reparser);
            lastUniquenessCheckTimeStamp = null;
        }
    }
    // update what is left
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        final Location temporalLocation = temp.getLocation();
        final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
        if (reparser.isAffected(cumulativeLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(temporalLocation));
                if (reparser.getNameChanged()) {
                    lastUniquenessCheckTimeStamp = null;
                    reparser.setNameChanged(false);
                }
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    definitions.remove(temp);
                    reparser.extendDamagedRegion(cumulativeLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser);
        lastUniquenessCheckTimeStamp = null;
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        final Location temporalLocation = temp.getLocation();
        final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
        if (reparser.isAffected(temporalLocation)) {
            if (!temporalLocation.equals(cumulativeLocation)) {
                reparser.updateLocation(cumulativeLocation);
            }
            reparser.updateLocation(temporalLocation);
        }
    }
    if (!enveloped && reparser.envelopsDamage(location)) {
        // whole definition region has to be re-parsed
        throw new ReParseException();
    }
    if (result != 0) {
        lastUniquenessCheckTimeStamp = null;
        throw new ReParseException(result);
    }
}
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 62 with Definition

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

the class Group method updateSyntax.

/**
 * Handles the incremental parsing of this list of definitions.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param allImportedModules
 *                the list of module importations found in the same
 *                module.
 * @param allDefinitions
 *                the list of definitions found in the same module.
 * @param allFriends
 *                the list of friend module declarations found in the
 *                same module.
 * @return in case of processing error the minimum amount of semantic
 *         levels that must be destroyed to handle the syntactic
 *         changes, otherwise 0.
 */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> allImportedModules, final List<Definition> allDefinitions, final List<FriendModule> allFriends) throws ReParseException {
    int result = 0;
    Location tempLocation = identifier.getLocation();
    if (reparser.isDamaged(tempLocation)) {
        if (reparser.envelopsDamage(tempLocation) || reparser.isExtending(tempLocation)) {
            reparser.extendDamagedRegion(tempLocation);
            result = reparseIdentifier(reparser);
            if (result != 0) {
                throw new ReParseException(result);
            }
        } else {
            throw new ReParseException();
        }
    } else {
        reparser.updateLocation(tempLocation);
    }
    if (reparser.isDamaged(innerLocation) && !reparser.envelopsDamage(innerLocation)) {
        throw new ReParseException();
    }
    boolean enveloped = false;
    int nofDamaged = 0;
    int leftBoundary = innerLocation.getOffset();
    int rightBoundary = innerLocation.getEndOffset();
    final int damageOffset = reparser.getDamageStart();
    IAppendableSyntax lastAppendableBeforeChange = null;
    IAppendableSyntax lastPrependableBeforeChange = null;
    for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.envelopsDamage(tempLocation)) {
            enveloped = true;
            leftBoundary = tempLocation.getOffset();
            rightBoundary = tempLocation.getEndOffset();
        } else if (reparser.isDamaged(tempLocation)) {
            nofDamaged++;
            if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
                lastAppendableBeforeChange = temp;
            } else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
                lastPrependableBeforeChange = temp;
            }
        // reparser.extendDamagedRegion(temp_location);
        } else {
            if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
                leftBoundary = tempLocation.getEndOffset();
                lastAppendableBeforeChange = temp;
            }
            if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
                rightBoundary = tempLocation.getOffset();
                lastPrependableBeforeChange = temp;
            }
        }
        final Location tempCommentLocation = temp.getCommentLocation();
        if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
            rightBoundary = tempCommentLocation.getOffset();
            lastPrependableBeforeChange = temp;
        }
    }
    // was not enveloped
    if (!enveloped && reparser.envelopsDamage(location)) {
        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) {
        // remove damaged stuff
        removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
    }
    // update what is left
    for (int i = 0; i < groups.size(); i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, allImportedModules, allDefinitions, friendModules);
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    groups.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < importedModules.size(); i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    importedModules.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (int i = 0; i < friendModules.size(); i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    friendModules.remove(i);
                    i--;
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            try {
                final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
                temp.updateSyntax(reparser, isDamaged);
                if (reparser.getNameChanged()) {
                    lastUniquenessCheckTimeStamp = null;
                    reparser.setNameChanged(false);
                }
                if (isDamaged) {
                    temp.checkRoot();
                }
            } catch (ReParseException e) {
                if (e.getDepth() == 1) {
                    enveloped = false;
                    definitions.remove(temp);
                    reparser.extendDamagedRegion(tempLocation);
                    result = 1;
                } else {
                    e.decreaseDepth();
                    throw e;
                }
            }
        }
    }
    if (result == 1) {
        removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
    }
    for (int i = 0, size = groups.size(); i < size; i++) {
        final Group temp = groups.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = importedModules.size(); i < size; i++) {
        final ImportModule temp = importedModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (int i = 0, size = friendModules.size(); i < size; i++) {
        final FriendModule temp = friendModules.get(i);
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
        final Definition temp = iterator.next();
        tempLocation = temp.getLocation();
        if (reparser.isAffected(tempLocation)) {
            reparser.updateLocation(tempLocation);
        }
    }
    if (withAttributesPath != null && reparser.isAffected(withAttributesPath.getLocation())) {
        if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
            reparser.extendDamagedRegion(withAttributesPath.getLocation());
            result = reparseOptionalWithStatement(reparser);
            if (result != 0) {
                throw new ReParseException(result);
            }
            return;
        }
        withAttributesPath.updateSyntax(reparser, reparser.envelopsDamage(withAttributesPath.getLocation()));
        reparser.updateLocation(withAttributesPath.getLocation());
    }
    if (!enveloped && reparser.envelopsDamage(innerLocation)) {
        reparser.extendDamagedRegion(leftBoundary, rightBoundary);
        result = reparseModuleDefinitionsList(reparser);
    }
    reparser.updateLocation(innerLocation);
    if (result > 1) {
        throw new ReParseException(result - 1);
    }
    return;
}
Also used : IAppendableSyntax(org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) Location(org.eclipse.titan.designer.AST.Location)

Example 63 with Definition

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

the class Def_Function method checkPrototype.

/**
 * Checks the prototype attribute set for this function definition.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
public void checkPrototype(final CompilationTimeStamp timestamp) {
    if (EncodingPrototype_type.NONE.equals(prototype)) {
        return;
    }
    // checking formal parameter list
    if (EncodingPrototype_type.CONVERT.equals(prototype)) {
        if (formalParList.getNofParameters() == 1) {
            final FormalParameter parameter = formalParList.getParameterByIndex(0);
            final Assignment_type assignmentType = parameter.getRealAssignmentType();
            if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(assignmentType)) {
                inputType = parameter.getType(timestamp);
            } else {
                parameter.getLocation().reportSemanticError(MessageFormat.format("The parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), parameter.getAssignmentName()));
            }
        } else {
            formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have one parameter instead of {0} for attribute `prototype({1})''", formalParList.getNofParameters(), prototype.getName()));
        }
    } else if (formalParList.getNofParameters() == 2) {
        final FormalParameter firstParameter = formalParList.getParameterByIndex(0);
        if (EncodingPrototype_type.SLIDING.equals(prototype)) {
            if (Assignment_type.A_PAR_VAL_INOUT.semanticallyEquals(firstParameter.getRealAssignmentType())) {
                final Type firstParameterType = firstParameter.getType(timestamp);
                final IType last = firstParameterType.getTypeRefdLast(timestamp);
                if (last.getIsErroneous(timestamp)) {
                    inputType = firstParameterType;
                } else {
                    switch(last.getTypetypeTtcn3()) {
                        case TYPE_OCTETSTRING:
                        case TYPE_CHARSTRING:
                            inputType = firstParameterType;
                            break;
                        default:
                            firstParameter.getLocation().reportSemanticError(MessageFormat.format("The type of the first parameter must be `octetstring'' or `charstring'' for attribute `prototype({0})''", prototype.getName()));
                            break;
                    }
                }
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `inout'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        } else {
            final Assignment_type assignmentType = firstParameter.getRealAssignmentType();
            if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(assignmentType) || Assignment_type.A_PAR_VAL.semanticallyEquals(assignmentType)) {
                inputType = firstParameter.getType(timestamp);
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        }
        final FormalParameter secondParameter = formalParList.getParameterByIndex(1);
        if (Assignment_type.A_PAR_VAL_OUT.semanticallyEquals(secondParameter.getRealAssignmentType())) {
            outputType = secondParameter.getType(timestamp);
        } else {
            secondParameter.getLocation().reportSemanticError(MessageFormat.format("The second parameter must be an `out'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), secondParameter.getAssignmentName()));
        }
    } else {
        formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have two parameters for attribute `prototype({0})'' instead of {1}", prototype.getName(), formalParList.getNofParameters()));
    }
    // checking the return type
    if (EncodingPrototype_type.FAST.equals(prototype)) {
        if (returnType != null) {
            returnType.getLocation().reportSemanticError(MessageFormat.format("The function cannot have return type for attribute `prototype({0})''", prototype.getName()));
        }
    } else {
        if (returnType == null) {
            location.reportSemanticError(MessageFormat.format("The function must have a return type for attribute `prototype({0})''", prototype.getName()));
        } else {
            if (Assignment_type.A_FUNCTION_RTEMP.semanticallyEquals(assignmentType)) {
                returnType.getLocation().reportSemanticError(MessageFormat.format("The function must return a value instead of a template for attribute `prototype({0})''", prototype.getName()));
            }
            if (EncodingPrototype_type.CONVERT.equals(prototype)) {
                outputType = returnType;
            } else {
                final IType last = returnType.getTypeRefdLast(timestamp);
                if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_INTEGER.equals(last.getTypetypeTtcn3())) {
                    returnType.getLocation().reportSemanticError(MessageFormat.format("The return type of the function must be `integer'' instead of `{0}'' for attribute `prototype({1})''", returnType.getTypename(), prototype.getName()));
                }
            }
        }
    }
    // checking the runs on clause
    if (runsOnType != null && runsOnRef != null) {
        runsOnRef.getLocation().reportSemanticError(MessageFormat.format("The function cannot have `runs on'' clause for attribute `prototype({0})''", prototype.getName()));
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) CodeSectionType(org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType)

Example 64 with Definition

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

the class Def_Timer method generateCodeArrayDuration.

private void generateCodeArrayDuration(final JavaGenData aData, final StringBuilder source, final String genName, final ArrayList<String> classNames, final Value defaultDuration2, final int startDim) {
    final ArrayDimension dim = dimensions.get(startDim);
    final int dim_size = (int) dim.getSize();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) defaultDuration2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (v.getValuetype() != Value_type.SEQUENCEOF_VALUE) {
        // ErrorReporter.INTERNAL_ERROR()
        return;
    }
    final SequenceOf_Value value = (SequenceOf_Value) v;
    if (value.getNofComponents() != dim_size && !value.isIndexed()) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    // Value-list notation.
    if (!value.isIndexed()) {
        if (startDim + 1 < dimensions.size()) {
            // boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
            for (int i = 0; i < dim_size; i++) {
                // get_comp_byIndex(i);
                final IValue v_elem = value.getValueByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final String embeddedName = MessageFormat.format("{0}.getAt({1})", genName, i + dim.getOffset());
                generateCodeArrayDuration(aData, source, embeddedName, classNames, (Value) v_elem, startDim + 1);
            }
        } else {
            // We are in the last dimension, the elements of "value" are floats.
            for (int i = 0; i < dim_size; i++) {
                final IValue v_elem = value.getValueByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final ExpressionStruct expression = new ExpressionStruct();
                expression.expression.append(genName);
                expression.expression.append(".getAt(").append(i + dim.getOffset()).append(")");
                // originally set_default_duration(obj_name, i)
                expression.expression.append(".assign(");
                v_elem.generateCodeExpression(aData, expression, true);
                expression.expression.append(')');
                expression.mergeExpression(source);
            }
        }
    // Indexed-list notation.
    } else {
        if (startDim + 1 < dimensions.size()) {
            // boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
            for (int i = 0; i < value.getNofComponents(); ++i) {
                final IValue v_elem = value.getValueByIndex(i);
                final IValue index = value.getIndexByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final String tempId1 = aData.getTemporaryVariableName();
                final String tempIdX = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
                index.generateCodeInit(aData, source, tempIdX);
                source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", classNames.get(classNames.size() - startDim - 2), tempId1, genName, tempIdX));
                generateCodeArrayDuration(aData, source, tempId1, classNames, (Value) v_elem, startDim + 1);
                source.append("}\n");
            }
        } else {
            for (int i = 0; i < value.getNofComponents(); ++i) {
                final IValue v_elem = value.getValueByIndex(i);
                final IValue v_elemIndex = value.getIndexByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final ExpressionStruct expression = new ExpressionStruct();
                final String tempIdX = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
                v_elemIndex.generateCodeInit(aData, source, tempIdX);
                final String embeddedName = MessageFormat.format("{0}.getAt(", genName);
                expression.expression.append(embeddedName).append(tempIdX).append(")");
                // originally set_default_duration(obj_name, i)
                expression.expression.append(".assign(");
                v_elem.generateCodeExpression(aData, expression, true);
                expression.expression.append(')');
                expression.mergeExpression(source);
                source.append("}\n");
            }
        }
    }
    return;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Example 65 with Definition

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

the class Def_Timer method generateCodeInitComp.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInitComp(final JavaGenData aData, final StringBuilder initComp, final Definition definition) {
    if (defaultDuration == null) {
        return;
    }
    if (!(definition instanceof Def_Timer)) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    final Def_Timer baseTimerDefinition = (Def_Timer) definition;
    if (baseTimerDefinition.defaultDuration == null) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    // constants in both timers
    if (defaultDuration.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || baseTimerDefinition.defaultDuration.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || defaultDuration.checkEquality(CompilationTimeStamp.getBaseTimestamp(), baseTimerDefinition.defaultDuration)) {
        if (dimensions == null) {
            final ExpressionStruct expression = new ExpressionStruct();
            expression.expression.append(baseTimerDefinition.getGenNameFromScope(aData, initComp, myScope, ""));
            expression.expression.append(".setDefaultDuration(");
            defaultDuration.generateCodeExpression(aData, expression, true);
            expression.expression.append(')');
            expression.mergeExpression(initComp);
        } else {
            generateCodeArrayDuration(aData, initComp, baseTimerDefinition.getGenNameFromScope(aData, initComp, myScope, ""), new ArrayList<String>(), baseTimerDefinition.defaultDuration, 0);
        }
    }
}
Also used : ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

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