use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method checkSingleDuration.
private void checkSingleDuration(final CompilationTimeStamp timestamp, final IValue duration) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final Value v = (Value) duration.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (v.getValuetype() == Value_type.REAL_VALUE) {
final Real_Value value = (Real_Value) v;
final double valueReal = value.getValue();
if (valueReal < 0.0 || value.isSpecialFloat()) {
duration.getLocation().reportSemanticError("A non-negative float value was expected as timer duration instead of" + valueReal);
}
} else {
duration.getLocation().reportSemanticError("Value is not real");
}
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method generateCodeArrayDuration.
private void generateCodeArrayDuration(final JavaGenData aData, final StringBuilder source, final String genName, final ArrayList<String> classNames, final Value defaultDuration2, final int startDim) {
final ArrayDimension dim = dimensions.get(startDim);
final int dim_size = (int) dim.getSize();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final Value v = (Value) defaultDuration2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (v.getValuetype() != Value_type.SEQUENCEOF_VALUE) {
// ErrorReporter.INTERNAL_ERROR()
return;
}
final SequenceOf_Value value = (SequenceOf_Value) v;
if (value.getNofComponents() != dim_size && !value.isIndexed()) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
return;
}
// Value-list notation.
if (!value.isIndexed()) {
if (startDim + 1 < dimensions.size()) {
// boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
for (int i = 0; i < dim_size; i++) {
// get_comp_byIndex(i);
final IValue v_elem = value.getValueByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final String embeddedName = MessageFormat.format("{0}.getAt({1})", genName, i + dim.getOffset());
generateCodeArrayDuration(aData, source, embeddedName, classNames, (Value) v_elem, startDim + 1);
}
} else {
// We are in the last dimension, the elements of "value" are floats.
for (int i = 0; i < dim_size; i++) {
final IValue v_elem = value.getValueByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(genName);
expression.expression.append(".getAt(").append(i + dim.getOffset()).append(")");
// originally set_default_duration(obj_name, i)
expression.expression.append(".assign(");
v_elem.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
expression.mergeExpression(source);
}
}
// Indexed-list notation.
} else {
if (startDim + 1 < dimensions.size()) {
// boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
for (int i = 0; i < value.getNofComponents(); ++i) {
final IValue v_elem = value.getValueByIndex(i);
final IValue index = value.getIndexByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final String tempId1 = aData.getTemporaryVariableName();
final String tempIdX = aData.getTemporaryVariableName();
source.append("{\n");
source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
index.generateCodeInit(aData, source, tempIdX);
source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", classNames.get(classNames.size() - startDim - 2), tempId1, genName, tempIdX));
generateCodeArrayDuration(aData, source, tempId1, classNames, (Value) v_elem, startDim + 1);
source.append("}\n");
}
} else {
for (int i = 0; i < value.getNofComponents(); ++i) {
final IValue v_elem = value.getValueByIndex(i);
final IValue v_elemIndex = value.getIndexByIndex(i);
if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
continue;
}
final ExpressionStruct expression = new ExpressionStruct();
final String tempIdX = aData.getTemporaryVariableName();
source.append("{\n");
source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
v_elemIndex.generateCodeInit(aData, source, tempIdX);
final String embeddedName = MessageFormat.format("{0}.getAt(", genName);
expression.expression.append(embeddedName).append(tempIdX).append(")");
// originally set_default_duration(obj_name, i)
expression.expression.append(".assign(");
v_elem.generateCodeExpression(aData, expression, true);
expression.expression.append(')');
expression.mergeExpression(source);
source.append("}\n");
}
}
}
return;
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class SelectWithNumbersSorted method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof SelectCase_Statement)) {
return;
}
final SelectCase_Statement s = (SelectCase_Statement) node;
final Value v = s.getExpression();
if (v == null || v.getIsErroneous(timestamp)) {
return;
}
final SelectCases scs = s.getSelectCases();
if (scs == null || scs.getSelectCaseArray() == null) {
return;
}
// if there is an else branch, no smell will be reported
for (final SelectCase sc : scs.getSelectCaseArray()) {
if (sc.hasElse()) {
return;
}
}
IType itype = v.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
// TODO Kristof: az ellenorzes folosleges.
if (itype instanceof Referenced_Type) {
itype = itype.getTypeRefdLast(timestamp);
}
if (itype == null || !(itype instanceof Integer_Type)) {
return;
}
// count number of cases in select, get used integer type case-items
final CaseVisitorInteger caseVisitorInteger = new CaseVisitorInteger();
scs.accept(caseVisitorInteger);
if (caseVisitorInteger.containsUnfoldable()) {
return;
}
final List<Long> usedIntegerItems = caseVisitorInteger.getItemsUsed();
if (!checkIfIntegerCasesSorted(usedIntegerItems)) {
problems.report(s.getLocation(), ERR_MSG);
}
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class VerdictWithoutReason method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof Setverdict_Statement)) {
return;
}
final Setverdict_Statement s = (Setverdict_Statement) node;
final Value verdictValue = s.getVerdictValue();
if (verdictValue == null) {
return;
}
final CompilationTimeStamp ct = CompilationTimeStamp.getBaseTimestamp();
final Type_type temp = verdictValue.getExpressionReturntype(ct, Expected_Value_type.EXPECTED_TEMPLATE);
if (Type_type.TYPE_VERDICT != temp) {
return;
}
final LogArguments verdictReason = s.getVerdictReason();
if (Value_type.VERDICT_VALUE.equals(verdictValue.getValuetype()) && !Verdict_type.PASS.equals(((Verdict_Value) verdictValue).getValue()) && verdictReason == null) {
final String msg = MessageFormat.format(WITHOUT_REASON, ((Verdict_Value) verdictValue).getValue());
problems.report(s.getLocation(), msg);
}
}
use of org.eclipse.titan.designer.AST.Value in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Enumerated_Type method check.
/**
* Does the semantic checking of the enumerations.
*
* @param timestamp the timestamp of the actual semantic check cycle.
*/
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
parseAttributes(timestamp);
nameMap = new HashMap<String, EnumItem>(items.getItems().size());
final Map<Long, EnumItem> valueMap = new HashMap<Long, EnumItem>(items.getItems().size());
final List<EnumItem> enumItems = items.getItems();
// check duplicated names and values
for (int i = 0, size = enumItems.size(); i < size; i++) {
final EnumItem item = enumItems.get(i);
final Identifier id = item.getId();
final String fieldName = id.getName();
if (nameMap.containsKey(fieldName)) {
nameMap.get(fieldName).getId().getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERFIRST, id.getDisplayName()));
id.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERREPEATED, id.getDisplayName()));
} else {
nameMap.put(fieldName, item);
}
final Value value = item.getValue();
if (value != null && item.isOriginal()) {
if (value.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(value.getValuetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", id.getDisplayName()));
setIsErroneous(true);
} else {
final Integer_Value enumValue = (Integer_Value) value;
if (!enumValue.isNative()) {
enumValue.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERERROR, enumValue.getValueValue()));
setIsErroneous(true);
} else {
final Long enumLong = enumValue.getValue();
if (valueMap.containsKey(enumLong)) {
valueMap.get(enumLong).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumLong, valueMap.get(enumLong).getId().getDisplayName()));
value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumLong, id.getDisplayName()));
setIsErroneous(true);
} else {
valueMap.put(enumLong, item);
}
}
}
}
}
// Assign default values
if (!getIsErroneous(timestamp) && lastTimeChecked == null) {
Long firstUnused = Long.valueOf(0);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
for (int i = 0, size = enumItems.size(); i < size; i++) {
final EnumItem item = enumItems.get(i);
if (!item.isOriginal()) {
// optimization: if the same value was already assigned, there is no need to create it again.
final IValue value = item.getValue();
if (value == null || ((Integer_Value) value).getValue() != firstUnused) {
final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
tempValue.setLocation(item.getLocation());
item.setValue(tempValue);
}
valueMap.put(firstUnused, item);
firstUnused = Long.valueOf(firstUnused.longValue() + 1);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
}
}
}
valueMap.clear();
lastTimeChecked = timestamp;
checkSubtypeRestrictions(timestamp);
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
Aggregations