use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Or4bExpression 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 (value1 == null || value2 == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
String str1;
String str2;
switch(last1.getValuetype()) {
case BITSTRING_VALUE:
str1 = ((Bitstring_Value) last1).getValue();
str2 = ((Bitstring_Value) last2).getValue();
lastValue = new Bitstring_Value(or4b(str1, str2));
lastValue.copyGeneralProperties(this);
break;
case HEXSTRING_VALUE:
str1 = ((Hexstring_Value) last1).getValue();
str2 = ((Hexstring_Value) last2).getValue();
lastValue = new Hexstring_Value(or4b(str1, str2));
lastValue.copyGeneralProperties(this);
break;
case OCTETSTRING_VALUE:
str1 = ((Octetstring_Value) last1).getValue();
str2 = ((Octetstring_Value) last2).getValue();
lastValue = new Octetstring_Value(or4b(str1, str2));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class OrExpression 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 (value1 == null || value2 == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
if (Value_type.BOOLEAN_VALUE.equals(last1.getValuetype())) {
if (((Boolean_Value) last1).getValue()) {
lastValue = new Boolean_Value(true);
lastValue.copyGeneralProperties(this);
} else {
final Boolean_Value temp = (Boolean_Value) value2.getValueRefdLast(timestamp, referenceChain);
lastValue = new Boolean_Value(temp.getValue());
lastValue.copyGeneralProperties(this);
}
} else {
// we must keep the left operand because of the
// potential side effects
// the right operand can only be eliminated if it is a
// literal "false"
final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
if (Value_type.BOOLEAN_VALUE.equals(last2.getValuetype()) && !((Boolean_Value) last2).getValue()) {
final Boolean_Value temp = (Boolean_Value) value1.getValueRefdLast(timestamp, referenceChain);
lastValue = new Boolean_Value(temp.getValue());
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 Referenced_Value method getValueRefdLast.
@Override
public /**
* {@inheritDoc}
*/
IValue getValueRefdLast(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return referencedValue;
}
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
referencedValue = this;
isErroneous = false;
if (reference == null) {
return referencedValue;
}
reference.setIsErroneous(false);
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
isErroneous = true;
return referencedValue;
}
switch(ass.getAssignmentType()) {
case A_OBJECT:
case A_OS:
{
final ISetting setting = reference.getRefdSetting(timestamp);
if (setting == null || setting.getIsErroneous(timestamp)) {
isErroneous = true;
} else if (!Setting_type.S_V.equals(setting.getSettingtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format(INFORMATIONFROMOBJECTNOTVALUE, reference));
isErroneous = true;
} else {
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
referencedValue = ((IValue) setting).getValueRefdLast(timestamp, expectedValue, referenceChain);
} else {
isErroneous = true;
}
tempReferenceChain.previousState();
}
break;
}
case A_CONST:
{
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
if (ass instanceof Def_Const) {
referencedValue = ((Def_Const) ass).getValue();
} else if (ass instanceof Value_Assignment) {
referencedValue = ((Value_Assignment) ass).getValue();
} else {
isErroneous = true;
}
if (referencedValue != null && !isErroneous) {
referencedValue = referencedValue.getReferencedSubValue(timestamp, reference, 1, tempReferenceChain);
} else {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
}
if (referencedValue != null) {
referencedValue = referencedValue.getValueRefdLast(timestamp, tempReferenceChain);
} else if (reference.hasUnfoldableIndexSubReference(timestamp)) {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
} else if (reference.getUsedInIsbound()) {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
} else {
isErroneous = true;
}
} else {
isErroneous = true;
}
tempReferenceChain.previousState();
break;
}
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_INOUT:
case A_PAR_TEMP_OUT:
referencedValue = this;
break;
case A_TEMPLATE:
case A_VAR_TEMPLATE:
// the referred definition is not a constant
// errors will be reported in Types.java
referencedValue = this;
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
}
break;
case A_FUNCTION:
case A_EXT_FUNCTION:
reference.getLocation().reportSemanticError(MessageFormat.format(VALUERETURNEXPECTED, ass.getDescription()));
isErroneous = true;
break;
default:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT1, ass.getDescription()));
} else {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
}
isErroneous = true;
break;
}
if (newChain) {
tempReferenceChain.release();
}
lastTimeChecked = timestamp;
if (referencedValue == null) {
referencedValue = this;
isErroneous = true;
}
return referencedValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Macro_Value method evaluateMacro.
/**
* Evaluates the value of the macro.
*
* @param expectedValue the kind of the value to be expected
*
* @return the actual or the evaluated value
*/
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
lastTimeChecked = timestamp;
lastValue = this;
switch(value) {
case MODULEID:
if (myScope != null && myScope.getModuleScope() != null) {
final Module module = myScope.getModuleScope();
if (module.getIdentifier() != null) {
lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
break;
case DEFINITIONID:
if (myScope != null) {
final StatementBlock block = myScope.getStatementBlockScope();
if (block != null) {
final Definition definition = block.getMyDefinition();
if (definition != null) {
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
} else {
setIsErroneous(true);
}
break;
case TESTCASEID:
if (myScope != null) {
final StatementBlock block = myScope.getStatementBlockScope();
if (block != null) {
final Definition definition = block.getMyDefinition();
if (definition == null) {
location.reportSemanticError(TESCASEIDINCONTROLPART);
setIsErroneous(true);
} else {
if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
// folding is possible in testcases only
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
} else {
location.reportSemanticError(TESTCASEIDNOTALLOWED);
setIsErroneous(true);
}
} else {
setIsErroneous(true);
}
break;
case FILENAME:
case BFILENAME:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Charstring_Value(location.getFile().getName());
lastValue.copyGeneralProperties(this);
}
break;
case FILEPATH:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
String canonicalPath;
final IPath absolutePath = location.getFile().getLocation();
if (absolutePath == null) {
location.reportSemanticError(UNDETERMINABLEPATH);
canonicalPath = location.getFile().getName();
setIsErroneous(true);
} else {
final File file = absolutePath.toFile();
try {
canonicalPath = file.getCanonicalPath();
} catch (IOException e) {
location.reportSemanticError(UNDETERMINABLEPATH);
canonicalPath = location.getFile().getName();
setIsErroneous(true);
}
}
lastValue = new Charstring_Value(canonicalPath);
lastValue.copyGeneralProperties(this);
}
break;
case LINENUMBER:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Charstring_Value(Long.toString(location.getLine()));
lastValue.copyGeneralProperties(this);
}
break;
case LINENUMBER_C:
if (NULL_Location.INSTANCE.equals(location)) {
setIsErroneous(true);
} else {
lastValue = new Integer_Value(location.getLine());
lastValue.copyGeneralProperties(this);
}
break;
case SCOPE:
if (myScope != null) {
lastValue = new Charstring_Value(myScope.getScopeMacroName());
lastValue.copyGeneralProperties(this);
} else {
location.reportSemanticError(UNDETERMINABLESCOPE);
setIsErroneous(true);
}
break;
default:
setIsErroneous(true);
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class DecvalueUnicharExpression method checkExpressionOperand1.
/**
* Checks the 1st operand
* inout universal charstring
* @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 checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (reference1 == null) {
setIsErroneous(true);
return;
}
final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
if (temporalAssignment == null) {
setIsErroneous(true);
return;
}
switch(temporalAssignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_TEMPLATE:
reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR2, temporalAssignment.getAssignmentName()));
setIsErroneous(true);
break;
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
break;
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final Referenced_Template template = new Referenced_Template(reference1);
template.setMyScope(getMyScope());
template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR3, last.getTemplateTypeName()));
setIsErroneous(true);
return;
}
break;
}
default:
reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR4, temporalAssignment.getAssignmentName()));
setIsErroneous(true);
return;
}
final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (temporalType == null) {
setIsErroneous(true);
return;
}
final Type_type type_type = temporalType.getTypeRefdLast(timestamp).getTypetype();
if (type_type != Type_type.TYPE_UCHARSTRING) {
if (!isErroneous) {
location.reportSemanticError(OPERAND1_ERROR1);
setIsErroneous(true);
}
return;
}
}
Aggregations