use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Enumerated_Type method isCompatible.
@Override
public final /**
* {@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 this == temp;
}
use of org.eclipse.titan.designer.AST.IType 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;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class TableConstraint method getOpenTypeAlternativeName.
// Original titan.core version: t_type->get_otaltname(is_strange);
private Identifier getOpenTypeAlternativeName(final CompilationTimeStamp timestamp, final Type type, final AtomicBoolean isStrange) {
StringBuffer sb = new StringBuffer();
// TODO: if (is_tagged() || is_constrained() || hasRawAttrs()) {
if (!type.getIsErroneous(timestamp) && type.isConstrained()) {
sb.append(type.getGenNameOwn());
isStrange.set(true);
} else if (!type.getIsErroneous(timestamp) && type instanceof Referenced_Type) {
Reference t_ref = ((Referenced_Type) type).getReference();
if (t_ref != null) {
final Identifier id = t_ref.getId();
final String dn = id.getDisplayName();
int i = dn.indexOf('.');
if (i >= 0 && i < dn.length()) {
// id is not regular because t_ref is a parameterized reference
sb.append(id.getName());
isStrange.set(true);
} else {
Assignment as = t_ref.getRefdAssignment(timestamp, true);
if (as == null) {
return null;
}
Scope assScope = as.getMyScope();
if (assScope.getParentScope() == assScope.getModuleScope()) {
sb.append(id.getName());
isStrange.set(false);
} else {
// t_ref is a dummy reference in a parameterized assignment
// (i.e. it points to a parameter assignment of an instantiation)
// perform the same examination recursively on the referenced type
// (which is the actual parameter)
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
chain.release();
return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
}
}
} else {
// the type comes from an information object [class]
// examine the referenced type recursively
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
chain.release();
return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
}
} else {
Identifier tmpId1 = new Identifier(Identifier_type.ID_NAME, type.getFullName());
String s = tmpId1.getDisplayName();
// module name will be cut off:
if (s.startsWith("@") && s.indexOf('.') > 0) {
s = s.substring(s.indexOf('.') + 1);
}
Identifier tmpId2 = new Identifier(Identifier_type.ID_ASN, s);
sb.append(tmpId2.getTtcnName());
}
// conversion to lower case initial:
sb.replace(0, 1, sb.substring(0, 1).toLowerCase());
// trick:
Identifier tmpId = new Identifier(Identifier_type.ID_NAME, sb.toString());
return new Identifier(Identifier_type.ID_ASN, tmpId.getAsnName());
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Indexed_Template_List method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
if (asValue != null) {
asValue.generateCodeInit(aData, source, name);
return;
}
if (myGovernor == null) {
return;
}
// FIXME actually a bit more complex
final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
String ofTypeName;
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
ofTypeName = ((SequenceOf_Type) type).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_SET_OF:
ofTypeName = ((SetOf_Type) type).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_ARRAY:
ofTypeName = ((Array_Type) type).getElementType().getGenNameTemplate(aData, source, myScope);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing indexed template `" + getFullName() + "''");
return;
}
if (indexedTemplates.getNofTemplates() == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
}
// else is not needed as the loop will not run
for (int i = 0; i < indexedTemplates.getNofTemplates(); i++) {
final IndexedTemplate indexedTemplate = indexedTemplates.getTemplateByIndex(i);
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
final Value index = indexedTemplate.getIndex().getValue();
if (Value_type.INTEGER_VALUE.equals(index.getValuetype())) {
source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", ofTypeName, tempId, name, ((Integer_Value) index).getValue()));
} else {
final String tempId2 = aData.getTemporaryVariableName();
source.append(MessageFormat.format("TitanInteger {0} = new TitanInteger();\n", tempId2));
index.generateCodeInit(aData, source, tempId2);
source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", ofTypeName, tempId, name, tempId2));
}
indexedTemplate.getTemplate().generateCodeInit(aData, source, tempId);
source.append("}\n");
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Indexed_Template_List method getReferencedArrayTemplate.
@Override
protected /**
* {@inheritDoc}
*/
ITTCN3Template getReferencedArrayTemplate(final CompilationTimeStamp timestamp, final IValue arrayIndex, final IReferenceChain referenceChain) {
IValue indexValue = arrayIndex.setLoweridToReference(timestamp);
indexValue = indexValue.getValueRefdLast(timestamp, referenceChain);
if (indexValue.getIsErroneous(timestamp)) {
return null;
}
long index = 0;
if (!indexValue.isUnfoldable(timestamp)) {
if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
index = ((Integer_Value) indexValue).getValue();
} else {
arrayIndex.getLocation().reportSemanticError("An integer value was expected as index");
return null;
}
} else {
return null;
}
final IType tempType = myGovernor.getTypeRefdLast(timestamp);
if (tempType.getIsErroneous(timestamp)) {
return null;
}
switch(tempType.getTypetype()) {
case TYPE_SEQUENCE_OF:
{
if (index < 0) {
final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `sequence of'' type `{1}''", index, tempType.getTypename());
arrayIndex.getLocation().reportSemanticError(message);
return null;
}
break;
}
case TYPE_SET_OF:
{
if (index < 0) {
final String message = MessageFormat.format("A non-negative integer value was expected instead of {0} for indexing a template of `set of'' type `{1}''", index, tempType.getTypename());
arrayIndex.getLocation().reportSemanticError(message);
return null;
}
break;
}
case TYPE_ARRAY:
{
final ArrayDimension dimension = ((Array_Type) tempType).getDimension();
dimension.checkIndex(timestamp, indexValue, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!dimension.getIsErroneous(timestamp)) {
// re-base the index
index -= dimension.getOffset();
if (index < 0 || index > getNofTemplates()) {
arrayIndex.getLocation().reportSemanticError(MessageFormat.format("The index value {0} is outside the array indexable range", index + dimension.getOffset()));
return null;
}
} else {
return null;
}
break;
}
default:
arrayIndex.getLocation().reportSemanticError(MessageFormat.format("Invalid array element reference: type `{0}'' cannot be indexed", tempType.getTypename()));
return null;
}
for (int i = 0, size = indexedTemplates.getNofTemplates(); i < size; i++) {
final IndexedTemplate template = indexedTemplates.getTemplateByIndex(i);
IValue lastValue = template.getIndex().getValue();
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
lastValue = lastValue.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(lastValue.getValuetype())) {
final long tempIndex = ((Integer_Value) lastValue).getValue();
if (index == tempIndex) {
final ITTCN3Template realTemplate = template.getTemplate();
if (Template_type.TEMPLATE_NOTUSED.equals(realTemplate.getTemplatetype())) {
if (baseTemplate != null) {
return baseTemplate.getTemplateReferencedLast(timestamp, referenceChain).getReferencedArrayTemplate(timestamp, indexValue, referenceChain);
}
return null;
}
return realTemplate;
}
}
}
switch(tempType.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_ARRAY:
// unfoldable (for now)
break;
default:
// the error was reported earlier
break;
}
return null;
}
Aggregations