use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkComponentReference.
/**
* Checks a reference to see if it really references a valid component
* type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the source statement to report errors to.
* @param value
* the value reference to check.
* @param allowMtc
* tells if the mtc component is allowed or not.
* @param allowSystem
* tells if the system component is allowed or not.
*
* @return the referenced component type, or null if there were
* problems.
*/
public static Component_Type checkComponentReference(final CompilationTimeStamp timestamp, final Statement source, final IValue value, final boolean allowMtc, final boolean allowSystem) {
if (source.getMyStatementBlock() != null && source.getMyStatementBlock().getMyDefinition() == null) {
source.getLocation().reportSemanticError(COMPONENTOPINCONTROLPART);
}
if (value == null || value.getIsErroneous(timestamp)) {
return null;
}
final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
switch(last.getValuetype()) {
case REFERENCED_VALUE:
break;
case TTCN3_NULL_VALUE:
value.getLocation().reportSemanticError(MessageFormat.format(NULLCOMPONENTREFERENCE, source.getStatementName()));
break;
case EXPRESSION_VALUE:
final Expression_Value expression = (Expression_Value) last;
switch(expression.getOperationType()) {
case APPLY_OPERATION:
if (!Type_type.TYPE_COMPONENT.equals(last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
value.getLocation().reportSemanticError(VALUERETURNEXPECTED);
}
break;
case COMPONENT_NULL_OPERATION:
value.getLocation().reportSemanticError(MessageFormat.format(NULLCOMPONENTREFERENCE, source.getStatementName()));
break;
case MTC_COMPONENT_OPERATION:
if (!allowMtc) {
value.getLocation().reportSemanticError(MessageFormat.format(MTCCOMPONENTREFERENCE, source.getStatementName()));
}
break;
case SYSTEM_COMPONENT_OPERATION:
if (!allowSystem) {
value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCOMPONENTREFERENCE, source.getStatementName()));
}
break;
case SELF_COMPONENT_OPERATION:
break;
case COMPONENT_CREATE_OPERATION:
break;
case VALUEOF_OPERATION:
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
((ValueofExpression) expression).evaluateValue(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
referenceChain.release();
break;
default:
value.getLocation().reportSemanticError(COMPONENTREFERENCEEXPECTED);
return null;
}
break;
default:
value.getLocation().reportSemanticError(COMPONENTREFERENCEEXPECTED);
return null;
}
IType result = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (result == null) {
return null;
}
result = result.getTypeRefdLast(timestamp);
if (result.getIsErroneous(timestamp)) {
return null;
} else if (Type_type.TYPE_COMPONENT.equals(result.getTypetype())) {
return (Component_Type) result;
}
value.getLocation().reportSemanticError(MessageFormat.format(COMPONENTTYPEMISMATCH, result.getTypename()));
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method generateCodeInitAllFrom.
public void generateCodeInitAllFrom(final JavaGenData aData, final StringBuilder source, final String name) {
final IValue value = ((SpecificValue_Template) allFrom).getValue();
Reference reference;
if (value.getValuetype() == Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE) {
// value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
reference = ((Undefined_LowerIdentifier_Value) value).getAsReference();
} else {
reference = ((Referenced_Value) value).getReference();
}
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
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;
}
// The caller will have to provide the for cycle with this variable
source.append(MessageFormat.format("{0}.assign({1}.getAt(i_i));\n", name, expression.expression));
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class Unknown_Start_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
return;
}
switch(assignment.getAssignmentType()) {
case A_PORT:
case A_PAR_PORT:
if (value != null) {
value.getLocation().reportSemanticError(NOARGUMENTEXPECTED);
}
if (realStatement == null || !Statement_type.S_START_PORT.equals(realStatement.getType())) {
realStatement = new Start_Port_Statement(reference);
realStatement.setMyScope(getMyScope());
realStatement.setFullNameParent(this);
realStatement.setLocation(location);
realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
}
realStatement.check(timestamp);
break;
case A_TIMER:
case A_PAR_TIMER:
if (realStatement == null || !Statement_type.S_START_TIMER.equals(realStatement.getType())) {
realStatement = new Start_Timer_Statement(reference, value);
realStatement.setMyScope(getMyScope());
realStatement.setFullNameParent(this);
realStatement.setLocation(location);
realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
}
realStatement.check(timestamp);
break;
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
if (value == null) {
location.reportSemanticError(MISSINGARGUMENT);
return;
}
if (!Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
value.getLocation().reportSemanticError(FUNCTIONARGUMENTEXPECTED);
return;
}
if (realStatement == null || !Statement_type.S_START_COMPONENT.equals(realStatement.getType())) {
realStatement = new Start_Component_Statement(new Referenced_Value(reference), ((Referenced_Value) value).getReference());
realStatement.setMyScope(getMyScope());
realStatement.setFullNameParent(this);
realStatement.setLocation(location);
realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
}
realStatement.check(timestamp);
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(UNEXPECEDSTARTREFERENCE, assignment.getDescription()));
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Function_Writer method writeAssignmentStatement.
// updated
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
StringBuilder functionString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
// TODO assignments for indexed bitstrings
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
}
/*StringBuilder functionString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if (specValTemplate.getSpecificValue() instanceof Bitstring_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BITSTRING(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Integer_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Charstring_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new CHARSTRING(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Boolean_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BOOLEAN("
+ functionAssignValues.get(assignCounter) + ");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Referenced_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if ((specValTemplate.getSpecificValue() instanceof AddExpression)
|| (specValTemplate.getSpecificValue() instanceof SubstractExpression)
|| (specValTemplate.getSpecificValue() instanceof MultiplyExpression)
|| (specValTemplate.getSpecificValue() instanceof DivideExpression)
|| (specValTemplate.getSpecificValue() instanceof ModuloExpression)
|| (specValTemplate.getSpecificValue() instanceof RemainderExpression)) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter)
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
}
*/
return functionString.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Testcase_Writer method writeAssignmentStatement.
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
StringBuilder testCaseString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
ComponentCreateExpression componenetCreateExp = (ComponentCreateExpression) specValTemplate.getSpecificValue();
createCounter++;
logCreateCounter++;
int logSizeValue = 1;
while (tcCreateCounter.get(logCreateCounter).equals(String.valueOf(createCounter))) {
logCreateCounter++;
logSizeValue++;
if (tcCreateCounter.size() == (logCreateCounter)) {
break;
}
}
String[] logValues = new String[logSizeValue];
int logWriteCounter = 0;
testCaseString.append("rownum=" + componenetCreateExp.getLocation().getLine() + ";\r\n");
if (tcAssignIdentifiers.get(assignCounter).endsWith("=")) {
tcAssignIdentifiers.set(assignCounter, tcAssignIdentifiers.get(assignCounter).substring(0, tcAssignIdentifiers.get(assignCounter).length() - 1));
}
testCaseString.append("hc.create(" + "\"" + tcAssignIdentifiers.get(assignCounter) + "\"");
logValues[logWriteCounter] = tcAssignIdentifiers.get(assignCounter);
currentCounterValue++;
// assignCounter++;
logWriteCounter++;
while (tcCreateCounter.get(currentCounterValue).equals(String.valueOf(createCounter))) {
testCaseString.append(",\"" + tcCreateValues.get(currentCounterValue) + "\"");
logValues[logWriteCounter] = tcCreateValues.get(currentCounterValue);
logWriteCounter++;
currentCounterValue++;
if (tcCreateCounter.size() == (currentCounterValue)) {
break;
}
}
testCaseString.append("); " + "\r\n");
testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + nodeName + "\", \"Starting PTC " + logValues[0] + " type " + logValues[1] + " on " + logValues[2] + "\", false);" + "\r\n");
} else if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
// TODO assignments for indexed bitstrings
testCaseString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
testCaseString.append(tcAssignIdentifiers.get(assignCounter) + tcAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
}
return testCaseString.toString();
}
Aggregations