use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method evaluateIsbound.
@Override
public /**
* {@inheritDoc}
*/
boolean evaluateIsbound(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return true;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return false;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
return false;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
return false;
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
return false;
}
break;
default:
return false;
}
if (values.hasNamedValueWithName(fieldId)) {
// we can move on with the check
return values.getNamedValueByName(fieldId).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
}
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
return false;
}
final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.evaluateIsbound(timestamp, reference, actualSubReference + 1);
} else if (compField.hasDefault()) {
return compField.getDefault().evaluateIsbound(timestamp, reference, actualSubReference + 1);
}
return false;
case parameterisedSubReference:
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method checkVarAssignment.
private void checkVarAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final IValue value) {
final IType varType = getType(timestamp, assignment);
if (varType == null || value == null) {
isErroneous = true;
return;
}
final IType type = varType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
isErroneous = true;
return;
}
value.setMyGovernor(type);
IValue lastValue = type.checkThisValueRef(timestamp, value);
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
lastValue = lastValue.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (Value_type.OMIT_VALUE.equals(lastValue.getValuetype())) {
final ISubReference lastReference = reference.removeLastSubReference();
if (lastReference == null || lastReference.getId() == null) {
value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
isErroneous = true;
reference.addSubReference(lastReference);
return;
}
final Identifier lastField = lastReference.getId();
final List<ISubReference> baseReference = reference.getSubreferences(0, reference.getSubreferences().size() - 1);
reference.addSubReference(lastReference);
final Reference newReference = new TemporalReference(null, baseReference);
newReference.clearStringElementReferencing();
IType baseType = varType.getFieldType(timestamp, newReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (baseType == null) {
isErroneous = true;
return;
}
baseType = baseType.getTypeRefdLast(timestamp);
if (baseType.getIsErroneous(timestamp)) {
isErroneous = true;
return;
}
CompField componentField;
switch(baseType.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
componentField = ((TTCN3_Sequence_Type) baseType).getComponentByName(lastField.getName());
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
case TYPE_ASN1_SEQUENCE:
componentField = ((ASN1_Sequence_Type) baseType).getComponentByName(lastField);
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
case TYPE_TTCN3_SET:
componentField = ((TTCN3_Set_Type) baseType).getComponentByName(lastField.getName());
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
case TYPE_ASN1_SET:
componentField = ((ASN1_Set_Type) baseType).getComponentByName(lastField);
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
default:
// TODO:check this!!!
value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
value.setIsErroneous(true);
isErroneous = true;
break;
}
} else {
final boolean isStringElement = reference.refersToStringElement();
selfReference = type.checkThisValue(timestamp, value, assignment, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, !isStringElement, false, isStringElement));
if (isStringElement) {
// The length of the right hand side should be 1
final IType lastType = type.getTypeRefdLast(timestamp);
int stringLength = 1;
switch(lastType.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
if (!Value_type.BITSTRING_VALUE.equals(lastValue.getValuetype())) {
return;
}
stringLength = ((Bitstring_Value) lastValue).getValueLength();
break;
case TYPE_HEXSTRING:
if (!Value_type.HEXSTRING_VALUE.equals(lastValue.getValuetype())) {
lastValue = null;
} else {
stringLength = ((Hexstring_Value) lastValue).getValueLength();
}
break;
case TYPE_OCTETSTRING:
if (!Value_type.OCTETSTRING_VALUE.equals(lastValue.getValuetype())) {
return;
}
stringLength = ((Octetstring_Value) lastValue).getValueLength();
break;
case TYPE_CHARSTRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_IA5STRING:
case TYPE_VISIBLESTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
if (!Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
return;
}
stringLength = ((Charstring_Value) lastValue).getValueLength();
break;
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_GRAPHICSTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_OBJECTDESCRIPTOR:
if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(lastValue.getValuetype())) {
stringLength = ((UniversalCharstring_Value) lastValue).getValueLength();
} else if (Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
stringLength = ((Charstring_Value) lastValue).getValueLength();
} else {
return;
}
break;
default:
lastValue = null;
return;
}
if (stringLength != 1) {
final String message = MessageFormat.format("The length of the string to be assigned to a string element of type `{0}'' should be 1 instead of {1}", type.getTypename(), stringLength);
value.getLocation().reportSemanticError(message);
value.setIsErroneous(true);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Sequence_Type method checkThisValueSeq.
/**
* Checks the Sequence_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 sequence type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param value
* the value to be checked
* @param expectedValue
* the expected kind of the value.
* @param incompleteAllowed
* wheather incomplete value is allowed or not.
* @param implicitOmit
* true if the implicit omit optional attribute was set
* for the value, false otherwise
*/
private boolean checkThisValueSeq(final CompilationTimeStamp timestamp, final Sequence_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
boolean selfReference = false;
final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
final CompilationTimeStamp valueTimeStamp = value.getLastTimeChecked();
if (valueTimeStamp == null || valueTimeStamp.isLess(timestamp)) {
value.removeGeneratedValues();
}
final boolean isAsn = value.isAsn();
boolean inSnyc = true;
final int nofTypeComponents = getNofComponents(timestamp);
final int nofValueComponents = value.getNofComponents();
int nextIndex = 0;
CompField lastCompField = null;
int sequenceIndex = 0;
for (int i = 0; i < nofValueComponents; i++, sequenceIndex++) {
final NamedValue namedValue = value.getSeqValueByIndex(i);
final Identifier valueId = namedValue.getName();
if (!hasComponentWithName(valueId)) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDERRORASN1 : NONEXISTENTFIELDERRORTTCN3, namedValue.getName().getDisplayName(), getTypename()));
inSnyc = false;
} else {
if (componentMap.containsKey(valueId.getName())) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUBLICATEDFIELDAGAINASN1 : DUBLICATEDFIELDAGAINTTCN3, valueId.getDisplayName()));
final Location tempLocation = componentMap.get(valueId.getName()).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEDFIELDFIRSTASN1 : DUPLICATEDFIELDFIRSTTTCN3, valueId.getDisplayName()));
inSnyc = false;
} else {
componentMap.put(valueId.getName(), namedValue);
}
final CompField componentField = getComponentByName(valueId);
if (inSnyc) {
if (incompleteAllowed) {
boolean found = false;
for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
final CompField field2 = getComponentByIndex(j);
if (valueId.getName().equals(field2.getIdentifier().getName())) {
lastCompField = field2;
nextIndex = j + 1;
found = true;
}
}
if (lastCompField != null && !found) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? WRONGFIELDORDERASN1 : WRONGFIELDORDERTTCN3, valueId.getDisplayName(), lastCompField.getIdentifier().getDisplayName()));
}
} else {
CompField field2 = getComponentByIndex(sequenceIndex);
final CompField field2Original = field2;
boolean isOptional = field2.isOptional();
if (!isOptional && field2.hasDefault() && defaultAsOptional) {
isOptional = true;
}
while (implicitOmit && sequenceIndex < getNofComponents(timestamp) && componentField != field2 && isOptional) {
++sequenceIndex;
field2 = getComponentByIndex(sequenceIndex);
}
if (sequenceIndex >= getNofComponents(timestamp) || componentField != field2) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? UNEXPECTEDFIELDASN1 : UNEXPECTEDFIELDTTCN3, valueId.getDisplayName(), field2Original.getIdentifier().getDisplayName()));
}
}
}
final Type type = componentField.getType();
final IValue componentValue = namedValue.getValue();
if (componentValue != null) {
componentValue.setMyGovernor(type);
final IValue temporalValue = type.checkThisValueRef(timestamp, componentValue);
boolean isOptional = componentField.isOptional();
if (!isOptional && componentField.hasDefault() && defaultAsOptional) {
isOptional = true;
}
selfReference |= type.checkThisValue(timestamp, temporalValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, isOptional, true, implicitOmit, strElem));
}
}
}
if (!incompleteAllowed || strictConstantCheckingSeverity) {
for (int i = 0; i < nofTypeComponents; i++) {
final Identifier id = getComponentByIndex(i).getIdentifier();
if (!componentMap.containsKey(id.getName())) {
if (getComponentByIndex(i).isOptional() && implicitOmit) {
value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
} else {
value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
}
}
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Sequence_Type method getSubrefsAsArray.
// This is the same as in ASN1_Set_type
@Override
public /**
* {@inheritDoc}
*/
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return true;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
return false;
case fieldSubReference:
{
if (components == null) {
return false;
}
final Identifier id = subreference.getId();
final CompField compField = components.getCompByName(id);
if (compField == null) {
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return false;
}
final IType fieldType = compField.getType();
if (fieldType == null) {
return false;
}
final int fieldIndex = components.indexOf(compField);
subrefsArray.add(fieldIndex);
typeArray.add(this);
return fieldType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
}
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return false;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Sequence_Type method isPresentAnyvalueEmbeddedField.
@Override
public /**
* {@inheritDoc}
*/
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return true;
}
if (beginIndex >= subreferences.size()) {
return true;
}
final ISubReference subReference = subreferences.get(beginIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return true;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
final CompField compField = getComponentByName(fieldId);
if (compField.isOptional()) {
return false;
}
return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
Aggregations