use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class ApplyExpression method getExpressionReturntype.
@Override
public /**
* {@inheritDoc}
*/
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (value == null) {
return Type_type.TYPE_UNDEFINED;
}
if (value.getIsErroneous(timestamp)) {
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
IType type = value.getExpressionGovernor(timestamp, expectedValue);
if (type == null) {
return Type_type.TYPE_UNDEFINED;
}
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_FUNCTION:
final IType returnType = ((Function_Type) type).getReturnType();
if (returnType == null) {
value.getLocation().reportSemanticError(MessageFormat.format(NORETURNTYPE, type.getTypename()));
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
return returnType.getTypeRefdLast(timestamp).getTypetype();
case TYPE_TESTCASE:
return Type_type.TYPE_VERDICT;
default:
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class ApplyExpression 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.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
IType type = null;
if (value != null) {
value.setLoweridToReference(timestamp);
type = value.getExpressionGovernor(timestamp, expectedValue);
}
if (type == null || type.getIsErroneous(timestamp)) {
setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format(VALUEXPECTED3, type.getTypename()));
setIsErroneous(true);
return;
}
if (myScope != null) {
myScope.checkRunsOnScope(timestamp, type, this, "call");
}
actualParameters = new ActualParameterList();
final FormalParameterList formalParameterList = ((Function_Type) type).getFormalParameters();
if (!formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameters)) {
actualParameters.setFullNameParent(this);
actualParameters.setMyScope(getMyScope());
}
switch(expectedValue) {
case EXPECTED_CONSTANT:
getLocation().reportSemanticError(EVALUATABLEEXPECTED);
setIsErroneous(true);
break;
case EXPECTED_STATIC_VALUE:
getLocation().reportSemanticError(STATICEXPECTED);
setIsErroneous(true);
break;
default:
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class Unknown_Applied_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (dereferredValue == null) {
return;
}
dereferredValue.setLoweridToReference(timestamp);
IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (type != null) {
type = type.getTypeRefdLast(timestamp);
}
if (type == null) {
return;
}
final ActualParameterList tempActualParameters = new ActualParameterList();
FormalParameterList formalParameterList;
switch(type.getTypetype()) {
case TYPE_FUNCTION:
if (realStatement == null || !Statement_type.S_FUNCTION_APPLIED.equals(realStatement.getType())) {
realStatement = new Function_Applied_Statement(dereferredValue, actualParameterList, tempActualParameters);
realStatement.setFullNameParent(this);
realStatement.setLocation(location);
realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
}
realStatement.check(timestamp);
if (((Function_Type) type).getReturnType() != null) {
location.reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNUSEDFUNCTIONRETURNVALUES, GeneralConstants.WARNING, null), MessageFormat.format(UNUSEDRETURNVALUE, type.getTypename()));
}
formalParameterList = ((Function_Type) type).getFormalParameters();
formalParameterList.checkActualParameterList(timestamp, actualParameterList, tempActualParameters);
break;
case TYPE_ALTSTEP:
if (realStatement == null || !Statement_type.S_ALTSTEP_APPLIED.equals(realStatement.getType())) {
realStatement = new Altstep_Applied_Statement(dereferredValue, actualParameterList, tempActualParameters);
realStatement.setFullNameParent(this);
realStatement.setLocation(location);
realStatement.setMyStatementBlock(getMyStatementBlock(), statementIndex);
}
realStatement.check(timestamp);
formalParameterList = ((Altstep_Type) type).getFormalParameters();
formalParameterList.checkActualParameterList(timestamp, actualParameterList, tempActualParameters);
break;
default:
dereferredValue.getLocation().reportSemanticError(MessageFormat.format(FUNCTIONORALTSTEPVALUEXPECTED, type.getTypename()));
break;
}
if (myStatementBlock != null) {
myStatementBlock.checkRunsOnScope(timestamp, type, this, "call");
}
tempActualParameters.setFullNameParent(this);
tempActualParameters.setMyScope(myScope);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisTemplateRef.
@Override
public /**
* {@inheritDoc}
*/
ITTCN3Template checkThisTemplateRef(final CompilationTimeStamp timestamp, final ITTCN3Template t, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
switch(t.getTemplatetype()) {
case SUPERSET_MATCH:
case SUBSET_MATCH:
final IType it1 = getTypeRefdLast(timestamp);
final Type_type tt = it1.getTypetype();
if (Type_type.TYPE_SEQUENCE_OF.equals(tt) || Type_type.TYPE_SET_OF.equals(tt)) {
return t;
} else {
t.getLocation().reportSemanticError(MessageFormat.format("{0} cannot be used for type {1}", t.getTemplateTypeName(), getTypename()));
t.setIsErroneous(true);
return t;
}
case SPECIFIC_VALUE:
// cont below
break;
default:
return t;
}
// Case of specific value:
final ITTCN3Template template = t;
IValue value = ((SpecificValue_Template) template).getSpecificValue();
if (value == null) {
return template;
}
value = checkThisValueRef(timestamp, value);
switch(value.getValuetype()) {
case REFERENCED_VALUE:
// FIXME: referenceChain or null?
final Assignment assignment = ((Referenced_Value) value).getReference().getRefdAssignment(timestamp, false, referenceChain);
if (assignment == null) {
template.setIsErroneous(true);
} else {
switch(assignment.getAssignmentType()) {
case A_VAR_TEMPLATE:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
template.setIsErroneous(true);
}
final IType type = ((Def_Var_Template) assignment).getType(timestamp);
switch(type.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_IA5STRING:
case TYPE_GRAPHICSTRING:
case TYPE_VISIBLESTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
case TYPE_OBJECTDESCRIPTOR:
{
final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
final int nofSubreferences = subReferences.size();
if (nofSubreferences > 1) {
final ISubReference subreference = subReferences.get(nofSubreferences - 1);
if (subreference instanceof ArraySubReference) {
template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
template.setIsErroneous(true);
return template;
}
}
break;
}
default:
break;
}
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
case A_CONST:
IType type1;
if (assignment instanceof Value_Assignment) {
type1 = ((Value_Assignment) assignment).getType(timestamp);
} else {
type1 = ((Def_Const) assignment).getType(timestamp);
}
switch(type1.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_IA5STRING:
case TYPE_GRAPHICSTRING:
case TYPE_VISIBLESTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
case TYPE_OBJECTDESCRIPTOR:
{
final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
final int nofSubreferences = subReferences.size();
if (nofSubreferences > 1) {
final ISubReference subreference = subReferences.get(nofSubreferences - 1);
if (subreference instanceof ArraySubReference) {
template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
template.setIsErroneous(true);
return template;
}
}
break;
}
default:
break;
}
break;
case A_TEMPLATE:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
template.setIsErroneous(true);
}
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
default:
break;
}
}
break;
case EXPRESSION_VALUE:
{
final Expression_Value expression = (Expression_Value) value;
if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
IType type = expression.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (type == null) {
break;
}
type = type.getTypeRefdLast(timestamp);
if (type != null && Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
}
}
break;
}
default:
break;
}
return template;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class RefersExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
if (governor == null || referredAssignment == null) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
return;
}
final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final String moduleName = referredAssignment.getMyScope().getModuleScope().getName();
final String functionName = referredAssignment.getIdentifier().getName();
expression.expression.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, expression.expression, myScope)));
expression.expression.append("@Override\n");
expression.expression.append("public String getModuleName() {\n");
expression.expression.append(MessageFormat.format("return \"{0}\";\n", moduleName));
expression.expression.append("}\n");
expression.expression.append("@Override\n");
expression.expression.append("public String getDefinitionName() {\n");
expression.expression.append(MessageFormat.format("return \"{0}\";\n", functionName));
expression.expression.append("}\n");
if (lastGovernor.getTypetype().equals(Type_type.TYPE_FUNCTION)) {
expression.expression.append("@Override\n");
expression.expression.append("public ");
final Function_Type functionType = (Function_Type) lastGovernor;
final Type returnType = functionType.getReturnType();
final StringBuilder actualParList = functionType.getFormalParameters().generateCodeActualParlist("");
if (returnType == null) {
expression.expression.append("void");
} else {
if (functionType.returnsTemplate()) {
expression.expression.append(returnType.getGenNameTemplate(aData, expression.expression, myScope));
} else {
expression.expression.append(returnType.getGenNameValue(aData, expression.expression, myScope));
}
}
expression.expression.append(" invoke(");
functionType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
if (returnType != null) {
expression.expression.append("return ");
}
expression.expression.append(referredAssignment.getIdentifier().getName());
expression.expression.append('(');
expression.expression.append(actualParList);
expression.expression.append(");\n");
expression.expression.append("}\n");
if (functionType.isStartable(CompilationTimeStamp.getBaseTimestamp())) {
aData.addBuiltinTypeImport("TitanComponent");
expression.expression.append("@Override\n");
expression.expression.append("public void start(final TitanComponent component_reference");
if (functionType.getFormalParameters().getNofParameters() > 0) {
expression.expression.append(", ");
functionType.getFormalParameters().generateCode(aData, expression.expression);
}
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("{0}.start_{1}(component_reference", moduleName, functionName));
if (actualParList != null && actualParList.length() > 0) {
expression.expression.append(MessageFormat.format(", {0}", actualParList));
}
expression.expression.append(");\n");
expression.expression.append("}\n");
}
} else if (lastGovernor.getTypetype().equals(Type_type.TYPE_ALTSTEP)) {
aData.addBuiltinTypeImport("Default_Base");
aData.addBuiltinTypeImport("TitanAlt_Status");
final Altstep_Type altstepType = (Altstep_Type) lastGovernor;
final String altstepName = referredAssignment.getIdentifier().getName();
final StringBuilder actualParList = altstepType.getFormalParameters().generateCodeActualParlist("");
expression.expression.append("@Override\n");
expression.expression.append("public void invoke_standalone(");
altstepType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("{0}({1});\n", altstepName, actualParList));
expression.expression.append("}\n");
expression.expression.append("@Override\n");
expression.expression.append("public Default_Base activate(");
altstepType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("return activate_{0}({1});\n", altstepName, actualParList));
expression.expression.append("}\n");
expression.expression.append("@Override\n");
expression.expression.append("public TitanAlt_Status invoke(");
altstepType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(") {\n");
expression.expression.append(MessageFormat.format("return {0}_instance({1});\n", altstepName, actualParList));
expression.expression.append("}\n");
} else if (lastGovernor.getTypetype().equals(Type_type.TYPE_TESTCASE)) {
aData.addBuiltinTypeImport("TitanVerdictType");
aData.addBuiltinTypeImport("TitanFloat");
expression.expression.append("@Override\n");
expression.expression.append("public ");
final Testcase_Type testcaseType = (Testcase_Type) lastGovernor;
expression.expression.append("TitanVerdictType");
expression.expression.append(" execute(");
if (testcaseType.getFormalParameters().getNofParameters() > 0) {
testcaseType.getFormalParameters().generateCode(aData, expression.expression);
expression.expression.append(", ");
}
expression.expression.append("boolean has_timer, TitanFloat timer_value");
expression.expression.append(") {\n");
expression.expression.append("return testcase_");
expression.expression.append(referredAssignment.getIdentifier().getName());
expression.expression.append('(');
if (testcaseType.getFormalParameters().getNofParameters() > 0) {
expression.expression.append(testcaseType.getFormalParameters().generateCodeActualParlist(""));
expression.expression.append(", ");
}
expression.expression.append("has_timer, timer_value");
expression.expression.append(");\n");
expression.expression.append("}\n");
}
expression.expression.append("})\n");
}
Aggregations