use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type in project titan.EclipsePlug-ins by eclipse.
the class InsertFieldWizardInputPage method checkName.
public void checkName() {
final Identifier id = new Identifier(Identifier_type.ID_TTCN, nameField.getText().trim());
settings.setId(id);
if (!Identifier.isValidInTtcn(settings.getId().getName())) {
nameErrorMessage = INVALIDNAME;
nameDone = false;
} else {
final IType type = selection.getType(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
final TTCN3_Set_Seq_Choice_BaseType ss = (TTCN3_Set_Seq_Choice_BaseType) type;
if (ss.hasComponentWithName(settings.getId().getName())) {
nameErrorMessage = NAMEEXISTS;
nameDone = false;
} else {
nameErrorMessage = "";
nameDone = true;
}
}
}
setErrorMessage(positionErrorMessage + typeErrorMessage + nameErrorMessage + valueErrorMessage);
setPageComplete(posDone && typeDone && nameDone && valueDone);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
* generate_code_init_se in the compiler
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
int nofComps = 0;
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
nofComps = ((TTCN3_Set_Type) type).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComps = ((ASN1_Set_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
if (nofComps == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
return source;
}
CompField compField = null;
for (int i = 0; i < nofComps; i++) {
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Type) type).getComponentByIndex(i);
break;
case TYPE_ASN1_SET:
compField = ((ASN1_Set_Type) type).getComponentByIndex(i);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
final Identifier fieldName = compField.getIdentifier();
IValue fieldValue;
if (hasComponentWithName(fieldName)) {
fieldValue = getComponentByName(fieldName).getValue();
if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
continue;
} else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
fieldValue = null;
}
} else // TODO add support for asn default values when needed
{
continue;
}
final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
if (fieldValue != null) {
// TODO handle the case when temporary reference is needed
final StringBuilder embeddedName = new StringBuilder();
embeddedName.append(name);
embeddedName.append(".get");
embeddedName.append(javaGetterName);
embeddedName.append("()");
if (compField.isOptional()) /*&& fieldValue.isCompound() */
{
embeddedName.append(".get()");
}
// TODO add extra handling for optional fields
fieldValue.generateCodeInit(aData, source, embeddedName.toString());
} else {
aData.addBuiltinTypeImport("Base_Template.template_sel");
source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
}
}
return source;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method setGenNameRecursive.
@Override
public /**
* {@inheritDoc}
*/
void setGenNameRecursive(final String parameterGenName) {
super.setGenNameRecursive(parameterGenName);
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
if (governor == null) {
return;
}
final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
for (int i = 0; i < values.getSize(); i++) {
final String name = values.getNamedValueByIndex(i).getName().getName();
if (((TTCN3_Set_Type) type).hasComponentWithName(name)) {
final StringBuilder embeddedName = new StringBuilder(parameterGenName);
embeddedName.append('.');
embeddedName.append(name);
embeddedName.append("()");
if (((TTCN3_Set_Type) type).getComponentByName(name).isOptional()) {
embeddedName.append(".get()");
}
values.getNamedValueByIndex(i).getValue().setGenNameRecursive(embeddedName.toString());
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method checkEquality.
@Override
public /**
* {@inheritDoc}
*/
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = other.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (!Value_type.SET_VALUE.equals(last.getValuetype())) {
return false;
}
if (myGovernor == null) {
return false;
}
final Set_Value otherSet = (Set_Value) last;
if (values.getSize() != otherSet.values.getSize()) {
return false;
}
int nofComps = 0;
final IType leftGovernor = myGovernor.getTypeRefdLast(timestamp);
switch(leftGovernor.getTypetype()) {
case TYPE_TTCN3_SET:
nofComps = ((TTCN3_Set_Type) leftGovernor).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComps = ((ASN1_Set_Type) leftGovernor).getNofComponents(timestamp);
break;
default:
return false;
}
CompField compField = null;
for (int i = 0; i < nofComps; i++) {
switch(leftGovernor.getTypetype()) {
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Type) leftGovernor).getComponentByIndex(i);
break;
case TYPE_ASN1_SET:
compField = ((ASN1_Set_Type) leftGovernor).getComponentByIndex(i);
break;
default:
return false;
}
final Identifier fieldName = compField.getIdentifier();
if (hasComponentWithName(fieldName)) {
final IValue leftValue = getComponentByName(fieldName).getValue();
if (otherSet.hasComponentWithName(fieldName)) {
final IValue otherValue = otherSet.getComponentByName(fieldName).getValue();
if ((Value_type.OMIT_VALUE.equals(leftValue.getValuetype()) && !Value_type.OMIT_VALUE.equals(otherValue.getValuetype())) || (!Value_type.OMIT_VALUE.equals(leftValue.getValuetype()) && Value_type.OMIT_VALUE.equals(otherValue.getValuetype()))) {
return false;
}
if (!leftValue.checkEquality(timestamp, otherValue)) {
return false;
}
} else {
if (compField.hasDefault()) {
if (!leftValue.checkEquality(timestamp, compField.getDefault())) {
return false;
}
} else {
if (!Value_type.OMIT_VALUE.equals(leftValue.getValuetype())) {
return false;
}
}
}
} else {
if (otherSet.hasComponentWithName(fieldName)) {
final IValue otherValue = otherSet.getComponentByName(fieldName).getValue();
if (compField.hasDefault()) {
if (Value_type.OMIT_VALUE.equals(otherValue.getValuetype())) {
return false;
}
if (!compField.getDefault().checkEquality(timestamp, otherValue)) {
return false;
}
}
}
}
}
return true;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
return null;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
return null;
case fieldSubReference:
final Identifier fieldId = ((FieldSubReference) subreference).getId();
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
return null;
}
break;
case TYPE_ASN1_SET:
if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
return null;
}
break;
default:
return null;
}
if (values.hasNamedValueWithName(fieldId)) {
return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
if (!reference.getUsedInIsbound()) {
subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound set field `{0}''", fieldId.getDisplayName()));
}
// this is an error, that was already reported
return null;
}
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.getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
} else if (compField.hasDefault()) {
return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
Aggregations