use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class SubType method addTtcnSingle.
/**
* add TTCN-3 single value sub-type constraint to this sub-type
*/
private boolean addTtcnSingle(final CompilationTimeStamp timestamp, final Value value, final int restrictionIndex) {
value.setMyScope(myOwner.getMyScope());
value.setMyGovernor(myOwner);
final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getTypename() + ".<single_restriction_" + restrictionIndex + ">");
value.setFullNameParent(bridge);
IValue last = myOwner.checkThisValueRef(timestamp, value);
// check if this is type reference, if not then fall through
final IValue refValue = value.setLoweridToReference(timestamp);
// Value_type.REFERENCED_VALUE);
if (refValue.getValuetype() == Value.Value_type.REFERENCED_VALUE) {
final Reference ref = ((Referenced_Value) refValue).getReference();
final Assignment ass = ref.getRefdAssignment(timestamp, false);
if (ass == null) {
// definition was not found, error was reported
return false;
}
if (ass.getAssignmentType() == Assignment.Assignment_type.A_TYPE) {
IType t = ass.getType(timestamp);
t.check(timestamp);
if (t.getIsErroneous(timestamp)) {
return false;
}
final List<ISubReference> subrefs = ref.getSubreferences();
if (subrefs.size() > 1) {
// if there were sub-references then get the referenced field's type
t = t.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
if ((t == null) || t.getIsErroneous(timestamp)) {
return false;
}
t.check(timestamp);
if (t.getIsErroneous(timestamp)) {
return false;
}
}
if (!t.isIdentical(timestamp, myOwner)) {
value.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' must refer to a type which has the same root type as this type", ref.getDisplayName()));
return false;
}
// check subtype of referenced type
final SubType tSt = t.getSubtype();
if ((tSt == null) || (tSt.subtypeConstraint == null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Type referenced by `{0}'' does not have a subtype", ref.getDisplayName()));
return false;
}
// check circular sub-type reference
if (!addParentSubtype(tSt)) {
return false;
}
if (tSt.getIsErroneous(timestamp)) {
return false;
}
if (tSt.subtypeType != subtypeType) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
// add the sub-type as union
if (subtypeConstraint == null) {
subtypeConstraint = tSt.subtypeConstraint;
} else {
subtypeConstraint = subtypeConstraint.union(tSt.subtypeConstraint);
}
return true;
}
}
myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
last = last.getValueRefdLast(timestamp, chain);
chain.release();
if (last.getIsErroneous(timestamp) || last.isUnfoldable(timestamp)) {
return false;
}
// create a single value constraint
SubtypeConstraint sc;
switch(subtypeType) {
case ST_INTEGER:
sc = new RangeListConstraint(new IntegerLimit(((Integer_Value) last).getValueValue()));
break;
case ST_FLOAT:
sc = new RealRangeListConstraint(((Real_Value) last).getValue());
break;
case ST_BOOLEAN:
sc = new BooleanListConstraint(((Boolean_Value) last).getValue());
break;
case ST_VERDICTTYPE:
sc = new VerdicttypeListConstraint(((Verdict_Value) last).getValue());
break;
case ST_BITSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, ((Bitstring_Value) last).getValue());
break;
case ST_HEXSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, ((Hexstring_Value) last).getValue());
break;
case ST_OCTETSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, ((Octetstring_Value) last).getValue());
break;
case ST_CHARSTRING:
if (last.getValuetype() != Value.Value_type.CHARSTRING_VALUE) {
return false;
}
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new StringValueConstraint(((Charstring_Value) last).getValue()));
break;
case ST_UNIVERSAL_CHARSTRING:
switch(last.getValuetype()) {
case CHARSTRING_VALUE:
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(new UniversalCharstring(((Charstring_Value) last).getValue())));
break;
case UNIVERSALCHARSTRING_VALUE:
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(((UniversalCharstring_Value) last).getValue()));
break;
default:
return false;
}
break;
case ST_OBJID:
case ST_ENUM:
case ST_UNION:
case ST_RECORD:
case ST_SET:
case ST_FUNCTION:
case ST_ALTSTEP:
case ST_TESTCASE:
sc = new ValueListConstraint(last);
break;
case ST_RECORDOF:
case ST_SETOF:
sc = new ValueListAndSizeConstraint(last);
break;
default:
ErrorReporter.INTERNAL_ERROR();
return false;
}
// add next value using union operation
if (subtypeConstraint == null) {
subtypeConstraint = sc;
} else {
subtypeConstraint = subtypeConstraint.union(sc);
}
return true;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
if (getIsErroneous(timestamp)) {
return false;
}
boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (last == null || last.getIsErroneous(timestamp)) {
return selfReference;
}
// already handled ones
switch(value.getValuetype()) {
case OMIT_VALUE:
case REFERENCED_VALUE:
return selfReference;
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
return selfReference;
}
break;
default:
break;
}
switch(last.getValuetype()) {
case SEQUENCE_VALUE:
last = last.setValuetype(timestamp, Value_type.SET_VALUE);
if (last.isAsn()) {
selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
} else {
selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
}
break;
case SEQUENCEOF_VALUE:
if (((SequenceOf_Value) last).isIndexed()) {
value.getLocation().reportSemanticError(MessageFormat.format("Indexed assignment notation cannot be used for SET type `{0}''", getFullName()));
value.setIsErroneous(true);
} else {
final SequenceOf_Value temporalValue = (SequenceOf_Value) last;
if (temporalValue.getNofComponents() == 0) {
if (getNofComponents(timestamp) == 0) {
last = last.setValuetype(timestamp, Value_type.SET_VALUE);
} else {
value.getLocation().reportSemanticError(MessageFormat.format(NONEMPTYEXPECTED, getFullName()));
value.setIsErroneous(true);
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? VALUELISTNOTATIONERRORASN1 : VALUELISTNOTATIONERRORTTCN3, getFullName()));
value.setIsErroneous(true);
}
}
break;
case SET_VALUE:
if (last.isAsn()) {
selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
} else {
selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
}
break;
case UNDEFINED_BLOCK:
last = last.setValuetype(timestamp, Value_type.SET_VALUE);
selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
break;
case EXPRESSION_VALUE:
case MACRO_VALUE:
// already checked
break;
default:
value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? SETVALUEXPECTEDASN1 : SETVALUEXPECTEDTTCN3, getFullName()));
value.setIsErroneous(true);
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class Open_Type method checkThisValue.
// FIXME add tests
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
if (getIsErroneous(timestamp)) {
return false;
}
boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (null == last || last.getIsErroneous(timestamp)) {
return selfReference;
}
// already handled ones
switch(value.getValuetype()) {
case OMIT_VALUE:
case REFERENCED_VALUE:
return selfReference;
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
return selfReference;
}
break;
default:
break;
}
this.check(timestamp);
switch(last.getValuetype()) {
case SEQUENCE_VALUE:
if (value.isAsn()) {
value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
value.setIsErroneous(true);
} else {
last = last.setValuetype(timestamp, Value_type.CHOICE_VALUE);
if (!last.getIsErroneous(timestamp)) {
selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
}
}
break;
case CHOICE_VALUE:
selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.str_elem);
break;
default:
if (value.isAsn()) {
value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
} else {
value.getLocation().reportSemanticError(MessageFormat.format(UNIONEXPECTED, getFullName()));
}
value.setIsErroneous(true);
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Choice_Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
if (getIsErroneous(timestamp)) {
return false;
}
boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (last == null || last.getIsErroneous(timestamp)) {
return selfReference;
}
// already handled ones
switch(value.getValuetype()) {
case OMIT_VALUE:
case REFERENCED_VALUE:
return selfReference;
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
return selfReference;
}
break;
default:
break;
}
switch(last.getValuetype()) {
case SEQUENCE_VALUE:
if (value.isAsn()) {
value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
value.setIsErroneous(true);
} else {
last = last.setValuetype(timestamp, Value_type.CHOICE_VALUE);
if (!last.getIsErroneous(timestamp)) {
selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed);
}
}
break;
case CHOICE_VALUE:
selfReference = checkThisValueChoice(timestamp, (Choice_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed);
break;
case EXPRESSION_VALUE:
case MACRO_VALUE:
// already checked
break;
default:
if (value.isAsn()) {
value.getLocation().reportSemanticError(MessageFormat.format(CHOICEEXPECTED, getFullName()));
value.setIsErroneous(true);
} else {
value.getLocation().reportSemanticError(MessageFormat.format(UNIONEXPECTED, getFullName()));
value.setIsErroneous(true);
}
value.setIsErroneous(true);
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class Undefined_FieldSpecification method classifyFieldSpecification.
private void classifyFieldSpecification(final CompilationTimeStamp timestamp) {
final IReferenceChain temporalReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
if (isOptional && (null != defaultSetting1 || null != mDefaultSetting)) {
location.reportSemanticError("OPTIONAL and DEFAULT are mutually exclusive");
isOptional = false;
}
if (temporalReferenceChain.add(this) && null != governorReference) {
governorReference.setMyScope(myObjectClass.getMyScope());
if (null != defaultSetting1) {
defaultSetting1.setMyScope(myObjectClass.getMyScope());
}
if (identifier.isvalidAsnObjectSetFieldReference() && governorReference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
ObjectSet defaultObjectset = null;
if (null != mDefaultSetting) {
defaultObjectset = new ObjectSet_definition(mDefaultSetting);
}
final ObjectClass_refd oc = new ObjectClass_refd(governorReference);
oc.setLocation(governorReference.getLocation());
fieldSpecification = new ObjectSet_FieldSpecification(identifier, oc, isOptional, defaultObjectset);
} else if (identifier.isvalidAsnObjectFieldReference() && governorReference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
ASN1Object defaultObject = null;
if (null != defaultSetting1) {
defaultObject = new ReferencedObject(defaultSetting1);
} else if (null != mDefaultSetting) {
defaultObject = new Object_Definition(mDefaultSetting);
}
fieldSpecification = new Object_FieldSpecification(identifier, new ObjectClass_refd(governorReference), isOptional, defaultObject);
} else if (identifier.isvalidAsnValueFieldReference() && (governorReference.refersToSettingType(timestamp, Setting_type.S_T, temporalReferenceChain) || governorReference.refersToSettingType(timestamp, Setting_type.S_VS, temporalReferenceChain))) {
IValue defaultValue = null;
if (null != defaultSetting1) {
if (defaultSetting1 instanceof Defined_Reference && null == defaultSetting1.getModuleIdentifier()) {
defaultValue = new Undefined_LowerIdentifier_Value(defaultSetting1.getId().newInstance());
} else {
defaultValue = new Referenced_Value(defaultSetting1);
}
} else if (null != mDefaultSetting) {
defaultValue = new Undefined_Block_Value(mDefaultSetting);
}
fieldSpecification = new FixedTypeValue_FieldSpecification(identifier, new Referenced_Type(governorReference), false, isOptional, null != defaultSetting1 && null != mDefaultSetting, defaultValue);
}
}
if (null == fieldSpecification) {
location.reportSemanticError(CANNOTRECOGNISE);
fieldSpecification = new Erroneous_FieldSpecification(identifier, isOptional, null != defaultSetting1 || null != mDefaultSetting);
} else {
if (null != myObjectClass) {
fieldSpecification.setMyObjectClass(myObjectClass);
}
}
fieldSpecification.setFullNameParent(getNameParent());
fieldSpecification.setLocation(location);
temporalReferenceChain.release();
}
Aggregations