use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType temp = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
return true;
}
if (info == null || noStructuredTypeCompatibility) {
return this == temp;
}
switch(temp.getTypetype()) {
case TYPE_ASN1_SET:
{
final ASN1_Set_Type tempType = (ASN1_Set_Type) temp;
if (this == tempType) {
return true;
}
if (getNofComponents(timestamp) != tempType.getNofComponents(timestamp)) {
info.setErrorStr(NOFFIELDSDONTMATCH);
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final CompField tempTypeCompField = tempType.getComponentByIndex(i);
final IType compFieldType = cf.getType().getTypeRefdLast(timestamp);
final IType tempTypeCompFieldType = tempTypeCompField.getType().getTypeRefdLast(timestamp);
if (cf.isOptional() != tempTypeCompField.isOptional()) {
final String compFieldName = cf.getIdentifier().getDisplayName();
final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName);
info.appendOp2Ref("." + tempTypeCompFieldName);
info.setOp1Type(compFieldType);
info.setOp2Type(tempTypeCompFieldType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(tempTypeCompFieldType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, tempTypeCompFieldType, false);
if (!compFieldType.equals(tempTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, tempTypeCompFieldType, infoTemp, lChain, rChain)) {
final String compFieldName = cf.getIdentifier().getDisplayName();
final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCompFieldName + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_TTCN3_SET:
{
final TTCN3_Set_Type tempType = (TTCN3_Set_Type) temp;
if (getNofComponents(timestamp) != tempType.getNofComponents()) {
info.setErrorStr(NOFFIELDSDONTMATCH);
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
final CompField compField = getComponentByIndex(i);
final CompField tempTypeCompField = tempType.getComponentByIndex(i);
final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
final IType tempTypeCompFieldType = tempTypeCompField.getType().getTypeRefdLast(timestamp);
if (compField.isOptional() != tempTypeCompField.isOptional()) {
final String compFieldName = compField.getIdentifier().getDisplayName();
final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName);
info.appendOp2Ref("." + tempTypeCompFieldName);
info.setOp1Type(compFieldType);
info.setOp2Type(tempTypeCompFieldType);
info.setErrorStr(BADOPTIONALITY);
return false;
}
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(tempTypeCompFieldType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, tempTypeCompFieldType, false);
if (!compFieldType.equals(tempTypeCompFieldType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, tempTypeCompFieldType, infoTemp, lChain, rChain)) {
final String compFieldName = compField.getIdentifier().getDisplayName();
final String tempTypeCompFieldName = tempTypeCompField.getIdentifier().getDisplayName();
info.appendOp1Ref("." + compFieldName + infoTemp.getOp1RefStr());
info.appendOp2Ref("." + tempTypeCompFieldName + infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_SET_OF:
{
final SetOf_Type tempType = (SetOf_Type) temp;
if (!tempType.isSubtypeCompatible(timestamp, this)) {
info.setErrorStr("Incompatible set of/SET OF subtypes");
return false;
}
final int nofComps = getNofComponents(timestamp);
if (nofComps == 0) {
return false;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(tempType);
}
for (int i = 0; i < nofComps; i++) {
final CompField compField = getComponentByIndex(i);
final IType compFieldType = compField.getType().getTypeRefdLast(timestamp);
final IType temporalTypeOfType = tempType.getOfType().getTypeRefdLast(timestamp);
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(temporalTypeOfType);
final TypeCompatibilityInfo infoTemp = new TypeCompatibilityInfo(compFieldType, temporalTypeOfType, false);
if (!compFieldType.equals(temporalTypeOfType) && !(lChain.hasRecursion() && rChain.hasRecursion()) && !compFieldType.isCompatible(timestamp, temporalTypeOfType, infoTemp, lChain, rChain)) {
info.appendOp1Ref("." + compField.getIdentifier().getDisplayName() + infoTemp.getOp1RefStr());
if (infoTemp.getOp2RefStr().length() > 0) {
info.appendOp2Ref("[]");
}
info.appendOp2Ref(infoTemp.getOp2RefStr());
info.setOp1Type(infoTemp.getOp1Type());
info.setOp2Type(infoTemp.getOp2Type());
info.setErrorStr(infoTemp.getErrorStr());
lChain.previousState();
rChain.previousState();
return false;
}
lChain.previousState();
rChain.previousState();
}
info.setNeedsConversion(true);
return true;
}
case TYPE_ASN1_CHOICE:
case TYPE_TTCN3_CHOICE:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNIONANYTYPE);
return false;
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_SEQUENCE_OF:
case TYPE_ARRAY:
info.setErrorStr(NOTCOMPATIBLESETSETOF);
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class CTs_EE_CTs method check.
public void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
if (null != myScope && null != lastTimeChecked) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
lastTimeChecked = timestamp;
return;
}
}
}
if (null == myType) {
return;
} else if (null == components) {
components = new ArrayList<CompField>();
componentsMap = new HashMap<String, CompField>();
}
lastTimeChecked = timestamp;
components.clear();
componentsMap.clear();
String typeName;
String componentName;
switch(myType.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
typeName = "SEQUENCE";
componentName = "Component";
break;
case TYPE_ASN1_SET:
typeName = "SET";
componentName = "Component";
break;
case TYPE_ASN1_CHOICE:
typeName = "CHOICE";
componentName = "Alternative";
break;
default:
// some INTERNAL ERROR
typeName = "<unknown>";
componentName = "component";
break;
}
for (int i = 0; i < componentTypeList1.getNofComps(); i++) {
checkComponentField(componentTypeList1.getCompByIndex(i), typeName, componentName);
}
if (null != extensionAndException) {
for (int i = 0; i < extensionAndException.getNofComps(); i++) {
checkComponentField(extensionAndException.getCompByIndex(i), typeName, componentName);
}
final ExceptionSpecification es = extensionAndException.getExceptionSpecification();
if (es != null) {
es.getType().check(timestamp);
}
}
for (int i = 0; i < componentTypeList2.getNofComps(); i++) {
checkComponentField(componentTypeList2.getCompByIndex(i), typeName, componentName);
}
components.trimToSize();
IType type;
for (final CompField componentField : components) {
type = componentField.getType();
type.setGenName(myType.getGenNameOwn(), componentField.getIdentifier().getName());
type.setParentType(myType);
componentField.check(timestamp);
}
}
use of org.eclipse.titan.designer.AST.IType 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.IType in project titan.EclipsePlug-ins by eclipse.
the class ASN1_BitString_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType temp = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp)) {
return true;
}
return Type_type.TYPE_BITSTRING.equals(temp.getTypetype()) || Type_type.TYPE_BITSTRING_A.equals(temp.getTypetype());
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Choice_Type method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
if (components == null) {
return;
}
final String genName = getGenNameOwn();
final String displayName = getFullName();
generateCodeTypedescriptor(aData, source);
final List<FieldInfo> fieldInfos = new ArrayList<FieldInfo>();
boolean hasOptional = false;
for (int i = 0; i < components.getNofComps(); i++) {
final CompField compField = components.getCompByIndex(i);
final IType cfType = compField.getType();
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
hasOptional |= compField.isOptional();
fieldInfos.add(fi);
}
for (int i = 0; i < components.getNofComps(); i++) {
final CompField compField = components.getCompByIndex(i);
final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
compField.getType().generateCode(aData, tempSource);
}
UnionGenerator.generateValueClass(aData, source, genName, displayName, fieldInfos, hasOptional, getGenerateCoderFunctions(MessageEncoding_type.RAW), null);
UnionGenerator.generateTemplateClass(aData, source, genName, displayName, fieldInfos, hasOptional);
generateCodeForCodingHandlers(aData, source);
}
Aggregations