use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const in project titan.EclipsePlug-ins by eclipse.
the class SizeOfExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*
* @return the size of the expression, or -1 in case of error
*/
private long checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
Expected_Value_type internalExpectedValue;
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
internalExpectedValue = Expected_Value_type.EXPECTED_TEMPLATE;
} else {
internalExpectedValue = expectedValue;
}
ITTCN3Template template = templateInstance.getTemplateBody();
template.setLoweridToReference(timestamp);
template = template.getTemplateReferencedLast(timestamp, referenceChain);
if (template.getIsErroneous(timestamp)) {
setIsErroneous(true);
return -1;
}
// Timer and port arrays are handled separately
if (template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
final SpecificValue_Template specValTempl = (SpecificValue_Template) template;
IValue val = specValTempl.getSpecificValue();
val.setMyGovernor(specValTempl.getMyGovernor());
if (val.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
val = val.setLoweridToReference(timestamp);
}
if (val != null && val.getValuetype() == Value_type.REFERENCED_VALUE) {
final Referenced_Value referencedValue = (Referenced_Value) val;
final Reference ref = referencedValue.getReference();
final Assignment temporalAss = ref.getRefdAssignment(timestamp, true);
if (temporalAss != null) {
final Assignment_type asstype = temporalAss.getAssignmentType();
ArrayDimensions dimensions;
if (asstype == Assignment_type.A_PORT) {
dimensions = ((Def_Port) temporalAss).getDimensions();
return checkTimerPort(timestamp, ref, dimensions, temporalAss);
} else if (asstype == Assignment_type.A_TIMER) {
dimensions = ((Def_Timer) temporalAss).getDimensions();
return checkTimerPort(timestamp, ref, dimensions, temporalAss);
}
}
}
}
IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectedValue);
if (governor == null) {
final ITTCN3Template templ = template.setLoweridToReference(timestamp);
governor = templ.getExpressionGovernor(timestamp, internalExpectedValue);
}
if (governor == null) {
if (!template.getIsErroneous(timestamp)) {
templateInstance.getLocation().reportSemanticError("Cannot determine the type of the argument in the `sizeof' operation. If type is known, use valueof(<type>: ...) as argument.");
}
setIsErroneous(true);
return -1;
}
IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, internalExpectedValue);
if (isErroneous) {
return -1;
}
IType type = governor.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
case TYPE_ARRAY:
case TYPE_OBJECTID:
case TYPE_ROID:
case TYPE_UNDEFINED:
break;
default:
templateInstance.getLocation().reportSemanticError("Reference to a value or template of type record, record of, set, set of, objid or array was expected");
setIsErroneous(true);
return -1;
}
IValue value = null;
Reference reference = null;
Assignment assignment = null;
List<ISubReference> subreferences = null;
switch(template.getTemplatetype()) {
case INDEXED_TEMPLATE_LIST:
return -1;
case TEMPLATE_REFD:
reference = ((Referenced_Template) template).getReference();
assignment = reference.getRefdAssignment(timestamp, false);
subreferences = reference.getSubreferences();
break;
case TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case SUBSET_MATCH:
case SUPERSET_MATCH:
// compute later
break;
case SPECIFIC_VALUE:
value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
if (value != null) {
switch(value.getValuetype()) {
case SEQUENCEOF_VALUE:
case SETOF_VALUE:
case ARRAY_VALUE:
case RELATIVEOBJECTIDENTIFIER_VALUE:
case OBJECTID_VALUE:
case SEQUENCE_VALUE:
case SET_VALUE:
break;
case REFERENCED_VALUE:
{
reference = ((Referenced_Value) value).getReference();
assignment = reference.getRefdAssignment(timestamp, false);
subreferences = reference.getSubreferences();
break;
}
default:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to `{0}''", value.createStringRepresentation()));
setIsErroneous(true);
return -1;
}
}
break;
default:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to {0}", template.getTemplateTypeName()));
setIsErroneous(true);
return -1;
}
if (assignment != null) {
if (assignment.getIsErroneous()) {
setIsErroneous(true);
return -1;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
value = ((Def_Const) assignment).getValue();
break;
case A_EXT_CONST:
case A_MODULEPAR:
case A_MODULEPAR_TEMPLATE:
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluable) constant value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
switch(internalExpectedValue) {
case EXPECTED_CONSTANT:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
case EXPECTED_STATIC_VALUE:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
default:
break;
}
break;
case A_TEMPLATE:
template = ((Def_Template) assignment).getTemplate(timestamp);
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
switch(internalExpectedValue) {
case EXPECTED_CONSTANT:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
case EXPECTED_STATIC_VALUE:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription()));
setIsErroneous(true);
return -1;
default:
break;
}
break;
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue)) {
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a value was expected instead of a call of {0}, which returns a template", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
break;
case A_TIMER:
case A_PORT:
// were already checked separately.
break;
default:
templateInstance.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectedValue) ? "value or template" : "value", assignment.getDescription()));
setIsErroneous(true);
return -1;
}
type = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null || type.getIsErroneous(timestamp)) {
setIsErroneous(true);
return -1;
}
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
case TYPE_ARRAY:
case TYPE_OBJECTID:
case TYPE_ROID:
case TYPE_UNDEFINED:
break;
default:
templateInstance.getLocation().reportSemanticError("Reference to a value or template of type record, record of, set, set of, objid or array was expected");
setIsErroneous(true);
return -1;
}
}
// check for index overflows in subrefs if possible
if (value != null) {
switch(value.getValuetype()) {
case SEQUENCEOF_VALUE:
if (((SequenceOf_Value) value).isIndexed()) {
return -1;
}
break;
case SETOF_VALUE:
if (((SetOf_Value) value).isIndexed()) {
return -1;
}
break;
case ARRAY_VALUE:
if (((Array_Value) value).isIndexed()) {
return -1;
}
break;
default:
break;
}
/* The reference points to a constant. */
if (subreferences != null && !reference.hasUnfoldableIndexSubReference(timestamp)) {
value = value.getReferencedSubValue(timestamp, reference, 1, referenceChain);
if (value == null) {
setIsErroneous(true);
return -1;
}
value = value.getValueRefdLast(timestamp, referenceChain);
} else {
// stop processing
value = null;
}
} else if (template != null) {
/* The size of INDEXED_TEMPLATE_LIST nodes is unknown at compile
time. Don't try to evaluate it at compile time. */
if (reference != null && reference.hasUnfoldableIndexSubReference(timestamp)) {
return -1;
}
if (reference != null && subreferences != null) {
template = template.getReferencedSubTemplate(timestamp, reference, referenceChain);
if (template == null) {
setIsErroneous(true);
return -1;
}
template = template.getTemplateReferencedLast(timestamp);
}
}
if (template != null) {
if (template.getIsErroneous(timestamp)) {
setIsErroneous(true);
return -1;
}
switch(template.getTemplatetype()) {
case TEMPLATE_REFD:
template = null;
break;
case SPECIFIC_VALUE:
value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
template = null;
break;
case TEMPLATE_LIST:
case NAMED_TEMPLATE_LIST:
case SUBSET_MATCH:
case SUPERSET_MATCH:
break;
default:
// FIXME this can not happen
templateInstance.getLocation().reportSemanticError(MessageFormat.format("`sizeof'' operation is not applicable to {0}", template.getTemplateTypeName()));
setIsErroneous(true);
return -1;
}
}
if (value != null) {
switch(value.getValuetype()) {
case SEQUENCEOF_VALUE:
case SETOF_VALUE:
case ARRAY_VALUE:
case RELATIVEOBJECTIDENTIFIER_VALUE:
case OBJECTID_VALUE:
case SEQUENCE_VALUE:
case SET_VALUE:
break;
default:
value = null;
return -1;
}
}
/* evaluation */
if (Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
return ((Array_Type) type).getDimension().getSize();
} else if (template != null) {
return evaluateTemplate(template, timestamp);
} else if (value != null) {
return evaluateValue(value);
} else {
return -1;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method getValueRefdLast.
@Override
public /**
* {@inheritDoc}
*/
IValue getValueRefdLast(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return referencedValue;
}
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
referencedValue = this;
isErroneous = false;
if (reference == null) {
return referencedValue;
}
reference.setIsErroneous(false);
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
isErroneous = true;
return referencedValue;
}
switch(ass.getAssignmentType()) {
case A_OBJECT:
case A_OS:
{
final ISetting setting = reference.getRefdSetting(timestamp);
if (setting == null || setting.getIsErroneous(timestamp)) {
isErroneous = true;
} else if (!Setting_type.S_V.equals(setting.getSettingtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format(INFORMATIONFROMOBJECTNOTVALUE, reference));
isErroneous = true;
} else {
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
referencedValue = ((IValue) setting).getValueRefdLast(timestamp, expectedValue, referenceChain);
} else {
isErroneous = true;
}
tempReferenceChain.previousState();
}
break;
}
case A_CONST:
{
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
if (ass instanceof Def_Const) {
referencedValue = ((Def_Const) ass).getValue();
} else if (ass instanceof Value_Assignment) {
referencedValue = ((Value_Assignment) ass).getValue();
} else {
isErroneous = true;
}
if (referencedValue != null && !isErroneous) {
referencedValue = referencedValue.getReferencedSubValue(timestamp, reference, 1, tempReferenceChain);
} else {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
}
if (referencedValue != null) {
referencedValue = referencedValue.getValueRefdLast(timestamp, tempReferenceChain);
} else if (reference.hasUnfoldableIndexSubReference(timestamp)) {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
} else if (reference.getUsedInIsbound()) {
referencedValue = this;
tempReferenceChain.previousState();
return referencedValue;
} else {
isErroneous = true;
}
} else {
isErroneous = true;
}
tempReferenceChain.previousState();
break;
}
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_INOUT:
case A_PAR_TEMP_OUT:
referencedValue = this;
break;
case A_TEMPLATE:
case A_VAR_TEMPLATE:
// the referred definition is not a constant
// errors will be reported in Types.java
referencedValue = this;
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
}
break;
case A_FUNCTION:
case A_EXT_FUNCTION:
reference.getLocation().reportSemanticError(MessageFormat.format(VALUERETURNEXPECTED, ass.getDescription()));
isErroneous = true;
break;
default:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT1, ass.getDescription()));
} else {
getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
}
isErroneous = true;
break;
}
if (newChain) {
tempReferenceChain.release();
}
lastTimeChecked = timestamp;
if (referencedValue == null) {
referencedValue = this;
isErroneous = true;
}
return referencedValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const 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.TTCN3.definitions.Def_Const in project titan.EclipsePlug-ins by eclipse.
the class TypenameInDef method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
return;
}
final Definition s = (Definition) node;
check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method getNofTemplatesNotAnyornone.
/**
* Calculates the number of list members which are not the any or none
* symbol.
*
* @return the number calculated.
*/
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
int result = 0;
if (allFrom == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
if (!((SpecificValue_Template) allFrom).isReference()) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
// isReference branch:
final Reference reference = ((SpecificValue_Template) allFrom).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
allFrom.getLocation().reportSemanticError("Assignment not found");
allFrom.setIsErroneous(true);
return result;
}
ITTCN3Template body = null;
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
body = ((Def_Template) assignment).getTemplate(timestamp);
break;
case A_VAR_TEMPLATE:
body = ((Def_Var_Template) assignment).getInitialValue();
break;
case A_CONST:
final IValue value = ((Def_Const) assignment).getValue();
return getNofValues(value, timestamp);
case A_MODULEPAR:
final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
return getNofValues(mvalue, timestamp);
case A_MODULEPAR_TEMPLATE:
body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
break;
default:
return result;
}
if (body == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
allFrom.setIsErroneous(true);
return result;
}
result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
return result;
}
Aggregations