use of org.eclipse.titan.designer.AST.Value 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.Value 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.Value in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method checkThisValueArray.
private boolean checkThisValueArray(final CompilationTimeStamp timestamp, final IValue originalValue, final Assignment lhs, final Array_Value lastValue, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
if (dimension == null) {
return false;
}
boolean selfReference = false;
final int nofValues = lastValue.getNofComponents();
if (!dimension.getIsErroneous(timestamp) && dimension.getSize() < nofValues) {
originalValue.getLocation().reportSemanticError(MessageFormat.format(TOOMANYEXPECTED, dimension.getSize(), nofValues));
originalValue.setIsErroneous(true);
}
if (lastValue.isIndexed()) {
boolean checkHoles = !dimension.getIsErroneous(timestamp) && Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
final long arraySize = dimension.getSize();
BigInteger maxIndex = BigInteger.valueOf(-1);
final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(lastValue.getNofComponents());
for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
final IValue component = lastValue.getValueByIndex(i);
final Value index = lastValue.getIndexByIndex(i);
dimension.checkIndex(timestamp, index, expectedValue);
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(indexLast.getValuetype())) {
checkHoles = false;
} else {
final BigInteger tempIndex = ((Integer_Value) indexLast).getValueValue();
if (tempIndex.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
index.getLocation().reportSemanticError(MessageFormat.format("A integer value less than `{0}'' was expected for indexing type `{1}'' instead of `{2}''", Integer.MAX_VALUE, getTypename(), tempIndex));
checkHoles = false;
} else if (tempIndex.compareTo(BigInteger.ZERO) == -1) {
index.getLocation().reportSemanticError(MessageFormat.format("A non-negative integer value was expected for indexing type `{0}'' instead of `{1}''", getTypename(), tempIndex));
checkHoles = false;
} else if (indexMap.containsKey(tempIndex)) {
index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value `{0}'' for components {1} and {2}", tempIndex, indexMap.get(tempIndex), i + 1));
checkHoles = false;
} else {
indexMap.put(tempIndex, Integer.valueOf(i + 1));
if (maxIndex.compareTo(tempIndex) == -1) {
maxIndex = tempIndex;
}
}
}
component.setMyGovernor(elementType);
final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
}
if (checkHoles) {
if (indexMap.size() < arraySize) {
lastValue.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
originalValue.setIsErroneous(true);
}
}
} else {
if (!dimension.getIsErroneous(timestamp)) {
final long arraySize = dimension.getSize();
if (arraySize > nofValues) {
originalValue.getLocation().reportSemanticError(MessageFormat.format("Too few elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
originalValue.setIsErroneous(true);
} else if (arraySize < nofValues) {
originalValue.getLocation().reportSemanticError(MessageFormat.format("Too many elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
originalValue.setIsErroneous(true);
}
}
for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
final IValue component = lastValue.getValueByIndex(i);
component.setMyGovernor(elementType);
if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
if (!incompleteAllowed) {
component.getLocation().reportSemanticError(AbstractOfType.INCOMPLETEPRESENTERROR);
}
} else {
final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
}
}
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.Value 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;
}
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class HexString_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