use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisReferencedValue.
/**
* Checks the provided referenced value.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param value
* the referenced value to be checked.
* @param lhs
* the assignment to check against
* @param expectedValue
* the expectations we have for the value.
* @param referenceChain
* the reference chain to detect circular references.
* @param strElem
* true if the value to be checked is an element of a
* string
* @return true if the value contains a reference to lhs
*/
private boolean checkThisReferencedValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final Expected_Value_type expectedValue, final IReferenceChain referenceChain, final boolean subCheck, final boolean strElem) {
final Reference reference = ((Referenced_Value) value).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true, referenceChain);
if (assignment == null) {
value.setIsErroneous(true);
return false;
}
final Assignment myAssignment = getDefiningAssignment();
if (myAssignment != null && myAssignment instanceof Definition) {
final String referingModuleName = value.getMyScope().getModuleScope().getName();
if (!((Definition) myAssignment).referingHere.contains(referingModuleName)) {
((Definition) myAssignment).referingHere.add(referingModuleName);
}
}
assignment.check(timestamp);
final boolean selfReference = assignment == lhs;
boolean isConst = false;
boolean errorFlag = false;
boolean checkRunsOn = false;
IType governor = null;
if (assignment.getIsErroneous()) {
value.setIsErroneous(true);
} else {
switch(assignment.getAssignmentType()) {
case A_CONST:
isConst = true;
break;
case A_OBJECT:
case A_OS:
final ISetting setting = reference.getRefdSetting(timestamp);
if (setting == null || setting.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
return selfReference;
}
if (!Setting_type.S_V.equals(setting.getSettingtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("This InformationFromObjects construct does not refer to a value: {0}", value.getFullName()));
value.setIsErroneous(true);
return selfReference;
}
governor = ((Value) setting).getMyGovernor();
if (governor != null) {
isConst = true;
}
break;
case A_EXT_CONST:
case A_MODULEPAR:
if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
value.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluatable) constant value was expected instead of {0}", assignment.getDescription()));
errorFlag = true;
}
break;
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
switch(expectedValue) {
case EXPECTED_CONSTANT:
value.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
errorFlag = true;
break;
case EXPECTED_STATIC_VALUE:
value.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
errorFlag = true;
break;
default:
break;
}
break;
case A_TEMPLATE:
case A_MODULEPAR_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
errorFlag = true;
}
break;
case A_FUNCTION_RVAL:
checkRunsOn = true;
switch(expectedValue) {
case EXPECTED_CONSTANT:
{
final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
value.getLocation().reportSemanticError(message);
errorFlag = true;
}
break;
case EXPECTED_STATIC_VALUE:
{
final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
value.getLocation().reportSemanticError(message);
errorFlag = true;
}
break;
default:
break;
}
break;
case A_EXT_FUNCTION_RVAL:
switch(expectedValue) {
case EXPECTED_CONSTANT:
{
final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
value.getLocation().reportSemanticError(message);
errorFlag = true;
}
break;
case EXPECTED_STATIC_VALUE:
{
final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
value.getLocation().reportSemanticError(message);
errorFlag = true;
}
break;
default:
break;
}
break;
case A_FUNCTION_RTEMP:
checkRunsOn = true;
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
errorFlag = true;
}
break;
case A_EXT_FUNCTION_RTEMP:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
errorFlag = true;
}
break;
case A_FUNCTION:
case A_EXT_FUNCTION:
value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of a call of {1}, which does not have a return type", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
value.setIsErroneous(true);
return selfReference;
default:
value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
value.setIsErroneous(true);
return selfReference;
}
}
if (checkRunsOn) {
reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
}
if (governor == null) {
final IType type = assignment.getType(timestamp);
if (type != null) {
governor = type.getFieldType(timestamp, reference, 1, expectedValue, referenceChain, false);
}
}
if (governor == null) {
value.setIsErroneous(true);
return selfReference;
}
final TypeCompatibilityInfo info = new TypeCompatibilityInfo(this, governor, true);
info.setStr1Elem(strElem);
info.setStr2Elem(reference.refersToStringElement());
final CompatibilityLevel compatibilityLevel = getCompatibility(timestamp, governor, info, null, null);
if (compatibilityLevel != CompatibilityLevel.COMPATIBLE) {
// Port or signature values do not exist at all. These
// errors are already
// reported at those definitions. Extra errors should
// not be reported
// here.
final IType type = getTypeRefdLast(timestamp, null);
switch(type.getTypetype()) {
case TYPE_PORT:
// neither port values nor templates exist
break;
case TYPE_SIGNATURE:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
final String message = MessageFormat.format("Type mismatch: a signature template of type `{0}'' was expected instead of `{1}''", getTypename(), governor.getTypename());
value.getLocation().reportSemanticError(message);
}
break;
case TYPE_SEQUENCE_OF:
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_ARRAY:
case TYPE_ASN1_SET:
case TYPE_TTCN3_SET:
case TYPE_SET_OF:
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
value.getLocation().reportSemanticError(info.getSubtypeError());
} else {
value.getLocation().reportSemanticError(info.toString());
}
break;
default:
if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
value.getLocation().reportSemanticError(info.getSubtypeError());
} else {
final String message = MessageFormat.format("Type mismatch: a {0} of type `{1}'' was expected instead of `{2}''", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", getTypename(), governor.getTypename());
value.getLocation().reportSemanticError(message);
}
break;
}
errorFlag = true;
} else {
if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
if (info.getNeedsConversion()) {
value.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, this.getTypename(), governor.getTypename()));
}
}
}
if (errorFlag) {
value.setIsErroneous(true);
return selfReference;
}
// checking for circular references
final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (isConst && !last.getIsErroneous(timestamp)) {
if (subCheck && (subType != null)) {
subType.checkThisValue(timestamp, value);
}
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.
the class UnionValueParser method process.
@Override
public Scope process(IVisitableNode node) {
if (node instanceof NamedTemplate) {
NamedTemplate nt = (NamedTemplate) node;
String name = nt.getName().toString();
subtype = map.get(name);
}
if (node instanceof TTCN3Template) {
return TemplateValueParser.getScope(this, union, subtype, node);
}
return this;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.
the class ASN1_BitString_Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
final 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;
}
if (last.isAsn()) {
if (last instanceof IReferencingType) {
final IType type = last.getMyGovernor().getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
break;
default:
value.getLocation().reportSemanticError("(reference to) BIT STRING value was expected");
value.setIsErroneous(true);
value.setLastTimeChecked(timestamp);
return selfReference;
}
}
switch(last.getValuetype()) {
case BITSTRING_VALUE:
break;
case HEXSTRING_VALUE:
last.setValuetype(timestamp, Value_type.BITSTRING_VALUE);
break;
case UNDEFINED_BLOCK:
{
last = last.setValuetype(timestamp, Value_type.NAMED_BITS);
if (namedValues == null) {
value.getLocation().reportSemanticError(MessageFormat.format("No named bits are defined in type `{0}''", getTypename()));
value.setIsErroneous(true);
value.setLastTimeChecked(timestamp);
return selfReference;
}
final Named_Bits namedBits = (Named_Bits) last;
final StringBuilder builder = new StringBuilder(namedBits.getNofIds());
for (int i = 0; i < namedBits.getNofIds(); i++) {
final Identifier id = namedBits.getIdByIndex(i);
if (!namedValues.hasNamedValueWithName(id)) {
id.getLocation().reportSemanticError(MessageFormat.format("No named bit with name `{0}'' is defined in type `{1}''", id.getDisplayName(), getTypename()));
value.setIsErroneous(true);
value.setLastTimeChecked(timestamp);
return selfReference;
}
IValue tempValue = namedValues.getNamedValueByName(id).getValue();
final ReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (!tempValue.getIsErroneous(timestamp) && Value_type.INTEGER_VALUE.equals(tempValue.getValuetype())) {
final int bitIndex = ((Integer_Value) tempValue).intValue();
while (builder.length() <= bitIndex) {
builder.append('0');
}
builder.setCharAt(bitIndex, '1');
} else {
// FIXME Most probably we were
// not able to build the
// semantic structure for
// something, because it is not
// yet supported, like
// referenced values in sets
}
}
last = new Bitstring_Value(builder.toString());
last.copyGeneralProperties(value);
namedBits.setRealValue((Bitstring_Value) last);
break;
}
default:
value.getLocation().reportSemanticError(BITSTRINGVALUEEXPECTED1);
value.setIsErroneous(true);
value.setLastTimeChecked(timestamp);
return selfReference;
}
} else {
switch(last.getValuetype()) {
case BITSTRING_VALUE:
break;
case EXPRESSION_VALUE:
case MACRO_VALUE:
// already checked
break;
default:
value.getLocation().reportSemanticError(BITSTRINGVALUEEXPECTED2);
value.setIsErroneous(true);
}
}
if (valueCheckingOptions.sub_check) {
// there is no parent type to check
if (subType != null) {
subType.checkThisValue(timestamp, last);
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
lastTimeChecked = null;
boolean handled = false;
if (ofType instanceof IIncrementallyUpdateable && reparser.envelopsDamage(ofType.getLocation())) {
((IIncrementallyUpdateable) ofType).updateSyntax(reparser, true);
reparser.updateLocation(ofType.getLocation());
handled = true;
}
if (subType != null) {
subType.updateSyntax(reparser, false);
handled = true;
}
if (handled) {
return;
}
throw new ReParseException();
}
if (ofType instanceof IIncrementallyUpdateable) {
((IIncrementallyUpdateable) ofType).updateSyntax(reparser, false);
reparser.updateLocation(ofType.getLocation());
} else if (ofType != null) {
throw new ReParseException();
}
if (subType != null) {
subType.updateSyntax(reparser, false);
}
if (withAttributesPath != null) {
withAttributesPath.updateSyntax(reparser, false);
reparser.updateLocation(withAttributesPath.getLocation());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method checkCodingAttributes.
@Override
public /**
* {@inheritDoc}
*/
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
// check raw attributes
if (subType != null) {
final int restrictionLength = subType.get_length_restriction();
if (restrictionLength != -1) {
if (rawAttribute == null) {
rawAttribute = new RawAST(getDefaultRawFieldLength());
}
rawAttribute.length_restriction = restrictionLength;
ofType.forceRaw(timestamp);
if (rawAttribute.fieldlength == 0 && rawAttribute.length_restriction != -1) {
rawAttribute.fieldlength = rawAttribute.length_restriction;
rawAttribute.length_restriction = -1;
}
if (rawAttribute.length_restriction != -1 && rawAttribute.length_restriction != rawAttribute.fieldlength) {
getLocation().reportSemanticError(MessageFormat.format("Invalid length specified in parameter FIELDLENGTH for type `{0}''. The FIELDLENGTH must be equal to specified length restriction", getFullName()));
}
}
}
if (refChain.contains(this)) {
return;
}
refChain.add(this);
refChain.markState();
ofType.checkCodingAttributes(timestamp, refChain);
refChain.previousState();
}
Aggregations