use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type 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.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method checkExpressionOmitComparison.
@Override
public /**
* {@inheritDoc}
*/
void checkExpressionOmitComparison(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (getIsErroneous(timestamp)) {
return;
}
final List<ISubReference> subreferences = new ArrayList<ISubReference>();
subreferences.addAll(reference.getSubreferences());
if (subreferences.size() <= 1) {
return;
}
final ISubReference subreference = subreferences.remove(subreferences.size() - 1);
final Identifier id = subreference.getId();
if (id == null) {
getLocation().reportSemanticError("Only a reference pointing to an optional record or set field can be compared with `omit'");
setIsErroneous(true);
return;
}
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return;
}
IType type = assignment.getType(timestamp);
if (type == null) {
setIsErroneous(true);
return;
}
final Reference tempReference = new Reference(null, subreferences);
tempReference.setFullNameParent(this);
tempReference.setMyScope(myScope);
type = type.getFieldType(timestamp, tempReference, 1, expectedValue, false);
if (type == null) {
setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type == null || type.getIsErroneous(timestamp)) {
setIsErroneous(true);
return;
}
switch(type.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
if (!((ASN1_Sequence_Type) type).hasComponentWithName(id)) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((ASN1_Sequence_Type) type).getComponentByName(id).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
case TYPE_TTCN3_SEQUENCE:
if (!((TTCN3_Sequence_Type) type).hasComponentWithName(id.getName())) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((TTCN3_Sequence_Type) type).getComponentByName(id.getName()).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(id)) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((ASN1_Set_Type) type).getComponentByName(id).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(id.getName())) {
getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not have field named `{1}''", type.getTypename(), id.getDisplayName()));
setIsErroneous(true);
} else if (!((TTCN3_Set_Type) type).getComponentByName(id.getName()).isOptional()) {
getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is mandatory in type`{1}''. It cannot be compared with `omit''", id.getDisplayName(), type.getTypename()));
setIsErroneous(true);
}
break;
default:
getLocation().reportSemanticError("Only a reference pointing to an optional record or set field can be compared with `omit'");
setIsErroneous(true);
break;
}
}
use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type 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.ASN1.types.ASN1_Sequence_Type 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.ASN1.types.ASN1_Sequence_Type in project titan.EclipsePlug-ins by eclipse.
the class TableConstraint method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
parseBlocks();
if (null == myType) {
return;
}
objectSet.setMyScope(myType.getMyScope());
BridgingNamedNode bridge = new BridgingNamedNode(this, FULLNAMEPART);
objectSet.setFullNameParent(bridge);
// search the constrained type (not the reference to it)
constrainedType = myType;
while (true) {
if (constrainedType.getIsErroneous(timestamp)) {
return;
}
if (Type_type.TYPE_OPENTYPE.equals(constrainedType.getTypetype()) || Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(constrainedType.getTypetype())) {
break;
} else if (constrainedType instanceof IReferencingType) {
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
constrainedType = ((IReferencingType) constrainedType).getTypeRefd(timestamp, chain);
chain.release();
} else {
myType.getLocation().reportSemanticError(OCFTEXPECTED);
return;
}
}
if (Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(constrainedType.getTypetype())) {
ObjectClassField_Type ocfType = (ObjectClassField_Type) constrainedType;
objectClassFieldname = ocfType.getObjectClassFieldName();
objectSet.setMyGovernor(ocfType.getMyObjectClass());
objectSet.check(timestamp);
return;
}
// opentype
final Open_Type openType = (Open_Type) constrainedType;
openType.setMyTableConstraint(this);
objectClassFieldname = openType.getObjectClassFieldName();
objectSet.setMyGovernor(openType.getMyObjectClass());
objectSet.check(timestamp);
if (null == atNotationList) {
return;
}
// componentrelationconstraint...
// search the outermost textually enclosing seq, set or choice
IType outermostParent = null;
IType tempType = myType;
do {
switch(tempType.getTypetype()) {
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_OPENTYPE:
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_ASN1_SET:
case TYPE_TTCN3_SET:
outermostParent = tempType;
break;
default:
break;
}
tempType = tempType.getParentType();
} while (null != tempType);
if (null == outermostParent) {
myType.getLocation().reportSemanticError(CANNOTDETERMINEPARENT);
return;
}
// outermostparent->set_opentype_outermost();
// TODO implement the setting of set_has_openType
AtNotation atNotation;
for (int i = 0; i < atNotationList.getNofAtNotations(); i++) {
atNotation = atNotationList.getAtNotationByIndex(i);
IType parent = null;
if (0 == atNotation.getLevels()) {
parent = outermostParent;
} else {
parent = myType;
for (int level = atNotation.getLevels(); level > 0; level--) {
parent = parent.getParentType();
if (null == parent) {
myType.getLocation().reportSemanticError(MessageFormat.format(TOOMANYDOTS, atNotation.getLevels()));
return;
}
}
}
tempType = parent;
atNotation.setFirstComponent(parent);
// component identifiers... do they exist? yes, if the refd type is constrained
FieldName componentIdentifiers = atNotation.getComponentIdentifiers();
for (int j = 0; j < componentIdentifiers.getNofFields(); j++) {
Identifier identifier = componentIdentifiers.getFieldByIndex(i);
switch(tempType.getTypetype()) {
case TYPE_ASN1_CHOICE:
{
final ASN1_Choice_Type temp2 = (ASN1_Choice_Type) tempType;
if (temp2.hasComponentWithName(identifier)) {
final CompField cf = temp2.getComponentByName(identifier);
tempType = cf.getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
case TYPE_TTCN3_CHOICE:
{
final TTCN3_Choice_Type temp2 = (TTCN3_Choice_Type) tempType;
if (temp2.hasComponentWithName(identifier.getName())) {
tempType = temp2.getComponentByName(identifier.getName()).getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
case TYPE_OPENTYPE:
{
final Open_Type temp2 = (Open_Type) tempType;
if (temp2.hasComponentWithName(identifier)) {
final CompField cf = temp2.getComponentByName(identifier);
tempType = cf.getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
case TYPE_ASN1_SEQUENCE:
{
final ASN1_Sequence_Type temp2 = (ASN1_Sequence_Type) tempType;
if (temp2.hasComponentWithName(identifier)) {
final CompField cf = temp2.getComponentByName(identifier);
tempType = cf.getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
case TYPE_TTCN3_SEQUENCE:
{
final TTCN3_Sequence_Type temp2 = (TTCN3_Sequence_Type) tempType;
if (temp2.hasComponentWithName(identifier.getName())) {
tempType = temp2.getComponentByName(identifier.getName()).getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
case TYPE_ASN1_SET:
{
final ASN1_Set_Type temp2 = (ASN1_Set_Type) tempType;
if (temp2.hasComponentWithName(identifier)) {
final CompField cf = temp2.getComponentByName(identifier);
tempType = cf.getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
case TYPE_TTCN3_SET:
{
final TTCN3_Set_Type temp2 = (TTCN3_Set_Type) tempType;
if (temp2.hasComponentWithName(identifier.getName())) {
tempType = temp2.getComponentByName(identifier.getName()).getType();
} else {
myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
return;
}
break;
}
default:
myType.getLocation().reportSemanticError(MessageFormat.format(SECHOEXPECTED, tempType.getFullName()));
return;
}
}
atNotation.setLastComponent(tempType);
/*
* check if the referenced component is constrained by the same objectset...
*/
boolean ok = false;
final Constraints constraints = tempType.getConstraints();
if (constraints != null) {
constraints.check(timestamp);
final TableConstraint tableConstraint = constraints.getTableConstraint();
if (tableConstraint != null) {
IType ocft = tableConstraint.constrainedType;
if (Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(ocft.getTypetype())) {
atNotation.setObjectClassFieldname(((ObjectClassField_Type) ocft).getObjectClassFieldName());
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
ObjectSet_definition osdef1 = tableConstraint.objectSet.getRefdLast(timestamp, chain);
chain.release();
chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final ObjectSet_definition osdef2 = objectSet.getRefdLast(timestamp, chain);
chain.release();
if (osdef1 == osdef2) {
ok = true;
} else {
ok = false;
}
}
}
}
if (!ok) {
myType.getLocation().reportSemanticError(SAMECONSTRAINTEXPECTED);
return;
}
}
if (objectSet instanceof Referenced_ObjectSet) {
final Identifier objectSetId = ((Referenced_ObjectSet) objectSet).getId();
collectTypesOfOpenType(timestamp, objectSet, openType, objectSetId);
} else {
// TODO: is it posssible? Perhaps log error!
return;
}
}
Aggregations