use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance 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.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class IsBoundExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (templateInstance == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
ITTCN3Template template = templateInstance.getTemplateBody();
template = template.getTemplateReferencedLast(timestamp);
boolean result = false;
if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
if (last != null && Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
result = ((SpecificValue_Template) last).getValue().evaluateIsbound(timestamp, ((Referenced_Template) template).getReference(), 1);
}
} else if (template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
final IValue value = ((SpecificValue_Template) template).getValue();
if (value.getValuetype() == Value_type.REFERENCED_VALUE) {
result = value.evaluateIsbound(timestamp, ((Referenced_Value) value).getReference(), 1);
} else {
result = !value.getIsErroneous(timestamp);
}
}
lastValue = new Boolean_Value(result);
lastValue.copyGeneralProperties(this);
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class IsBoundExpression method isUnfoldable.
@Override
public /**
* {@inheritDoc}
*/
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (templateInstance == null) {
return true;
}
final ITTCN3Template template = templateInstance.getTemplateBody().setLoweridToReference(timestamp);
if (templateInstance.getDerivedReference() != null) {
return true;
}
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
final IValue specificValue = ((SpecificValue_Template) template).getValue();
if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
final Reference reference = ((Referenced_Value) specificValue).getReference();
final Assignment ass = reference.getRefdAssignment(timestamp, false);
if (ass == null) {
return true;
}
switch(ass.getAssignmentType()) {
case A_OBJECT:
case A_OS:
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
break;
default:
return true;
}
// TODO improve to better detect unbound
// elements
final IValue last = specificValue.getValueRefdLast(timestamp, expectedValue, null);
if (last == null) {
return true;
}
if (last == this) {
return getIsErroneous(timestamp);
}
return last.isUnfoldable(timestamp, expectedValue, referenceChain);
}
return specificValue.isUnfoldable(timestamp, expectedValue, referenceChain);
} else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
final Reference reference = ((Referenced_Template) template).getReference();
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
return true;
}
switch(ass.getAssignmentType()) {
case A_TEMPLATE:
break;
default:
return true;
}
// TODO improve to better detect unbound elements
final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
if (last == null) {
return true;
}
if (last == template) {
return last.getIsErroneous(timestamp);
}
if (Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
return ((SpecificValue_Template) last).getValue().isUnfoldable(timestamp, expectedValue, referenceChain);
}
}
return true;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class IsBoundExpression method checkExpressionTemplateInstance.
/**
* Checks if the templateinstance parameter (which is a parameter of the
* expression parameter) is actually a constant or static value or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expression
* the expression to report the possible errors to.
* @param instance
* the template instance parameter of the expression to
* be checked.
* @param type
* the type against which the template instance shall be
* checked.
* @param referenceChain
* the reference chain to detect circular references.
* @param expectedValue
* the expected value of the template instance.
*/
private static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
Expected_Value_type internalExpectation;
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
} else {
internalExpectation = expectedValue;
}
final ITTCN3Template body = instance.getTemplateBody();
if (Template_type.TEMPLATE_REFD.equals(body.getTemplatetype())) {
((Referenced_Template) body).getReference().setUsedInIsbound();
} else if (Template_type.SPECIFIC_VALUE.equals(body.getTemplatetype())) {
final IValue value = ((SpecificValue_Template) body).getValue();
if (value != null && Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
((Referenced_Value) value).getReference().setUsedInIsbound();
}
}
instance.check(timestamp, type);
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
instance.getLocation().reportSemanticError(CONSTEXPECTED1);
} else {
instance.getLocation().reportSemanticError(STATICEXPECTED1);
}
expression.setIsErroneous(true);
}
ITTCN3Template template = instance.getTemplateBody();
if (template.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
switch(template.getTemplatetype()) {
case TEMPLATE_REFD:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
template = template.getTemplateReferencedLast(timestamp, referenceChain);
if (template.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
}
} else {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
} else {
instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
}
expression.setIsErroneous(true);
}
break;
case SPECIFIC_VALUE:
final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
switch(tempValue.getValuetype()) {
case REFERENCED_VALUE:
type.checkThisValueRef(timestamp, tempValue);
break;
case EXPRESSION_VALUE:
tempValue.getValueRefdLast(timestamp, referenceChain);
break;
default:
break;
}
if (tempValue.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
}
break;
default:
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class IsBoundExpression 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 referenceChain
* the reference chain to detect circular references.
* @param expectedValue
* the expected value of the template instance.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
ITTCN3Template template = templateInstance.getTemplateBody();
if (governor == null) {
template = template.setLoweridToReference(timestamp);
governor = template.getExpressionGovernor(timestamp, internalExpectation);
}
if (governor == null) {
if (!template.getIsErroneous(timestamp)) {
templateInstance.getLocation().reportSemanticError(OPERANDERROR);
}
setIsErroneous(true);
} else {
templateInstance.getExpressionReturntype(timestamp, internalExpectation);
checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
// setMyGovernor(governor);
}
}
Aggregations