public void check(final CompilationTimeStamp timestamp, final Scope scope) { templateInst.setMyScope(scope); if (isOmit()) { // special case, no type needed if (indicator == Indicator_Type.Before_Indicator || indicator == Indicator_Type.After_Indicator) { if (!hasAllKeyword) { final String message = MessageFormat.format( "Keyword `all'' is expected after `omit'' when omitting all fields {0} the specified field", indicator.getDisplayName()); templateInst.getLocation().reportSemanticError(message); } } else { if (hasAllKeyword) { templateInst .getLocation() .reportSemanticError("Unexpected `all' keyword after `omit' when omitting one field"); } } type = null; return; } if (hasAllKeyword) { templateInst .getLocation() .reportSemanticError("Unexpected `all' keyword after the in-line template"); } // determine the type of the tmpl_inst type = templateInst.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE); if (type == null) { templateInst.getTemplateBody().setLoweridToReference(timestamp); type = templateInst.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE); } if (type == null) { templateInst .getLocation() .reportSemanticError("Cannot determine the type of the in-line template"); return; } type.check(timestamp); IType typeLast = type.getTypeRefdLast(timestamp); if (typeLast == null || typeLast.getIsErroneous(timestamp)) { type = null; return; } if (isRaw) { switch (typeLast.getTypetypeTtcn3()) { case TYPE_BITSTRING: case TYPE_OCTETSTRING: case TYPE_CHARSTRING: case TYPE_UCHARSTRING: break; default: templateInst .getLocation() .reportSemanticError( MessageFormat.format( "An in-line template of type `{0}'' cannot be used as a `raw'' erroneous value", typeLast.getTypename())); } } if (templateInst.getDerivedReference() != null) { templateInst .getLocation() .reportSemanticError( "Reference to a constant value was expected instead of an in-line modified template"); type = null; return; } ITTCN3Template templ = templateInst.getTemplateBody(); if (templ.isValue(timestamp)) { value = templ.getValue(); value.setMyGovernor(type); type.checkThisValueRef(timestamp, value); type.checkThisValue( timestamp, value, new ValueCheckingOptions( Expected_Value_type.EXPECTED_CONSTANT, false, false, true, false, false)); } else { templateInst .getLocation() .reportSemanticError("A specific value without matching symbols was expected"); type = null; return; } }
/** * Checks the SequenceOf_value kind value against this type. * * <p>Please note, that this function can only be called once we know for sure that the value is * of set-of type. * * @param timestamp the timestamp of the actual semantic check cycle. * @param value the value to be checked * @param expectedValue the kind of value expected here. * @param incompleteAllowed wheather incomplete value is allowed or not. * @param implicit_omit true if the implicit omit optional attribute was set for the value, false * otherwise */ public void checkThisValueSequenceOf( final CompilationTimeStamp timestamp, final SequenceOf_Value value, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicit_omit, final boolean strElem) { if (value.isIndexed()) { boolean checkHoles = Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue); BigInteger maxIndex = BigInteger.valueOf(-1); Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(value.getNofComponents()); for (int i = 0, size = value.getNofComponents(); i < size; i++) { IValue component = value.getValueByIndex(i); IValue index = value.getIndexByIndex(i); IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true); IValue indexLast = index.getValueRefdLast(timestamp, referenceChain); referenceChain.release(); if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(indexLast.getValuetype())) { checkHoles = false; } else { BigInteger tempIndex = ((Integer_Value) indexLast).getValueValue(); if (tempIndex.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) { index .getLocation() .reportSemanticError( MessageFormat.format( "A integer value less than `{0}'' was expected for indexing type `{1}'' instead of `{2}''", Integer.MAX_VALUE, getTypename(), tempIndex)); checkHoles = false; } else if (tempIndex.compareTo(BigInteger.ZERO) == -1) { index .getLocation() .reportSemanticError( MessageFormat.format( "A non-negative integer value was expected for indexing type `{0}'' instead of `{1}''", getTypename(), tempIndex)); checkHoles = false; } else if (indexMap.containsKey(tempIndex)) { index .getLocation() .reportSemanticError( MessageFormat.format( "Duplicate index value `{0}'' for components {1} and {2}", tempIndex, indexMap.get(tempIndex), i + 1)); checkHoles = false; } else { indexMap.put(tempIndex, Integer.valueOf(i + 1)); if (maxIndex.compareTo(tempIndex) == -1) { maxIndex = tempIndex; } } } component.setMyGovernor(getOfType()); IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component); getOfType() .checkThisValue( timestamp, tempValue2, new ValueCheckingOptions( expectedValue, incompleteAllowed, false, true, implicit_omit, strElem)); } if (checkHoles) { if (maxIndex.compareTo(BigInteger.valueOf(indexMap.size() - 1)) != 0) { value .getLocation() .reportSemanticError("It's not allowed to create hole(s) in constant values"); } } } else { for (int i = 0, size = value.getNofComponents(); i < size; i++) { IValue component = value.getValueByIndex(i); component.setMyGovernor(getOfType()); if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) { if (!incompleteAllowed) { component.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR); } } else { IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component); getOfType() .checkThisValue( timestamp, tempValue2, new ValueCheckingOptions( expectedValue, incompleteAllowed, false, true, implicit_omit, strElem)); } } } }