use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class SizeOfExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*
* @return the size of the expression, or -1 in case of error
*/
private long checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
Expected_Value_type internalExpectedValue;
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
internalExpectedValue = Expected_Value_type.EXPECTED_TEMPLATE;
} else {
internalExpectedValue = expectedValue;
}
ITTCN3Template template = templateInstance.getTemplateBody();
template.setLoweridToReference(timestamp);
template = template.getTemplateReferencedLast(timestamp, referenceChain);
if (template.getIsErroneous(timestamp)) {
setIsErroneous(true);
return -1;
}
// Timer and port arrays are handled separately
if (template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
final SpecificValue_Template specValTempl = (SpecificValue_Template) template;
IValue val = specValTempl.getSpecificValue();
val.setMyGovernor(specValTempl.getMyGovernor());
if (val.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
val = val.setLoweridToReference(timestamp);
}
if (val != null && val.getValuetype() == Value_type.REFERENCED_VALUE) {
final Referenced_Value referencedValue = (Referenced_Value) val;
final Reference ref = referencedValue.getReference();
final Assignment temporalAss = ref.getRefdAssignment(timestamp, true);
if (temporalAss != null) {
final Assignment_type asstype = temporalAss.getAssignmentType();
ArrayDimensions dimensions;
if (asstype == Assignment_type.A_PORT) {
dimensions = ((Def_Port) temporalAss).getDimensions();
return checkTimerPort(timestamp, ref, dimensions, temporalAss);
} else if (asstype == Assignment_type.A_TIMER) {
dimensions = ((Def_Timer) temporalAss).getDimensions();
return checkTimerPort(timestamp, ref, dimensions, temporalAss);
}
}
}
}
IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectedValue);
if (governor == null) {
final ITTCN3Template templ = template.setLoweridToReference(timestamp);
governor = templ.getExpressionGovernor(timestamp, internalExpectedValue);
}
if (governor == null) {
if (!template.getIsErroneous(timestamp)) {
templateInstance.getLocation().reportSemanticError("Cannot determine the type of the argument in the `sizeof' operation. If type is known, use valueof(<type>: ...) as argument.");
}
setIsErroneous(true);
return -1;
}
IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, internalExpectedValue);
if (isErroneous) {
return -1;
}
IType type = governor.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
case TYPE_ARRAY:
case TYPE_OBJECTID:
case TYPE_ROID:
case TYPE_UNDEFINED:
break;
default:
templateInstance.getLocation().reportSemanticError("Reference to a value or template of type record, record of, set, set of, objid or array was expected");
setIsErroneous(true);
return -1;
}
IValue value = null;
Reference reference = null;
Assignment assignment = null;
List<ISubReference> subreferences = null;
switch(template.getTemplatetype()) {
case INDEXED_TEMPLATE_LIST:
return -1;
case TEMPLATE_REFD:
reference = ((Referenced_Template) template).getReference();
assignment = reference.getRefdAssignment(timestamp, false);
subreferences = reference.getSubreferences();
break;
case TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case SUBSET_MATCH:
case SUPERSET_MATCH:
// compute later
break;
case SPECIFIC_VALUE:
value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
if (value != null) {
switch(value.getValuetype()) {
case SEQUENCEOF_VALUE:
case SETOF_VALUE:
case ARRAY_VALUE:
case RELATIVEOBJECTIDENTIFIER_VALUE:
case OBJECTID_VALUE:
case SEQUENCE_VALUE:
case SET_VALUE:
break;
case REFERENCED_VALUE:
{
reference = ((Referenced_Value) value).getReference();
assignment = reference.getRefdAssignment(timestamp, false);
subreferences = reference.getSubreferences();
break;
}
default:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to `{0}''", value.createStringRepresentation()));
setIsErroneous(true);
return -1;
}
}
break;
default:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to {0}", template.getTemplateTypeName()));
setIsErroneous(true);
return -1;
}
if (assignment != null) {
if (assignment.getIsErroneous()) {
setIsErroneous(true);
return -1;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
value = ((Def_Const) assignment).getValue();
break;
case A_EXT_CONST:
case A_MODULEPAR:
case A_MODULEPAR_TEMPLATE:
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluable) constant value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
switch(internalExpectedValue) {
case EXPECTED_CONSTANT:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
case EXPECTED_STATIC_VALUE:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
default:
break;
}
break;
case A_TEMPLATE:
template = ((Def_Template) assignment).getTemplate(timestamp);
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
switch(internalExpectedValue) {
case EXPECTED_CONSTANT:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
case EXPECTED_STATIC_VALUE:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
default:
break;
}
break;
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of a call of {0}, which returns a template", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_TIMER:
case A_PORT:
// were already checked separately.
break;
default:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue) ? "value or template" : "value", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
type = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null || type.getIsErroneous(timestamp)) {
setIsErroneous(true);
return -1;
}
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
case TYPE_ARRAY:
case TYPE_OBJECTID:
case TYPE_ROID:
case TYPE_UNDEFINED:
break;
default:
templateInstance.getLocation().reportSemanticError("Reference to a value or template of type record, record of, set, set of, objid or array was expected");
setIsErroneous(true);
return -1;
}
}
// check for index overflows in subrefs if possible
if (value != null) {
switch(value.getValuetype()) {
case SEQUENCEOF_VALUE:
if (((SequenceOf_Value) value).isIndexed()) {
return -1;
}
break;
case SETOF_VALUE:
if (((SetOf_Value) value).isIndexed()) {
return -1;
}
break;
case ARRAY_VALUE:
if (((Array_Value) value).isIndexed()) {
return -1;
}
break;
default:
break;
}
/* The reference points to a constant. */
if (subreferences != null && !reference.hasUnfoldableIndexSubReference(timestamp)) {
value = value.getReferencedSubValue(timestamp, reference, 1, referenceChain);
if (value == null) {
setIsErroneous(true);
return -1;
}
value = value.getValueRefdLast(timestamp, referenceChain);
} else {
// stop processing
value = null;
}
} else if (template != null) {
/* The size of INDEXED_TEMPLATE_LIST nodes is unknown at compile
time. Don't try to evaluate it at compile time. */
if (reference != null && reference.hasUnfoldableIndexSubReference(timestamp)) {
return -1;
}
if (reference != null && subreferences != null) {
template = template.getReferencedSubTemplate(timestamp, reference, referenceChain);
if (template == null) {
setIsErroneous(true);
return -1;
}
template = template.getTemplateReferencedLast(timestamp);
}
}
if (template != null) {
if (template.getIsErroneous(timestamp)) {
setIsErroneous(true);
return -1;
}
switch(template.getTemplatetype()) {
case TEMPLATE_REFD:
template = null;
break;
case SPECIFIC_VALUE:
value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
template = null;
break;
case TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case SUBSET_MATCH:
case SUPERSET_MATCH:
break;
default:
// FIXME this can not happen
templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to {0}", template.getTemplateTypeName()));
setIsErroneous(true);
return -1;
}
}
if (value != null) {
switch(value.getValuetype()) {
case SEQUENCEOF_VALUE:
case SETOF_VALUE:
case ARRAY_VALUE:
case RELATIVEOBJECTIDENTIFIER_VALUE:
case OBJECTID_VALUE:
case SEQUENCE_VALUE:
case SET_VALUE:
break;
default:
value = null;
return -1;
}
}
/* evaluation */
if (Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
return ((Array_Type) type).getDimension().getSize();
} else if (template != null) {
return evaluateTemplate(template, timestamp);
} else if (value != null) {
return evaluateValue(value);
} else {
return -1;
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Octetstring_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
final Value arrayIndex = ((ArraySubReference) subreference).getValue();
final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, refChain);
if (!valueIndex.isUnfoldable(timestamp)) {
if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
final int index = ((Integer_Value) valueIndex).intValue();
return getStringElement(index, arrayIndex.getLocation());
}
arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
return null;
}
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Real_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method checkExpressionOmitComparison.
@Override
public /**
* {@inheritDoc}
*/
void checkExpressionOmitComparison(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (getIsErroneous(timestamp)) {
return;
}
final List<ISubReference> subreferences = new ArrayList<ISubReference>();
subreferences.addAll(reference.getSubreferences());
if (subreferences.size() <= 1) {
return;
}
final ISubReference subreference = subreferences.remove(subreferences.size() - 1);
final Identifier id = subreference.getId();
if (id == null) {
getLocation().reportSemanticError("Only a reference pointing to an optional record or set field can be compared with `omit'");
setIsErroneous(true);
return;
}
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return;
}
IType type = assignment.getType(timestamp);
if (type == null) {
setIsErroneous(true);
return;
}
final Reference tempReference = new Reference(null, subreferences);
tempReference.setFullNameParent(this);
tempReference.setMyScope(myScope);
type = type.getFieldType(timestamp, tempReference, 1, expectedValue, false);
if (type == null) {
setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type == null || type.getIsErroneous(timestamp)) {
setIsErroneous(true);
return;
}
switch(type.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
if (!((ASN1_Sequence_Type) type).hasComponentWithName(id)) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((ASN1_Sequence_Type) type).getComponentByName(id).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
case TYPE_TTCN3_SEQUENCE:
if (!((TTCN3_Sequence_Type) type).hasComponentWithName(id.getName())) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((TTCN3_Sequence_Type) type).getComponentByName(id.getName()).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(id)) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((ASN1_Set_Type) type).getComponentByName(id).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(id.getName())) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((TTCN3_Set_Type) type).getComponentByName(id.getName()).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
default:
getLocation().reportSemanticError("Only a reference pointing to an optional record or set field can be compared with `omit'");
setIsErroneous(true);
break;
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
IValue result = getValueRefdLast(timestamp, refChain);
if (result != null && result != this) {
result = result.getReferencedSubValue(timestamp, reference, actualSubReference, refChain);
if (result != null && result.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
return result;
}
return this;
}
Aggregations