use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class Def_Var_Template method generateCodeString.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenName();
// FIXME temporal code until generate_code_object is supported for templates
final String typeGeneratedName = type.getGenNameTemplate(aData, source, getMyScope());
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sb);
arrayType.generateCodeTemplate(aData, sb);
}
source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeGeneratedName, genName));
if (initialValue != null) {
initialValue.generateCodeInit(aData, source, genName);
if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
TemplateRestriction.generateRestrictionCheckCode(aData, source, location, genName, templateRestriction);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterTemplate.
private ActualParameter checkActualParameterTemplate(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter) {
actualParameter.check(timestamp, type);
final TemplateInstance instance = new TemplateInstance(actualParameter.getType(), actualParameter.getDerivedReference(), actualParameter.getTemplateBody());
final ActualParameter returnValue = new Template_ActualParameter(instance);
if (!Restriction_type.TR_NONE.equals(templateRestriction)) {
instance.checkRestriction(timestamp, this);
}
return returnValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterByReference.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a reference parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parameter
* the template instance assigned as actual parameter to
* this formal parameter
* @param isTemplate
* true if the formal parameter is template, false
* otherwise
* @param expectedValue
* the value kind expected from the actual parameter.
*
* @return the actual parameter created from the value, or null if there
* was an error.
*/
private ActualParameter checkActualParameterByReference(final CompilationTimeStamp timestamp, final TemplateInstance parameter, final boolean isTemplate, final Expected_Value_type expectedValue) {
final Type parameterType = parameter.getType();
if (parameterType != null) {
parameterType.getLocation().reportSemanticWarning(MessageFormat.format(EXPLICITESPECIFICATIONFORREFERENCE, getAssignmentName()));
parameter.checkType(timestamp, type);
}
final Reference derivedReference = parameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError(MessageFormat.format(INLINETEMPLATEFORREFERENCE, getAssignmentName()));
parameter.checkDerivedReference(timestamp, type);
}
String expectedString;
if (isTemplate) {
expectedString = "template variable or template parameter";
} else {
expectedString = "variable or value parameter";
}
final ITTCN3Template template = parameter.getTemplateBody();
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
final Reference reference = ((SpecificValue_Template) template).getReference();
reference.setUsedOnLeftHandSide();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
boolean assignmentTypeIsCorrect;
switch(assignment.getAssignmentType()) {
case A_PAR_VAL_IN:
((FormalParameter) assignment).useAsLValue(reference);
assignmentTypeIsCorrect = !isTemplate;
break;
case A_PAR_VAL:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
((FormalParameter) assignment).setWritten();
assignmentTypeIsCorrect = !isTemplate;
break;
case A_VAR:
((Def_Var) assignment).setWritten();
assignmentTypeIsCorrect = !isTemplate;
break;
case A_PAR_TEMP_IN:
assignmentTypeIsCorrect = isTemplate;
((FormalParameter) assignment).useAsLValue(reference);
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
assignmentTypeIsCorrect = isTemplate;
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
assignmentTypeIsCorrect = isTemplate;
break;
default:
assignmentTypeIsCorrect = false;
break;
}
if (assignmentTypeIsCorrect) {
final IType fieldType = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (fieldType != null) {
if (type != null && !type.isCompatible(timestamp, fieldType, null, null, null)) {
reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, expectedString, type.getTypename(), fieldType.getTypename()));
} else if (type != null && type.getSubtype() != null && fieldType.getSubtype() != null && !type.getSubtype().isCompatible(timestamp, fieldType.getSubtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBTYPEMISMATCH, type.getSubtype().toString(), fieldType.getSubtype().toString()));
}
if (!reference.getSubreferences().isEmpty() && reference.refersToStringElement()) {
reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED3, fieldType.getTypename()));
}
}
} else {
reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED1, expectedString, getAssignmentName(), assignment.getDescription()));
}
final ActualParameter returnActualParameter = new Referenced_ActualParameter(reference);
if (isTemplate && assignmentTypeIsCorrect) {
TemplateRestriction.Restriction_type refdRestriction;
switch(assignment.getAssignmentType()) {
case A_VAR_TEMPLATE:
{
final Def_Var_Template temp = (Def_Var_Template) assignment;
refdRestriction = temp.getTemplateRestriction();
break;
}
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final FormalParameter par = (FormalParameter) assignment;
refdRestriction = par.getTemplateRestriction();
break;
}
default:
return returnActualParameter;
}
TemplateRestriction.getSubRestriction(refdRestriction, timestamp, reference);
if (templateRestriction != refdRestriction) {
final boolean preCallCheck = TemplateRestriction.isLessRestrictive(templateRestriction, refdRestriction);
final boolean postCallCheck = TemplateRestriction.isLessRestrictive(refdRestriction, templateRestriction);
if (preCallCheck || postCallCheck) {
final String message = MessageFormat.format("Inadequate restriction on the referenced {0} `{1}'' this may cause a dynamic test case error at runtime", assignment.getAssignmentName(), reference.getDisplayName());
reference.getLocation().reportSemanticWarning(message);
}
}
// written C++ code
if (!Restriction_type.TR_NONE.equals(refdRestriction)) {
switch(myParameterList.getMyDefinition().getAssignmentType()) {
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
// here
break;
default:
break;
}
}
}
return returnActualParameter;
}
parameter.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED2, expectedString, getAssignmentName()));
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class Def_Template method generateCodeString.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenName();
if (formalParList == null) {
final String typeName = type.getGenNameTemplate(aData, source, getMyScope());
if (baseTemplate == null) {
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sb);
arrayType.generateCodeTemplate(aData, sb);
}
source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeName, genName));
if (body != null) {
// TODO can optimize for single expressions;
body.generateCodeInit(aData, source, genName);
}
} else {
source.append(MessageFormat.format("{0} {1} = new {0}({2});\n", typeName, genName, baseTemplate.getGenNameFromScope(aData, source, myScope, "")));
if (body != null) {
body.generateCodeInit(aData, source, genName);
}
}
} else {
source.append(MessageFormat.format("Code generation for parameterized local template `{0}' is not supported", identifier.getDisplayName()));
}
if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
TemplateRestriction.generateRestrictionCheckCode(aData, source, location, genName, templateRestriction);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction in project titan.EclipsePlug-ins by eclipse.
the class Def_Template method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final boolean cleanUp) {
final String genName = getGenName();
final StringBuilder sb = aData.getSrc();
final StringBuilder source = new StringBuilder();
if (!isLocal()) {
if (VisibilityModifier.Private.equals(getVisibilityModifier())) {
source.append("private");
} else {
source.append("public");
}
source.append(" static ");
}
final String typeName = type.getGenNameTemplate(aData, source, getMyScope());
if (formalParList == null) {
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sbforTemp = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sbforTemp);
arrayType.generateCodeTemplate(aData, sbforTemp);
}
source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeName, genName));
if (baseTemplate != null) {
// modified template
if (baseTemplate.myScope.getModuleScope() == myScope.getModuleScope()) {
// if the base template is in the same module its body has to be
// initialized first
getLocation().update_location_object(aData, aData.getPostInit());
baseTemplate.body.generateCodeInit(aData, aData.getPostInit(), body.get_lhs_name());
}
}
if (body != null) {
getLocation().update_location_object(aData, aData.getPostInit());
body.generateCodeInit(aData, aData.getPostInit(), body.get_lhs_name());
if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
TemplateRestriction.generateRestrictionCheckCode(aData, source, location, genName, templateRestriction);
}
}
} else {
final StringBuilder formalParameters = formalParList.generateCode(aData);
source.append(MessageFormat.format("{0} {1}({2}) '{'\n", typeName, genName, formalParameters));
getLocation().create_location_object(aData, source, getIdentifier().getDisplayName());
if (baseTemplate == null) {
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sbforTemp = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sbforTemp);
arrayType.generateCodeTemplate(aData, sbforTemp);
}
source.append(MessageFormat.format("{0} ret_val = new {0}();\n", typeName));
} else {
// modified template
source.append(MessageFormat.format("{0} ret_val = new {0}({1}", typeName, baseTemplate.getGenNameFromScope(aData, source, myScope, "")));
if (baseTemplate.formalParList != null) {
// the base is also parameterized
source.append('(');
for (int i = 0; i < baseTemplate.formalParList.getNofParameters(); i++) {
if (i > 0) {
source.append(", ");
}
source.append(formalParList.getParameterByIndex(i).getIdentifier().getName());
}
source.append(')');
}
source.append(");\n");
}
if (body != null) {
body.generateCodeInit(aData, source, "ret_val");
if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
TemplateRestriction.generateRestrictionCheckCode(aData, source, location, "ret_val", templateRestriction);
}
}
getLocation().release_location_object(aData, source);
source.append("return ret_val;\n");
source.append("}\n\n");
}
sb.append(source);
}
Aggregations