use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Type_Visit_Handler method visitDefTypeChildrenNodes.
public void visitDefTypeChildrenNodes(IVisitableNode node) {
if (node instanceof Def_Port) {
Def_Port port = (Def_Port) node;
componentPortNames.add(port.getIdentifier().toString());
}
if (node instanceof Def_Var) {
Def_Var var = (Def_Var) node;
componentVarNames.add(var.getIdentifier().toString());
if (var.getType(compilationCounter) instanceof Integer_Type) {
componentVarTypes.add("INTEGER");
}
}
if (waitForCompReference && (node instanceof Reference)) {
componentPortTypes.add(((Reference) node).getId().toString());
}
if (waitForSetOfFieldType) {
if (node instanceof Reference) {
setOfFieldType = node.toString();
myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
waitForSetOfFieldType = false;
} else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SetOf_Type)) {
Type type = (Type) node;
setOfFieldType = TypeMapper.map(type.getTypename());
myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
waitForSetOfFieldType = false;
}
}
if (waitForRecordOfFieldType) {
if (node instanceof Reference) {
recordOfFieldType = node.toString();
myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
waitForRecordOfFieldType = false;
} else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SequenceOf_Type)) {
Type type = (Type) node;
recordOfFieldType = TypeMapper.map(type.getTypename());
myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
waitForRecordOfFieldType = false;
}
}
if (node instanceof CompField) {
// component
CompField compFieldNode = (CompField) node;
if (compFieldNode.getType() instanceof Referenced_Type) {
compFieldTypes.add(((Referenced_Type) compFieldNode.getType()).getReference().getId().toString());
} else {
compFieldTypes.add(myASTVisitor.cutModuleNameFromBeginning(compFieldNode.getType().getTypename()));
}
compFieldNames.add(compFieldNode.getIdentifier().toString());
}
if (node instanceof Charstring_Value) {
// charstring
Charstring_Value singleValuedNode = (Charstring_Value) node;
charstringValue = singleValuedNode.getValue();
}
if (node instanceof Integer_Value) {
String value = ((Integer_Value) node).toString();
if (myASTVisitor.isNextIntegerNegative) {
value = "-" + value;
}
expressionValue.add("new INTEGER(\"" + value + "\")");
}
if (node instanceof Real_Value) {
String value = ((Real_Value) node).toString();
if (myASTVisitor.isNextIntegerNegative) {
value = "-" + value;
}
if (value.equals("-Infinity") || value.equals("Infinity")) {
value = "null";
}
expressionValue.add(value);
}
if (node instanceof Undefined_LowerIdentifier_Value) {
String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString();
if (myASTVisitor.isNextIntegerNegative) {
value = "-" + value;
}
expressionValue.add(value);
}
if (node instanceof EnumerationItems) {
for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) {
enumItems.add(((EnumerationItems) node).getItems().get(i).getId().toString());
if (((EnumerationItems) node).getItems().get(i).getValue() != null) {
enumItemValues.add(((EnumerationItems) node).getItems().get(i).getValue().toString());
} else {
enumItemValues.add(null);
}
}
}
if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) {
isPortTypeAReferencedType = true;
}
if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) {
PortTypeBody body = (PortTypeBody) node;
int inCount = body.getInMessages().getNofTypes();
int outCount = body.getOutMessage().getNofTypes();
for (int i = 0; i < inCount; i++) {
inMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getInMessages().getTypeByIndex(i).getTypename()));
}
for (int i = 0; i < outCount; i++) {
outMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getOutMessage().getTypeByIndex(i).getTypename()));
}
int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName.size() : outMessageName.size();
// if inout delete from both lists and add to inout
for (int i = 0; i < inMessageName.size(); i++) {
for (int j = 0; j < outMessageName.size(); j++) {
if (inMessageName.get(i).equals(outMessageName.get(j))) {
inOutMessageName.add(inMessageName.get(i));
inMessageName.remove(i);
if (j == (outMessageName.size() - 1)) {
i--;
}
outMessageName.remove(j);
j--;
}
}
}
myASTVisitor.portNamePortTypeHashMap.put(currentPortName, body.getTestportType().toString());
portTypeList.add(body.getTestportType().toString());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ShiftLeftExpression 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) {
Type_type tempType1 = null;
Type_type tempType2 = null;
long stringSize = 0;
long shiftSize = 0;
IValue tempValue;
if (value1 != null) {
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
switch(tempType1) {
case TYPE_BITSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
stringSize = ((Bitstring_Value) tempValue).getValueLength();
}
break;
case TYPE_HEXSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
stringSize = ((Hexstring_Value) tempValue).getValueLength();
}
break;
case TYPE_OCTETSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
stringSize = ((Octetstring_Value) tempValue).getValueLength();
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(FIRSTOPERANDERROR);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
if (!((Integer_Value) tempValue).isNative()) {
value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
setIsErroneous(true);
break;
}
shiftSize = ((Integer_Value) tempValue).getValue();
if (value1 != null && !value1.isUnfoldable(timestamp)) {
final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
if (shiftSize < 0) {
location.reportConfigurableSemanticProblem(severity, NEGATIVESHIFTPROBLEM);
} else if (shiftSize == 0) {
location.reportConfigurableSemanticProblem(severity, ZEROSHIFTPROBLEM);
} else if (shiftSize > stringSize) {
location.reportConfigurableSemanticProblem(severity, MessageFormat.format(TOOBIGSHIFTPROBLEM, stringSize, shiftSize));
}
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(SECONDOPERANDERROR);
setIsErroneous(true);
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ShiftRightExpression 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);
final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
String string;
long shiftSize;
switch(last1.getValuetype()) {
case BITSTRING_VALUE:
string = ((Bitstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).getValue();
lastValue = new Bitstring_Value(shiftRight(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case HEXSTRING_VALUE:
string = ((Hexstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).getValue();
lastValue = new Hexstring_Value(shiftRight(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case OCTETSTRING_VALUE:
string = ((Octetstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).getValue() * 2;
lastValue = new Octetstring_Value(shiftRight(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ShiftRightExpression 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) {
Type_type tempType1 = null;
Type_type tempType2 = null;
long stringSize = 0;
long shiftSize = 0;
IValue tempValue;
if (value1 != null) {
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
switch(tempType1) {
case TYPE_BITSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
stringSize = ((Bitstring_Value) tempValue).getValueLength();
}
break;
case TYPE_HEXSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
stringSize = ((Hexstring_Value) tempValue).getValueLength();
}
break;
case TYPE_OCTETSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
stringSize = ((Octetstring_Value) tempValue).getValueLength();
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(FIRSTOPERANDERROR);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
if (!((Integer_Value) tempValue).isNative()) {
value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
setIsErroneous(true);
break;
}
shiftSize = ((Integer_Value) tempValue).getValue();
if (value1 != null && !value1.isUnfoldable(timestamp)) {
final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
if (shiftSize < 0) {
location.reportConfigurableSemanticProblem(severity, NEGATIVESHIFTPROBLEM);
} else if (shiftSize == 0) {
location.reportConfigurableSemanticProblem(severity, ZEROSHIFTPROBLEM);
} else if (shiftSize > stringSize) {
location.reportConfigurableSemanticProblem(severity, MessageFormat.format(TOOBIGSHIFTPROBLEM, stringSize, shiftSize));
}
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(SECONDOPERANDERROR);
setIsErroneous(true);
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class SizeOfExpression method evaluateTemplate.
/**
* Evaluates a checked template.
*
* @param template
* The template to evaluate
* @param timestamp
* The compilation timestamp
* @return The folded value or -1 if the template is unfoldable.
*/
private long evaluateTemplate(final ITTCN3Template template, final CompilationTimeStamp timestamp) {
switch(template.getTemplatetype()) {
case TEMPLATE_LIST:
{
final Template_List temp = (Template_List) template;
if (temp.templateContainsAnyornone()) {
final LengthRestriction lengthRestriction = temp.getLengthRestriction();
if (lengthRestriction == null) {
templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without length restriction");
setIsErroneous(true);
return -1;
}
if (lengthRestriction instanceof RangeLenghtRestriction) {
final IValue upper = ((RangeLenghtRestriction) lengthRestriction).getUpperValue(timestamp);
if (Value_type.REAL_VALUE.equals(upper.getValuetype()) && ((Real_Value) upper).isPositiveInfinity()) {
templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates containing `*' without upper boundary in the length restriction");
setIsErroneous(true);
return -1;
}
if (Value_type.INTEGER_VALUE.equals(upper.getValuetype())) {
final int nofComponents = temp.getNofTemplatesNotAnyornone(timestamp);
if (nofComponents == ((Integer_Value) upper).intValue()) {
return nofComponents;
}
final IValue lower = ((RangeLenghtRestriction) lengthRestriction).getLowerValue(timestamp);
if (lower != null && Value_type.INTEGER_VALUE.equals(lower.getValuetype()) && ((Integer_Value) upper).intValue() == ((Integer_Value) lower).intValue()) {
return ((Integer_Value) upper).intValue();
}
templateInstance.getLocation().reportSemanticError("`sizeof' operation is not applicable for templates without exact size");
setIsErroneous(true);
return -1;
}
} else {
final IValue restriction = ((SingleLenghtRestriction) lengthRestriction).getRestriction(timestamp);
if (Value_type.INTEGER_VALUE.equals(restriction.getValuetype())) {
return ((Integer_Value) restriction).intValue();
}
}
} else {
int result = 0;
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i);
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
++result;
}
break;
default:
++result;
}
}
return result;
}
break;
}
case NAMED_TEMPLATE_LIST:
{
int result = 0;
final Named_Template_List temp = (Named_Template_List) template;
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i).getTemplate();
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
if (tmp.getValue().getValuetype() != Value_type.OMIT_VALUE) {
++result;
}
break;
default:
++result;
}
}
return result;
}
case SUBSET_MATCH:
{
final LengthRestriction restriction = template.getLengthRestriction();
if (restriction instanceof SingleLenghtRestriction) {
final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
return ((Integer_Value) value).getValue();
} else {
return -1;
}
} else if (restriction instanceof RangeLenghtRestriction) {
final IValue minValue = ((RangeLenghtRestriction) restriction).getLowerValue(timestamp);
if (minValue.getValuetype() != Value_type.INTEGER_VALUE || minValue.isUnfoldable(timestamp)) {
return -1;
}
final SubsetMatch_Template temp = (SubsetMatch_Template) template;
if (temp.getNofTemplates() != ((Integer_Value) minValue).getValue()) {
return -1;
}
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i);
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
break;
default:
return -1;
}
}
return temp.getNofTemplates();
}
return -1;
}
case SUPERSET_MATCH:
{
final LengthRestriction restriction = template.getLengthRestriction();
if (restriction instanceof SingleLenghtRestriction) {
final IValue value = ((SingleLenghtRestriction) restriction).getRestriction(timestamp);
if (value.getValuetype() == Value_type.INTEGER_VALUE && !value.isUnfoldable(timestamp)) {
return ((Integer_Value) value).getValue();
} else {
return -1;
}
} else if (restriction instanceof RangeLenghtRestriction) {
final IValue maxValue = ((RangeLenghtRestriction) restriction).getUpperValue(timestamp);
if (maxValue.getValuetype() != Value_type.INTEGER_VALUE || maxValue.isUnfoldable(timestamp)) {
return -1;
}
final SupersetMatch_Template temp = (SupersetMatch_Template) template;
if (temp.getNofTemplates() != ((Integer_Value) maxValue).getValue()) {
return -1;
}
for (int i = 0, size = temp.getNofTemplates(); i < size; i++) {
final ITTCN3Template tmp = temp.getTemplateByIndex(i);
switch(tmp.getTemplatetype()) {
case SPECIFIC_VALUE:
break;
default:
return -1;
}
}
return temp.getNofTemplates();
}
return -1;
}
default:
return -1;
}
return -1;
}
Aggregations