use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method getSubrefsAsArray.
@Override
public /**
* {@inheritDoc}
*/
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return true;
}
final ISubReference subreference = subreferences.get(actualSubReference);
if (subreference.getReferenceType() != Subreference_type.arraySubReference) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
final Value indexValue = ((ArraySubReference) subreference).getValue();
if (indexValue == null) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
final IValue last = indexValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_CONSTANT, null);
if (last == null) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
if (last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_CONSTANT) != Type_type.TYPE_INTEGER) {
return false;
}
if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
return false;
}
final Integer_Value lastInteger = (Integer_Value) last;
if (lastInteger.isNative()) {
final int fieldIndex = (int) lastInteger.getValue();
if (fieldIndex < 0) {
return false;
}
subrefsArray.add(fieldIndex);
typeArray.add(this);
} else {
return false;
}
if (ofType == null) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
return ofType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
}
use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method getFieldType.
@Override
public /**
* {@inheritDoc}
*/
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return this;
}
final Expected_Value_type internalExpectation = (expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE) ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
final Value indexValue = ((ArraySubReference) subreference).getValue();
if (dimension != null) {
dimension.checkIndex(timestamp, indexValue, expectedIndex);
}
if (elementType != null) {
return elementType.getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
}
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method generateCodeIsPresentBoundChosen.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, final String field) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return;
}
if (subReferenceIndex >= subreferences.size()) {
return;
}
final StringBuilder closingBrackets = new StringBuilder();
if (isTemplate) {
boolean anyvalueReturnValue = true;
if (optype == Operation_type.ISPRESENT_OPERATION) {
anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
anyvalueReturnValue = false;
}
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case ANY_VALUE:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("case SPECIFIC_VALUE:{\n");
closingBrackets.append("break;}\n");
closingBrackets.append("default:\n");
closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
closingBrackets.append("break;\n");
closingBrackets.append("}\n");
closingBrackets.append("}\n");
}
final ISubReference subReference = subreferences.get(subReferenceIndex);
if (!(subReference instanceof ArraySubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return;
}
final IType nextType = elementType;
final Value indexValue = ((ArraySubReference) subReference).getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = indexValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalIndexId = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("TitanInteger {0} = ", temporalIndexId));
last.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(";\n");
expression.expression.append(MessageFormat.format("{0} = {1}.isGreaterThanOrEqual(0) && {1}.isLessThan({2}.{3});\n", globalId, temporalIndexId, externalId, isTemplate ? "n_elem()" : "sizeOf()"));
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
if (isTemplate) {
expression.expression.append(MessageFormat.format("{0} {1} = {2}.constGetAt({3});\n", nextType.getGenNameTemplate(aData, expression.expression, myScope), temporalId, externalId, temporalIndexId));
} else {
expression.expression.append(MessageFormat.format("{0} {1} = {2}.constGetAt({3});\n", nextType.getGenNameValue(aData, expression.expression, myScope), temporalId, externalId, temporalIndexId));
}
final boolean isLast = subReferenceIndex == (subreferences.size() - 1);
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.{2}({3});\n", globalId, temporalId, !isLast ? "isBound" : "isPresent", isLast && isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId, field));
expression.expression.append("}\n");
}
}
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId, isTemplate, optype, field);
expression.expression.append(closingBrackets);
}
use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method isPresentAnyvalueEmbeddedField.
@Override
public /**
* {@inheritDoc}
*/
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return true;
}
if (beginIndex >= subreferences.size()) {
return true;
}
final ISubReference subReference = subreferences.get(beginIndex);
if (!(subReference instanceof ArraySubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return true;
}
if (elementType == null) {
return true;
}
return elementType.isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class UniversalCharstring_Type method getFieldType.
@Override
public /**
* {@inheritDoc}
*/
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return this;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
if (subreferences.size() > actualSubReference + 1) {
subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
return null;
} else if (subreferences.size() == actualSubReference + 1) {
reference.setStringElementReferencing();
}
final Value indexValue = ((ArraySubReference) subreference).getValue();
checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
return this;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
Aggregations