use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class SubsetMatch_Template 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();
aData.addBuiltinTypeImport("Base_Template.template_sel");
String ofTypeName;
switch(myGovernor.getTypetype()) {
case TYPE_SEQUENCE_OF:
ofTypeName = ((SequenceOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_SET_OF:
ofTypeName = ((SetOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_ARRAY:
ofTypeName = ((Array_Type) myGovernor).getElementType().getGenNameTemplate(aData, source, myScope);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing subset match template `" + getFullName() + "''");
return;
}
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
expression.expression.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
final String embeddedName = MessageFormat.format("{0}.setItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.setItem({3}{4});\n", ofTypeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.setItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.setItem({3});\n", ofTypeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.setItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
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.Reference in project titan.EclipsePlug-ins by eclipse.
the class ValueList_Template 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();
aData.addBuiltinTypeImport("Base_Template.template_sel");
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.VALUE_LIST, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
expression.expression.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
final String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.VALUE_LIST, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
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.Reference in project titan.EclipsePlug-ins by eclipse.
the class Component_Type method checkExpressionOperandComponentRefernce.
/**
* Checks if the provided value is a reference to a component or not.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param value the value to be checked
* @param expected_value the value kind expected from the actual parameter.
*/
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
switch(value.getValuetype()) {
case EXPRESSION_VALUE:
{
final Expression_Value expression = (Expression_Value) value;
if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, chain);
chain.release();
if (last == null || last.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
return;
}
IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
}
break;
}
case REFERENCED_VALUE:
{
final Reference reference = ((Referenced_Value) value).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
value.setIsErroneous(true);
return;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
{
IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
IValue tempValue = ((Def_Const) assignment).getValue();
if (tempValue == null) {
return;
}
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
chain.release();
if (tempValue == null) {
return;
}
chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
value.setIsErroneous(true);
return;
}
if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
return;
}
switch(((Expression_Value) tempValue).getOperationType()) {
case MTC_COMPONENT_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
value.setIsErroneous(true);
return;
case COMPONENT_NULL_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
value.setIsErroneous(true);
return;
case SYSTEM_COMPONENT_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
value.setIsErroneous(true);
return;
default:
break;
}
break;
}
case A_EXT_CONST:
{
IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_MODULEPAR:
{
IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_VAR:
{
IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_FUNCTION_RVAL:
{
IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_EXT_FUNCTION_RVAL:
{
IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
{
IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
default:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
value.setIsErroneous(true);
return;
}
break;
}
default:
// the error was already reported if possible.
return;
}
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class SubType method addTtcnSingle.
/**
* add TTCN-3 single value sub-type constraint to this sub-type
*/
private boolean addTtcnSingle(final CompilationTimeStamp timestamp, final Value value, final int restrictionIndex) {
value.setMyScope(myOwner.getMyScope());
value.setMyGovernor(myOwner);
final BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getTypename() + ".<single_restriction_" + restrictionIndex + ">");
value.setFullNameParent(bridge);
IValue last = myOwner.checkThisValueRef(timestamp, value);
// check if this is type reference, if not then fall through
final IValue refValue = value.setLoweridToReference(timestamp);
// Value_type.REFERENCED_VALUE);
if (refValue.getValuetype() == Value.Value_type.REFERENCED_VALUE) {
final Reference ref = ((Referenced_Value) refValue).getReference();
final Assignment ass = ref.getRefdAssignment(timestamp, false);
if (ass == null) {
// definition was not found, error was reported
return false;
}
if (ass.getAssignmentType() == Assignment.Assignment_type.A_TYPE) {
IType t = ass.getType(timestamp);
t.check(timestamp);
if (t.getIsErroneous(timestamp)) {
return false;
}
final List<ISubReference> subrefs = ref.getSubreferences();
if (subrefs.size() > 1) {
// if there were sub-references then get the referenced field's type
t = t.getFieldType(timestamp, ref, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
if ((t == null) || t.getIsErroneous(timestamp)) {
return false;
}
t.check(timestamp);
if (t.getIsErroneous(timestamp)) {
return false;
}
}
if (!t.isIdentical(timestamp, myOwner)) {
value.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' must refer to a type which has the same root type as this type", ref.getDisplayName()));
return false;
}
// check subtype of referenced type
final SubType tSt = t.getSubtype();
if ((tSt == null) || (tSt.subtypeConstraint == null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Type referenced by `{0}'' does not have a subtype", ref.getDisplayName()));
return false;
}
// check circular sub-type reference
if (!addParentSubtype(tSt)) {
return false;
}
if (tSt.getIsErroneous(timestamp)) {
return false;
}
if (tSt.subtypeType != subtypeType) {
ErrorReporter.INTERNAL_ERROR();
return false;
}
// add the sub-type as union
if (subtypeConstraint == null) {
subtypeConstraint = tSt.subtypeConstraint;
} else {
subtypeConstraint = subtypeConstraint.union(tSt.subtypeConstraint);
}
return true;
}
}
myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
last = last.getValueRefdLast(timestamp, chain);
chain.release();
if (last.getIsErroneous(timestamp) || last.isUnfoldable(timestamp)) {
return false;
}
// create a single value constraint
SubtypeConstraint sc;
switch(subtypeType) {
case ST_INTEGER:
sc = new RangeListConstraint(new IntegerLimit(((Integer_Value) last).getValueValue()));
break;
case ST_FLOAT:
sc = new RealRangeListConstraint(((Real_Value) last).getValue());
break;
case ST_BOOLEAN:
sc = new BooleanListConstraint(((Boolean_Value) last).getValue());
break;
case ST_VERDICTTYPE:
sc = new VerdicttypeListConstraint(((Verdict_Value) last).getValue());
break;
case ST_BITSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.BITSTRING, ((Bitstring_Value) last).getValue());
break;
case ST_HEXSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.HEXSTRING, ((Hexstring_Value) last).getValue());
break;
case ST_OCTETSTRING:
sc = new StringSizeAndValueListConstraint(StringSizeAndValueListConstraint.Type.OCTETSTRING, ((Octetstring_Value) last).getValue());
break;
case ST_CHARSTRING:
if (last.getValuetype() != Value.Value_type.CHARSTRING_VALUE) {
return false;
}
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new StringValueConstraint(((Charstring_Value) last).getValue()));
break;
case ST_UNIVERSAL_CHARSTRING:
switch(last.getValuetype()) {
case CHARSTRING_VALUE:
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(new UniversalCharstring(((Charstring_Value) last).getValue())));
break;
case UNIVERSALCHARSTRING_VALUE:
sc = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.VALUE_CONSTRAINT, new UStringValueConstraint(((UniversalCharstring_Value) last).getValue()));
break;
default:
return false;
}
break;
case ST_OBJID:
case ST_ENUM:
case ST_UNION:
case ST_RECORD:
case ST_SET:
case ST_FUNCTION:
case ST_ALTSTEP:
case ST_TESTCASE:
sc = new ValueListConstraint(last);
break;
case ST_RECORDOF:
case ST_SETOF:
sc = new ValueListAndSizeConstraint(last);
break;
default:
ErrorReporter.INTERNAL_ERROR();
return false;
}
// add next value using union operation
if (subtypeConstraint == null) {
subtypeConstraint = sc;
} else {
subtypeConstraint = subtypeConstraint.union(sc);
}
return true;
}
use of org.eclipse.titan.designer.AST.Reference in project titan.EclipsePlug-ins by eclipse.
the class IterateOnWrongArray method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof For_Statement)) {
return;
}
final For_Statement fs = (For_Statement) node;
// find the loop variable
final LoopVariableFinder lvVisitor = new LoopVariableFinder();
fs.accept(lvVisitor);
final Reference loopVar = lvVisitor.getLoopVariable();
if (loopVar == null) {
return;
}
final Assignment loopVarDef = loopVar.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (loopVarDef == null) {
return;
}
// find the array over which the loop iterates
final Value finalExpr = fs.getFinalExpression();
if (finalExpr == null) {
return;
}
final FinalExprVisitor exprVisitor = new FinalExprVisitor();
finalExpr.accept(exprVisitor);
final List<Reference> arraysIterated = exprVisitor.getArraysIterated();
if (arraysIterated.isEmpty()) {
return;
}
/* search every statement block for references that has the loop variable in them and the
* reference differs from the reference of the array over which the for loop iterates */
final StatementBlock sb = fs.getStatementBlock();
if (sb == null) {
return;
}
final StatementBlockVisitor sbVisitor = new StatementBlockVisitor(loopVar, arraysIterated);
sb.accept(sbVisitor);
final List<Reference> matchingRefs = sbVisitor.getMatchingReferences();
for (final Reference r : matchingRefs) {
if (r.getUsedOnLeftHandSide()) {
continue;
}
problems.report(r.getLocation(), MessageFormat.format(ERR_MSG, loopVar));
}
}
Aggregations