use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class IsPresentExpression 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.
*/
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);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class IsPresentExpression 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();
if (template.getIfPresent()) {
lastValue = new Boolean_Value(false);
lastValue.copyGeneralProperties(this);
return lastValue;
}
template = template.getTemplateReferencedLast(timestamp);
if (template.getIfPresent()) {
lastValue = new Boolean_Value(false);
lastValue.copyGeneralProperties(this);
return lastValue;
}
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().evaluateIspresent(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.evaluateIspresent(timestamp, ((Referenced_Value) value).getReference(), 1);
} else if (value.getValuetype() == Value_type.OMIT_VALUE) {
result = false;
} else {
result = !value.getIsErroneous(timestamp);
}
}
lastValue = new Boolean_Value(result);
lastValue.copyGeneralProperties(this);
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class IsPresentExpression 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.getIfPresent()) {
return false;
}
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_CONST:
// const is foldable
return false;
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 (last.getIfPresent()) {
return false;
}
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.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class IsTemplateKindExpression method checkExpressionOperand2.
/**
* Checks the 2nd operand
* in charstring (optional)
* @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.
*/
private void checkExpressionOperand2(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (value == null) {
setIsErroneous(true);
return;
}
value.setLoweridToReference(timestamp);
final Type_type tempType = value.getExpressionReturntype(timestamp, expectedValue);
switch(tempType) {
case TYPE_CHARSTRING:
final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last.isUnfoldable(timestamp)) {
final String originalString = ((Charstring_Value) last).getValue();
final CharstringExtractor cs = new CharstringExtractor(originalString);
if (cs.isErrorneous()) {
value.getLocation().reportSemanticError(cs.getErrorMessage());
setIsErroneous(true);
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
if (!isErroneous) {
location.reportSemanticError(OPERAND2_ERROR1);
setIsErroneous(true);
}
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Unichar2IntExpression 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 (value == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case UNIVERSALCHARSTRING_VALUE:
{
final UniversalCharstring string = ((UniversalCharstring_Value) last).getValue();
final UniversalChar uchar = string.get(0);
final int result = (uchar.group() << 24) | (uchar.plane() << 16) | (uchar.row() << 8) | uchar.cell();
lastValue = new Integer_Value(result);
break;
}
case CHARSTRING_VALUE:
{
final String string = ((Charstring_Value) last).getValue();
lastValue = new Integer_Value(string.charAt(0));
break;
}
default:
setIsErroneous(true);
return this;
}
lastValue.copyGeneralProperties(this);
return lastValue;
}
Aggregations