use of org.eclipse.titan.designer.AST.TTCN3.types.CompField 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.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Type method fieldIsOptional.
@Override
public /**
* {@inheritDoc}
*/
boolean fieldIsOptional(final List<ISubReference> subReferences) {
// TODO there must be a better implementation
if (subReferences == null) {
return false;
}
if (subReferences.isEmpty()) {
return false;
}
final ISubReference lastSubReference = subReferences.get(subReferences.size() - 1);
if (!(lastSubReference instanceof FieldSubReference)) {
return false;
}
IType type = this;
CompField compField = null;
for (int i = 1; i < subReferences.size(); i++) {
if (type != null) {
type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
}
final ISubReference subreference = subReferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
final Identifier id = ((FieldSubReference) subreference).getId();
if (type != null) {
switch(type.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
break;
case TYPE_ANYTYPE:
compField = ((Anytype_Type) type).getComponentByName(id.getName());
break;
case TYPE_OPENTYPE:
compField = ((Open_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SEQUENCE:
((ASN1_Sequence_Type) type).parseBlockSequence();
compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SET:
((ASN1_Set_Type) type).parseBlockSet();
compField = ((ASN1_Set_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_CHOICE:
((ASN1_Choice_Type) type).parseBlockChoice();
compField = ((ASN1_Choice_Type) type).getComponentByName(id);
break;
default:
// TODO fatal error:
return false;
}
if (compField == null) {
// TODO fatal error
return false;
}
type = compField.getType();
}
} else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
final Value value = ((ArraySubReference) subreference).getValue();
// TODO actually should get the last governor
final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
if (type != null) {
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
type = ((AbstractOfType) type).getOfType();
break;
case TYPE_ARRAY:
type = ((Array_Type) type).getElementType();
break;
default:
type = null;
return false;
}
}
}
}
if (compField != null && compField.isOptional()) {
return true;
}
return false;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method evaluateIspresent.
@Override
public /**
* {@inheritDoc}
*/
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return true;
}
if (convertedValue != null && convertedValue != this) {
return convertedValue.evaluateIsbound(timestamp, reference, actualSubReference);
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return false;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
return false;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
return false;
}
break;
case TYPE_ASN1_SEQUENCE:
if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
return false;
}
break;
default:
return false;
}
if (values.hasNamedValueWithName(fieldId)) {
// we can move on with the check
return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
}
if (Type_type.TYPE_TTCN3_SEQUENCE.equals(type.getTypetype())) {
return false;
}
final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
} else if (compField.hasDefault()) {
return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
}
return false;
case parameterisedSubReference:
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method evaluateIsbound.
@Override
public /**
* {@inheritDoc}
*/
boolean evaluateIsbound(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return true;
}
if (convertedValue != null && convertedValue != this) {
return convertedValue.evaluateIsbound(timestamp, reference, actualSubReference);
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return false;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
return false;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
return false;
}
break;
case TYPE_ASN1_SEQUENCE:
if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
return false;
}
break;
default:
return false;
}
if (values.hasNamedValueWithName(fieldId)) {
// we can move on with the check
return values.getNamedValueByName(fieldId).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
}
if (Type_type.TYPE_TTCN3_SEQUENCE.equals(type.getTypetype())) {
return false;
}
final CompField compField = ((ASN1_Sequence_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.evaluateIsbound(timestamp, reference, actualSubReference + 1);
} else if (compField.hasDefault()) {
return compField.getDefault().evaluateIsbound(timestamp, reference, actualSubReference + 1);
}
return false;
case parameterisedSubReference:
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method evaluateIspresent.
@Override
public /**
* {@inheritDoc}
*/
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return true;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return false;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
return false;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
return false;
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
return false;
}
break;
default:
return false;
}
if (values.hasNamedValueWithName(fieldId)) {
// we can move on with the check
return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
}
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
return false;
}
final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
if (compField.isOptional()) {
// create an explicit omit value
final Value result = new Omit_Value();
final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
result.setFullNameParent(bridge);
result.setMyScope(getMyScope());
return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
} else if (compField.hasDefault()) {
return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
}
return false;
case parameterisedSubReference:
return false;
default:
return false;
}
}
Aggregations