use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Indexed_Template_List method generateCodeExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
if (asValue != null) {
asValue.generateCodeExpression(aData, expression, true);
return;
}
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
return;
}
final String tempId = aData.getTemporaryVariableName();
final String genName = governor.getGenNameTemplate(aData, expression.expression, myScope);
expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", genName, tempId));
setGenNameRecursive(genName);
generateCodeInit(aData, expression.preamble, tempId);
if (templateRestriction != Restriction_type.TR_NONE) {
TemplateRestriction.generateRestrictionCheckCode(aData, expression.expression, location, tempId, templateRestriction);
}
expression.expression.append(tempId);
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method getExpressionGovernor.
@Override
public /**
* {@inheritDoc}
*/
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (myGovernor != null) {
return myGovernor;
}
if (value == null) {
setIsErroneous(true);
return null;
}
IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError(VALUEXPECTED1);
}
setIsErroneous(true);
return null;
}
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_FUNCTION:
final Type result = ((Function_Type) type).getReturnType();
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && ((Function_Type) type).returnsTemplate()) {
location.reportSemanticError(MessageFormat.format(VALUEXPECTED2, type.getTypename(), result.getTypename()));
}
return result;
case TYPE_ALTSTEP:
setIsErroneous(true);
return null;
default:
value.getLocation().reportSemanticError(MessageFormat.format(FUNCTIONEXPECTED, type.getTypename()));
}
return null;
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method generateCodeExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
return;
}
if (lengthRestriction == null && !isIfpresent && templateRestriction == Restriction_type.TR_NONE) {
// The single expression must be tried first because this rule might cover some referenced templates.
if (hasSingleExpression()) {
final String genName = governor.getGenNameTemplate(aData, expression.expression, myScope);
expression.expression.append(MessageFormat.format("new {0}(", genName));
if (governor.getTypetype() == Type_type.TYPE_ARRAY) {
final Array_Type array_type = (Array_Type) governor;
expression.expression.append(MessageFormat.format(" {0}.class, ", array_type.getElementType().getGenNameTemplate(aData, expression.expression, myScope)));
}
expression.expression.append(getSingleExpression(aData, true));
expression.expression.append(')');
return;
}
generateCodeExpressionInvoke(aData, expression);
return;
}
final String tempId = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", governor.getGenNameTemplate(aData, expression.expression, myScope), tempId));
generateCodeInit(aData, expression.preamble, tempId);
if (templateRestriction != Restriction_type.TR_NONE) {
TemplateRestriction.generateRestrictionCheckCode(aData, expression.expression, location, tempId, templateRestriction);
}
expression.expression.append(tempId);
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method checkInvoke.
public void checkInvoke(final CompilationTimeStamp timestamp) {
if (getIsErroneous(timestamp) || actualParameterList == null || value == null) {
return;
}
value.setLoweridToReference(timestamp);
IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type != null) {
type = type.getTypeRefdLast(timestamp);
}
if (type == null) {
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError("A value of type function was expected in the argument");
}
setIsErroneous(true);
return;
}
if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument instead of `{0}''", type.getTypename()));
setIsErroneous(true);
return;
}
if (myScope == null) {
return;
}
myScope.checkRunsOnScope(timestamp, type, this, "call");
final FormalParameterList formalParameterList = ((Function_Type) type).getFormalParameters();
actualParameter_list = new ActualParameterList();
if (!formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameter_list)) {
actualParameter_list.setFullNameParent(this);
actualParameter_list.setMyScope(getMyScope());
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method generateCodeExpressionInvoke.
private void generateCodeExpressionInvoke(final JavaGenData aData, final ExpressionStruct expression) {
if (value == null || actualParameter_list == null) {
return;
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
final Definition function = ((Function_Reference_Value) last).getReferredFunction();
expression.expression.append(MessageFormat.format("{0}(", function.getGenNameFromScope(aData, expression.expression, myScope, "")));
actualParameter_list.generateCodeAlias(aData, expression);
} else {
value.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".invoke(");
IType governor = value.getMyGovernor();
if (governor == null) {
governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
return;
}
actualParameter_list.generateCodeAlias(aData, expression);
}
expression.expression.append(')');
}
Aggregations