use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class Int2Enum_Statement method generateCode.
@Override
public void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct valueExpression = new ExpressionStruct();
value.generateCodeExpression(aData, valueExpression, true);
final ExpressionStruct referenceExpression = new ExpressionStruct();
reference.generateCode(aData, referenceExpression);
boolean isOptional = false;
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
isOptional = true;
}
source.append(valueExpression.preamble);
source.append(referenceExpression.preamble);
source.append(MessageFormat.format("{0}{1}.int2enum({2});\n", referenceExpression.expression, isOptional ? ".get()" : "", valueExpression.expression));
source.append(valueExpression.postamble);
source.append(referenceExpression.postamble);
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class Start_Timer_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
checkTimerReference(timestamp, timerReference);
if (timerValue == null) {
final Assignment assignment = timerReference.getRefdAssignment(timestamp, true);
if (assignment != null && Assignment_type.A_TIMER.semanticallyEquals(assignment.getAssignmentType())) {
final Def_Timer defTimer = (Def_Timer) assignment;
if (!defTimer.hasDefaultDuration(timestamp, timerReference)) {
location.reportSemanticError(MessageFormat.format(MISSINGDEFAULTDURATION, assignment.getDescription()));
}
}
} else {
timerValue.setLoweridToReference(timestamp);
final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
switch(temporalType) {
case TYPE_REAL:
{
final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (!last.isUnfoldable(timestamp)) {
final Real_Value real = (Real_Value) last;
final double val = real.getValue();
if (val < 0.0) {
timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real));
} else if (real.isPositiveInfinity()) {
timerValue.getLocation().reportSemanticError(MessageFormat.format(INFINITYDURATION, real.createStringRepresentation()));
}
}
return;
}
case TYPE_UNDEFINED:
return;
default:
timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
return;
}
}
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class StatementBlock method registerDefinition.
/**
* Registers a definition (for example new variable) into the list of
* definitions available in this statement block.
*
* Please note, that this is done while the semantic check is happening,
* as it must not be allowed to reach definitions not yet defined.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param definition
* the definition to register.
*/
public void registerDefinition(final CompilationTimeStamp timestamp, final Definition definition) {
if (definition == null) {
return;
}
final Identifier identifier = definition.getIdentifier();
if (identifier == null) {
return;
}
if (definitionMap == null) {
definitionMap = new HashMap<String, Definition>(3);
}
final String definitionName = identifier.getName();
if (definitionMap.containsKey(definitionName)) {
if (definition.getLocation() != null && definitionMap.get(definitionName).getLocation() != null) {
final Location otherLocation = definitionMap.get(definitionName).getLocation();
otherLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
definition.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
}
} else {
definitionMap.put(definitionName, definition);
if (parentScope != null && definition.getLocation() != null) {
if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
definition.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName()));
final List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(identifier));
final Reference reference = new Reference(null, subReferences);
final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
if (assignment != null && assignment.getLocation() != null) {
assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, identifier.getDisplayName()));
}
} else if (parentScope.isValidModuleId(identifier)) {
definition.getLocation().reportSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
}
}
}
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class LogArgument method checkReference.
/**
* Does the semantic checking of the log argument. Once it was
* determined that it is a reference.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param reference
* the reference contained in the log argument.
*/
private void checkReference(final CompilationTimeStamp timestamp, final Reference reference) {
if (reference == null) {
return;
}
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null || assignment.getIsErroneous()) {
return;
}
switch(assignment.getAssignmentType()) {
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
{
reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null) {
assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
}
break;
}
case A_CONST:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
if (assignment instanceof Def_Const) {
((Def_Const) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
} else {
((Value_Assignment) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
}
chain.release();
}
break;
}
case A_TEMPLATE:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
((Def_Template) assignment).getTemplate(timestamp).getReferencedSubTemplate(timestamp, reference, chain);
chain.release();
}
break;
}
case A_MODULEPAR_TEMPLATE:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null) {
assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
}
break;
}
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_VAR_TEMPLATE:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final IType assingmentType = assignment.getType(timestamp);
if (assingmentType != null) {
assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
}
break;
}
case A_PORT:
{
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
} else if (reference.getSubreferences().size() > 1) {
getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
isErroneous = true;
}
break;
}
case A_TIMER:
{
final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
} else if (reference.getSubreferences().size() > 1) {
getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
isErroneous = true;
}
break;
}
case A_PAR_TIMER:
case A_PAR_PORT:
if (reference.getSubreferences().size() > 1) {
getLocation().reportSemanticError(MessageFormat.format("Reference to {0} cannot have field or array sub-references", assignment.getDescription()));
isErroneous = true;
}
break;
case A_FUNCTION:
case A_EXT_FUNCTION:
getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was ecpected instead of a call of {0}, which does not have a return type", assignment.getDescription()));
isErroneous = true;
break;
default:
getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was expected instead of {0}", assignment.getDescription()));
isErroneous = true;
break;
}
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class String2Ttcn_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
if (value != null) {
value.setLoweridToReference(timestamp);
final Type_type temporalType = value.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
switch(temporalType) {
case TYPE_CHARSTRING:
value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
break;
case TYPE_UNDEFINED:
setIsErroneous();
break;
default:
if (!isErroneous) {
value.getLocation().reportSemanticError(OPERANDERROR1);
setIsErroneous();
}
}
}
if (reference != null) {
final Assignment assignment = reference.getRefdAssignment(timestamp, false);
if (assignment == null) {
reference.getLocation().reportSemanticError(OPERANDERROR2);
setIsErroneous();
} else {
switch(assignment.getAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_TEMP_IN:
case A_VAR:
case A_VAR_TEMPLATE:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
// valid assignment types
break;
default:
reference.getLocation().reportSemanticError(OPERANDERROR3);
setIsErroneous();
}
}
}
lastTimeChecked = timestamp;
}
Aggregations