use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class Reference method generateConstRef.
public void generateConstRef(final JavaGenData aData, final ExpressionStruct expression) {
if (referredAssignment == null) {
// TODO: handle null
return;
}
boolean isTemplate;
switch(referredAssignment.getAssignmentType()) {
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:
isTemplate = false;
break;
case A_MODULEPAR_TEMPLATE:
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
isTemplate = true;
break;
default:
isTemplate = false;
break;
}
FormalParameterList formalParameterList;
switch(referredAssignment.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
formalParameterList = ((Def_Function) referredAssignment).getFormalParameterList();
break;
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
formalParameterList = ((Def_Extfunction) referredAssignment).getFormalParameterList();
break;
case A_TEMPLATE:
formalParameterList = ((Def_Template) referredAssignment).getFormalParameterList();
break;
default:
formalParameterList = null;
break;
}
final IType referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
// ha parameterezett
if (subReferences.get(0) instanceof ParameterisedSubReference) {
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
expression.expression.append("( ");
final ParameterisedSubReference temp = ((ParameterisedSubReference) subReferences.get(0));
final ActualParameterList actualParameterList = temp.getActualParameters();
if (actualParameterList != null) {
actualParameterList.generateCodeAlias(aData, expression);
}
expression.expression.append(" )");
} else if (formalParameterList != null) {
// the reference does not have an actual parameter list, but the assignment has
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
expression.expression.append("( ");
// FieldSubReference temp = ((FieldSubReference)subReferences.get(0));
for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
if (i > 0) {
expression.expression.append(", ");
}
formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, expression);
}
// temp.getActualParameters().generateCodeAlias(aData, expression);
expression.expression.append(" )");
} else {
// TODO add fuzzy handling
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
}
generateCode(aData, expression, isTemplate, true, referedGovernor);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class Reference method generateCode.
/**
* Add generated java code on this level.
* @param aData only used to update imports if needed
* @param expression the expression for code generated
*/
public void generateCode(final JavaGenData aData, final ExpressionStruct expression) {
if (referredAssignment == null) {
return;
}
boolean isTemplate;
IType referedGovernor;
switch(referredAssignment.getAssignmentType()) {
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:
isTemplate = false;
referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
break;
case A_MODULEPAR_TEMPLATE:
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
isTemplate = true;
referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
break;
default:
isTemplate = false;
referedGovernor = null;
break;
}
FormalParameterList formalParameterList;
switch(referredAssignment.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
formalParameterList = ((Def_Function) referredAssignment).getFormalParameterList();
break;
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
formalParameterList = ((Def_Extfunction) referredAssignment).getFormalParameterList();
break;
case A_TEMPLATE:
formalParameterList = ((Def_Template) referredAssignment).getFormalParameterList();
break;
default:
formalParameterList = null;
break;
}
if (subReferences.get(0) instanceof ParameterisedSubReference) {
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
expression.expression.append("( ");
final ParameterisedSubReference temp = ((ParameterisedSubReference) subReferences.get(0));
temp.getActualParameters().generateCodeAlias(aData, expression);
expression.expression.append(" )");
} else if (formalParameterList != null) {
// the reference does not have an actual parameter list, but the assignment has
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
expression.expression.append("( ");
// FieldSubReference temp = ((FieldSubReference)subReferences.get(0));
for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
if (i > 0) {
expression.expression.append(", ");
}
formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, expression);
}
// temp.getActualParameters().generateCodeAlias(aData, expression);
expression.expression.append(" )");
} else {
// TODO add fuzzy handling
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
}
generateCode(aData, expression, isTemplate, false, referedGovernor);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class TemplateInstance method reArrangeInitCode.
/**
* Walks through the templateinstance recursively and appends the java
* initialization sequence of all (directly or indirectly) referenced
* non-parameterized templates and the default values of all
* parameterized templates to source and returns the resulting string.
* Only objects belonging to module usageModule are initialized.
*
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source for code generated
* @param usageModule the module where the template is to be used.
*/
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
if (derivedReference != null) {
final List<ISubReference> subreferences = derivedReference.getSubreferences();
if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
final ActualParameterList actualParameterList = subreference.getActualParameters();
if (actualParameterList != null) {
actualParameterList.reArrangeInitCode(aData, source, usageModule);
}
}
final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null) {
return;
}
if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
if (formalParameterList != null) {
// the referred template is parameterized
// the embedded referenced templates shall be visited
template.reArrangeInitCode(aData, source, usageModule);
// FIXME implement
} else {
// its entire body has to be initialized now
if (assignment.getMyScope().getModuleScope() == usageModule) {
template.generateCodeInit(aData, source, template.get_lhs_name());
}
}
}
}
if (templateBody != null) {
templateBody.reArrangeInitCode(aData, source, usageModule);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template in project titan.EclipsePlug-ins by eclipse.
the class TemplateInstance method checkBaseTypeCompatibility.
private IType checkBaseTypeCompatibility(final CompilationTimeStamp timestamp, final IType governor, final Assignment derivedAssignment, final boolean setBaseTemplate) {
boolean internalSetBase = setBaseTemplate;
IType tempGovernor = governor;
if (tempGovernor == null) {
tempGovernor = type;
}
final IType baseTemplateType = derivedAssignment.getType(timestamp);
if (tempGovernor != null) {
if (!tempGovernor.isCompatible(timestamp, baseTemplateType, null, null, null)) {
derivedReference.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEBASETYPE, derivedAssignment.getFullName(), tempGovernor.getTypename(), baseTemplateType.getTypename()));
if (type == null) {
tempGovernor = baseTemplateType;
}
internalSetBase = false;
}
} else {
tempGovernor = baseTemplateType;
}
if (internalSetBase && derivedAssignment instanceof Def_Template) {
templateBody.setBaseTemplate(((Def_Template) derivedAssignment).getTemplate(timestamp));
}
return tempGovernor;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template 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);
}
Aggregations